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 | /** |
| 1592 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1593 | * @vsi: the VSI being setup |
| 1594 | * @ctxt: VSI context structure |
| 1595 | * @enabled_tc: Enabled TCs bitmap |
| 1596 | * @is_add: True if called before Add VSI |
| 1597 | * |
| 1598 | * Setup VSI queue mapping for enabled traffic classes. |
| 1599 | **/ |
| 1600 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1601 | struct i40e_vsi_context *ctxt, |
| 1602 | u8 enabled_tc, |
| 1603 | bool is_add) |
| 1604 | { |
| 1605 | struct i40e_pf *pf = vsi->back; |
| 1606 | u16 sections = 0; |
| 1607 | u8 netdev_tc = 0; |
| 1608 | u16 numtc = 0; |
| 1609 | u16 qcount; |
| 1610 | u8 offset; |
| 1611 | u16 qmap; |
| 1612 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1613 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1614 | |
| 1615 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1616 | offset = 0; |
| 1617 | |
| 1618 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1619 | /* Find numtc from enabled TC bitmap */ |
| 1620 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1621 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1622 | numtc++; |
| 1623 | } |
| 1624 | if (!numtc) { |
| 1625 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1626 | numtc = 1; |
| 1627 | } |
| 1628 | } else { |
| 1629 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1630 | numtc = 1; |
| 1631 | } |
| 1632 | |
| 1633 | vsi->tc_config.numtc = numtc; |
| 1634 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1635 | /* Number of queues per enabled TC */ |
Catherine Sullivan | 7d64402 | 2016-05-16 10:26:41 -0700 | [diff] [blame] | 1636 | qcount = vsi->alloc_queue_pairs; |
| 1637 | |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1638 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1639 | 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] | 1640 | |
| 1641 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1642 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1643 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1644 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1645 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1646 | int pow, num_qps; |
| 1647 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1648 | switch (vsi->type) { |
| 1649 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1650 | qcount = min_t(int, pf->alloc_rss_size, |
| 1651 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1652 | break; |
| 1653 | case I40E_VSI_FDIR: |
| 1654 | case I40E_VSI_SRIOV: |
| 1655 | case I40E_VSI_VMDQ2: |
| 1656 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1657 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1658 | WARN_ON(i != 0); |
| 1659 | break; |
| 1660 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1661 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1662 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1663 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1664 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1665 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1666 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1667 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1668 | pow++; |
| 1669 | num_qps >>= 1; |
| 1670 | } |
| 1671 | |
| 1672 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1673 | qmap = |
| 1674 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1675 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1676 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1677 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1678 | } else { |
| 1679 | /* TC is not enabled so set the offset to |
| 1680 | * default queue and allocate one queue |
| 1681 | * for the given TC. |
| 1682 | */ |
| 1683 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1684 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1685 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1686 | |
| 1687 | qmap = 0; |
| 1688 | } |
| 1689 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1690 | } |
| 1691 | |
| 1692 | /* Set actual Tx/Rx queue pairs */ |
| 1693 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1694 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1695 | if (vsi->req_queue_pairs > 0) |
| 1696 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1697 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1698 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1699 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1700 | |
| 1701 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1702 | if (is_add) { |
| 1703 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1704 | |
| 1705 | ctxt->info.up_enable_bits = enabled_tc; |
| 1706 | } |
| 1707 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1708 | ctxt->info.mapping_flags |= |
| 1709 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1710 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1711 | ctxt->info.queue_mapping[i] = |
| 1712 | cpu_to_le16(vsi->base_queue + i); |
| 1713 | } else { |
| 1714 | ctxt->info.mapping_flags |= |
| 1715 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1716 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1717 | } |
| 1718 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1719 | } |
| 1720 | |
| 1721 | /** |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1722 | * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address |
| 1723 | * @netdev: the netdevice |
| 1724 | * @addr: address to add |
| 1725 | * |
| 1726 | * Called by __dev_(mc|uc)_sync when an address needs to be added. We call |
| 1727 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1728 | */ |
| 1729 | static int i40e_addr_sync(struct net_device *netdev, const u8 *addr) |
| 1730 | { |
| 1731 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1732 | struct i40e_vsi *vsi = np->vsi; |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1733 | |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1734 | if (i40e_add_mac_filter(vsi, addr)) |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1735 | return 0; |
| 1736 | else |
| 1737 | return -ENOMEM; |
| 1738 | } |
| 1739 | |
| 1740 | /** |
| 1741 | * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address |
| 1742 | * @netdev: the netdevice |
| 1743 | * @addr: address to add |
| 1744 | * |
| 1745 | * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call |
| 1746 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1747 | */ |
| 1748 | static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr) |
| 1749 | { |
| 1750 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1751 | struct i40e_vsi *vsi = np->vsi; |
| 1752 | |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1753 | i40e_del_mac_filter(vsi, addr); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1754 | |
| 1755 | return 0; |
| 1756 | } |
| 1757 | |
| 1758 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1759 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1760 | * @netdev: network interface device structure |
| 1761 | **/ |
| 1762 | static void i40e_set_rx_mode(struct net_device *netdev) |
| 1763 | { |
| 1764 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1765 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1766 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1767 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1768 | |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1769 | __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
| 1770 | __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1771 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1772 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1773 | |
| 1774 | /* check for other flag changes */ |
| 1775 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1776 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1777 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | /** |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1782 | * 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] | 1783 | * @vsi: Pointer to VSI struct |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1784 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1785 | * those entries needs to be undone. |
| 1786 | * |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1787 | * MAC filter entries from this list were slated for deletion. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1788 | **/ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1789 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1790 | struct hlist_head *from) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1791 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1792 | struct i40e_mac_filter *f; |
| 1793 | struct hlist_node *h; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1794 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1795 | hlist_for_each_entry_safe(f, h, from, hlist) { |
| 1796 | u64 key = i40e_addr_to_hkey(f->macaddr); |
| 1797 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1798 | /* Move the element back into MAC filter list*/ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1799 | hlist_del(&f->hlist); |
| 1800 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1801 | } |
| 1802 | } |
| 1803 | |
| 1804 | /** |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1805 | * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries |
| 1806 | * @vsi: Pointer to vsi struct |
| 1807 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1808 | * those entries needs to be undone. |
| 1809 | * |
| 1810 | * MAC filter entries from this list were slated for addition. |
| 1811 | **/ |
| 1812 | static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi, |
| 1813 | struct hlist_head *from) |
| 1814 | { |
| 1815 | struct i40e_new_mac_filter *new; |
| 1816 | struct hlist_node *h; |
| 1817 | |
| 1818 | hlist_for_each_entry_safe(new, h, from, hlist) { |
| 1819 | /* We can simply free the wrapper structure */ |
| 1820 | hlist_del(&new->hlist); |
| 1821 | kfree(new); |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | /** |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1826 | * i40e_next_entry - Get the next non-broadcast filter from a list |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1827 | * @next: pointer to filter in list |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1828 | * |
| 1829 | * Returns the next non-broadcast filter in the list. Required so that we |
| 1830 | * ignore broadcast filters within the list, since these are not handled via |
| 1831 | * the normal firmware update path. |
| 1832 | */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1833 | static |
| 1834 | 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] | 1835 | { |
Jacob Keller | 584a887 | 2017-03-07 15:17:52 -0800 | [diff] [blame] | 1836 | hlist_for_each_entry_continue(next, hlist) { |
| 1837 | if (!is_broadcast_ether_addr(next->f->macaddr)) |
| 1838 | return next; |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1839 | } |
| 1840 | |
Jacob Keller | 584a887 | 2017-03-07 15:17:52 -0800 | [diff] [blame] | 1841 | return NULL; |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | /** |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1845 | * i40e_update_filter_state - Update filter state based on return data |
| 1846 | * from firmware |
| 1847 | * @count: Number of filters added |
| 1848 | * @add_list: return data from fw |
| 1849 | * @head: pointer to first filter in current batch |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1850 | * |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1851 | * MAC filter entries from list were slated to be added to device. Returns |
| 1852 | * number of successful filters. Note that 0 does NOT mean success! |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1853 | **/ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1854 | static int |
| 1855 | i40e_update_filter_state(int count, |
| 1856 | struct i40e_aqc_add_macvlan_element_data *add_list, |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1857 | struct i40e_new_mac_filter *add_head) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1858 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1859 | int retval = 0; |
| 1860 | int i; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1861 | |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1862 | for (i = 0; i < count; i++) { |
| 1863 | /* Always check status of each filter. We don't need to check |
| 1864 | * the firmware return status because we pre-set the filter |
| 1865 | * status to I40E_AQC_MM_ERR_NO_RES when sending the filter |
| 1866 | * request to the adminq. Thus, if it no longer matches then |
| 1867 | * we know the filter is active. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1868 | */ |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1869 | if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1870 | add_head->state = I40E_FILTER_FAILED; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1871 | } else { |
| 1872 | add_head->state = I40E_FILTER_ACTIVE; |
| 1873 | retval++; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1874 | } |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1875 | |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1876 | add_head = i40e_next_filter(add_head); |
| 1877 | if (!add_head) |
| 1878 | break; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1879 | } |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1880 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1881 | return retval; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | /** |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1885 | * i40e_aqc_del_filters - Request firmware to delete a set of filters |
| 1886 | * @vsi: ptr to the VSI |
| 1887 | * @vsi_name: name to display in messages |
| 1888 | * @list: the list of filters to send to firmware |
| 1889 | * @num_del: the number of filters to delete |
| 1890 | * @retval: Set to -EIO on failure to delete |
| 1891 | * |
| 1892 | * Send a request to firmware via AdminQ to delete a set of filters. Uses |
| 1893 | * *retval instead of a return value so that success does not force ret_val to |
| 1894 | * be set to 0. This ensures that a sequence of calls to this function |
| 1895 | * preserve the previous value of *retval on successful delete. |
| 1896 | */ |
| 1897 | static |
| 1898 | void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 1899 | struct i40e_aqc_remove_macvlan_element_data *list, |
| 1900 | int num_del, int *retval) |
| 1901 | { |
| 1902 | struct i40e_hw *hw = &vsi->back->hw; |
| 1903 | i40e_status aq_ret; |
| 1904 | int aq_err; |
| 1905 | |
| 1906 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL); |
| 1907 | aq_err = hw->aq.asq_last_status; |
| 1908 | |
| 1909 | /* Explicitly ignore and do not report when firmware returns ENOENT */ |
| 1910 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { |
| 1911 | *retval = -EIO; |
| 1912 | dev_info(&vsi->back->pdev->dev, |
| 1913 | "ignoring delete macvlan error on %s, err %s, aq_err %s\n", |
| 1914 | vsi_name, i40e_stat_str(hw, aq_ret), |
| 1915 | i40e_aq_str(hw, aq_err)); |
| 1916 | } |
| 1917 | } |
| 1918 | |
| 1919 | /** |
| 1920 | * i40e_aqc_add_filters - Request firmware to add a set of filters |
| 1921 | * @vsi: ptr to the VSI |
| 1922 | * @vsi_name: name to display in messages |
| 1923 | * @list: the list of filters to send to firmware |
| 1924 | * @add_head: Position in the add hlist |
| 1925 | * @num_add: the number of filters to add |
| 1926 | * @promisc_change: set to true on exit if promiscuous mode was forced on |
| 1927 | * |
| 1928 | * Send a request to firmware via AdminQ to add a chunk of filters. Will set |
| 1929 | * promisc_changed to true if the firmware has run out of space for more |
| 1930 | * filters. |
| 1931 | */ |
| 1932 | static |
| 1933 | void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 1934 | struct i40e_aqc_add_macvlan_element_data *list, |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1935 | struct i40e_new_mac_filter *add_head, |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1936 | int num_add, bool *promisc_changed) |
| 1937 | { |
| 1938 | struct i40e_hw *hw = &vsi->back->hw; |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1939 | int aq_err, fcnt; |
| 1940 | |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1941 | i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1942 | aq_err = hw->aq.asq_last_status; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1943 | fcnt = i40e_update_filter_state(num_add, list, add_head); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1944 | |
| 1945 | if (fcnt != num_add) { |
| 1946 | *promisc_changed = true; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 1947 | set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1948 | dev_warn(&vsi->back->pdev->dev, |
| 1949 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", |
| 1950 | i40e_aq_str(hw, aq_err), |
| 1951 | vsi_name); |
| 1952 | } |
| 1953 | } |
| 1954 | |
| 1955 | /** |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1956 | * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags |
| 1957 | * @vsi: pointer to the VSI |
| 1958 | * @f: filter data |
| 1959 | * |
| 1960 | * This function sets or clears the promiscuous broadcast flags for VLAN |
| 1961 | * filters in order to properly receive broadcast frames. Assumes that only |
| 1962 | * broadcast filters are passed. |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1963 | * |
| 1964 | * Returns status indicating success or failure; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1965 | **/ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1966 | static i40e_status |
| 1967 | i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name, |
| 1968 | struct i40e_mac_filter *f) |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1969 | { |
| 1970 | bool enable = f->state == I40E_FILTER_NEW; |
| 1971 | struct i40e_hw *hw = &vsi->back->hw; |
| 1972 | i40e_status aq_ret; |
| 1973 | |
| 1974 | if (f->vlan == I40E_VLAN_ANY) { |
| 1975 | aq_ret = i40e_aq_set_vsi_broadcast(hw, |
| 1976 | vsi->seid, |
| 1977 | enable, |
| 1978 | NULL); |
| 1979 | } else { |
| 1980 | aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw, |
| 1981 | vsi->seid, |
| 1982 | enable, |
| 1983 | f->vlan, |
| 1984 | NULL); |
| 1985 | } |
| 1986 | |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1987 | if (aq_ret) |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1988 | dev_warn(&vsi->back->pdev->dev, |
| 1989 | "Error %s setting broadcast promiscuous mode on %s\n", |
| 1990 | i40e_aq_str(hw, hw->aq.asq_last_status), |
| 1991 | vsi_name); |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1992 | |
| 1993 | return aq_ret; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1997 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1998 | * @vsi: ptr to the VSI |
| 1999 | * |
| 2000 | * Push any outstanding VSI filter changes through the AdminQ. |
| 2001 | * |
| 2002 | * Returns 0 or error value |
| 2003 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2004 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2005 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2006 | struct hlist_head tmp_add_list, tmp_del_list; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2007 | struct i40e_mac_filter *f; |
| 2008 | struct i40e_new_mac_filter *new, *add_head = NULL; |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2009 | struct i40e_hw *hw = &vsi->back->hw; |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2010 | unsigned int failed_filters = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2011 | unsigned int vlan_filters = 0; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2012 | bool promisc_changed = false; |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2013 | char vsi_name[16] = "PF"; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2014 | int filter_list_len = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2015 | i40e_status aq_ret = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2016 | u32 changed_flags = 0; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2017 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2018 | struct i40e_pf *pf; |
| 2019 | int num_add = 0; |
| 2020 | int num_del = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2021 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2022 | u16 cmd_flags; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2023 | int list_size; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2024 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2025 | |
| 2026 | /* empty array typed pointers, kcalloc later */ |
| 2027 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 2028 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 2029 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2030 | while (test_and_set_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2031 | usleep_range(1000, 2000); |
| 2032 | pf = vsi->back; |
| 2033 | |
| 2034 | if (vsi->netdev) { |
| 2035 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 2036 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 2037 | } |
| 2038 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2039 | INIT_HLIST_HEAD(&tmp_add_list); |
| 2040 | INIT_HLIST_HEAD(&tmp_del_list); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2041 | |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2042 | if (vsi->type == I40E_VSI_SRIOV) |
| 2043 | snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id); |
| 2044 | else if (vsi->type != I40E_VSI_MAIN) |
| 2045 | snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid); |
| 2046 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2047 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 2048 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 2049 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2050 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2051 | /* Create a list of filters to delete. */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2052 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2053 | if (f->state == I40E_FILTER_REMOVE) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2054 | /* Move the element into temporary del_list */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2055 | hash_del(&f->hlist); |
| 2056 | hlist_add_head(&f->hlist, &tmp_del_list); |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2057 | |
| 2058 | /* Avoid counting removed filters */ |
| 2059 | continue; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2060 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2061 | if (f->state == I40E_FILTER_NEW) { |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2062 | /* Create a temporary i40e_new_mac_filter */ |
| 2063 | new = kzalloc(sizeof(*new), GFP_ATOMIC); |
| 2064 | if (!new) |
| 2065 | goto err_no_memory_locked; |
| 2066 | |
| 2067 | /* Store pointer to the real filter */ |
| 2068 | new->f = f; |
| 2069 | new->state = f->state; |
| 2070 | |
| 2071 | /* Add it to the hash list */ |
| 2072 | hlist_add_head(&new->hlist, &tmp_add_list); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2073 | } |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2074 | |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2075 | /* Count the number of active (current and new) VLAN |
| 2076 | * filters we have now. Does not count filters which |
| 2077 | * are marked for deletion. |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2078 | */ |
| 2079 | if (f->vlan > 0) |
| 2080 | vlan_filters++; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2083 | retval = i40e_correct_mac_vlan_filters(vsi, |
| 2084 | &tmp_add_list, |
| 2085 | &tmp_del_list, |
| 2086 | vlan_filters); |
| 2087 | if (retval) |
| 2088 | goto err_no_memory_locked; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2089 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2090 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | /* Now process 'del_list' outside the lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2094 | if (!hlist_empty(&tmp_del_list)) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2095 | filter_list_len = hw->aq.asq_buf_size / |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2096 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2097 | list_size = filter_list_len * |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2098 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2099 | del_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2100 | if (!del_list) |
| 2101 | goto err_no_memory; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2102 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2103 | hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2104 | cmd_flags = 0; |
| 2105 | |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2106 | /* handle broadcast filters by updating the broadcast |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 2107 | * promiscuous flag and release filter list. |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2108 | */ |
| 2109 | if (is_broadcast_ether_addr(f->macaddr)) { |
| 2110 | i40e_aqc_broadcast_filter(vsi, vsi_name, f); |
| 2111 | |
| 2112 | hlist_del(&f->hlist); |
| 2113 | kfree(f); |
| 2114 | continue; |
| 2115 | } |
| 2116 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2117 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2118 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2119 | if (f->vlan == I40E_VLAN_ANY) { |
| 2120 | del_list[num_del].vlan_tag = 0; |
Alan Brady | a6cb914 | 2016-09-06 18:05:07 -0700 | [diff] [blame] | 2121 | cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2122 | } else { |
| 2123 | del_list[num_del].vlan_tag = |
| 2124 | cpu_to_le16((u16)(f->vlan)); |
| 2125 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2126 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2127 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 2128 | del_list[num_del].flags = cmd_flags; |
| 2129 | num_del++; |
| 2130 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2131 | /* flush a full buffer */ |
| 2132 | if (num_del == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2133 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2134 | num_del, &retval); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2135 | memset(del_list, 0, list_size); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2136 | num_del = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2137 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2138 | /* Release memory for MAC filter entries which were |
| 2139 | * synced up with HW. |
| 2140 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2141 | hlist_del(&f->hlist); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2142 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2143 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2144 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2145 | if (num_del) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2146 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2147 | num_del, &retval); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | kfree(del_list); |
| 2151 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2152 | } |
| 2153 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2154 | if (!hlist_empty(&tmp_add_list)) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2155 | /* Do all the adds now. */ |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2156 | filter_list_len = hw->aq.asq_buf_size / |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2157 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2158 | list_size = filter_list_len * |
| 2159 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
| 2160 | add_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2161 | if (!add_list) |
| 2162 | goto err_no_memory; |
| 2163 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2164 | num_add = 0; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2165 | hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) { |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 2166 | if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2167 | vsi->state)) { |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2168 | new->state = I40E_FILTER_FAILED; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2169 | continue; |
| 2170 | } |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2171 | |
| 2172 | /* handle broadcast filters by updating the broadcast |
| 2173 | * promiscuous flag instead of adding a MAC filter. |
| 2174 | */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2175 | if (is_broadcast_ether_addr(new->f->macaddr)) { |
| 2176 | if (i40e_aqc_broadcast_filter(vsi, vsi_name, |
| 2177 | new->f)) |
| 2178 | new->state = I40E_FILTER_FAILED; |
| 2179 | else |
| 2180 | new->state = I40E_FILTER_ACTIVE; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2181 | continue; |
| 2182 | } |
| 2183 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2184 | /* add to add array */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2185 | if (num_add == 0) |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2186 | add_head = new; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2187 | cmd_flags = 0; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2188 | ether_addr_copy(add_list[num_add].mac_addr, |
| 2189 | new->f->macaddr); |
| 2190 | if (new->f->vlan == I40E_VLAN_ANY) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2191 | add_list[num_add].vlan_tag = 0; |
| 2192 | cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; |
| 2193 | } else { |
| 2194 | add_list[num_add].vlan_tag = |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2195 | cpu_to_le16((u16)(new->f->vlan)); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2196 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2197 | add_list[num_add].queue_number = 0; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 2198 | /* set invalid match method for later detection */ |
Keller, Jacob E | 0266ac4 | 2016-12-09 13:39:21 -0800 | [diff] [blame] | 2199 | add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2200 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2201 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2202 | num_add++; |
| 2203 | |
| 2204 | /* flush a full buffer */ |
| 2205 | if (num_add == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2206 | i40e_aqc_add_filters(vsi, vsi_name, add_list, |
| 2207 | add_head, num_add, |
| 2208 | &promisc_changed); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2209 | memset(add_list, 0, list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2210 | num_add = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2211 | } |
| 2212 | } |
| 2213 | if (num_add) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2214 | i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head, |
| 2215 | num_add, &promisc_changed); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2216 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2217 | /* Now move all of the filters from the temp add list back to |
| 2218 | * the VSI's list. |
| 2219 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2220 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2221 | hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) { |
| 2222 | /* Only update the state if we're still NEW */ |
| 2223 | if (new->f->state == I40E_FILTER_NEW) |
| 2224 | new->f->state = new->state; |
| 2225 | hlist_del(&new->hlist); |
| 2226 | kfree(new); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2227 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2228 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2229 | kfree(add_list); |
| 2230 | add_list = NULL; |
| 2231 | } |
| 2232 | |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2233 | /* Determine the number of active and failed filters. */ |
| 2234 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2235 | vsi->active_filters = 0; |
| 2236 | hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) { |
| 2237 | if (f->state == I40E_FILTER_ACTIVE) |
| 2238 | vsi->active_filters++; |
| 2239 | else if (f->state == I40E_FILTER_FAILED) |
| 2240 | failed_filters++; |
| 2241 | } |
| 2242 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 2243 | |
| 2244 | /* If promiscuous mode has changed, we need to calculate a new |
| 2245 | * threshold for when we are safe to exit |
| 2246 | */ |
| 2247 | if (promisc_changed) |
| 2248 | vsi->promisc_threshold = (vsi->active_filters * 3) / 4; |
| 2249 | |
| 2250 | /* Check if we are able to exit overflow promiscuous mode. We can |
| 2251 | * safely exit if we didn't just enter, we no longer have any failed |
| 2252 | * filters, and we have reduced filters below the threshold value. |
| 2253 | */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2254 | if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state) && |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2255 | !promisc_changed && !failed_filters && |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2256 | (vsi->active_filters < vsi->promisc_threshold)) { |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2257 | dev_info(&pf->pdev->dev, |
| 2258 | "filter logjam cleared on %s, leaving overflow promiscuous mode\n", |
| 2259 | vsi_name); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2260 | clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2261 | promisc_changed = true; |
| 2262 | vsi->promisc_threshold = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2263 | } |
| 2264 | |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2265 | /* if the VF is not trusted do not do promisc */ |
| 2266 | if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2267 | clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2268 | goto out; |
| 2269 | } |
| 2270 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2271 | /* check for changes in promiscuous modes */ |
| 2272 | if (changed_flags & IFF_ALLMULTI) { |
| 2273 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2274 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2275 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2276 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2277 | vsi->seid, |
| 2278 | cur_multipromisc, |
| 2279 | NULL); |
| 2280 | if (aq_ret) { |
| 2281 | retval = i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2282 | hw->aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2283 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2284 | "set multi promisc failed on %s, err %s aq_err %s\n", |
| 2285 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2286 | i40e_stat_str(hw, aq_ret), |
| 2287 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2288 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2289 | } |
Alan Brady | e588723 | 2017-06-07 05:43:10 -0400 | [diff] [blame] | 2290 | |
| 2291 | if ((changed_flags & IFF_PROMISC) || promisc_changed) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2292 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2293 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2294 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 2295 | test_bit(__I40E_VSI_OVERFLOW_PROMISC, |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2296 | vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2297 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2298 | (pf->lan_veb != I40E_NO_VEB) && |
| 2299 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2300 | /* set defport ON for Main VSI instead of true promisc |
| 2301 | * this way we will get all unicast/multicast and VLAN |
| 2302 | * promisc behavior but will not get VF or VMDq traffic |
| 2303 | * replicated on the Main VSI. |
| 2304 | */ |
| 2305 | if (pf->cur_promisc != cur_promisc) { |
| 2306 | pf->cur_promisc = cur_promisc; |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2307 | if (cur_promisc) |
| 2308 | aq_ret = |
| 2309 | i40e_aq_set_default_vsi(hw, |
| 2310 | vsi->seid, |
| 2311 | NULL); |
| 2312 | else |
| 2313 | aq_ret = |
| 2314 | i40e_aq_clear_default_vsi(hw, |
| 2315 | vsi->seid, |
| 2316 | NULL); |
| 2317 | if (aq_ret) { |
| 2318 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2319 | hw->aq.asq_last_status); |
| 2320 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2321 | "Set default VSI failed on %s, err %s, aq_err %s\n", |
| 2322 | vsi_name, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2323 | i40e_stat_str(hw, aq_ret), |
| 2324 | i40e_aq_str(hw, |
| 2325 | hw->aq.asq_last_status)); |
| 2326 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2327 | } |
| 2328 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2329 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2330 | hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2331 | vsi->seid, |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 2332 | cur_promisc, NULL, |
| 2333 | true); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2334 | if (aq_ret) { |
| 2335 | retval = |
| 2336 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2337 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2338 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2339 | "set unicast promisc failed on %s, err %s, aq_err %s\n", |
| 2340 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2341 | i40e_stat_str(hw, aq_ret), |
| 2342 | i40e_aq_str(hw, |
| 2343 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2344 | } |
| 2345 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2346 | hw, |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2347 | vsi->seid, |
| 2348 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2349 | if (aq_ret) { |
| 2350 | retval = |
| 2351 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2352 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2353 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2354 | "set multicast promisc failed on %s, err %s, aq_err %s\n", |
| 2355 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2356 | i40e_stat_str(hw, aq_ret), |
| 2357 | i40e_aq_str(hw, |
| 2358 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2359 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2360 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2361 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2362 | vsi->seid, |
| 2363 | cur_promisc, NULL); |
| 2364 | if (aq_ret) { |
| 2365 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2366 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2367 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2368 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2369 | i40e_stat_str(hw, aq_ret), |
| 2370 | i40e_aq_str(hw, |
| 2371 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2372 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2373 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2374 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2375 | /* if something went wrong then set the changed flag so we try again */ |
| 2376 | if (retval) |
| 2377 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2378 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2379 | clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2380 | return retval; |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2381 | |
| 2382 | err_no_memory: |
| 2383 | /* Restore elements on the temporary add and delete lists */ |
| 2384 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2385 | err_no_memory_locked: |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2386 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 2387 | i40e_undo_add_filter_entries(vsi, &tmp_add_list); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2388 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 2389 | |
| 2390 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 2391 | clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2392 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | /** |
| 2396 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2397 | * @pf: board private structure |
| 2398 | **/ |
| 2399 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2400 | { |
| 2401 | int v; |
| 2402 | |
| 2403 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2404 | return; |
| 2405 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2406 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2407 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2408 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2409 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2410 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2411 | |
| 2412 | if (ret) { |
| 2413 | /* come back and try again later */ |
| 2414 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2415 | break; |
| 2416 | } |
| 2417 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2418 | } |
| 2419 | } |
| 2420 | |
| 2421 | /** |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 2422 | * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP |
| 2423 | * @vsi: the vsi |
| 2424 | **/ |
| 2425 | static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi) |
| 2426 | { |
| 2427 | if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) |
| 2428 | return I40E_RXBUFFER_2048; |
| 2429 | else |
| 2430 | return I40E_RXBUFFER_3072; |
| 2431 | } |
| 2432 | |
| 2433 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2434 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2435 | * @netdev: network interface device structure |
| 2436 | * @new_mtu: new value for maximum frame size |
| 2437 | * |
| 2438 | * Returns 0 on success, negative on failure |
| 2439 | **/ |
| 2440 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2441 | { |
| 2442 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2443 | struct i40e_vsi *vsi = np->vsi; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 2444 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2445 | |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 2446 | if (i40e_enabled_xdp_vsi(vsi)) { |
| 2447 | int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
| 2448 | |
| 2449 | if (frame_size > i40e_max_xdp_frame_size(vsi)) |
| 2450 | return -EINVAL; |
| 2451 | } |
| 2452 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2453 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2454 | netdev->mtu, new_mtu); |
| 2455 | netdev->mtu = new_mtu; |
| 2456 | if (netif_running(netdev)) |
| 2457 | i40e_vsi_reinit_locked(vsi); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 2458 | pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED | |
| 2459 | I40E_FLAG_CLIENT_L2_CHANGE); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2460 | return 0; |
| 2461 | } |
| 2462 | |
| 2463 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2464 | * i40e_ioctl - Access the hwtstamp interface |
| 2465 | * @netdev: network interface device structure |
| 2466 | * @ifr: interface request data |
| 2467 | * @cmd: ioctl command |
| 2468 | **/ |
| 2469 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2470 | { |
| 2471 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2472 | struct i40e_pf *pf = np->vsi->back; |
| 2473 | |
| 2474 | switch (cmd) { |
| 2475 | case SIOCGHWTSTAMP: |
| 2476 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2477 | case SIOCSHWTSTAMP: |
| 2478 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2479 | default: |
| 2480 | return -EOPNOTSUPP; |
| 2481 | } |
| 2482 | } |
| 2483 | |
| 2484 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2485 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2486 | * @vsi: the vsi being adjusted |
| 2487 | **/ |
| 2488 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2489 | { |
| 2490 | struct i40e_vsi_context ctxt; |
| 2491 | i40e_status ret; |
| 2492 | |
| 2493 | if ((vsi->info.valid_sections & |
| 2494 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2495 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2496 | return; /* already enabled */ |
| 2497 | |
| 2498 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2499 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2500 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2501 | |
| 2502 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2503 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2504 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2505 | if (ret) { |
| 2506 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2507 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2508 | i40e_stat_str(&vsi->back->hw, ret), |
| 2509 | i40e_aq_str(&vsi->back->hw, |
| 2510 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2511 | } |
| 2512 | } |
| 2513 | |
| 2514 | /** |
| 2515 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2516 | * @vsi: the vsi being adjusted |
| 2517 | **/ |
| 2518 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2519 | { |
| 2520 | struct i40e_vsi_context ctxt; |
| 2521 | i40e_status ret; |
| 2522 | |
| 2523 | if ((vsi->info.valid_sections & |
| 2524 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2525 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2526 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2527 | return; /* already disabled */ |
| 2528 | |
| 2529 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2530 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2531 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2532 | |
| 2533 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2534 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2535 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2536 | if (ret) { |
| 2537 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2538 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2539 | i40e_stat_str(&vsi->back->hw, ret), |
| 2540 | i40e_aq_str(&vsi->back->hw, |
| 2541 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | /** |
| 2546 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2547 | * @netdev: network interface to be adjusted |
| 2548 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2549 | **/ |
| 2550 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2551 | { |
| 2552 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2553 | struct i40e_vsi *vsi = np->vsi; |
| 2554 | |
| 2555 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2556 | i40e_vlan_stripping_enable(vsi); |
| 2557 | else |
| 2558 | i40e_vlan_stripping_disable(vsi); |
| 2559 | } |
| 2560 | |
| 2561 | /** |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2562 | * 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] | 2563 | * @vsi: the vsi being configured |
| 2564 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2565 | * |
| 2566 | * This is a helper function for adding a new MAC/VLAN filter with the |
| 2567 | * specified VLAN for each existing MAC address already in the hash table. |
| 2568 | * This function does *not* perform any accounting to update filters based on |
| 2569 | * VLAN mode. |
| 2570 | * |
| 2571 | * NOTE: this function expects to be called while under the |
| 2572 | * mac_filter_hash_lock |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2573 | **/ |
Jacob Keller | 9af52f6 | 2016-11-11 12:39:30 -0800 | [diff] [blame] | 2574 | int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2575 | { |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2576 | struct i40e_mac_filter *f, *add_f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2577 | struct hlist_node *h; |
| 2578 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2579 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2580 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 2581 | if (f->state == I40E_FILTER_REMOVE) |
| 2582 | continue; |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2583 | add_f = i40e_add_filter(vsi, f->macaddr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2584 | if (!add_f) { |
| 2585 | dev_info(&vsi->back->pdev->dev, |
| 2586 | "Could not add vlan filter %d for %pM\n", |
| 2587 | vid, f->macaddr); |
| 2588 | return -ENOMEM; |
| 2589 | } |
| 2590 | } |
| 2591 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2592 | return 0; |
| 2593 | } |
| 2594 | |
| 2595 | /** |
| 2596 | * i40e_vsi_add_vlan - Add VSI membership for given VLAN |
| 2597 | * @vsi: the VSI being configured |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2598 | * @vid: VLAN id to be added |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2599 | **/ |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2600 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2601 | { |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2602 | int err; |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2603 | |
Jacob Keller | fcf6cfc | 2017-06-23 04:24:51 -0400 | [diff] [blame] | 2604 | if (vsi->info.pvid) |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2605 | return -EINVAL; |
| 2606 | |
Jacob Keller | fcf6cfc | 2017-06-23 04:24:51 -0400 | [diff] [blame] | 2607 | /* The network stack will attempt to add VID=0, with the intention to |
| 2608 | * receive priority tagged packets with a VLAN of 0. Our HW receives |
| 2609 | * these packets by default when configured to receive untagged |
| 2610 | * packets, so we don't need to add a filter for this case. |
| 2611 | * Additionally, HW interprets adding a VID=0 filter as meaning to |
| 2612 | * receive *only* tagged traffic and stops receiving untagged traffic. |
| 2613 | * Thus, we do not want to actually add a filter for VID=0 |
| 2614 | */ |
| 2615 | if (!vid) |
| 2616 | return 0; |
| 2617 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2618 | /* Locked once because all functions invoked below iterates list*/ |
| 2619 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2620 | err = i40e_add_vlan_all_mac(vsi, vid); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2621 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2622 | if (err) |
| 2623 | return err; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2624 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2625 | /* schedule our worker thread which will take care of |
| 2626 | * applying the new filter changes |
| 2627 | */ |
| 2628 | i40e_service_event_schedule(vsi->back); |
| 2629 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | /** |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2633 | * 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] | 2634 | * @vsi: the vsi being configured |
| 2635 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2636 | * |
| 2637 | * This function should be used to remove all VLAN filters which match the |
| 2638 | * given VID. It does not schedule the service event and does not take the |
| 2639 | * mac_filter_hash_lock so it may be combined with other operations under |
| 2640 | * a single invocation of the mac_filter_hash_lock. |
| 2641 | * |
| 2642 | * NOTE: this function expects to be called while under the |
| 2643 | * mac_filter_hash_lock |
| 2644 | */ |
Jacob Keller | 9af52f6 | 2016-11-11 12:39:30 -0800 | [diff] [blame] | 2645 | void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2646 | { |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2647 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2648 | struct hlist_node *h; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2649 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2650 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2651 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 2652 | if (f->vlan == vid) |
| 2653 | __i40e_del_filter(vsi, f); |
| 2654 | } |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2655 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2656 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2657 | /** |
| 2658 | * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN |
| 2659 | * @vsi: the VSI being configured |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2660 | * @vid: VLAN id to be removed |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2661 | **/ |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2662 | void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2663 | { |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2664 | if (!vid || vsi->info.pvid) |
| 2665 | return; |
| 2666 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2667 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2668 | i40e_rm_vlan_all_mac(vsi, vid); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2669 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2670 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2671 | /* schedule our worker thread which will take care of |
| 2672 | * applying the new filter changes |
| 2673 | */ |
| 2674 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | /** |
| 2678 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2679 | * @netdev: network interface to be adjusted |
| 2680 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2681 | * |
| 2682 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2683 | **/ |
| 2684 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2685 | __always_unused __be16 proto, u16 vid) |
| 2686 | { |
| 2687 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2688 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2689 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2690 | |
Jacob Keller | 6a112785 | 2016-10-25 16:08:49 -0700 | [diff] [blame] | 2691 | if (vid >= VLAN_N_VID) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2692 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2693 | |
Jacob Keller | fcf6cfc | 2017-06-23 04:24:51 -0400 | [diff] [blame] | 2694 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jacob Keller | 6a112785 | 2016-10-25 16:08:49 -0700 | [diff] [blame] | 2695 | if (!ret) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2696 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2697 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2698 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | /** |
| 2702 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2703 | * @netdev: network interface to be adjusted |
| 2704 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2705 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2706 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2707 | **/ |
| 2708 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2709 | __always_unused __be16 proto, u16 vid) |
| 2710 | { |
| 2711 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2712 | struct i40e_vsi *vsi = np->vsi; |
| 2713 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2714 | /* return code is ignored as there is nothing a user |
| 2715 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2716 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2717 | */ |
| 2718 | i40e_vsi_kill_vlan(vsi, vid); |
| 2719 | |
| 2720 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2721 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2722 | return 0; |
| 2723 | } |
| 2724 | |
| 2725 | /** |
| 2726 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2727 | * @vsi: the vsi being brought back up |
| 2728 | **/ |
| 2729 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2730 | { |
| 2731 | u16 vid; |
| 2732 | |
| 2733 | if (!vsi->netdev) |
| 2734 | return; |
| 2735 | |
| 2736 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2737 | |
| 2738 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2739 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2740 | vid); |
| 2741 | } |
| 2742 | |
| 2743 | /** |
| 2744 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2745 | * @vsi: the vsi being adjusted |
| 2746 | * @vid: the vlan id to set as a PVID |
| 2747 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2748 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2749 | { |
| 2750 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2751 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2752 | |
| 2753 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2754 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2755 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2756 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2757 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2758 | |
| 2759 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2760 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2761 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2762 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2763 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2764 | "add pvid failed, err %s aq_err %s\n", |
| 2765 | i40e_stat_str(&vsi->back->hw, ret), |
| 2766 | i40e_aq_str(&vsi->back->hw, |
| 2767 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2768 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2769 | } |
| 2770 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2771 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | /** |
| 2775 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2776 | * @vsi: the vsi being adjusted |
| 2777 | * |
| 2778 | * Just use the vlan_rx_register() service to put it back to normal |
| 2779 | **/ |
| 2780 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2781 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2782 | i40e_vlan_stripping_disable(vsi); |
| 2783 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2784 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | /** |
| 2788 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2789 | * @vsi: ptr to the VSI |
| 2790 | * |
| 2791 | * If this function returns with an error, then it's possible one or |
| 2792 | * more of the rings is populated (while the rest are not). It is the |
| 2793 | * callers duty to clean those orphaned rings. |
| 2794 | * |
| 2795 | * Return 0 on success, negative on failure |
| 2796 | **/ |
| 2797 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2798 | { |
| 2799 | int i, err = 0; |
| 2800 | |
| 2801 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2802 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2803 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 2804 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 2805 | return err; |
| 2806 | |
| 2807 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
| 2808 | err = i40e_setup_tx_descriptors(vsi->xdp_rings[i]); |
| 2809 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2810 | return err; |
| 2811 | } |
| 2812 | |
| 2813 | /** |
| 2814 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2815 | * @vsi: ptr to the VSI |
| 2816 | * |
| 2817 | * Free VSI's transmit software resources |
| 2818 | **/ |
| 2819 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2820 | { |
| 2821 | int i; |
| 2822 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 2823 | if (vsi->tx_rings) { |
| 2824 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 2825 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
| 2826 | i40e_free_tx_resources(vsi->tx_rings[i]); |
| 2827 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2828 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 2829 | if (vsi->xdp_rings) { |
| 2830 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 2831 | if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc) |
| 2832 | i40e_free_tx_resources(vsi->xdp_rings[i]); |
| 2833 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | /** |
| 2837 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2838 | * @vsi: ptr to the VSI |
| 2839 | * |
| 2840 | * If this function returns with an error, then it's possible one or |
| 2841 | * more of the rings is populated (while the rest are not). It is the |
| 2842 | * callers duty to clean those orphaned rings. |
| 2843 | * |
| 2844 | * Return 0 on success, negative on failure |
| 2845 | **/ |
| 2846 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2847 | { |
| 2848 | int i, err = 0; |
| 2849 | |
| 2850 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2851 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2852 | return err; |
| 2853 | } |
| 2854 | |
| 2855 | /** |
| 2856 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2857 | * @vsi: ptr to the VSI |
| 2858 | * |
| 2859 | * Free all receive software resources |
| 2860 | **/ |
| 2861 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2862 | { |
| 2863 | int i; |
| 2864 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2865 | if (!vsi->rx_rings) |
| 2866 | return; |
| 2867 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2868 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2869 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2870 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2874 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2875 | * @ring: The Tx ring to configure |
| 2876 | * |
| 2877 | * This enables/disables XPS for a given Tx descriptor ring |
| 2878 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2879 | **/ |
| 2880 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2881 | { |
| 2882 | struct i40e_vsi *vsi = ring->vsi; |
Jacob Keller | be664cb | 2017-08-29 05:32:31 -0400 | [diff] [blame] | 2883 | int cpu; |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2884 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2885 | if (!ring->q_vector || !ring->netdev) |
| 2886 | return; |
| 2887 | |
Jacob Keller | ba4460d | 2017-07-14 09:10:08 -0400 | [diff] [blame] | 2888 | if ((vsi->tc_config.numtc <= 1) && |
Jesse Brandeburg | bd6cd4e | 2017-08-29 05:32:35 -0400 | [diff] [blame] | 2889 | !test_and_set_bit(__I40E_TX_XPS_INIT_DONE, ring->state)) { |
Jacob Keller | be664cb | 2017-08-29 05:32:31 -0400 | [diff] [blame] | 2890 | cpu = cpumask_local_spread(ring->q_vector->v_idx, -1); |
| 2891 | netif_set_xps_queue(ring->netdev, get_cpu_mask(cpu), |
Jacob Keller | ba4460d | 2017-07-14 09:10:08 -0400 | [diff] [blame] | 2892 | ring->queue_index); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2893 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2894 | |
| 2895 | /* schedule our worker thread which will take care of |
| 2896 | * applying the new filter changes |
| 2897 | */ |
| 2898 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2902 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2903 | * @ring: The Tx ring to configure |
| 2904 | * |
| 2905 | * Configure the Tx descriptor ring in the HMC context. |
| 2906 | **/ |
| 2907 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2908 | { |
| 2909 | struct i40e_vsi *vsi = ring->vsi; |
| 2910 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2911 | struct i40e_hw *hw = &vsi->back->hw; |
| 2912 | struct i40e_hmc_obj_txq tx_ctx; |
| 2913 | i40e_status err = 0; |
| 2914 | u32 qtx_ctl = 0; |
| 2915 | |
| 2916 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2917 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2918 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2919 | ring->atr_count = 0; |
| 2920 | } else { |
| 2921 | ring->atr_sample_rate = 0; |
| 2922 | } |
| 2923 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2924 | /* configure XPS */ |
| 2925 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2926 | |
| 2927 | /* clear the context structure first */ |
| 2928 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2929 | |
| 2930 | tx_ctx.new_context = 1; |
| 2931 | tx_ctx.base = (ring->dma / 128); |
| 2932 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2933 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2934 | I40E_FLAG_FD_ATR_ENABLED)); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2935 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2936 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2937 | if (vsi->type != I40E_VSI_FDIR) |
| 2938 | tx_ctx.head_wb_ena = 1; |
| 2939 | tx_ctx.head_wb_addr = ring->dma + |
| 2940 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2941 | |
| 2942 | /* As part of VSI creation/update, FW allocates certain |
| 2943 | * Tx arbitration queue sets for each TC enabled for |
| 2944 | * the VSI. The FW returns the handles to these queue |
| 2945 | * sets as part of the response buffer to Add VSI, |
| 2946 | * Update VSI, etc. AQ commands. It is expected that |
| 2947 | * these queue set handles be associated with the Tx |
| 2948 | * queues by the driver as part of the TX queue context |
| 2949 | * initialization. This has to be done regardless of |
| 2950 | * DCB as by default everything is mapped to TC0. |
| 2951 | */ |
| 2952 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2953 | tx_ctx.rdylist_act = 0; |
| 2954 | |
| 2955 | /* clear the context in the HMC */ |
| 2956 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2957 | if (err) { |
| 2958 | dev_info(&vsi->back->pdev->dev, |
| 2959 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2960 | ring->queue_index, pf_q, err); |
| 2961 | return -ENOMEM; |
| 2962 | } |
| 2963 | |
| 2964 | /* set the context in the HMC */ |
| 2965 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2966 | if (err) { |
| 2967 | dev_info(&vsi->back->pdev->dev, |
| 2968 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2969 | ring->queue_index, pf_q, err); |
| 2970 | return -ENOMEM; |
| 2971 | } |
| 2972 | |
| 2973 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2974 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2975 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2976 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2977 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2978 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2979 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2980 | } |
| 2981 | |
Shannon Nelson | 13fd977 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2982 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2983 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2984 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2985 | i40e_flush(hw); |
| 2986 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2987 | /* cache tail off for easier writes later */ |
| 2988 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2989 | |
| 2990 | return 0; |
| 2991 | } |
| 2992 | |
| 2993 | /** |
| 2994 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2995 | * @ring: The Rx ring to configure |
| 2996 | * |
| 2997 | * Configure the Rx descriptor ring in the HMC context. |
| 2998 | **/ |
| 2999 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 3000 | { |
| 3001 | struct i40e_vsi *vsi = ring->vsi; |
| 3002 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 3003 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 3004 | struct i40e_hw *hw = &vsi->back->hw; |
| 3005 | struct i40e_hmc_obj_rxq rx_ctx; |
| 3006 | i40e_status err = 0; |
| 3007 | |
Jesse Brandeburg | bd6cd4e | 2017-08-29 05:32:35 -0400 | [diff] [blame] | 3008 | bitmap_zero(ring->state, __I40E_RING_STATE_NBITS); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3009 | |
| 3010 | /* clear the context structure first */ |
| 3011 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 3012 | |
| 3013 | ring->rx_buf_len = vsi->rx_buf_len; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3014 | |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 3015 | rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len, |
| 3016 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3017 | |
| 3018 | rx_ctx.base = (ring->dma / 128); |
| 3019 | rx_ctx.qlen = ring->count; |
| 3020 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 3021 | /* use 32 byte descriptors */ |
| 3022 | rx_ctx.dsize = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3023 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 3024 | /* descriptor type is always zero |
| 3025 | * rx_ctx.dtype = 0; |
| 3026 | */ |
Jesse Brandeburg | b32bfa17 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 3027 | rx_ctx.hsplit_0 = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3028 | |
Jesse Brandeburg | b32bfa17 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 3029 | 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] | 3030 | if (hw->revision_id == 0) |
| 3031 | rx_ctx.lrxqthresh = 0; |
| 3032 | else |
| 3033 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3034 | rx_ctx.crcstrip = 1; |
| 3035 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 3036 | /* this controls whether VLAN is stripped from inner headers */ |
| 3037 | rx_ctx.showiv = 0; |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 3038 | /* set the prefena field to 1 because the manual says to */ |
| 3039 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3040 | |
| 3041 | /* clear the context in the HMC */ |
| 3042 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 3043 | if (err) { |
| 3044 | dev_info(&vsi->back->pdev->dev, |
| 3045 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 3046 | ring->queue_index, pf_q, err); |
| 3047 | return -ENOMEM; |
| 3048 | } |
| 3049 | |
| 3050 | /* set the context in the HMC */ |
| 3051 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 3052 | if (err) { |
| 3053 | dev_info(&vsi->back->pdev->dev, |
| 3054 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 3055 | ring->queue_index, pf_q, err); |
| 3056 | return -ENOMEM; |
| 3057 | } |
| 3058 | |
Alexander Duyck | ca9ec08 | 2017-04-05 07:51:02 -0400 | [diff] [blame] | 3059 | /* configure Rx buffer alignment */ |
| 3060 | if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) |
| 3061 | clear_ring_build_skb_enabled(ring); |
| 3062 | else |
| 3063 | set_ring_build_skb_enabled(ring); |
| 3064 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3065 | /* cache tail for quicker writes, and clear the reg before use */ |
| 3066 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 3067 | writel(0, ring->tail); |
| 3068 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 3069 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3070 | |
| 3071 | return 0; |
| 3072 | } |
| 3073 | |
| 3074 | /** |
| 3075 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 3076 | * @vsi: VSI structure describing this set of rings and resources |
| 3077 | * |
| 3078 | * Configure the Tx VSI for operation. |
| 3079 | **/ |
| 3080 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 3081 | { |
| 3082 | int err = 0; |
| 3083 | u16 i; |
| 3084 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3085 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 3086 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3087 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3088 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 3089 | return err; |
| 3090 | |
| 3091 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 3092 | err = i40e_configure_tx_ring(vsi->xdp_rings[i]); |
| 3093 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3094 | return err; |
| 3095 | } |
| 3096 | |
| 3097 | /** |
| 3098 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 3099 | * @vsi: the VSI being configured |
| 3100 | * |
| 3101 | * Configure the Rx VSI for operation. |
| 3102 | **/ |
| 3103 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 3104 | { |
| 3105 | int err = 0; |
| 3106 | u16 i; |
| 3107 | |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 3108 | if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) { |
| 3109 | vsi->max_frame = I40E_MAX_RXBUFFER; |
| 3110 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 3111 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | ca9ec08 | 2017-04-05 07:51:02 -0400 | [diff] [blame] | 3112 | } else if (!I40E_2K_TOO_SMALL_WITH_PADDING && |
| 3113 | (vsi->netdev->mtu <= ETH_DATA_LEN)) { |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 3114 | vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN; |
| 3115 | vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN; |
| 3116 | #endif |
| 3117 | } else { |
| 3118 | vsi->max_frame = I40E_MAX_RXBUFFER; |
Alexander Duyck | 98efd69 | 2017-04-05 07:51:01 -0400 | [diff] [blame] | 3119 | vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 : |
| 3120 | I40E_RXBUFFER_2048; |
Alexander Duyck | dab86af | 2017-03-14 10:15:27 -0700 | [diff] [blame] | 3121 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3122 | |
| 3123 | /* set up individual rings */ |
| 3124 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3125 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3126 | |
| 3127 | return err; |
| 3128 | } |
| 3129 | |
| 3130 | /** |
| 3131 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3132 | * @vsi: ptr to the VSI |
| 3133 | **/ |
| 3134 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3135 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3136 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3137 | u16 qoffset, qcount; |
| 3138 | int i, n; |
| 3139 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3140 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3141 | /* Reset the TC information */ |
| 3142 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3143 | rx_ring = vsi->rx_rings[i]; |
| 3144 | tx_ring = vsi->tx_rings[i]; |
| 3145 | rx_ring->dcb_tc = 0; |
| 3146 | tx_ring->dcb_tc = 0; |
| 3147 | } |
| 3148 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3149 | |
| 3150 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3151 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3152 | continue; |
| 3153 | |
| 3154 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3155 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3156 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3157 | rx_ring = vsi->rx_rings[i]; |
| 3158 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3159 | rx_ring->dcb_tc = n; |
| 3160 | tx_ring->dcb_tc = n; |
| 3161 | } |
| 3162 | } |
| 3163 | } |
| 3164 | |
| 3165 | /** |
| 3166 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3167 | * @vsi: ptr to the VSI |
| 3168 | **/ |
| 3169 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3170 | { |
| 3171 | if (vsi->netdev) |
| 3172 | i40e_set_rx_mode(vsi->netdev); |
| 3173 | } |
| 3174 | |
| 3175 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3176 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3177 | * @vsi: Pointer to the targeted VSI |
| 3178 | * |
| 3179 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3180 | * filters were saved. |
| 3181 | **/ |
| 3182 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3183 | { |
| 3184 | struct i40e_fdir_filter *filter; |
| 3185 | struct i40e_pf *pf = vsi->back; |
| 3186 | struct hlist_node *node; |
| 3187 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3188 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3189 | return; |
| 3190 | |
Jacob Keller | 6d06942 | 2017-02-06 14:38:44 -0800 | [diff] [blame] | 3191 | /* Reset FDir counters as we're replaying all existing filters */ |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 3192 | pf->fd_tcp4_filter_cnt = 0; |
| 3193 | pf->fd_udp4_filter_cnt = 0; |
Jacob Keller | f223c87 | 2017-02-06 14:38:51 -0800 | [diff] [blame] | 3194 | pf->fd_sctp4_filter_cnt = 0; |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 3195 | pf->fd_ip4_filter_cnt = 0; |
Jacob Keller | 6d06942 | 2017-02-06 14:38:44 -0800 | [diff] [blame] | 3196 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3197 | hlist_for_each_entry_safe(filter, node, |
| 3198 | &pf->fdir_filter_list, fdir_node) { |
| 3199 | i40e_add_del_fdir(vsi, filter, true); |
| 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3204 | * i40e_vsi_configure - Set up the VSI for action |
| 3205 | * @vsi: the VSI being configured |
| 3206 | **/ |
| 3207 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3208 | { |
| 3209 | int err; |
| 3210 | |
| 3211 | i40e_set_vsi_rx_mode(vsi); |
| 3212 | i40e_restore_vlan(vsi); |
| 3213 | i40e_vsi_config_dcb_rings(vsi); |
| 3214 | err = i40e_vsi_configure_tx(vsi); |
| 3215 | if (!err) |
| 3216 | err = i40e_vsi_configure_rx(vsi); |
| 3217 | |
| 3218 | return err; |
| 3219 | } |
| 3220 | |
| 3221 | /** |
| 3222 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3223 | * @vsi: the VSI being configured |
| 3224 | **/ |
| 3225 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3226 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3227 | bool has_xdp = i40e_enabled_xdp_vsi(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3228 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3229 | struct i40e_hw *hw = &pf->hw; |
| 3230 | u16 vector; |
| 3231 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3232 | u32 qp; |
| 3233 | |
| 3234 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3235 | * and PFINT_LNKLSTn registers, e.g.: |
| 3236 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3237 | */ |
| 3238 | qp = vsi->base_queue; |
| 3239 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3240 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3241 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3242 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3243 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3244 | 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] | 3245 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3246 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3247 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3248 | 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] | 3249 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3250 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3251 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3252 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
Alan Brady | 1c0e6a3 | 2016-11-28 16:06:02 -0800 | [diff] [blame] | 3253 | i40e_intrl_usec_to_reg(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3254 | |
| 3255 | /* Linked list for the queuepairs assigned to this vector */ |
| 3256 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3257 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3258 | u32 nextqp = has_xdp ? qp + vsi->alloc_queue_pairs : qp; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3259 | u32 val; |
| 3260 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3261 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3262 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3263 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3264 | (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) | |
| 3265 | (I40E_QUEUE_TYPE_TX << |
| 3266 | I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3267 | |
| 3268 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3269 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3270 | if (has_xdp) { |
| 3271 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3272 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3273 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3274 | (qp << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) | |
| 3275 | (I40E_QUEUE_TYPE_TX << |
| 3276 | I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3277 | |
| 3278 | wr32(hw, I40E_QINT_TQCTL(nextqp), val); |
| 3279 | } |
| 3280 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3281 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3282 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3283 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3284 | ((qp + 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) | |
| 3285 | (I40E_QUEUE_TYPE_RX << |
| 3286 | I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3287 | |
| 3288 | /* Terminate the linked list */ |
| 3289 | if (q == (q_vector->num_ringpairs - 1)) |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3290 | val |= (I40E_QUEUE_END_OF_LIST << |
| 3291 | I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3292 | |
| 3293 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3294 | qp++; |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | i40e_flush(hw); |
| 3299 | } |
| 3300 | |
| 3301 | /** |
| 3302 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3303 | * @hw: ptr to the hardware info |
| 3304 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3305 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3306 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3307 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3308 | u32 val; |
| 3309 | |
| 3310 | /* clear things first */ |
| 3311 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3312 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3313 | |
| 3314 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3315 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3316 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3317 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3318 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3319 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3320 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3321 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3322 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3323 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3324 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3325 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3326 | if (pf->flags & I40E_FLAG_PTP) |
| 3327 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3328 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3329 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3330 | |
| 3331 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3332 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3333 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3334 | |
| 3335 | /* OTHER_ITR_IDX = 0 */ |
| 3336 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3337 | } |
| 3338 | |
| 3339 | /** |
| 3340 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3341 | * @vsi: the VSI being configured |
| 3342 | **/ |
| 3343 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3344 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3345 | u32 nextqp = i40e_enabled_xdp_vsi(vsi) ? vsi->alloc_queue_pairs : 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3346 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3347 | struct i40e_pf *pf = vsi->back; |
| 3348 | struct i40e_hw *hw = &pf->hw; |
| 3349 | u32 val; |
| 3350 | |
| 3351 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3352 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3353 | 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] | 3354 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3355 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3356 | 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] | 3357 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3358 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3359 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3360 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3361 | |
| 3362 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3363 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3364 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3365 | /* 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] | 3366 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3367 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3368 | (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3369 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3370 | |
| 3371 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3372 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3373 | if (i40e_enabled_xdp_vsi(vsi)) { |
| 3374 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3375 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)| |
| 3376 | (I40E_QUEUE_TYPE_TX |
| 3377 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3378 | |
| 3379 | wr32(hw, I40E_QINT_TQCTL(nextqp), val); |
| 3380 | } |
| 3381 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3382 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3383 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3384 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3385 | |
| 3386 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3387 | i40e_flush(hw); |
| 3388 | } |
| 3389 | |
| 3390 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3391 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3392 | * @pf: board private structure |
| 3393 | **/ |
| 3394 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3395 | { |
| 3396 | struct i40e_hw *hw = &pf->hw; |
| 3397 | |
| 3398 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3399 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3400 | i40e_flush(hw); |
| 3401 | } |
| 3402 | |
| 3403 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3404 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3405 | * @pf: board private structure |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3406 | * @clearpba: true when all pending interrupt events should be cleared |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3407 | **/ |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3408 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3409 | { |
| 3410 | struct i40e_hw *hw = &pf->hw; |
| 3411 | u32 val; |
| 3412 | |
| 3413 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3414 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3415 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3416 | |
| 3417 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3418 | i40e_flush(hw); |
| 3419 | } |
| 3420 | |
| 3421 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3422 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3423 | * @irq: interrupt number |
| 3424 | * @data: pointer to a q_vector |
| 3425 | **/ |
| 3426 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3427 | { |
| 3428 | struct i40e_q_vector *q_vector = data; |
| 3429 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3430 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3431 | return IRQ_HANDLED; |
| 3432 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3433 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3434 | |
| 3435 | return IRQ_HANDLED; |
| 3436 | } |
| 3437 | |
| 3438 | /** |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3439 | * i40e_irq_affinity_notify - Callback for affinity changes |
| 3440 | * @notify: context as to what irq was changed |
| 3441 | * @mask: the new affinity mask |
| 3442 | * |
| 3443 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3444 | * so that we may register to receive changes to the irq affinity masks. |
| 3445 | **/ |
| 3446 | static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify, |
| 3447 | const cpumask_t *mask) |
| 3448 | { |
| 3449 | struct i40e_q_vector *q_vector = |
| 3450 | container_of(notify, struct i40e_q_vector, affinity_notify); |
| 3451 | |
Jacob Keller | 7e4d01e | 2017-07-12 05:46:05 -0400 | [diff] [blame] | 3452 | cpumask_copy(&q_vector->affinity_mask, mask); |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | /** |
| 3456 | * i40e_irq_affinity_release - Callback for affinity notifier release |
| 3457 | * @ref: internal core kernel usage |
| 3458 | * |
| 3459 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3460 | * to inform the current notification subscriber that they will no longer |
| 3461 | * receive notifications. |
| 3462 | **/ |
| 3463 | static void i40e_irq_affinity_release(struct kref *ref) {} |
| 3464 | |
| 3465 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3466 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3467 | * @vsi: the VSI being configured |
| 3468 | * @basename: name for the vector |
| 3469 | * |
| 3470 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3471 | **/ |
| 3472 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3473 | { |
| 3474 | int q_vectors = vsi->num_q_vectors; |
| 3475 | struct i40e_pf *pf = vsi->back; |
| 3476 | int base = vsi->base_vector; |
| 3477 | int rx_int_idx = 0; |
| 3478 | int tx_int_idx = 0; |
| 3479 | int vector, err; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3480 | int irq_num; |
Jacob Keller | be664cb | 2017-08-29 05:32:31 -0400 | [diff] [blame] | 3481 | int cpu; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3482 | |
| 3483 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3484 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3485 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3486 | irq_num = pf->msix_entries[base + vector].vector; |
| 3487 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3488 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3489 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3490 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3491 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3492 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3493 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3494 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3495 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3496 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3497 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3498 | } else { |
| 3499 | /* skip this unused q_vector */ |
| 3500 | continue; |
| 3501 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3502 | err = request_irq(irq_num, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3503 | vsi->irq_handler, |
| 3504 | 0, |
| 3505 | q_vector->name, |
| 3506 | q_vector); |
| 3507 | if (err) { |
| 3508 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3509 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3510 | goto free_queue_irqs; |
| 3511 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3512 | |
| 3513 | /* register for affinity change notifications */ |
| 3514 | q_vector->affinity_notify.notify = i40e_irq_affinity_notify; |
| 3515 | q_vector->affinity_notify.release = i40e_irq_affinity_release; |
| 3516 | irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify); |
Jacob Keller | be664cb | 2017-08-29 05:32:31 -0400 | [diff] [blame] | 3517 | /* Spread affinity hints out across online CPUs. |
| 3518 | * |
| 3519 | * get_cpu_mask returns a static constant mask with |
| 3520 | * a permanent lifetime so it's ok to pass to |
| 3521 | * irq_set_affinity_hint without making a copy. |
Jacob Keller | 759dc4a | 2017-07-14 09:10:10 -0400 | [diff] [blame] | 3522 | */ |
Jacob Keller | be664cb | 2017-08-29 05:32:31 -0400 | [diff] [blame] | 3523 | cpu = cpumask_local_spread(q_vector->v_idx, -1); |
| 3524 | irq_set_affinity_hint(irq_num, get_cpu_mask(cpu)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3525 | } |
| 3526 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3527 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3528 | return 0; |
| 3529 | |
| 3530 | free_queue_irqs: |
| 3531 | while (vector) { |
| 3532 | vector--; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3533 | irq_num = pf->msix_entries[base + vector].vector; |
| 3534 | irq_set_affinity_notifier(irq_num, NULL); |
| 3535 | irq_set_affinity_hint(irq_num, NULL); |
| 3536 | free_irq(irq_num, &vsi->q_vectors[vector]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3537 | } |
| 3538 | return err; |
| 3539 | } |
| 3540 | |
| 3541 | /** |
| 3542 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3543 | * @vsi: the VSI being un-configured |
| 3544 | **/ |
| 3545 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3546 | { |
| 3547 | struct i40e_pf *pf = vsi->back; |
| 3548 | struct i40e_hw *hw = &pf->hw; |
| 3549 | int base = vsi->base_vector; |
| 3550 | int i; |
| 3551 | |
Shannon Nelson | 2e5c26ea | 2017-06-07 05:43:11 -0400 | [diff] [blame] | 3552 | /* disable interrupt causation from each queue */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3553 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Shannon Nelson | 2e5c26ea | 2017-06-07 05:43:11 -0400 | [diff] [blame] | 3554 | u32 val; |
| 3555 | |
| 3556 | val = rd32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx)); |
| 3557 | val &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK; |
| 3558 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val); |
| 3559 | |
| 3560 | val = rd32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx)); |
| 3561 | val &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK; |
| 3562 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), val); |
| 3563 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3564 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 3565 | continue; |
| 3566 | wr32(hw, I40E_QINT_TQCTL(vsi->xdp_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3567 | } |
| 3568 | |
Shannon Nelson | 2e5c26ea | 2017-06-07 05:43:11 -0400 | [diff] [blame] | 3569 | /* disable each interrupt */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3570 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3571 | for (i = vsi->base_vector; |
| 3572 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3573 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3574 | |
| 3575 | i40e_flush(hw); |
| 3576 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3577 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3578 | } else { |
| 3579 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3580 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3581 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3582 | i40e_flush(hw); |
| 3583 | synchronize_irq(pf->pdev->irq); |
| 3584 | } |
| 3585 | } |
| 3586 | |
| 3587 | /** |
| 3588 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3589 | * @vsi: the VSI being configured |
| 3590 | **/ |
| 3591 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3592 | { |
| 3593 | struct i40e_pf *pf = vsi->back; |
| 3594 | int i; |
| 3595 | |
| 3596 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3597 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3598 | i40e_irq_dynamic_enable(vsi, i); |
| 3599 | } else { |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3600 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3601 | } |
| 3602 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3603 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3604 | return 0; |
| 3605 | } |
| 3606 | |
| 3607 | /** |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 3608 | * i40e_free_misc_vector - Free the vector that handles non-queue events |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3609 | * @pf: board private structure |
| 3610 | **/ |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 3611 | static void i40e_free_misc_vector(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3612 | { |
| 3613 | /* Disable ICR 0 */ |
| 3614 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3615 | i40e_flush(&pf->hw); |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 3616 | |
| 3617 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
| 3618 | synchronize_irq(pf->msix_entries[0].vector); |
| 3619 | free_irq(pf->msix_entries[0].vector, pf); |
| 3620 | clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state); |
| 3621 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | /** |
| 3625 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3626 | * @irq: interrupt number |
| 3627 | * @data: pointer to a q_vector |
| 3628 | * |
| 3629 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3630 | * with both queue and non-queue interrupts. This is also used in |
| 3631 | * MSIX mode to handle the non-queue interrupts. |
| 3632 | **/ |
| 3633 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3634 | { |
| 3635 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3636 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3637 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3638 | u32 icr0, icr0_remaining; |
| 3639 | u32 val, ena_mask; |
| 3640 | |
| 3641 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3642 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3643 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3644 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3645 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3646 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3647 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3648 | /* if interrupt but no bits showing, must be SWINT */ |
| 3649 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3650 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3651 | pf->sw_int_count++; |
| 3652 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3653 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
Catherine Sullivan | 7642984 | 2017-06-07 05:43:12 -0400 | [diff] [blame] | 3654 | (icr0 & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3655 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
Carolyn Wyborny | 23bb6dc | 2016-11-08 13:05:12 -0800 | [diff] [blame] | 3656 | dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
Catherine Sullivan | 7642984 | 2017-06-07 05:43:12 -0400 | [diff] [blame] | 3657 | set_bit(__I40E_CORE_RESET_REQUESTED, pf->state); |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3658 | } |
| 3659 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3660 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3661 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3662 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3663 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3664 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3665 | /* We do not have a way to disarm Queue causes while leaving |
| 3666 | * interrupt enabled for all other causes, ideally |
| 3667 | * interrupt should be disabled while we are in NAPI but |
| 3668 | * this is not a performance path and napi_schedule() |
| 3669 | * can deal with rescheduling. |
| 3670 | */ |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 3671 | if (!test_bit(__I40E_DOWN, pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3672 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3676 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3677 | set_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3678 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3679 | } |
| 3680 | |
| 3681 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3682 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3683 | set_bit(__I40E_MDD_EVENT_PENDING, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3687 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3688 | set_bit(__I40E_VFLR_EVENT_PENDING, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3689 | } |
| 3690 | |
| 3691 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3692 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) |
| 3693 | set_bit(__I40E_RESET_INTR_RECEIVED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3694 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3695 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3696 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3697 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3698 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3699 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3700 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3701 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3702 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3703 | pf->empr_count++; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3704 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3705 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3706 | } |
| 3707 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3708 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3709 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3710 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3711 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3712 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3713 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3714 | } |
| 3715 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3716 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3717 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3718 | |
| 3719 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3720 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3721 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3722 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3723 | } |
| 3724 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3725 | /* If a critical error is pending we have no choice but to reset the |
| 3726 | * device. |
| 3727 | * Report and mask out any remaining unexpected interrupts. |
| 3728 | */ |
| 3729 | icr0_remaining = icr0 & ena_mask; |
| 3730 | if (icr0_remaining) { |
| 3731 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3732 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3733 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3734 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3735 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3736 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3737 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3738 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3739 | } |
| 3740 | ena_mask &= ~icr0_remaining; |
| 3741 | } |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3742 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3743 | |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3744 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3745 | /* re-enable interrupt causes */ |
| 3746 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 3747 | if (!test_bit(__I40E_DOWN, pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3748 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3749 | i40e_irq_dynamic_enable_icr0(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3750 | } |
| 3751 | |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3752 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3753 | } |
| 3754 | |
| 3755 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3756 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3757 | * @tx_ring: tx ring to clean |
| 3758 | * @budget: how many cleans we're allowed |
| 3759 | * |
| 3760 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3761 | **/ |
| 3762 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3763 | { |
| 3764 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3765 | u16 i = tx_ring->next_to_clean; |
| 3766 | struct i40e_tx_buffer *tx_buf; |
| 3767 | struct i40e_tx_desc *tx_desc; |
| 3768 | |
| 3769 | tx_buf = &tx_ring->tx_bi[i]; |
| 3770 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3771 | i -= tx_ring->count; |
| 3772 | |
| 3773 | do { |
| 3774 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3775 | |
| 3776 | /* if next_to_watch is not set then there is no work pending */ |
| 3777 | if (!eop_desc) |
| 3778 | break; |
| 3779 | |
| 3780 | /* prevent any other reads prior to eop_desc */ |
| 3781 | read_barrier_depends(); |
| 3782 | |
| 3783 | /* if the descriptor isn't done, no work yet to do */ |
| 3784 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3785 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3786 | break; |
| 3787 | |
| 3788 | /* clear next_to_watch to prevent false hangs */ |
| 3789 | tx_buf->next_to_watch = NULL; |
| 3790 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3791 | tx_desc->buffer_addr = 0; |
| 3792 | tx_desc->cmd_type_offset_bsz = 0; |
| 3793 | /* move past filter desc */ |
| 3794 | tx_buf++; |
| 3795 | tx_desc++; |
| 3796 | i++; |
| 3797 | if (unlikely(!i)) { |
| 3798 | i -= tx_ring->count; |
| 3799 | tx_buf = tx_ring->tx_bi; |
| 3800 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3801 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3802 | /* unmap skb header data */ |
| 3803 | dma_unmap_single(tx_ring->dev, |
| 3804 | dma_unmap_addr(tx_buf, dma), |
| 3805 | dma_unmap_len(tx_buf, len), |
| 3806 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3807 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3808 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3809 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3810 | tx_buf->raw_buf = NULL; |
| 3811 | tx_buf->tx_flags = 0; |
| 3812 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3813 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3814 | tx_desc->buffer_addr = 0; |
| 3815 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3816 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3817 | /* 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] | 3818 | tx_buf++; |
| 3819 | tx_desc++; |
| 3820 | i++; |
| 3821 | if (unlikely(!i)) { |
| 3822 | i -= tx_ring->count; |
| 3823 | tx_buf = tx_ring->tx_bi; |
| 3824 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3825 | } |
| 3826 | |
| 3827 | /* update budget accounting */ |
| 3828 | budget--; |
| 3829 | } while (likely(budget)); |
| 3830 | |
| 3831 | i += tx_ring->count; |
| 3832 | tx_ring->next_to_clean = i; |
| 3833 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3834 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3835 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3836 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3837 | return budget > 0; |
| 3838 | } |
| 3839 | |
| 3840 | /** |
| 3841 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3842 | * @irq: interrupt number |
| 3843 | * @data: pointer to a q_vector |
| 3844 | **/ |
| 3845 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3846 | { |
| 3847 | struct i40e_q_vector *q_vector = data; |
| 3848 | struct i40e_vsi *vsi; |
| 3849 | |
| 3850 | if (!q_vector->tx.ring) |
| 3851 | return IRQ_HANDLED; |
| 3852 | |
| 3853 | vsi = q_vector->tx.ring->vsi; |
| 3854 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3855 | |
| 3856 | return IRQ_HANDLED; |
| 3857 | } |
| 3858 | |
| 3859 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3860 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3861 | * @vsi: the VSI being configured |
| 3862 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3863 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3864 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3865 | 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] | 3866 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3867 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3868 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3869 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3870 | |
| 3871 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3872 | tx_ring->next = q_vector->tx.ring; |
| 3873 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3874 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3875 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 3876 | /* Place XDP Tx ring in the same q_vector ring list as regular Tx */ |
| 3877 | if (i40e_enabled_xdp_vsi(vsi)) { |
| 3878 | struct i40e_ring *xdp_ring = vsi->xdp_rings[qp_idx]; |
| 3879 | |
| 3880 | xdp_ring->q_vector = q_vector; |
| 3881 | xdp_ring->next = q_vector->tx.ring; |
| 3882 | q_vector->tx.ring = xdp_ring; |
| 3883 | q_vector->tx.count++; |
| 3884 | } |
| 3885 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3886 | rx_ring->q_vector = q_vector; |
| 3887 | rx_ring->next = q_vector->rx.ring; |
| 3888 | q_vector->rx.ring = rx_ring; |
| 3889 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3890 | } |
| 3891 | |
| 3892 | /** |
| 3893 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3894 | * @vsi: the VSI being configured |
| 3895 | * |
| 3896 | * This function maps descriptor rings to the queue-specific vectors |
| 3897 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3898 | * one vector per queue pair, but on a constrained vector budget, we |
| 3899 | * group the queue pairs as "efficiently" as possible. |
| 3900 | **/ |
| 3901 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3902 | { |
| 3903 | int qp_remaining = vsi->num_queue_pairs; |
| 3904 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3905 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3906 | int v_start = 0; |
| 3907 | int qp_idx = 0; |
| 3908 | |
| 3909 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3910 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3911 | * It is also important to go through all the vectors available to be |
| 3912 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3913 | * are cleared. This is especially important when decreasing the |
| 3914 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3915 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3916 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3917 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3918 | |
| 3919 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3920 | |
| 3921 | q_vector->num_ringpairs = num_ringpairs; |
| 3922 | |
| 3923 | q_vector->rx.count = 0; |
| 3924 | q_vector->tx.count = 0; |
| 3925 | q_vector->rx.ring = NULL; |
| 3926 | q_vector->tx.ring = NULL; |
| 3927 | |
| 3928 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3929 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3930 | qp_idx++; |
| 3931 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3932 | } |
| 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | /** |
| 3937 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3938 | * @vsi: the VSI being configured |
| 3939 | * @basename: name for the vector |
| 3940 | **/ |
| 3941 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3942 | { |
| 3943 | struct i40e_pf *pf = vsi->back; |
| 3944 | int err; |
| 3945 | |
| 3946 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3947 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3948 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3949 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3950 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3951 | else |
| 3952 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3953 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3954 | |
| 3955 | if (err) |
| 3956 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3957 | |
| 3958 | return err; |
| 3959 | } |
| 3960 | |
| 3961 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3962 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3963 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3964 | * @netdev: network interface device structure |
| 3965 | * |
| 3966 | * This is used by netconsole to send skbs without having to re-enable |
| 3967 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3968 | **/ |
| 3969 | static void i40e_netpoll(struct net_device *netdev) |
| 3970 | { |
| 3971 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3972 | struct i40e_vsi *vsi = np->vsi; |
| 3973 | struct i40e_pf *pf = vsi->back; |
| 3974 | int i; |
| 3975 | |
| 3976 | /* if interface is down do nothing */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 3977 | if (test_bit(__I40E_VSI_DOWN, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3978 | return; |
| 3979 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3980 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3981 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3982 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3983 | } else { |
| 3984 | i40e_intr(pf->pdev->irq, netdev); |
| 3985 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3986 | } |
| 3987 | #endif |
| 3988 | |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 3989 | #define I40E_QTX_ENA_WAIT_COUNT 50 |
| 3990 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3991 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3992 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3993 | * @pf: the PF being configured |
| 3994 | * @pf_q: the PF queue |
| 3995 | * @enable: enable or disable state of the queue |
| 3996 | * |
| 3997 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3998 | * enabled or disabled state. |
| 3999 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 4000 | * multiple retries; else will return 0 in case of success. |
| 4001 | **/ |
| 4002 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 4003 | { |
| 4004 | int i; |
| 4005 | u32 tx_reg; |
| 4006 | |
| 4007 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 4008 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 4009 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 4010 | break; |
| 4011 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 4012 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4013 | } |
| 4014 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 4015 | return -ETIMEDOUT; |
| 4016 | |
| 4017 | return 0; |
| 4018 | } |
| 4019 | |
| 4020 | /** |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4021 | * i40e_control_tx_q - Start or stop a particular Tx queue |
| 4022 | * @pf: the PF structure |
| 4023 | * @pf_q: the PF queue to configure |
| 4024 | * @enable: start or stop the queue |
| 4025 | * |
| 4026 | * This function enables or disables a single queue. Note that any delay |
| 4027 | * required after the operation is expected to be handled by the caller of |
| 4028 | * this function. |
| 4029 | **/ |
| 4030 | static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable) |
| 4031 | { |
| 4032 | struct i40e_hw *hw = &pf->hw; |
| 4033 | u32 tx_reg; |
| 4034 | int i; |
| 4035 | |
| 4036 | /* warn the TX unit of coming changes */ |
| 4037 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 4038 | if (!enable) |
| 4039 | usleep_range(10, 20); |
| 4040 | |
| 4041 | for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) { |
| 4042 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
| 4043 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 4044 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 4045 | break; |
| 4046 | usleep_range(1000, 2000); |
| 4047 | } |
| 4048 | |
| 4049 | /* Skip if the queue is already in the requested state */ |
| 4050 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 4051 | return; |
| 4052 | |
| 4053 | /* turn on/off the queue */ |
| 4054 | if (enable) { |
| 4055 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
| 4056 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
| 4057 | } else { |
| 4058 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
| 4059 | } |
| 4060 | |
| 4061 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
| 4062 | } |
| 4063 | |
| 4064 | /** |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 4065 | * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion |
| 4066 | * @seid: VSI SEID |
| 4067 | * @pf: the PF structure |
| 4068 | * @pf_q: the PF queue to configure |
| 4069 | * @is_xdp: true if the queue is used for XDP |
| 4070 | * @enable: start or stop the queue |
| 4071 | **/ |
| 4072 | static int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q, |
| 4073 | bool is_xdp, bool enable) |
| 4074 | { |
| 4075 | int ret; |
| 4076 | |
| 4077 | i40e_control_tx_q(pf, pf_q, enable); |
| 4078 | |
| 4079 | /* wait for the change to finish */ |
| 4080 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 4081 | if (ret) { |
| 4082 | dev_info(&pf->pdev->dev, |
| 4083 | "VSI seid %d %sTx ring %d %sable timeout\n", |
| 4084 | seid, (is_xdp ? "XDP " : ""), pf_q, |
| 4085 | (enable ? "en" : "dis")); |
| 4086 | } |
| 4087 | |
| 4088 | return ret; |
| 4089 | } |
| 4090 | |
| 4091 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4092 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 4093 | * @vsi: the VSI being configured |
| 4094 | * @enable: start or stop the rings |
| 4095 | **/ |
| 4096 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 4097 | { |
| 4098 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4099 | int i, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4100 | |
| 4101 | pf_q = vsi->base_queue; |
| 4102 | 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] | 4103 | ret = i40e_control_wait_tx_q(vsi->seid, pf, |
| 4104 | pf_q, |
| 4105 | false /*is xdp*/, enable); |
| 4106 | if (ret) |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4107 | break; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 4108 | |
| 4109 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 4110 | continue; |
| 4111 | |
| 4112 | ret = i40e_control_wait_tx_q(vsi->seid, pf, |
| 4113 | pf_q + vsi->alloc_queue_pairs, |
| 4114 | true /*is xdp*/, enable); |
| 4115 | if (ret) |
| 4116 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4117 | } |
| 4118 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4119 | return ret; |
| 4120 | } |
| 4121 | |
| 4122 | /** |
| 4123 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 4124 | * @pf: the PF being configured |
| 4125 | * @pf_q: the PF queue |
| 4126 | * @enable: enable or disable state of the queue |
| 4127 | * |
| 4128 | * This routine will wait for the given Rx queue of the PF to reach the |
| 4129 | * enabled or disabled state. |
| 4130 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 4131 | * multiple retries; else will return 0 in case of success. |
| 4132 | **/ |
| 4133 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 4134 | { |
| 4135 | int i; |
| 4136 | u32 rx_reg; |
| 4137 | |
| 4138 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 4139 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 4140 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 4141 | break; |
| 4142 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 4143 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4144 | } |
| 4145 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 4146 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 4147 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4148 | return 0; |
| 4149 | } |
| 4150 | |
| 4151 | /** |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4152 | * i40e_control_rx_q - Start or stop a particular Rx queue |
| 4153 | * @pf: the PF structure |
| 4154 | * @pf_q: the PF queue to configure |
| 4155 | * @enable: start or stop the queue |
| 4156 | * |
| 4157 | * This function enables or disables a single queue. Note that any delay |
| 4158 | * required after the operation is expected to be handled by the caller of |
| 4159 | * this function. |
| 4160 | **/ |
| 4161 | static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable) |
| 4162 | { |
| 4163 | struct i40e_hw *hw = &pf->hw; |
| 4164 | u32 rx_reg; |
| 4165 | int i; |
| 4166 | |
| 4167 | for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) { |
| 4168 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
| 4169 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 4170 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 4171 | break; |
| 4172 | usleep_range(1000, 2000); |
| 4173 | } |
| 4174 | |
| 4175 | /* Skip if the queue is already in the requested state */ |
| 4176 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 4177 | return; |
| 4178 | |
| 4179 | /* turn on/off the queue */ |
| 4180 | if (enable) |
| 4181 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
| 4182 | else |
| 4183 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
| 4184 | |
| 4185 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
| 4186 | } |
| 4187 | |
| 4188 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4189 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 4190 | * @vsi: the VSI being configured |
| 4191 | * @enable: start or stop the rings |
| 4192 | **/ |
| 4193 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 4194 | { |
| 4195 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4196 | int i, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4197 | |
| 4198 | pf_q = vsi->base_queue; |
| 4199 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Jacob Keller | c768e49 | 2017-04-13 04:45:47 -0400 | [diff] [blame] | 4200 | i40e_control_rx_q(pf, pf_q, enable); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4201 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4202 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4203 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 4204 | if (ret) { |
| 4205 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4206 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 4207 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4208 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4209 | } |
| 4210 | } |
| 4211 | |
Wyborny, Carolyn | d08a9f6 | 2017-03-28 08:00:48 -0700 | [diff] [blame] | 4212 | /* Due to HW errata, on Rx disable only, the register can indicate done |
| 4213 | * before it really is. Needs 50ms to be sure |
| 4214 | */ |
| 4215 | if (!enable) |
| 4216 | mdelay(50); |
| 4217 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4218 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | /** |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4222 | * i40e_vsi_start_rings - Start a VSI's rings |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4223 | * @vsi: the VSI being configured |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4224 | **/ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4225 | int i40e_vsi_start_rings(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4226 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 4227 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4228 | |
| 4229 | /* do rx first for enable and last for disable */ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4230 | ret = i40e_vsi_control_rx(vsi, true); |
| 4231 | if (ret) |
| 4232 | return ret; |
| 4233 | ret = i40e_vsi_control_tx(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4234 | |
| 4235 | return ret; |
| 4236 | } |
| 4237 | |
| 4238 | /** |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4239 | * i40e_vsi_stop_rings - Stop a VSI's rings |
| 4240 | * @vsi: the VSI being configured |
| 4241 | **/ |
| 4242 | void i40e_vsi_stop_rings(struct i40e_vsi *vsi) |
| 4243 | { |
Jacob Keller | 3480756 | 2017-04-13 04:45:53 -0400 | [diff] [blame] | 4244 | /* When port TX is suspended, don't wait */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4245 | if (test_bit(__I40E_PORT_SUSPENDED, vsi->back->state)) |
Jacob Keller | 3480756 | 2017-04-13 04:45:53 -0400 | [diff] [blame] | 4246 | return i40e_vsi_stop_rings_no_wait(vsi); |
| 4247 | |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4248 | /* do rx first for enable and last for disable |
| 4249 | * Ignore return value, we need to shutdown whatever we can |
| 4250 | */ |
| 4251 | i40e_vsi_control_tx(vsi, false); |
| 4252 | i40e_vsi_control_rx(vsi, false); |
| 4253 | } |
| 4254 | |
| 4255 | /** |
Jacob Keller | e4b433f | 2017-04-13 04:45:52 -0400 | [diff] [blame] | 4256 | * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay |
| 4257 | * @vsi: the VSI being shutdown |
| 4258 | * |
| 4259 | * This function stops all the rings for a VSI but does not delay to verify |
| 4260 | * that rings have been disabled. It is expected that the caller is shutting |
| 4261 | * down multiple VSIs at once and will delay together for all the VSIs after |
| 4262 | * initiating the shutdown. This is particularly useful for shutting down lots |
| 4263 | * of VFs together. Otherwise, a large delay can be incurred while configuring |
| 4264 | * each VSI in serial. |
| 4265 | **/ |
| 4266 | void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi) |
| 4267 | { |
| 4268 | struct i40e_pf *pf = vsi->back; |
| 4269 | int i, pf_q; |
| 4270 | |
| 4271 | pf_q = vsi->base_queue; |
| 4272 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4273 | i40e_control_tx_q(pf, pf_q, false); |
| 4274 | i40e_control_rx_q(pf, pf_q, false); |
| 4275 | } |
| 4276 | } |
| 4277 | |
| 4278 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4279 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 4280 | * @vsi: the VSI being configured |
| 4281 | **/ |
| 4282 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 4283 | { |
| 4284 | struct i40e_pf *pf = vsi->back; |
| 4285 | struct i40e_hw *hw = &pf->hw; |
| 4286 | int base = vsi->base_vector; |
| 4287 | u32 val, qp; |
| 4288 | int i; |
| 4289 | |
| 4290 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4291 | if (!vsi->q_vectors) |
| 4292 | return; |
| 4293 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 4294 | if (!vsi->irqs_ready) |
| 4295 | return; |
| 4296 | |
| 4297 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4298 | for (i = 0; i < vsi->num_q_vectors; i++) { |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4299 | int irq_num; |
| 4300 | u16 vector; |
| 4301 | |
| 4302 | vector = i + base; |
| 4303 | irq_num = pf->msix_entries[vector].vector; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4304 | |
| 4305 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 4306 | if (!vsi->q_vectors[i] || |
| 4307 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4308 | continue; |
| 4309 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4310 | /* clear the affinity notifier in the IRQ descriptor */ |
| 4311 | irq_set_affinity_notifier(irq_num, NULL); |
Jacob Keller | 759dc4a | 2017-07-14 09:10:10 -0400 | [diff] [blame] | 4312 | /* remove our suggested affinity mask for this IRQ */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4313 | irq_set_affinity_hint(irq_num, NULL); |
| 4314 | synchronize_irq(irq_num); |
| 4315 | free_irq(irq_num, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4316 | |
| 4317 | /* Tear down the interrupt queue link list |
| 4318 | * |
| 4319 | * We know that they come in pairs and always |
| 4320 | * the Rx first, then the Tx. To clear the |
| 4321 | * link list, stick the EOL value into the |
| 4322 | * next_q field of the registers. |
| 4323 | */ |
| 4324 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4325 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4326 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4327 | val |= I40E_QUEUE_END_OF_LIST |
| 4328 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4329 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4330 | |
| 4331 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4332 | u32 next; |
| 4333 | |
| 4334 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4335 | |
| 4336 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4337 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4338 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4339 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4340 | |
| 4341 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4342 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4343 | |
| 4344 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4345 | |
| 4346 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4347 | |
| 4348 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4349 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4350 | |
| 4351 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4352 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4353 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4354 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4355 | |
| 4356 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4357 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4358 | |
| 4359 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4360 | qp = next; |
| 4361 | } |
| 4362 | } |
| 4363 | } else { |
| 4364 | free_irq(pf->pdev->irq, pf); |
| 4365 | |
| 4366 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4367 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4368 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4369 | val |= I40E_QUEUE_END_OF_LIST |
| 4370 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4371 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4372 | |
| 4373 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4374 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4375 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4376 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4377 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4378 | |
| 4379 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4380 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4381 | |
| 4382 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4383 | |
| 4384 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4385 | |
| 4386 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4387 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4388 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4389 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4390 | |
| 4391 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4392 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4393 | |
| 4394 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4395 | } |
| 4396 | } |
| 4397 | |
| 4398 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4399 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4400 | * @vsi: the VSI being configured |
| 4401 | * @v_idx: Index of vector to be freed |
| 4402 | * |
| 4403 | * This function frees the memory allocated to the q_vector. In addition if |
| 4404 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4405 | * to freeing the q_vector. |
| 4406 | **/ |
| 4407 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4408 | { |
| 4409 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4410 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4411 | |
| 4412 | if (!q_vector) |
| 4413 | return; |
| 4414 | |
| 4415 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4416 | i40e_for_each_ring(ring, q_vector->tx) |
| 4417 | ring->q_vector = NULL; |
| 4418 | |
| 4419 | i40e_for_each_ring(ring, q_vector->rx) |
| 4420 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4421 | |
| 4422 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4423 | if (vsi->netdev) |
| 4424 | netif_napi_del(&q_vector->napi); |
| 4425 | |
| 4426 | vsi->q_vectors[v_idx] = NULL; |
| 4427 | |
| 4428 | kfree_rcu(q_vector, rcu); |
| 4429 | } |
| 4430 | |
| 4431 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4432 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4433 | * @vsi: the VSI being un-configured |
| 4434 | * |
| 4435 | * This frees the memory allocated to the q_vectors and |
| 4436 | * deletes references to the NAPI struct. |
| 4437 | **/ |
| 4438 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4439 | { |
| 4440 | int v_idx; |
| 4441 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4442 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4443 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | /** |
| 4447 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4448 | * @pf: board private structure |
| 4449 | **/ |
| 4450 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4451 | { |
| 4452 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4453 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4454 | pci_disable_msix(pf->pdev); |
| 4455 | kfree(pf->msix_entries); |
| 4456 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4457 | kfree(pf->irq_pile); |
| 4458 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4459 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4460 | pci_disable_msi(pf->pdev); |
| 4461 | } |
| 4462 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4463 | } |
| 4464 | |
| 4465 | /** |
| 4466 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4467 | * @pf: board private structure |
| 4468 | * |
| 4469 | * We go through and clear interrupt specific resources and reset the structure |
| 4470 | * to pre-load conditions |
| 4471 | **/ |
| 4472 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4473 | { |
| 4474 | int i; |
| 4475 | |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 4476 | i40e_free_misc_vector(pf); |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4477 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4478 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4479 | I40E_IWARP_IRQ_PILE_ID); |
| 4480 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4481 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4482 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4483 | if (pf->vsi[i]) |
| 4484 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4485 | i40e_reset_interrupt_capability(pf); |
| 4486 | } |
| 4487 | |
| 4488 | /** |
| 4489 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4490 | * @vsi: the VSI being configured |
| 4491 | **/ |
| 4492 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4493 | { |
| 4494 | int q_idx; |
| 4495 | |
| 4496 | if (!vsi->netdev) |
| 4497 | return; |
| 4498 | |
Alexander Duyck | 13a8cd1 | 2017-03-24 15:01:42 -0700 | [diff] [blame] | 4499 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) { |
| 4500 | struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx]; |
| 4501 | |
| 4502 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 4503 | napi_enable(&q_vector->napi); |
| 4504 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4505 | } |
| 4506 | |
| 4507 | /** |
| 4508 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4509 | * @vsi: the VSI being configured |
| 4510 | **/ |
| 4511 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4512 | { |
| 4513 | int q_idx; |
| 4514 | |
| 4515 | if (!vsi->netdev) |
| 4516 | return; |
| 4517 | |
Alexander Duyck | 13a8cd1 | 2017-03-24 15:01:42 -0700 | [diff] [blame] | 4518 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) { |
| 4519 | struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx]; |
| 4520 | |
| 4521 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 4522 | napi_disable(&q_vector->napi); |
| 4523 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4524 | } |
| 4525 | |
| 4526 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4527 | * i40e_vsi_close - Shut down a VSI |
| 4528 | * @vsi: the vsi to be quelled |
| 4529 | **/ |
| 4530 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4531 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 4532 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4533 | if (!test_and_set_bit(__I40E_VSI_DOWN, vsi->state)) |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4534 | i40e_down(vsi); |
| 4535 | i40e_vsi_free_irq(vsi); |
| 4536 | i40e_vsi_free_tx_resources(vsi); |
| 4537 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4538 | vsi->current_netdev_flags = 0; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 4539 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4540 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 4541 | pf->flags |= I40E_FLAG_CLIENT_RESET; |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4542 | } |
| 4543 | |
| 4544 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4545 | * i40e_quiesce_vsi - Pause a given VSI |
| 4546 | * @vsi: the VSI being paused |
| 4547 | **/ |
| 4548 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4549 | { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4550 | if (test_bit(__I40E_VSI_DOWN, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4551 | return; |
| 4552 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4553 | set_bit(__I40E_VSI_NEEDS_RESTART, vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4554 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4555 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4556 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4557 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4558 | } |
| 4559 | |
| 4560 | /** |
| 4561 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4562 | * @vsi: the VSI being resumed |
| 4563 | **/ |
| 4564 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4565 | { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4566 | if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4567 | return; |
| 4568 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4569 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4570 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4571 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4572 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4573 | } |
| 4574 | |
| 4575 | /** |
| 4576 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4577 | * @pf: the PF |
| 4578 | **/ |
| 4579 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4580 | { |
| 4581 | int v; |
| 4582 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4583 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4584 | if (pf->vsi[v]) |
| 4585 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4586 | } |
| 4587 | } |
| 4588 | |
| 4589 | /** |
| 4590 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4591 | * @pf: the PF |
| 4592 | **/ |
| 4593 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4594 | { |
| 4595 | int v; |
| 4596 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4597 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4598 | if (pf->vsi[v]) |
| 4599 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4600 | } |
| 4601 | } |
| 4602 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4603 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4604 | * 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] | 4605 | * @vsi: the VSI being configured |
| 4606 | * |
Jacob Keller | af26ce2 | 2017-04-05 07:50:58 -0400 | [diff] [blame] | 4607 | * Wait until all queues on a given VSI have been disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4608 | **/ |
Jacob Keller | e4b433f | 2017-04-13 04:45:52 -0400 | [diff] [blame] | 4609 | int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4610 | { |
| 4611 | struct i40e_pf *pf = vsi->back; |
| 4612 | int i, pf_q, ret; |
| 4613 | |
| 4614 | pf_q = vsi->base_queue; |
| 4615 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Jacob Keller | af26ce2 | 2017-04-05 07:50:58 -0400 | [diff] [blame] | 4616 | /* Check and wait for the Tx queue */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4617 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4618 | if (ret) { |
| 4619 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4620 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4621 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4622 | return ret; |
| 4623 | } |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 4624 | |
| 4625 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 4626 | goto wait_rx; |
| 4627 | |
| 4628 | /* Check and wait for the XDP Tx queue */ |
| 4629 | ret = i40e_pf_txq_wait(pf, pf_q + vsi->alloc_queue_pairs, |
| 4630 | false); |
| 4631 | if (ret) { |
| 4632 | dev_info(&pf->pdev->dev, |
| 4633 | "VSI seid %d XDP Tx ring %d disable timeout\n", |
| 4634 | vsi->seid, pf_q); |
| 4635 | return ret; |
| 4636 | } |
| 4637 | wait_rx: |
| 4638 | /* Check and wait for the Rx queue */ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4639 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4640 | if (ret) { |
| 4641 | dev_info(&pf->pdev->dev, |
| 4642 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4643 | vsi->seid, pf_q); |
| 4644 | return ret; |
| 4645 | } |
| 4646 | } |
| 4647 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4648 | return 0; |
| 4649 | } |
| 4650 | |
Jacob Keller | e4b433f | 2017-04-13 04:45:52 -0400 | [diff] [blame] | 4651 | #ifdef CONFIG_I40E_DCB |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4652 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4653 | * 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] | 4654 | * @pf: the PF |
| 4655 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4656 | * 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] | 4657 | * VSIs that are managed by this PF. |
| 4658 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4659 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4660 | { |
| 4661 | int v, ret = 0; |
| 4662 | |
| 4663 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Alexander Duyck | c76cb6e | 2017-02-21 15:55:48 -0800 | [diff] [blame] | 4664 | if (pf->vsi[v]) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4665 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4666 | if (ret) |
| 4667 | break; |
| 4668 | } |
| 4669 | } |
| 4670 | |
| 4671 | return ret; |
| 4672 | } |
| 4673 | |
| 4674 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4675 | |
| 4676 | /** |
| 4677 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4678 | * @q_idx: TX queue number |
| 4679 | * @vsi: Pointer to VSI struct |
| 4680 | * |
| 4681 | * This function checks specified queue for given VSI. Detects hung condition. |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4682 | * We proactively detect hung TX queues by checking if interrupts are disabled |
| 4683 | * but there are pending descriptors. If it appears hung, attempt to recover |
| 4684 | * by triggering a SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4685 | **/ |
| 4686 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4687 | { |
| 4688 | struct i40e_ring *tx_ring = NULL; |
| 4689 | struct i40e_pf *pf; |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4690 | u32 val, tx_pending; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4691 | int i; |
| 4692 | |
| 4693 | pf = vsi->back; |
| 4694 | |
| 4695 | /* now that we have an index, find the tx_ring struct */ |
| 4696 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4697 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4698 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4699 | tx_ring = vsi->tx_rings[i]; |
| 4700 | break; |
| 4701 | } |
| 4702 | } |
| 4703 | } |
| 4704 | |
| 4705 | if (!tx_ring) |
| 4706 | return; |
| 4707 | |
| 4708 | /* Read interrupt register */ |
| 4709 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4710 | val = rd32(&pf->hw, |
| 4711 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4712 | tx_ring->vsi->base_vector - 1)); |
| 4713 | else |
| 4714 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4715 | |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4716 | tx_pending = i40e_get_tx_pending(tx_ring); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4717 | |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4718 | /* Interrupts are disabled and TX pending is non-zero, |
| 4719 | * trigger the SW interrupt (don't wait). Worst case |
| 4720 | * there will be one extra interrupt which may result |
| 4721 | * into not cleaning any queues because queues are cleaned. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4722 | */ |
Alan Brady | 17daabb | 2017-04-05 07:50:56 -0400 | [diff] [blame] | 4723 | if (tx_pending && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) |
| 4724 | i40e_force_wb(vsi, tx_ring->q_vector); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | /** |
| 4728 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4729 | * @pf: pointer to PF struct |
| 4730 | * |
| 4731 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4732 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4733 | * SW interrupt. |
| 4734 | **/ |
| 4735 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4736 | { |
| 4737 | struct net_device *netdev; |
| 4738 | struct i40e_vsi *vsi; |
Jesse Brandeburg | b85c94b | 2017-06-20 15:16:59 -0700 | [diff] [blame] | 4739 | unsigned int i; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4740 | |
| 4741 | /* Only for LAN VSI */ |
| 4742 | vsi = pf->vsi[pf->lan_vsi]; |
| 4743 | |
| 4744 | if (!vsi) |
| 4745 | return; |
| 4746 | |
| 4747 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 4748 | if (test_bit(__I40E_VSI_DOWN, vsi->back->state) || |
| 4749 | test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state)) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4750 | return; |
| 4751 | |
| 4752 | /* Make sure type is MAIN VSI */ |
| 4753 | if (vsi->type != I40E_VSI_MAIN) |
| 4754 | return; |
| 4755 | |
| 4756 | netdev = vsi->netdev; |
| 4757 | if (!netdev) |
| 4758 | return; |
| 4759 | |
| 4760 | /* Bail out if netif_carrier is not OK */ |
| 4761 | if (!netif_carrier_ok(netdev)) |
| 4762 | return; |
| 4763 | |
| 4764 | /* Go thru' TX queues for netdev */ |
| 4765 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4766 | struct netdev_queue *q; |
| 4767 | |
| 4768 | q = netdev_get_tx_queue(netdev, i); |
| 4769 | if (q) |
| 4770 | i40e_detect_recover_hung_queue(i, vsi); |
| 4771 | } |
| 4772 | } |
| 4773 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4774 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4775 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4776 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4777 | * |
| 4778 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4779 | * and LAN TC. |
| 4780 | **/ |
| 4781 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4782 | { |
| 4783 | struct i40e_dcb_app_priority_table app; |
| 4784 | struct i40e_hw *hw = &pf->hw; |
| 4785 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4786 | u8 tc, i; |
| 4787 | /* Get the iSCSI APP TLV */ |
| 4788 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4789 | |
| 4790 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4791 | app = dcbcfg->app[i]; |
| 4792 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4793 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4794 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4795 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4796 | break; |
| 4797 | } |
| 4798 | } |
| 4799 | |
| 4800 | return enabled_tc; |
| 4801 | } |
| 4802 | |
| 4803 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4804 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4805 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4806 | * |
| 4807 | * Return the number of TCs from given DCBx configuration |
| 4808 | **/ |
| 4809 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4810 | { |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4811 | int i, tc_unused = 0; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4812 | u8 num_tc = 0; |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4813 | u8 ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4814 | |
| 4815 | /* Scan the ETS Config Priority Table to find |
| 4816 | * traffic class enabled for a given priority |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4817 | * and create a bitmask of enabled TCs |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4818 | */ |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4819 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) |
| 4820 | num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]); |
| 4821 | |
| 4822 | /* Now scan the bitmask to check for |
| 4823 | * contiguous TCs starting with TC0 |
| 4824 | */ |
| 4825 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4826 | if (num_tc & BIT(i)) { |
| 4827 | if (!tc_unused) { |
| 4828 | ret++; |
| 4829 | } else { |
| 4830 | pr_err("Non-contiguous TC - Disabling DCB\n"); |
| 4831 | return 1; |
| 4832 | } |
| 4833 | } else { |
| 4834 | tc_unused = 1; |
| 4835 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4836 | } |
| 4837 | |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4838 | /* There is always at least TC0 */ |
| 4839 | if (!ret) |
| 4840 | ret = 1; |
| 4841 | |
| 4842 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4843 | } |
| 4844 | |
| 4845 | /** |
| 4846 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4847 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4848 | * |
| 4849 | * Query the current DCB configuration and return the number of |
| 4850 | * traffic classes enabled from the given DCBX config |
| 4851 | **/ |
| 4852 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4853 | { |
| 4854 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4855 | u8 enabled_tc = 1; |
| 4856 | u8 i; |
| 4857 | |
| 4858 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4859 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4860 | |
| 4861 | return enabled_tc; |
| 4862 | } |
| 4863 | |
| 4864 | /** |
| 4865 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4866 | * @pf: PF being queried |
| 4867 | * |
| 4868 | * Return number of traffic classes enabled for the given PF |
| 4869 | **/ |
| 4870 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4871 | { |
| 4872 | struct i40e_hw *hw = &pf->hw; |
Dave Ertman | 52a08ca | 2016-07-27 12:02:34 -0700 | [diff] [blame] | 4873 | u8 i, enabled_tc = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4874 | u8 num_tc = 0; |
| 4875 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4876 | |
| 4877 | /* If DCB is not enabled then always in single TC */ |
| 4878 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4879 | return 1; |
| 4880 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4881 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4882 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4883 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4884 | |
| 4885 | /* MFP mode return count of enabled TCs for this PF */ |
| 4886 | if (pf->hw.func_caps.iscsi) |
| 4887 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4888 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4889 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4890 | |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4891 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4892 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4893 | num_tc++; |
| 4894 | } |
| 4895 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4896 | } |
| 4897 | |
| 4898 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4899 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4900 | * @pf: PF being queried |
| 4901 | * |
| 4902 | * Return a bitmap for enabled traffic classes for this PF. |
| 4903 | **/ |
| 4904 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4905 | { |
| 4906 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4907 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4908 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4909 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4910 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4911 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4912 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4913 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4914 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4915 | if (pf->hw.func_caps.iscsi) |
| 4916 | return i40e_get_iscsi_tc_map(pf); |
| 4917 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4918 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4919 | } |
| 4920 | |
| 4921 | /** |
| 4922 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4923 | * @vsi: the VSI being queried |
| 4924 | * |
| 4925 | * Returns 0 on success, negative value on failure |
| 4926 | **/ |
| 4927 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4928 | { |
| 4929 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4930 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4931 | struct i40e_pf *pf = vsi->back; |
| 4932 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4933 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4934 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4935 | int i; |
| 4936 | |
| 4937 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4938 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4939 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4940 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4941 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4942 | i40e_stat_str(&pf->hw, ret), |
| 4943 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4944 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4945 | } |
| 4946 | |
| 4947 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4948 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4949 | NULL); |
| 4950 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4951 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4952 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4953 | i40e_stat_str(&pf->hw, ret), |
| 4954 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4955 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4956 | } |
| 4957 | |
| 4958 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4959 | dev_info(&pf->pdev->dev, |
| 4960 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4961 | bw_config.tc_valid_bits, |
| 4962 | bw_ets_config.tc_valid_bits); |
| 4963 | /* Still continuing */ |
| 4964 | } |
| 4965 | |
| 4966 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4967 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4968 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4969 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4970 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4971 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4972 | vsi->bw_ets_limit_credits[i] = |
| 4973 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4974 | /* 3 bits out of 4 for each TC */ |
| 4975 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4976 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4977 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4978 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | /** |
| 4982 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4983 | * @vsi: the VSI being configured |
| 4984 | * @enabled_tc: TC bitmap |
| 4985 | * @bw_credits: BW shared credits per TC |
| 4986 | * |
| 4987 | * Returns 0 on success, negative value on failure |
| 4988 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4989 | 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] | 4990 | u8 *bw_share) |
| 4991 | { |
| 4992 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4993 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4994 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4995 | |
| 4996 | bw_data.tc_valid_bits = enabled_tc; |
| 4997 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4998 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4999 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5000 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 5001 | NULL); |
| 5002 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5003 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5004 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 5005 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 5006 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 5010 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 5011 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 5012 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5013 | } |
| 5014 | |
| 5015 | /** |
| 5016 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 5017 | * @vsi: the VSI being configured |
| 5018 | * @enabled_tc: TC map to be enabled |
| 5019 | * |
| 5020 | **/ |
| 5021 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 5022 | { |
| 5023 | struct net_device *netdev = vsi->netdev; |
| 5024 | struct i40e_pf *pf = vsi->back; |
| 5025 | struct i40e_hw *hw = &pf->hw; |
| 5026 | u8 netdev_tc = 0; |
| 5027 | int i; |
| 5028 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 5029 | |
| 5030 | if (!netdev) |
| 5031 | return; |
| 5032 | |
| 5033 | if (!enabled_tc) { |
| 5034 | netdev_reset_tc(netdev); |
| 5035 | return; |
| 5036 | } |
| 5037 | |
| 5038 | /* Set up actual enabled TCs on the VSI */ |
| 5039 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 5040 | return; |
| 5041 | |
| 5042 | /* set per TC queues for the VSI */ |
| 5043 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 5044 | /* Only set TC queues for enabled tcs |
| 5045 | * |
| 5046 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 5047 | * enabled_tc bitmap would be 0x00001001; the driver |
| 5048 | * will set the numtc for netdev as 2 that will be |
| 5049 | * referenced by the netdev layer as TC 0 and 1. |
| 5050 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5051 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5052 | netdev_set_tc_queue(netdev, |
| 5053 | vsi->tc_config.tc_info[i].netdev_tc, |
| 5054 | vsi->tc_config.tc_info[i].qcount, |
| 5055 | vsi->tc_config.tc_info[i].qoffset); |
| 5056 | } |
| 5057 | |
| 5058 | /* Assign UP2TC map for the VSI */ |
| 5059 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 5060 | /* Get the actual TC# for the UP */ |
| 5061 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 5062 | /* Get the mapped netdev TC# for the UP */ |
| 5063 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 5064 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 5065 | } |
| 5066 | } |
| 5067 | |
| 5068 | /** |
| 5069 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 5070 | * @vsi: the VSI being configured |
| 5071 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 5072 | **/ |
| 5073 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 5074 | struct i40e_vsi_context *ctxt) |
| 5075 | { |
| 5076 | /* copy just the sections touched not the entire info |
| 5077 | * since not all sections are valid as returned by |
| 5078 | * update vsi params |
| 5079 | */ |
| 5080 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 5081 | memcpy(&vsi->info.queue_mapping, |
| 5082 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 5083 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 5084 | sizeof(vsi->info.tc_mapping)); |
| 5085 | } |
| 5086 | |
| 5087 | /** |
| 5088 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 5089 | * @vsi: VSI to be configured |
| 5090 | * @enabled_tc: TC bitmap |
| 5091 | * |
| 5092 | * This configures a particular VSI for TCs that are mapped to the |
| 5093 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 5094 | * VSIs to configure TC for a particular VSI. |
| 5095 | * |
| 5096 | * NOTE: |
| 5097 | * It is expected that the VSI queues have been quisced before calling |
| 5098 | * this function. |
| 5099 | **/ |
| 5100 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 5101 | { |
| 5102 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 5103 | struct i40e_vsi_context ctxt; |
| 5104 | int ret = 0; |
| 5105 | int i; |
| 5106 | |
| 5107 | /* Check if enabled_tc is same as existing or new TCs */ |
| 5108 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 5109 | return ret; |
| 5110 | |
| 5111 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 5112 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5113 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5114 | bw_share[i] = 1; |
| 5115 | } |
| 5116 | |
| 5117 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 5118 | if (ret) { |
| 5119 | dev_info(&vsi->back->pdev->dev, |
| 5120 | "Failed configuring TC map %d for VSI %d\n", |
| 5121 | enabled_tc, vsi->seid); |
| 5122 | goto out; |
| 5123 | } |
| 5124 | |
| 5125 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 5126 | ctxt.seid = vsi->seid; |
| 5127 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 5128 | ctxt.vf_num = 0; |
| 5129 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5130 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5131 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 5132 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5133 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 5134 | ctxt.info.valid_sections |= |
| 5135 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 5136 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 5137 | } |
| 5138 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5139 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 5140 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 5141 | if (ret) { |
| 5142 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5143 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 5144 | i40e_stat_str(&vsi->back->hw, ret), |
| 5145 | i40e_aq_str(&vsi->back->hw, |
| 5146 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5147 | goto out; |
| 5148 | } |
| 5149 | /* update the local VSI info with updated queue map */ |
| 5150 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 5151 | vsi->info.valid_sections = 0; |
| 5152 | |
| 5153 | /* Update current VSI BW information */ |
| 5154 | ret = i40e_vsi_get_bw_info(vsi); |
| 5155 | if (ret) { |
| 5156 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5157 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 5158 | i40e_stat_str(&vsi->back->hw, ret), |
| 5159 | i40e_aq_str(&vsi->back->hw, |
| 5160 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5161 | goto out; |
| 5162 | } |
| 5163 | |
| 5164 | /* Update the netdev TC setup */ |
| 5165 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 5166 | out: |
| 5167 | return ret; |
| 5168 | } |
| 5169 | |
| 5170 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5171 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 5172 | * @veb: given VEB |
| 5173 | * @enabled_tc: TC bitmap |
| 5174 | * |
| 5175 | * Configures given TC bitmap for VEB (switching) element |
| 5176 | **/ |
| 5177 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 5178 | { |
| 5179 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 5180 | struct i40e_pf *pf = veb->pf; |
| 5181 | int ret = 0; |
| 5182 | int i; |
| 5183 | |
| 5184 | /* No TCs or already enabled TCs just return */ |
| 5185 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 5186 | return ret; |
| 5187 | |
| 5188 | bw_data.tc_valid_bits = enabled_tc; |
| 5189 | /* bw_data.absolute_credits is not set (relative) */ |
| 5190 | |
| 5191 | /* Enable ETS TCs with equal BW Share for now */ |
| 5192 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5193 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5194 | bw_data.tc_bw_share_credits[i] = 1; |
| 5195 | } |
| 5196 | |
| 5197 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 5198 | &bw_data, NULL); |
| 5199 | if (ret) { |
| 5200 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5201 | "VEB bw config failed, err %s aq_err %s\n", |
| 5202 | i40e_stat_str(&pf->hw, ret), |
| 5203 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5204 | goto out; |
| 5205 | } |
| 5206 | |
| 5207 | /* Update the BW information */ |
| 5208 | ret = i40e_veb_get_bw_info(veb); |
| 5209 | if (ret) { |
| 5210 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5211 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 5212 | i40e_stat_str(&pf->hw, ret), |
| 5213 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5214 | } |
| 5215 | |
| 5216 | out: |
| 5217 | return ret; |
| 5218 | } |
| 5219 | |
| 5220 | #ifdef CONFIG_I40E_DCB |
| 5221 | /** |
| 5222 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 5223 | * @pf: PF struct |
| 5224 | * |
| 5225 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 5226 | * the caller would've quiesce all the VSIs before calling |
| 5227 | * this function |
| 5228 | **/ |
| 5229 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 5230 | { |
| 5231 | u8 tc_map = 0; |
| 5232 | int ret; |
| 5233 | u8 v; |
| 5234 | |
| 5235 | /* Enable the TCs available on PF to all VEBs */ |
| 5236 | tc_map = i40e_pf_get_tc_map(pf); |
| 5237 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 5238 | if (!pf->veb[v]) |
| 5239 | continue; |
| 5240 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 5241 | if (ret) { |
| 5242 | dev_info(&pf->pdev->dev, |
| 5243 | "Failed configuring TC for VEB seid=%d\n", |
| 5244 | pf->veb[v]->seid); |
| 5245 | /* Will try to configure as many components */ |
| 5246 | } |
| 5247 | } |
| 5248 | |
| 5249 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5250 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5251 | if (!pf->vsi[v]) |
| 5252 | continue; |
| 5253 | |
| 5254 | /* - Enable all TCs for the LAN VSI |
| 5255 | * - For all others keep them at TC0 for now |
| 5256 | */ |
| 5257 | if (v == pf->lan_vsi) |
| 5258 | tc_map = i40e_pf_get_tc_map(pf); |
| 5259 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5260 | tc_map = I40E_DEFAULT_TRAFFIC_CLASS; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5261 | |
| 5262 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 5263 | if (ret) { |
| 5264 | dev_info(&pf->pdev->dev, |
| 5265 | "Failed configuring TC for VSI seid=%d\n", |
| 5266 | pf->vsi[v]->seid); |
| 5267 | /* Will try to configure as many components */ |
| 5268 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 5269 | /* Re-configure VSI vectors based on updated TC map */ |
| 5270 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5271 | if (pf->vsi[v]->netdev) |
| 5272 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 5273 | } |
| 5274 | } |
| 5275 | } |
| 5276 | |
| 5277 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5278 | * i40e_resume_port_tx - Resume port Tx |
| 5279 | * @pf: PF struct |
| 5280 | * |
| 5281 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 5282 | * resume. |
| 5283 | **/ |
| 5284 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 5285 | { |
| 5286 | struct i40e_hw *hw = &pf->hw; |
| 5287 | int ret; |
| 5288 | |
| 5289 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 5290 | if (ret) { |
| 5291 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5292 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 5293 | i40e_stat_str(&pf->hw, ret), |
| 5294 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5295 | /* Schedule PF reset to recover */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5296 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5297 | i40e_service_event_schedule(pf); |
| 5298 | } |
| 5299 | |
| 5300 | return ret; |
| 5301 | } |
| 5302 | |
| 5303 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5304 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 5305 | * @pf: PF being configured |
| 5306 | * |
| 5307 | * Query the current DCB configuration and cache it |
| 5308 | * in the hardware structure |
| 5309 | **/ |
| 5310 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 5311 | { |
| 5312 | struct i40e_hw *hw = &pf->hw; |
| 5313 | int err = 0; |
| 5314 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5315 | /* 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] | 5316 | if (pf->hw_features & I40E_HW_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5317 | goto out; |
| 5318 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5319 | /* Get the initial DCB configuration */ |
| 5320 | err = i40e_init_dcb(hw); |
| 5321 | if (!err) { |
| 5322 | /* Device/Function is not DCBX capable */ |
| 5323 | if ((!hw->func_caps.dcb) || |
| 5324 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5325 | dev_info(&pf->pdev->dev, |
| 5326 | "DCBX offload is not supported or is disabled for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5327 | } else { |
| 5328 | /* When status is not DISABLED then DCBX in FW */ |
| 5329 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5330 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5331 | |
| 5332 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5333 | /* Enable DCB tagging only when more than one TC |
| 5334 | * or explicitly disable if only one TC |
| 5335 | */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5336 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5337 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5338 | else |
| 5339 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5340 | dev_dbg(&pf->pdev->dev, |
| 5341 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5342 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5343 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5344 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5345 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5346 | i40e_stat_str(&pf->hw, err), |
| 5347 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | out: |
| 5351 | return err; |
| 5352 | } |
| 5353 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5354 | #define SPEED_SIZE 14 |
| 5355 | #define FC_SIZE 8 |
| 5356 | /** |
| 5357 | * i40e_print_link_message - print link up or down |
| 5358 | * @vsi: the VSI for which link needs a message |
| 5359 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5360 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5361 | { |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 5362 | enum i40e_aq_link_speed new_speed; |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 5363 | struct i40e_pf *pf = vsi->back; |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5364 | char *speed = "Unknown"; |
| 5365 | char *fc = "Unknown"; |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5366 | char *fec = ""; |
Mariusz Stachura | 68e4970 | 2017-07-12 05:46:14 -0400 | [diff] [blame] | 5367 | char *req_fec = ""; |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5368 | char *an = ""; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5369 | |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 5370 | new_speed = pf->hw.phy.link_info.link_speed; |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 5371 | |
| 5372 | if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed)) |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5373 | return; |
| 5374 | vsi->current_isup = isup; |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 5375 | vsi->current_speed = new_speed; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5376 | if (!isup) { |
| 5377 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5378 | return; |
| 5379 | } |
| 5380 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5381 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5382 | * least 10GB |
| 5383 | */ |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 5384 | if (pf->hw.func_caps.npar_enable && |
| 5385 | (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5386 | pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5387 | netdev_warn(vsi->netdev, |
| 5388 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5389 | |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 5390 | switch (pf->hw.phy.link_info.link_speed) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5391 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5392 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5393 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5394 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5395 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5396 | break; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 5397 | case I40E_LINK_SPEED_25GB: |
| 5398 | speed = "25 G"; |
| 5399 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5400 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5401 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5402 | break; |
| 5403 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5404 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5405 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5406 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5407 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5408 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5409 | default: |
| 5410 | break; |
| 5411 | } |
| 5412 | |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 5413 | switch (pf->hw.fc.current_mode) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5414 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5415 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5416 | break; |
| 5417 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5418 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5419 | break; |
| 5420 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5421 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5422 | break; |
| 5423 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5424 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5425 | break; |
| 5426 | } |
| 5427 | |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 5428 | if (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) { |
Mariusz Stachura | 68e4970 | 2017-07-12 05:46:14 -0400 | [diff] [blame] | 5429 | req_fec = ", Requested FEC: None"; |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5430 | fec = ", FEC: None"; |
| 5431 | an = ", Autoneg: False"; |
| 5432 | |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 5433 | if (pf->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED) |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5434 | an = ", Autoneg: True"; |
| 5435 | |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 5436 | if (pf->hw.phy.link_info.fec_info & |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5437 | I40E_AQ_CONFIG_FEC_KR_ENA) |
| 5438 | fec = ", FEC: CL74 FC-FEC/BASE-R"; |
Sudheer Mogilappagari | 3fded46 | 2017-07-14 09:10:18 -0400 | [diff] [blame] | 5439 | else if (pf->hw.phy.link_info.fec_info & |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5440 | I40E_AQ_CONFIG_FEC_RS_ENA) |
| 5441 | fec = ", FEC: CL108 RS-FEC"; |
Mariusz Stachura | 68e4970 | 2017-07-12 05:46:14 -0400 | [diff] [blame] | 5442 | |
| 5443 | /* 'CL108 RS-FEC' should be displayed when RS is requested, or |
| 5444 | * both RS and FC are requested |
| 5445 | */ |
| 5446 | if (vsi->back->hw.phy.link_info.req_fec_info & |
| 5447 | (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS)) { |
| 5448 | if (vsi->back->hw.phy.link_info.req_fec_info & |
| 5449 | I40E_AQ_REQUEST_FEC_RS) |
| 5450 | req_fec = ", Requested FEC: CL108 RS-FEC"; |
| 5451 | else |
| 5452 | req_fec = ", Requested FEC: CL74 FC-FEC/BASE-R"; |
| 5453 | } |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5454 | } |
| 5455 | |
Mariusz Stachura | 68e4970 | 2017-07-12 05:46:14 -0400 | [diff] [blame] | 5456 | netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s%s, Flow Control: %s\n", |
| 5457 | speed, req_fec, fec, an, fc); |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5458 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5459 | |
| 5460 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5461 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5462 | * @vsi: the VSI being configured |
| 5463 | **/ |
| 5464 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5465 | { |
| 5466 | struct i40e_pf *pf = vsi->back; |
| 5467 | int err; |
| 5468 | |
| 5469 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5470 | i40e_vsi_configure_msix(vsi); |
| 5471 | else |
| 5472 | i40e_configure_msi_and_legacy(vsi); |
| 5473 | |
| 5474 | /* start rings */ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 5475 | err = i40e_vsi_start_rings(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5476 | if (err) |
| 5477 | return err; |
| 5478 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5479 | clear_bit(__I40E_VSI_DOWN, vsi->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5480 | i40e_napi_enable_all(vsi); |
| 5481 | i40e_vsi_enable_irq(vsi); |
| 5482 | |
| 5483 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5484 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5485 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5486 | netif_tx_start_all_queues(vsi->netdev); |
| 5487 | netif_carrier_on(vsi->netdev); |
| 5488 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5489 | |
| 5490 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5491 | if (vsi->type == I40E_VSI_FDIR) { |
| 5492 | /* reset fd counters */ |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5493 | pf->fd_add_err = 0; |
| 5494 | pf->fd_atr_cnt = 0; |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5495 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5496 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5497 | |
| 5498 | /* On the next run of the service_task, notify any clients of the new |
| 5499 | * opened netdev |
| 5500 | */ |
| 5501 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5502 | i40e_service_event_schedule(pf); |
| 5503 | |
| 5504 | return 0; |
| 5505 | } |
| 5506 | |
| 5507 | /** |
| 5508 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5509 | * @vsi: the VSI being configured |
| 5510 | * |
| 5511 | * Rebuild the ring structs after some configuration |
| 5512 | * has changed, e.g. MTU size. |
| 5513 | **/ |
| 5514 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5515 | { |
| 5516 | struct i40e_pf *pf = vsi->back; |
| 5517 | |
| 5518 | WARN_ON(in_interrupt()); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5519 | while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5520 | usleep_range(1000, 2000); |
| 5521 | i40e_down(vsi); |
| 5522 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5523 | i40e_up(vsi); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5524 | clear_bit(__I40E_CONFIG_BUSY, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | /** |
| 5528 | * i40e_up - Bring the connection back up after being down |
| 5529 | * @vsi: the VSI being configured |
| 5530 | **/ |
| 5531 | int i40e_up(struct i40e_vsi *vsi) |
| 5532 | { |
| 5533 | int err; |
| 5534 | |
| 5535 | err = i40e_vsi_configure(vsi); |
| 5536 | if (!err) |
| 5537 | err = i40e_up_complete(vsi); |
| 5538 | |
| 5539 | return err; |
| 5540 | } |
| 5541 | |
| 5542 | /** |
| 5543 | * i40e_down - Shutdown the connection processing |
| 5544 | * @vsi: the VSI being stopped |
| 5545 | **/ |
| 5546 | void i40e_down(struct i40e_vsi *vsi) |
| 5547 | { |
| 5548 | int i; |
| 5549 | |
| 5550 | /* It is assumed that the caller of this function |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 5551 | * sets the vsi->state __I40E_VSI_DOWN bit. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5552 | */ |
| 5553 | if (vsi->netdev) { |
| 5554 | netif_carrier_off(vsi->netdev); |
| 5555 | netif_tx_disable(vsi->netdev); |
| 5556 | } |
| 5557 | i40e_vsi_disable_irq(vsi); |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 5558 | i40e_vsi_stop_rings(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5559 | i40e_napi_disable_all(vsi); |
| 5560 | |
| 5561 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5562 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 5563 | if (i40e_enabled_xdp_vsi(vsi)) |
| 5564 | i40e_clean_tx_ring(vsi->xdp_rings[i]); |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5565 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5566 | } |
Catherine Sullivan | f980d44 | 2016-05-16 10:26:34 -0700 | [diff] [blame] | 5567 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | /** |
| 5571 | * i40e_setup_tc - configure multiple traffic classes |
| 5572 | * @netdev: net device to configure |
| 5573 | * @tc: number of traffic classes to enable |
| 5574 | **/ |
| 5575 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5576 | { |
| 5577 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5578 | struct i40e_vsi *vsi = np->vsi; |
| 5579 | struct i40e_pf *pf = vsi->back; |
| 5580 | u8 enabled_tc = 0; |
| 5581 | int ret = -EINVAL; |
| 5582 | int i; |
| 5583 | |
| 5584 | /* Check if DCB enabled to continue */ |
| 5585 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5586 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5587 | goto exit; |
| 5588 | } |
| 5589 | |
| 5590 | /* Check if MFP enabled */ |
| 5591 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5592 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5593 | goto exit; |
| 5594 | } |
| 5595 | |
| 5596 | /* Check whether tc count is within enabled limit */ |
| 5597 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5598 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5599 | goto exit; |
| 5600 | } |
| 5601 | |
| 5602 | /* Generate TC map for number of tc requested */ |
| 5603 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5604 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5605 | |
| 5606 | /* Requesting same TC configuration as already enabled */ |
| 5607 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5608 | return 0; |
| 5609 | |
| 5610 | /* Quiesce VSI queues */ |
| 5611 | i40e_quiesce_vsi(vsi); |
| 5612 | |
| 5613 | /* Configure VSI for enabled TCs */ |
| 5614 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5615 | if (ret) { |
| 5616 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5617 | vsi->seid); |
| 5618 | goto exit; |
| 5619 | } |
| 5620 | |
| 5621 | /* Unquiesce VSI */ |
| 5622 | i40e_unquiesce_vsi(vsi); |
| 5623 | |
| 5624 | exit: |
| 5625 | return ret; |
| 5626 | } |
| 5627 | |
Jiri Pirko | 2572ac5 | 2017-08-07 10:15:17 +0200 | [diff] [blame] | 5628 | 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] | 5629 | void *type_data) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5630 | { |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 5631 | struct tc_mqprio_qopt *mqprio = type_data; |
| 5632 | |
Jiri Pirko | 2572ac5 | 2017-08-07 10:15:17 +0200 | [diff] [blame] | 5633 | if (type != TC_SETUP_MQPRIO) |
Jiri Pirko | 38cf042 | 2017-08-07 10:15:31 +0200 | [diff] [blame] | 5634 | return -EOPNOTSUPP; |
Amritha Nambiar | 56f36ac | 2017-03-15 10:39:25 -0700 | [diff] [blame] | 5635 | |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 5636 | mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS; |
Amritha Nambiar | 56f36ac | 2017-03-15 10:39:25 -0700 | [diff] [blame] | 5637 | |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 5638 | return i40e_setup_tc(netdev, mqprio->num_tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5639 | } |
| 5640 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5641 | /** |
| 5642 | * i40e_open - Called when a network interface is made active |
| 5643 | * @netdev: network interface device structure |
| 5644 | * |
| 5645 | * The open entry point is called when a network interface is made |
| 5646 | * active by the system (IFF_UP). At this point all resources needed |
| 5647 | * for transmit and receive operations are allocated, the interrupt |
| 5648 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5649 | * enabled, and the stack is notified that the interface is ready. |
| 5650 | * |
| 5651 | * Returns 0 on success, negative value on failure |
| 5652 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5653 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5654 | { |
| 5655 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5656 | struct i40e_vsi *vsi = np->vsi; |
| 5657 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5658 | int err; |
| 5659 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5660 | /* disallow open during test or if eeprom is broken */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5661 | if (test_bit(__I40E_TESTING, pf->state) || |
| 5662 | test_bit(__I40E_BAD_EEPROM, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5663 | return -EBUSY; |
| 5664 | |
| 5665 | netif_carrier_off(netdev); |
| 5666 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5667 | err = i40e_vsi_open(vsi); |
| 5668 | if (err) |
| 5669 | return err; |
| 5670 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5671 | /* configure global TSO hardware offload settings */ |
| 5672 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5673 | TCP_FLAG_FIN) >> 16); |
| 5674 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5675 | TCP_FLAG_FIN | |
| 5676 | TCP_FLAG_CWR) >> 16); |
| 5677 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5678 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 5679 | udp_tunnel_get_rx_info(netdev); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5680 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5681 | return 0; |
| 5682 | } |
| 5683 | |
| 5684 | /** |
| 5685 | * i40e_vsi_open - |
| 5686 | * @vsi: the VSI to open |
| 5687 | * |
| 5688 | * Finish initialization of the VSI. |
| 5689 | * |
| 5690 | * Returns 0 on success, negative value on failure |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 5691 | * |
| 5692 | * Note: expects to be called while under rtnl_lock() |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5693 | **/ |
| 5694 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5695 | { |
| 5696 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5697 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5698 | int err; |
| 5699 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5700 | /* allocate descriptors */ |
| 5701 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5702 | if (err) |
| 5703 | goto err_setup_tx; |
| 5704 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5705 | if (err) |
| 5706 | goto err_setup_rx; |
| 5707 | |
| 5708 | err = i40e_vsi_configure(vsi); |
| 5709 | if (err) |
| 5710 | goto err_setup_rx; |
| 5711 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5712 | if (vsi->netdev) { |
| 5713 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5714 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5715 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5716 | if (err) |
| 5717 | goto err_setup_rx; |
| 5718 | |
| 5719 | /* Notify the stack of the actual queue counts. */ |
| 5720 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5721 | vsi->num_queue_pairs); |
| 5722 | if (err) |
| 5723 | goto err_set_queues; |
| 5724 | |
| 5725 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5726 | vsi->num_queue_pairs); |
| 5727 | if (err) |
| 5728 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5729 | |
| 5730 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5731 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5732 | dev_driver_string(&pf->pdev->dev), |
| 5733 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5734 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5735 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5736 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5737 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5738 | goto err_setup_rx; |
| 5739 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5740 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5741 | err = i40e_up_complete(vsi); |
| 5742 | if (err) |
| 5743 | goto err_up_complete; |
| 5744 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5745 | return 0; |
| 5746 | |
| 5747 | err_up_complete: |
| 5748 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5749 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5750 | i40e_vsi_free_irq(vsi); |
| 5751 | err_setup_rx: |
| 5752 | i40e_vsi_free_rx_resources(vsi); |
| 5753 | err_setup_tx: |
| 5754 | i40e_vsi_free_tx_resources(vsi); |
| 5755 | if (vsi == pf->vsi[pf->lan_vsi]) |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 5756 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED), true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5757 | |
| 5758 | return err; |
| 5759 | } |
| 5760 | |
| 5761 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5762 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5763 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5764 | * |
| 5765 | * This function destroys the hlist where all the Flow Director |
| 5766 | * filters were saved. |
| 5767 | **/ |
| 5768 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5769 | { |
| 5770 | struct i40e_fdir_filter *filter; |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame] | 5771 | struct i40e_flex_pit *pit_entry, *tmp; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5772 | struct hlist_node *node2; |
| 5773 | |
| 5774 | hlist_for_each_entry_safe(filter, node2, |
| 5775 | &pf->fdir_filter_list, fdir_node) { |
| 5776 | hlist_del(&filter->fdir_node); |
| 5777 | kfree(filter); |
| 5778 | } |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5779 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame] | 5780 | list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) { |
| 5781 | list_del(&pit_entry->list); |
| 5782 | kfree(pit_entry); |
| 5783 | } |
| 5784 | INIT_LIST_HEAD(&pf->l3_flex_pit_list); |
| 5785 | |
| 5786 | list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) { |
| 5787 | list_del(&pit_entry->list); |
| 5788 | kfree(pit_entry); |
| 5789 | } |
| 5790 | INIT_LIST_HEAD(&pf->l4_flex_pit_list); |
| 5791 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5792 | pf->fdir_pf_active_filters = 0; |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5793 | pf->fd_tcp4_filter_cnt = 0; |
| 5794 | pf->fd_udp4_filter_cnt = 0; |
Jacob Keller | f223c87 | 2017-02-06 14:38:51 -0800 | [diff] [blame] | 5795 | pf->fd_sctp4_filter_cnt = 0; |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5796 | pf->fd_ip4_filter_cnt = 0; |
Jacob Keller | 3bcee1e | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5797 | |
| 5798 | /* Reprogram the default input set for TCP/IPv4 */ |
| 5799 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP, |
| 5800 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | |
| 5801 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); |
| 5802 | |
| 5803 | /* Reprogram the default input set for UDP/IPv4 */ |
| 5804 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP, |
| 5805 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | |
| 5806 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); |
| 5807 | |
| 5808 | /* Reprogram the default input set for SCTP/IPv4 */ |
| 5809 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP, |
| 5810 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | |
| 5811 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); |
| 5812 | |
| 5813 | /* Reprogram the default input set for Other/IPv4 */ |
| 5814 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER, |
| 5815 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5819 | * i40e_close - Disables a network interface |
| 5820 | * @netdev: network interface device structure |
| 5821 | * |
| 5822 | * The close entry point is called when an interface is de-activated |
| 5823 | * by the OS. The hardware is still under the driver's control, but |
| 5824 | * this netdev interface is disabled. |
| 5825 | * |
| 5826 | * Returns 0, this is not allowed to fail |
| 5827 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5828 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5829 | { |
| 5830 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5831 | struct i40e_vsi *vsi = np->vsi; |
| 5832 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5833 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5834 | |
| 5835 | return 0; |
| 5836 | } |
| 5837 | |
| 5838 | /** |
| 5839 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5840 | * @pf: board private structure |
| 5841 | * @reset_flags: which reset is requested |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 5842 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 5843 | * before this function was called. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5844 | * |
| 5845 | * The essential difference in resets is that the PF Reset |
| 5846 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5847 | * firmware, and doesn't bother the other PFs on the chip. |
| 5848 | **/ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 5849 | 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] | 5850 | { |
| 5851 | u32 val; |
| 5852 | |
| 5853 | WARN_ON(in_interrupt()); |
| 5854 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5855 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5856 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5857 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5858 | |
| 5859 | /* Request a Global Reset |
| 5860 | * |
| 5861 | * This will start the chip's countdown to the actual full |
| 5862 | * chip reset event, and a warning interrupt to be sent |
| 5863 | * to all PFs, including the requestor. Our handler |
| 5864 | * for the warning interrupt will deal with the shutdown |
| 5865 | * and recovery of the switch setup. |
| 5866 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5867 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5868 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5869 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5870 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5871 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5872 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5873 | |
| 5874 | /* Request a Core Reset |
| 5875 | * |
| 5876 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5877 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5878 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5879 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5880 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5881 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5882 | i40e_flush(&pf->hw); |
| 5883 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5884 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5885 | |
| 5886 | /* Request a PF Reset |
| 5887 | * |
| 5888 | * Resets only the PF-specific registers |
| 5889 | * |
| 5890 | * This goes directly to the tear-down and rebuild of |
| 5891 | * the switch, since we need to do all the recovery as |
| 5892 | * for the Core Reset. |
| 5893 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5894 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 5895 | i40e_handle_reset_warning(pf, lock_acquired); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5896 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5897 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5898 | int v; |
| 5899 | |
| 5900 | /* Find the VSI(s) that requested a re-init */ |
| 5901 | dev_info(&pf->pdev->dev, |
| 5902 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5903 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5904 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5905 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5906 | if (vsi != NULL && |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 5907 | test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED, |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5908 | vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5909 | i40e_vsi_reinit_locked(pf->vsi[v]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5910 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5911 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5912 | int v; |
| 5913 | |
| 5914 | /* Find the VSI(s) that needs to be brought down */ |
| 5915 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5916 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5917 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5918 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5919 | if (vsi != NULL && |
Jacob Keller | d19cb64 | 2017-04-21 13:38:05 -0700 | [diff] [blame] | 5920 | test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED, |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 5921 | vsi->state)) { |
| 5922 | set_bit(__I40E_VSI_DOWN, vsi->state); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5923 | i40e_down(vsi); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5924 | } |
| 5925 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5926 | } else { |
| 5927 | dev_info(&pf->pdev->dev, |
| 5928 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5929 | } |
| 5930 | } |
| 5931 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5932 | #ifdef CONFIG_I40E_DCB |
| 5933 | /** |
| 5934 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5935 | * @pf: board private structure |
| 5936 | * @old_cfg: current DCB config |
| 5937 | * @new_cfg: new DCB config |
| 5938 | **/ |
| 5939 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5940 | struct i40e_dcbx_config *old_cfg, |
| 5941 | struct i40e_dcbx_config *new_cfg) |
| 5942 | { |
| 5943 | bool need_reconfig = false; |
| 5944 | |
| 5945 | /* Check if ETS configuration has changed */ |
| 5946 | if (memcmp(&new_cfg->etscfg, |
| 5947 | &old_cfg->etscfg, |
| 5948 | sizeof(new_cfg->etscfg))) { |
| 5949 | /* If Priority Table has changed reconfig is needed */ |
| 5950 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5951 | &old_cfg->etscfg.prioritytable, |
| 5952 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5953 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5954 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5955 | } |
| 5956 | |
| 5957 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5958 | &old_cfg->etscfg.tcbwtable, |
| 5959 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5960 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5961 | |
| 5962 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5963 | &old_cfg->etscfg.tsatable, |
| 5964 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5965 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | /* Check if PFC configuration has changed */ |
| 5969 | if (memcmp(&new_cfg->pfc, |
| 5970 | &old_cfg->pfc, |
| 5971 | sizeof(new_cfg->pfc))) { |
| 5972 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5973 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | /* Check if APP Table has changed */ |
| 5977 | if (memcmp(&new_cfg->app, |
| 5978 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5979 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5980 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5981 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5982 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5983 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5984 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5985 | return need_reconfig; |
| 5986 | } |
| 5987 | |
| 5988 | /** |
| 5989 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5990 | * @pf: board private structure |
| 5991 | * @e: event info posted on ARQ |
| 5992 | **/ |
| 5993 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5994 | struct i40e_arq_event_info *e) |
| 5995 | { |
| 5996 | struct i40e_aqc_lldp_get_mib *mib = |
| 5997 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5998 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5999 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 6000 | bool need_reconfig = false; |
| 6001 | int ret = 0; |
| 6002 | u8 type; |
| 6003 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 6004 | /* Not DCB capable or capability disabled */ |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 6005 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 6006 | return ret; |
| 6007 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6008 | /* Ignore if event is not for Nearest Bridge */ |
| 6009 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 6010 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 6011 | 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] | 6012 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 6013 | return ret; |
| 6014 | |
| 6015 | /* Check MIB Type and return if event for Remote MIB update */ |
| 6016 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 6017 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 6018 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6019 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 6020 | /* Update the remote cached instance and return */ |
| 6021 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 6022 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 6023 | &hw->remote_dcbx_config); |
| 6024 | goto exit; |
| 6025 | } |
| 6026 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 6027 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 6028 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 6029 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 6030 | /* Reset the old DCBx configuration data */ |
| 6031 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 6032 | /* Get updated DCBX data from firmware */ |
| 6033 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6034 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6035 | dev_info(&pf->pdev->dev, |
| 6036 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 6037 | i40e_stat_str(&pf->hw, ret), |
| 6038 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6039 | goto exit; |
| 6040 | } |
| 6041 | |
| 6042 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 6043 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 6044 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6045 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6046 | goto exit; |
| 6047 | } |
| 6048 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 6049 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 6050 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6051 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 6052 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6053 | |
| 6054 | if (!need_reconfig) |
| 6055 | goto exit; |
| 6056 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 6057 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 6058 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 6059 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 6060 | else |
| 6061 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 6062 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6063 | set_bit(__I40E_PORT_SUSPENDED, pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6064 | /* Reconfiguration needed quiesce all VSIs */ |
| 6065 | i40e_pf_quiesce_all_vsi(pf); |
| 6066 | |
| 6067 | /* Changes in configuration update VEB/VSI */ |
| 6068 | i40e_dcb_reconfigure(pf); |
| 6069 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 6070 | ret = i40e_resume_port_tx(pf); |
| 6071 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6072 | clear_bit(__I40E_PORT_SUSPENDED, pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 6073 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 6074 | if (ret) |
| 6075 | goto exit; |
| 6076 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 6077 | /* Wait for the PF's queues to be disabled */ |
| 6078 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 6079 | if (ret) { |
| 6080 | /* Schedule PF reset to recover */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6081 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 6082 | i40e_service_event_schedule(pf); |
| 6083 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 6084 | i40e_pf_unquiesce_all_vsi(pf); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 6085 | pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED | |
| 6086 | I40E_FLAG_CLIENT_L2_CHANGE); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 6087 | } |
| 6088 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6089 | exit: |
| 6090 | return ret; |
| 6091 | } |
| 6092 | #endif /* CONFIG_I40E_DCB */ |
| 6093 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6094 | /** |
Anjali Singhai Jain | 23326186 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6095 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 6096 | * @pf: board private structure |
| 6097 | * @reset_flags: which reset is requested |
| 6098 | * |
| 6099 | **/ |
| 6100 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 6101 | { |
| 6102 | rtnl_lock(); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 6103 | i40e_do_reset(pf, reset_flags, true); |
Anjali Singhai Jain | 23326186 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6104 | rtnl_unlock(); |
| 6105 | } |
| 6106 | |
| 6107 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6108 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 6109 | * @pf: board private structure |
| 6110 | * @e: event info posted on ARQ |
| 6111 | * |
| 6112 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 6113 | * and VF queues |
| 6114 | **/ |
| 6115 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 6116 | struct i40e_arq_event_info *e) |
| 6117 | { |
| 6118 | struct i40e_aqc_lan_overflow *data = |
| 6119 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 6120 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 6121 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 6122 | struct i40e_hw *hw = &pf->hw; |
| 6123 | struct i40e_vf *vf; |
| 6124 | u16 vf_id; |
| 6125 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6126 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 6127 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6128 | |
| 6129 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 6130 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 6131 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 6132 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 6133 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 6134 | vf_id -= hw->func_caps.vf_base_id; |
| 6135 | vf = &pf->vf[vf_id]; |
| 6136 | i40e_vc_notify_vf_reset(vf); |
| 6137 | /* Allow VF to process pending reset notification */ |
| 6138 | msleep(20); |
| 6139 | i40e_reset_vf(vf, false); |
| 6140 | } |
| 6141 | } |
| 6142 | |
| 6143 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6144 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 6145 | * @pf: board private structure |
| 6146 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6147 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6148 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6149 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6150 | |
| 6151 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 6152 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 6153 | return fcnt_prog; |
| 6154 | } |
| 6155 | |
| 6156 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6157 | * 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] | 6158 | * @pf: board private structure |
| 6159 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6160 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6161 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6162 | u32 val, fcnt_prog; |
| 6163 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6164 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 6165 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 6166 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 6167 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 6168 | return fcnt_prog; |
| 6169 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6170 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6171 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6172 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 6173 | * @pf: board private structure |
| 6174 | **/ |
| 6175 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 6176 | { |
| 6177 | u32 val, fcnt_prog; |
| 6178 | |
| 6179 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 6180 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 6181 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 6182 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 6183 | return fcnt_prog; |
| 6184 | } |
| 6185 | |
| 6186 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6187 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 6188 | * @pf: board private structure |
| 6189 | **/ |
| 6190 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 6191 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6192 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6193 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6194 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6195 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6196 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6197 | return; |
| 6198 | |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 6199 | /* 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] | 6200 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6201 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6202 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 6203 | (pf->fd_add_err == 0) || |
| 6204 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 6205 | if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED) { |
| 6206 | pf->flags &= ~I40E_FLAG_FD_SB_AUTO_DISABLED; |
| 6207 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 6208 | (I40E_DEBUG_FD & pf->hw.debug_mask)) |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 6209 | 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] | 6210 | } |
| 6211 | } |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6212 | |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 6213 | /* We should wait for even more space before re-enabling ATR. |
| 6214 | * Additionally, we cannot enable ATR as long as we still have TCP SB |
| 6215 | * rules active. |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6216 | */ |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 6217 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) && |
| 6218 | (pf->fd_tcp4_filter_cnt == 0)) { |
| 6219 | if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) { |
| 6220 | pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED; |
| 6221 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 6222 | (I40E_DEBUG_FD & pf->hw.debug_mask)) |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6223 | 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] | 6224 | } |
| 6225 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6226 | |
| 6227 | /* if hw had a problem adding a filter, delete it */ |
| 6228 | if (pf->fd_inv > 0) { |
| 6229 | hlist_for_each_entry_safe(filter, node, |
| 6230 | &pf->fdir_filter_list, fdir_node) { |
| 6231 | if (filter->fd_id == pf->fd_inv) { |
| 6232 | hlist_del(&filter->fdir_node); |
| 6233 | kfree(filter); |
| 6234 | pf->fdir_pf_active_filters--; |
Filip Sadowski | 013df59 | 2017-08-29 05:32:38 -0400 | [diff] [blame] | 6235 | pf->fd_inv = 0; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6236 | } |
| 6237 | } |
| 6238 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6239 | } |
| 6240 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6241 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6242 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6243 | /** |
| 6244 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 6245 | * @pf: board private structure |
| 6246 | **/ |
| 6247 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 6248 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6249 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6250 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6251 | bool disable_atr = false; |
| 6252 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6253 | int reg; |
| 6254 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6255 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 6256 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 6257 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6258 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6259 | /* If the flush is happening too quick and we have mostly SB rules we |
| 6260 | * should not re-enable ATR for some time. |
| 6261 | */ |
| 6262 | min_flush_time = pf->fd_flush_timestamp + |
| 6263 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 6264 | 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] | 6265 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6266 | if (!(time_after(jiffies, min_flush_time)) && |
| 6267 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 6268 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6269 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 6270 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6271 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6272 | |
| 6273 | pf->fd_flush_timestamp = jiffies; |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 6274 | pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6275 | /* flush all filters */ |
| 6276 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 6277 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 6278 | i40e_flush(&pf->hw); |
| 6279 | pf->fd_flush_cnt++; |
| 6280 | pf->fd_add_err = 0; |
| 6281 | do { |
| 6282 | /* Check FD flush status every 5-6msec */ |
| 6283 | usleep_range(5000, 6000); |
| 6284 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 6285 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 6286 | break; |
| 6287 | } while (flush_wait_retry--); |
| 6288 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 6289 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 6290 | } else { |
| 6291 | /* replay sideband filters */ |
| 6292 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 6293 | if (!disable_atr && !pf->fd_tcp4_filter_cnt) |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 6294 | pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6295 | clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state); |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6296 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6297 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 6298 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | /** |
| 6302 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 6303 | * @pf: board private structure |
| 6304 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6305 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6306 | { |
| 6307 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 6308 | } |
| 6309 | |
| 6310 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 6311 | * being applied really fast; before we see the first |
| 6312 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 6313 | * reacting will make sure we don't cause flush too often. |
| 6314 | */ |
| 6315 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 6316 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6317 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6318 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 6319 | * @pf: board private structure |
| 6320 | **/ |
| 6321 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 6322 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6323 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6324 | /* if interface is down do nothing */ |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 6325 | if (test_bit(__I40E_DOWN, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6326 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6327 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6328 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6329 | i40e_fdir_flush_and_replay(pf); |
| 6330 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6331 | i40e_fdir_check_and_reenable(pf); |
| 6332 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6333 | } |
| 6334 | |
| 6335 | /** |
| 6336 | * i40e_vsi_link_event - notify VSI of a link event |
| 6337 | * @vsi: vsi to be notified |
| 6338 | * @link_up: link up or down |
| 6339 | **/ |
| 6340 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 6341 | { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6342 | if (!vsi || test_bit(__I40E_VSI_DOWN, vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6343 | return; |
| 6344 | |
| 6345 | switch (vsi->type) { |
| 6346 | case I40E_VSI_MAIN: |
| 6347 | if (!vsi->netdev || !vsi->netdev_registered) |
| 6348 | break; |
| 6349 | |
| 6350 | if (link_up) { |
| 6351 | netif_carrier_on(vsi->netdev); |
| 6352 | netif_tx_wake_all_queues(vsi->netdev); |
| 6353 | } else { |
| 6354 | netif_carrier_off(vsi->netdev); |
| 6355 | netif_tx_stop_all_queues(vsi->netdev); |
| 6356 | } |
| 6357 | break; |
| 6358 | |
| 6359 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6360 | case I40E_VSI_VMDQ2: |
| 6361 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6362 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6363 | case I40E_VSI_MIRROR: |
| 6364 | default: |
| 6365 | /* there is no notification for other VSIs */ |
| 6366 | break; |
| 6367 | } |
| 6368 | } |
| 6369 | |
| 6370 | /** |
| 6371 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6372 | * @veb: veb to be notified |
| 6373 | * @link_up: link up or down |
| 6374 | **/ |
| 6375 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6376 | { |
| 6377 | struct i40e_pf *pf; |
| 6378 | int i; |
| 6379 | |
| 6380 | if (!veb || !veb->pf) |
| 6381 | return; |
| 6382 | pf = veb->pf; |
| 6383 | |
| 6384 | /* depth first... */ |
| 6385 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6386 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6387 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6388 | |
| 6389 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6390 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6391 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6392 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6393 | } |
| 6394 | |
| 6395 | /** |
| 6396 | * i40e_link_event - Update netif_carrier status |
| 6397 | * @pf: board private structure |
| 6398 | **/ |
| 6399 | static void i40e_link_event(struct i40e_pf *pf) |
| 6400 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6401 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6402 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6403 | i40e_status status; |
| 6404 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6405 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6406 | /* save off old link status information */ |
| 6407 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6408 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6409 | /* set this to force the get_link_status call to refresh state */ |
| 6410 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6411 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6412 | 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] | 6413 | |
| 6414 | status = i40e_get_link_status(&pf->hw, &new_link); |
Harshitha Ramamurthy | ae13670 | 2016-12-12 15:44:16 -0800 | [diff] [blame] | 6415 | |
| 6416 | /* On success, disable temp link polling */ |
| 6417 | if (status == I40E_SUCCESS) { |
| 6418 | if (pf->flags & I40E_FLAG_TEMP_LINK_POLLING) |
| 6419 | pf->flags &= ~I40E_FLAG_TEMP_LINK_POLLING; |
| 6420 | } else { |
| 6421 | /* Enable link polling temporarily until i40e_get_link_status |
| 6422 | * returns I40E_SUCCESS |
| 6423 | */ |
| 6424 | pf->flags |= I40E_FLAG_TEMP_LINK_POLLING; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6425 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6426 | status); |
| 6427 | return; |
| 6428 | } |
| 6429 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6430 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6431 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6432 | |
| 6433 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6434 | new_link_speed == old_link_speed && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6435 | (test_bit(__I40E_VSI_DOWN, vsi->state) || |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6436 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6437 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6438 | |
Sudheer Mogilappagari | 9a03449 | 2017-07-14 09:10:16 -0400 | [diff] [blame] | 6439 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6440 | |
| 6441 | /* Notify the base of the switch tree connected to |
| 6442 | * the link. Floating VEBs are not notified. |
| 6443 | */ |
| 6444 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6445 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6446 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6447 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6448 | |
| 6449 | if (pf->vf) |
| 6450 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6451 | |
| 6452 | if (pf->flags & I40E_FLAG_PTP) |
| 6453 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6454 | } |
| 6455 | |
| 6456 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6457 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6458 | * @pf: board private structure |
| 6459 | **/ |
| 6460 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6461 | { |
| 6462 | int i; |
| 6463 | |
| 6464 | /* if interface is down do nothing */ |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 6465 | if (test_bit(__I40E_DOWN, pf->state) || |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6466 | test_bit(__I40E_CONFIG_BUSY, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6467 | return; |
| 6468 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6469 | /* make sure we don't do these things too often */ |
| 6470 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6471 | pf->service_timer_period))) |
| 6472 | return; |
| 6473 | pf->service_timer_previous = jiffies; |
| 6474 | |
Harshitha Ramamurthy | ae13670 | 2016-12-12 15:44:16 -0800 | [diff] [blame] | 6475 | if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) || |
| 6476 | (pf->flags & I40E_FLAG_TEMP_LINK_POLLING)) |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6477 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6478 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6479 | /* Update the stats for active netdevs so the network stack |
| 6480 | * can look at updated numbers whenever it cares to |
| 6481 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6482 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6483 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6484 | i40e_update_stats(pf->vsi[i]); |
| 6485 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6486 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6487 | /* Update the stats for the active switching components */ |
| 6488 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6489 | if (pf->veb[i]) |
| 6490 | i40e_update_veb_stats(pf->veb[i]); |
| 6491 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6492 | |
Jacob Keller | 6118955 | 2017-05-03 10:29:01 -0700 | [diff] [blame] | 6493 | i40e_ptp_rx_hang(pf); |
Jacob Keller | 0bc0706 | 2017-05-03 10:29:02 -0700 | [diff] [blame] | 6494 | i40e_ptp_tx_hang(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6495 | } |
| 6496 | |
| 6497 | /** |
| 6498 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6499 | * @pf: board private structure |
| 6500 | **/ |
| 6501 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6502 | { |
| 6503 | u32 reset_flags = 0; |
| 6504 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6505 | if (test_bit(__I40E_REINIT_REQUESTED, pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6506 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6507 | clear_bit(__I40E_REINIT_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6508 | } |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6509 | if (test_bit(__I40E_PF_RESET_REQUESTED, pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6510 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6511 | clear_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6512 | } |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6513 | if (test_bit(__I40E_CORE_RESET_REQUESTED, pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6514 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6515 | clear_bit(__I40E_CORE_RESET_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6516 | } |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6517 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6518 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6519 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6520 | } |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 6521 | if (test_bit(__I40E_DOWN_REQUESTED, pf->state)) { |
| 6522 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
| 6523 | clear_bit(__I40E_DOWN_REQUESTED, pf->state); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6524 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6525 | |
| 6526 | /* If there's a recovery already waiting, it takes |
| 6527 | * precedence before starting a new reset sequence. |
| 6528 | */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6529 | if (test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) { |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 6530 | i40e_prep_for_reset(pf, false); |
| 6531 | i40e_reset(pf); |
| 6532 | i40e_rebuild(pf, false, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6533 | } |
| 6534 | |
| 6535 | /* If we're already down or resetting, just bail */ |
| 6536 | if (reset_flags && |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 6537 | !test_bit(__I40E_DOWN, pf->state) && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6538 | !test_bit(__I40E_CONFIG_BUSY, pf->state)) { |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 6539 | i40e_do_reset(pf, reset_flags, false); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 6540 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6541 | } |
| 6542 | |
| 6543 | /** |
| 6544 | * i40e_handle_link_event - Handle link event |
| 6545 | * @pf: board private structure |
| 6546 | * @e: event info posted on ARQ |
| 6547 | **/ |
| 6548 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6549 | struct i40e_arq_event_info *e) |
| 6550 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6551 | struct i40e_aqc_get_link_status *status = |
| 6552 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6553 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6554 | /* Do a new status request to re-enable LSE reporting |
| 6555 | * and load new status information into the hw struct |
| 6556 | * This completely ignores any state information |
| 6557 | * in the ARQ event info, instead choosing to always |
| 6558 | * issue the AQ update link status command. |
| 6559 | */ |
| 6560 | i40e_link_event(pf); |
| 6561 | |
Filip Sadowski | 9a85817 | 2017-08-29 05:32:37 -0400 | [diff] [blame] | 6562 | /* Check if module meets thermal requirements */ |
| 6563 | if (status->phy_type == I40E_PHY_TYPE_NOT_SUPPORTED_HIGH_TEMP) { |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6564 | dev_err(&pf->pdev->dev, |
Filip Sadowski | 9a85817 | 2017-08-29 05:32:37 -0400 | [diff] [blame] | 6565 | "Rx/Tx is disabled on this device because the module does not meet thermal requirements.\n"); |
| 6566 | dev_err(&pf->pdev->dev, |
| 6567 | "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n"); |
| 6568 | } else { |
| 6569 | /* check for unqualified module, if link is down, suppress |
| 6570 | * the message if link was forced to be down. |
| 6571 | */ |
| 6572 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6573 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6574 | (!(status->link_info & I40E_AQ_LINK_UP)) && |
| 6575 | (!(pf->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED))) { |
| 6576 | dev_err(&pf->pdev->dev, |
| 6577 | "Rx/Tx is disabled on this device because an unsupported SFP module type was detected.\n"); |
| 6578 | dev_err(&pf->pdev->dev, |
| 6579 | "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n"); |
| 6580 | } |
| 6581 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6582 | } |
| 6583 | |
| 6584 | /** |
| 6585 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6586 | * @pf: board private structure |
| 6587 | **/ |
| 6588 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6589 | { |
| 6590 | struct i40e_arq_event_info event; |
| 6591 | struct i40e_hw *hw = &pf->hw; |
| 6592 | u16 pending, i = 0; |
| 6593 | i40e_status ret; |
| 6594 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6595 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6596 | u32 val; |
| 6597 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6598 | /* Do not run clean AQ when PF reset fails */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6599 | if (test_bit(__I40E_RESET_FAILED, pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6600 | return; |
| 6601 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6602 | /* check for error indications */ |
| 6603 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6604 | oldval = val; |
| 6605 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6606 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6607 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6608 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6609 | } |
| 6610 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6611 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6612 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6613 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6614 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6615 | } |
| 6616 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6617 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6618 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6619 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6620 | } |
| 6621 | if (oldval != val) |
| 6622 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6623 | |
| 6624 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6625 | oldval = val; |
| 6626 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6627 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6628 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6629 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6630 | } |
| 6631 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6632 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6633 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6634 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6635 | } |
| 6636 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6637 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6638 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6639 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6640 | } |
| 6641 | if (oldval != val) |
| 6642 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6643 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6644 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6645 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6646 | if (!event.msg_buf) |
| 6647 | return; |
| 6648 | |
| 6649 | do { |
| 6650 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6651 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6652 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6653 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6654 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6655 | break; |
| 6656 | } |
| 6657 | |
| 6658 | opcode = le16_to_cpu(event.desc.opcode); |
| 6659 | switch (opcode) { |
| 6660 | |
| 6661 | case i40e_aqc_opc_get_link_status: |
| 6662 | i40e_handle_link_event(pf, &event); |
| 6663 | break; |
| 6664 | case i40e_aqc_opc_send_msg_to_pf: |
| 6665 | ret = i40e_vc_process_vf_msg(pf, |
| 6666 | le16_to_cpu(event.desc.retval), |
| 6667 | le32_to_cpu(event.desc.cookie_high), |
| 6668 | le32_to_cpu(event.desc.cookie_low), |
| 6669 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6670 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6671 | break; |
| 6672 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6673 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6674 | #ifdef CONFIG_I40E_DCB |
| 6675 | rtnl_lock(); |
| 6676 | ret = i40e_handle_lldp_event(pf, &event); |
| 6677 | rtnl_unlock(); |
| 6678 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6679 | break; |
| 6680 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6681 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6682 | i40e_handle_lan_overflow_event(pf, &event); |
| 6683 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6684 | case i40e_aqc_opc_send_msg_to_peer: |
| 6685 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6686 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6687 | case i40e_aqc_opc_nvm_erase: |
| 6688 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6689 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 6690 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 6691 | "ARQ NVM operation 0x%04x completed\n", |
| 6692 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6693 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6694 | default: |
| 6695 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 6696 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6697 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6698 | break; |
| 6699 | } |
Christopher N Bednarz | 1fca326 | 2017-03-10 12:22:03 -0800 | [diff] [blame] | 6700 | } while (i++ < pf->adminq_work_limit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6701 | |
Christopher N Bednarz | 1fca326 | 2017-03-10 12:22:03 -0800 | [diff] [blame] | 6702 | if (i < pf->adminq_work_limit) |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6703 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state); |
Christopher N Bednarz | 1fca326 | 2017-03-10 12:22:03 -0800 | [diff] [blame] | 6704 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6705 | /* re-enable Admin queue interrupt cause */ |
| 6706 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6707 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6708 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6709 | i40e_flush(hw); |
| 6710 | |
| 6711 | kfree(event.msg_buf); |
| 6712 | } |
| 6713 | |
| 6714 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6715 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6716 | * @pf: board private structure |
| 6717 | **/ |
| 6718 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6719 | { |
| 6720 | int err; |
| 6721 | |
| 6722 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6723 | if (err) { |
| 6724 | /* retry in case of garbage read */ |
| 6725 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6726 | if (err) { |
| 6727 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6728 | err); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6729 | set_bit(__I40E_BAD_EEPROM, pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6730 | } |
| 6731 | } |
| 6732 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 6733 | if (!err && test_bit(__I40E_BAD_EEPROM, pf->state)) { |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6734 | 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] | 6735 | clear_bit(__I40E_BAD_EEPROM, pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6736 | } |
| 6737 | } |
| 6738 | |
| 6739 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6740 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6741 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6742 | * |
| 6743 | * enable switch loop back or die - no point in a return value |
| 6744 | **/ |
| 6745 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6746 | { |
| 6747 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6748 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6749 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6750 | |
| 6751 | ctxt.seid = pf->main_vsi_seid; |
| 6752 | ctxt.pf_num = pf->hw.pf_id; |
| 6753 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6754 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6755 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6756 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6757 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6758 | i40e_stat_str(&pf->hw, ret), |
| 6759 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6760 | return; |
| 6761 | } |
| 6762 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6763 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6764 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6765 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6766 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6767 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6768 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6769 | "update vsi switch failed, err %s aq_err %s\n", |
| 6770 | i40e_stat_str(&pf->hw, ret), |
| 6771 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6772 | } |
| 6773 | } |
| 6774 | |
| 6775 | /** |
| 6776 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6777 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6778 | * |
| 6779 | * disable switch loop back or die - no point in a return value |
| 6780 | **/ |
| 6781 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6782 | { |
| 6783 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6784 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6785 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6786 | |
| 6787 | ctxt.seid = pf->main_vsi_seid; |
| 6788 | ctxt.pf_num = pf->hw.pf_id; |
| 6789 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6790 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6791 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6792 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6793 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6794 | i40e_stat_str(&pf->hw, ret), |
| 6795 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6796 | return; |
| 6797 | } |
| 6798 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6799 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6800 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6801 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6802 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6803 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6804 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6805 | "update vsi switch failed, err %s aq_err %s\n", |
| 6806 | i40e_stat_str(&pf->hw, ret), |
| 6807 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6808 | } |
| 6809 | } |
| 6810 | |
| 6811 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6812 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6813 | * @veb: pointer to the bridge instance |
| 6814 | * |
| 6815 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6816 | * specified HW bridge instance. It is expected this function is called |
| 6817 | * when a new HW bridge is instantiated. |
| 6818 | **/ |
| 6819 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6820 | { |
| 6821 | struct i40e_pf *pf = veb->pf; |
| 6822 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6823 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6824 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6825 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6826 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6827 | i40e_disable_pf_switch_lb(pf); |
| 6828 | else |
| 6829 | i40e_enable_pf_switch_lb(pf); |
| 6830 | } |
| 6831 | |
| 6832 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6833 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6834 | * @veb: pointer to the VEB instance |
| 6835 | * |
| 6836 | * This is a recursive function that first builds the attached VSIs then |
| 6837 | * recurses in to build the next layer of VEB. We track the connections |
| 6838 | * through our own index numbers because the seid's from the HW could |
| 6839 | * change across the reset. |
| 6840 | **/ |
| 6841 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6842 | { |
| 6843 | struct i40e_vsi *ctl_vsi = NULL; |
| 6844 | struct i40e_pf *pf = veb->pf; |
| 6845 | int v, veb_idx; |
| 6846 | int ret; |
| 6847 | |
| 6848 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6849 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6850 | if (pf->vsi[v] && |
| 6851 | pf->vsi[v]->veb_idx == veb->idx && |
| 6852 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6853 | ctl_vsi = pf->vsi[v]; |
| 6854 | break; |
| 6855 | } |
| 6856 | } |
| 6857 | if (!ctl_vsi) { |
| 6858 | dev_info(&pf->pdev->dev, |
| 6859 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6860 | ret = -ENOENT; |
| 6861 | goto end_reconstitute; |
| 6862 | } |
| 6863 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6864 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6865 | ret = i40e_add_vsi(ctl_vsi); |
| 6866 | if (ret) { |
| 6867 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6868 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6869 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6870 | goto end_reconstitute; |
| 6871 | } |
| 6872 | i40e_vsi_reset_stats(ctl_vsi); |
| 6873 | |
| 6874 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6875 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6876 | if (ret) |
| 6877 | goto end_reconstitute; |
| 6878 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6879 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6880 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6881 | else |
| 6882 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6883 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6884 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6885 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6886 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6887 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6888 | continue; |
| 6889 | |
| 6890 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6891 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6892 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6893 | vsi->uplink_seid = veb->seid; |
| 6894 | ret = i40e_add_vsi(vsi); |
| 6895 | if (ret) { |
| 6896 | dev_info(&pf->pdev->dev, |
| 6897 | "rebuild of vsi_idx %d failed: %d\n", |
| 6898 | v, ret); |
| 6899 | goto end_reconstitute; |
| 6900 | } |
| 6901 | i40e_vsi_reset_stats(vsi); |
| 6902 | } |
| 6903 | } |
| 6904 | |
| 6905 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6906 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6907 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6908 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6909 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6910 | if (ret) |
| 6911 | break; |
| 6912 | } |
| 6913 | } |
| 6914 | |
| 6915 | end_reconstitute: |
| 6916 | return ret; |
| 6917 | } |
| 6918 | |
| 6919 | /** |
| 6920 | * i40e_get_capabilities - get info about the HW |
| 6921 | * @pf: the PF struct |
| 6922 | **/ |
| 6923 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6924 | { |
| 6925 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6926 | u16 data_size; |
| 6927 | int buf_len; |
| 6928 | int err; |
| 6929 | |
| 6930 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6931 | do { |
| 6932 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6933 | if (!cap_buf) |
| 6934 | return -ENOMEM; |
| 6935 | |
| 6936 | /* this loads the data into the hw struct for us */ |
| 6937 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6938 | &data_size, |
| 6939 | i40e_aqc_opc_list_func_capabilities, |
| 6940 | NULL); |
| 6941 | /* data loaded, buffer no longer needed */ |
| 6942 | kfree(cap_buf); |
| 6943 | |
| 6944 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6945 | /* retry with a larger buffer */ |
| 6946 | buf_len = data_size; |
| 6947 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6948 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6949 | "capability discovery failed, err %s aq_err %s\n", |
| 6950 | i40e_stat_str(&pf->hw, err), |
| 6951 | i40e_aq_str(&pf->hw, |
| 6952 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6953 | return -ENODEV; |
| 6954 | } |
| 6955 | } while (err); |
| 6956 | |
| 6957 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6958 | dev_info(&pf->pdev->dev, |
| 6959 | "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", |
| 6960 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6961 | pf->hw.func_caps.num_msix_vectors, |
| 6962 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6963 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6964 | pf->hw.func_caps.fd_filters_best_effort, |
| 6965 | pf->hw.func_caps.num_tx_qp, |
| 6966 | pf->hw.func_caps.num_vsis); |
| 6967 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6968 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6969 | + pf->hw.func_caps.num_vfs) |
| 6970 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6971 | dev_info(&pf->pdev->dev, |
| 6972 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6973 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6974 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6975 | } |
| 6976 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6977 | return 0; |
| 6978 | } |
| 6979 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6980 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6981 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6982 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6983 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6984 | * @pf: board private structure |
| 6985 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6986 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6987 | { |
| 6988 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6989 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6990 | /* quick workaround for an NVM issue that leaves a critical register |
| 6991 | * uninitialized |
| 6992 | */ |
| 6993 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6994 | static const u32 hkey[] = { |
| 6995 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6996 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6997 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6998 | 0x95b3a76d}; |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6999 | int i; |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 7000 | |
| 7001 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 7002 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 7003 | } |
| 7004 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 7005 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7006 | return; |
| 7007 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 7008 | /* find existing VSI and see if it needs configuring */ |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 7009 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 7010 | |
| 7011 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7012 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 7013 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 7014 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7015 | if (!vsi) { |
| 7016 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 7017 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7018 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7019 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7020 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 7021 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 7022 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7023 | } |
| 7024 | |
| 7025 | /** |
| 7026 | * i40e_fdir_teardown - release the Flow Director resources |
| 7027 | * @pf: board private structure |
| 7028 | **/ |
| 7029 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 7030 | { |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 7031 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7032 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 7033 | i40e_fdir_filter_exit(pf); |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 7034 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
| 7035 | if (vsi) |
| 7036 | i40e_vsi_release(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7037 | } |
| 7038 | |
| 7039 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7040 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7041 | * @pf: board private structure |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7042 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 7043 | * before this function was called. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7044 | * |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7045 | * 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] | 7046 | **/ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7047 | 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] | 7048 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7049 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 7050 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7051 | u32 v; |
| 7052 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7053 | clear_bit(__I40E_RESET_INTR_RECEIVED, pf->state); |
| 7054 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 7055 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 7056 | if (i40e_check_asq_alive(&pf->hw)) |
| 7057 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7058 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7059 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7060 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7061 | /* quiesce the VSIs and their queues that are not already DOWN */ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7062 | /* pf_quiesce_all_vsi modifies netdev structures -rtnl_lock needed */ |
| 7063 | if (!lock_acquired) |
| 7064 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7065 | i40e_pf_quiesce_all_vsi(pf); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7066 | if (!lock_acquired) |
| 7067 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7068 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7069 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7070 | if (pf->vsi[v]) |
| 7071 | pf->vsi[v]->seid = 0; |
| 7072 | } |
| 7073 | |
| 7074 | i40e_shutdown_adminq(&pf->hw); |
| 7075 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7076 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 7077 | if (hw->hmc.hmc_obj) { |
| 7078 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 7079 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 7080 | dev_warn(&pf->pdev->dev, |
| 7081 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7082 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7083 | } |
| 7084 | |
| 7085 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 7086 | * i40e_send_version - update firmware with driver version |
| 7087 | * @pf: PF struct |
| 7088 | */ |
| 7089 | static void i40e_send_version(struct i40e_pf *pf) |
| 7090 | { |
| 7091 | struct i40e_driver_version dv; |
| 7092 | |
| 7093 | dv.major_version = DRV_VERSION_MAJOR; |
| 7094 | dv.minor_version = DRV_VERSION_MINOR; |
| 7095 | dv.build_version = DRV_VERSION_BUILD; |
| 7096 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 7097 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 7098 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 7099 | } |
| 7100 | |
| 7101 | /** |
Filip Sadowski | 5bbb2e2 | 2017-06-07 05:43:09 -0400 | [diff] [blame] | 7102 | * i40e_get_oem_version - get OEM specific version information |
| 7103 | * @hw: pointer to the hardware structure |
| 7104 | **/ |
| 7105 | static void i40e_get_oem_version(struct i40e_hw *hw) |
| 7106 | { |
| 7107 | u16 block_offset = 0xffff; |
| 7108 | u16 block_length = 0; |
| 7109 | u16 capabilities = 0; |
| 7110 | u16 gen_snap = 0; |
| 7111 | u16 release = 0; |
| 7112 | |
| 7113 | #define I40E_SR_NVM_OEM_VERSION_PTR 0x1B |
| 7114 | #define I40E_NVM_OEM_LENGTH_OFFSET 0x00 |
| 7115 | #define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01 |
| 7116 | #define I40E_NVM_OEM_GEN_OFFSET 0x02 |
| 7117 | #define I40E_NVM_OEM_RELEASE_OFFSET 0x03 |
| 7118 | #define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F |
| 7119 | #define I40E_NVM_OEM_LENGTH 3 |
| 7120 | |
| 7121 | /* Check if pointer to OEM version block is valid. */ |
| 7122 | i40e_read_nvm_word(hw, I40E_SR_NVM_OEM_VERSION_PTR, &block_offset); |
| 7123 | if (block_offset == 0xffff) |
| 7124 | return; |
| 7125 | |
| 7126 | /* Check if OEM version block has correct length. */ |
| 7127 | i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_LENGTH_OFFSET, |
| 7128 | &block_length); |
| 7129 | if (block_length < I40E_NVM_OEM_LENGTH) |
| 7130 | return; |
| 7131 | |
| 7132 | /* Check if OEM version format is as expected. */ |
| 7133 | i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_CAPABILITIES_OFFSET, |
| 7134 | &capabilities); |
| 7135 | if ((capabilities & I40E_NVM_OEM_CAPABILITIES_MASK) != 0) |
| 7136 | return; |
| 7137 | |
| 7138 | i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_GEN_OFFSET, |
| 7139 | &gen_snap); |
| 7140 | i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_RELEASE_OFFSET, |
| 7141 | &release); |
| 7142 | hw->nvm.oem_ver = (gen_snap << I40E_OEM_SNAP_SHIFT) | release; |
| 7143 | hw->nvm.eetrack = I40E_OEM_EETRACK_ID; |
| 7144 | } |
| 7145 | |
| 7146 | /** |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7147 | * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen |
| 7148 | * @pf: board private structure |
| 7149 | **/ |
| 7150 | static int i40e_reset(struct i40e_pf *pf) |
| 7151 | { |
| 7152 | struct i40e_hw *hw = &pf->hw; |
| 7153 | i40e_status ret; |
| 7154 | |
| 7155 | ret = i40e_pf_reset(hw); |
| 7156 | if (ret) { |
| 7157 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7158 | set_bit(__I40E_RESET_FAILED, pf->state); |
| 7159 | clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7160 | } else { |
| 7161 | pf->pfr_count++; |
| 7162 | } |
| 7163 | return ret; |
| 7164 | } |
| 7165 | |
| 7166 | /** |
| 7167 | * i40e_rebuild - rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7168 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7169 | * @reinit: if the Main VSI needs to re-initialized. |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7170 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 7171 | * before this function was called. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7172 | **/ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7173 | 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] | 7174 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7175 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7176 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7177 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 7178 | u32 val; |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7179 | int v; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7180 | |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 7181 | if (test_bit(__I40E_DOWN, pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7182 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7183 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7184 | |
| 7185 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 7186 | ret = i40e_init_adminq(&pf->hw); |
| 7187 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7188 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 7189 | i40e_stat_str(&pf->hw, ret), |
| 7190 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7191 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7192 | } |
Filip Sadowski | 5bbb2e2 | 2017-06-07 05:43:09 -0400 | [diff] [blame] | 7193 | i40e_get_oem_version(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7194 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 7195 | /* re-verify the eeprom if we just had an EMP reset */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7196 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 7197 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 7198 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 7199 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7200 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7201 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7202 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7203 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7204 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
Alexander Duyck | c76cb6e | 2017-02-21 15:55:48 -0800 | [diff] [blame] | 7205 | hw->func_caps.num_rx_qp, 0, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7206 | if (ret) { |
| 7207 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 7208 | goto end_core_reset; |
| 7209 | } |
| 7210 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 7211 | if (ret) { |
| 7212 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 7213 | goto end_core_reset; |
| 7214 | } |
| 7215 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7216 | #ifdef CONFIG_I40E_DCB |
| 7217 | ret = i40e_init_pf_dcb(pf); |
| 7218 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 7219 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 7220 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 7221 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7222 | } |
| 7223 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7224 | /* do basic switch setup */ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7225 | if (!lock_acquired) |
| 7226 | rtnl_lock(); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7227 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7228 | if (ret) |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7229 | goto end_unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7230 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 7231 | /* The driver only wants link up/down and module qualification |
| 7232 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 7233 | */ |
| 7234 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 7235 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 7236 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 7237 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 7238 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7239 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 7240 | i40e_stat_str(&pf->hw, ret), |
| 7241 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 7242 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7243 | /* make sure our flow control settings are restored */ |
| 7244 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 7245 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 7246 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 7247 | i40e_stat_str(&pf->hw, ret), |
| 7248 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7249 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7250 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 7251 | * They are still in our local switch element arrays, so only |
| 7252 | * need to rebuild the switch model in the HW. |
| 7253 | * |
| 7254 | * If there were VEBs but the reconstitution failed, we'll try |
| 7255 | * try to recover minimal use by getting the basic PF VSI working. |
| 7256 | */ |
| 7257 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7258 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7259 | /* find the one VEB connected to the MAC, and find orphans */ |
| 7260 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 7261 | if (!pf->veb[v]) |
| 7262 | continue; |
| 7263 | |
| 7264 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 7265 | pf->veb[v]->uplink_seid == 0) { |
| 7266 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 7267 | |
| 7268 | if (!ret) |
| 7269 | continue; |
| 7270 | |
| 7271 | /* If Main VEB failed, we're in deep doodoo, |
| 7272 | * so give up rebuilding the switch and set up |
| 7273 | * for minimal rebuild of PF VSI. |
| 7274 | * If orphan failed, we'll report the error |
| 7275 | * but try to keep going. |
| 7276 | */ |
| 7277 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 7278 | dev_info(&pf->pdev->dev, |
| 7279 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 7280 | ret); |
| 7281 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 7282 | = pf->mac_seid; |
| 7283 | break; |
| 7284 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 7285 | dev_info(&pf->pdev->dev, |
| 7286 | "rebuild of orphan VEB failed: %d\n", |
| 7287 | ret); |
| 7288 | } |
| 7289 | } |
| 7290 | } |
| 7291 | } |
| 7292 | |
| 7293 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 7294 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7295 | /* no VEB, so rebuild only the Main VSI */ |
| 7296 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 7297 | if (ret) { |
| 7298 | dev_info(&pf->pdev->dev, |
| 7299 | "rebuild of Main VSI failed: %d\n", ret); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7300 | goto end_unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7301 | } |
| 7302 | } |
| 7303 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 7304 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 7305 | * of TSO, so that we avoid the MDD being fired and causing |
| 7306 | * a reset in the case of small MSS+TSO. |
| 7307 | */ |
| 7308 | #define I40E_REG_MSS 0x000E64DC |
| 7309 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 7310 | #define I40E_64BYTE_MSS 0x400000 |
| 7311 | val = rd32(hw, I40E_REG_MSS); |
| 7312 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 7313 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 7314 | val |= I40E_64BYTE_MSS; |
| 7315 | wr32(hw, I40E_REG_MSS, val); |
| 7316 | } |
| 7317 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 7318 | if (pf->hw_features & I40E_HW_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 7319 | msleep(75); |
| 7320 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 7321 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7322 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 7323 | i40e_stat_str(&pf->hw, ret), |
| 7324 | i40e_aq_str(&pf->hw, |
| 7325 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7326 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7327 | /* reinit the misc interrupt */ |
| 7328 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7329 | ret = i40e_setup_misc_vector(pf); |
| 7330 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 7331 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 7332 | * transmitted. By doing so we stop a malicious VF from sending out |
| 7333 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 7334 | * PF/VF VSIs. |
| 7335 | * The FW can still send Flow control frames if enabled. |
| 7336 | */ |
| 7337 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 7338 | pf->main_vsi_seid); |
| 7339 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7340 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 7341 | i40e_pf_unquiesce_all_vsi(pf); |
| 7342 | |
Jacob Keller | 024b05f | 2017-04-13 04:45:46 -0400 | [diff] [blame] | 7343 | /* Release the RTNL lock before we start resetting VFs */ |
| 7344 | if (!lock_acquired) |
| 7345 | rtnl_unlock(); |
| 7346 | |
Jacob Keller | e4b433f | 2017-04-13 04:45:52 -0400 | [diff] [blame] | 7347 | i40e_reset_all_vfs(pf, true); |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 7348 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7349 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 7350 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7351 | |
Jacob Keller | 024b05f | 2017-04-13 04:45:46 -0400 | [diff] [blame] | 7352 | /* We've already released the lock, so don't do it again */ |
| 7353 | goto end_core_reset; |
| 7354 | |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7355 | end_unlock: |
Jacob Keller | 024b05f | 2017-04-13 04:45:46 -0400 | [diff] [blame] | 7356 | if (!lock_acquired) |
| 7357 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7358 | end_core_reset: |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7359 | clear_bit(__I40E_RESET_FAILED, pf->state); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7360 | clear_recovery: |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7361 | clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7362 | } |
| 7363 | |
| 7364 | /** |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7365 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
| 7366 | * @pf: board private structure |
| 7367 | * @reinit: if the Main VSI needs to re-initialized. |
| 7368 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 7369 | * before this function was called. |
| 7370 | **/ |
| 7371 | static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit, |
| 7372 | bool lock_acquired) |
| 7373 | { |
| 7374 | int ret; |
| 7375 | /* Now we wait for GRST to settle out. |
| 7376 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 7377 | * because the reset will make them disappear. |
| 7378 | */ |
| 7379 | ret = i40e_reset(pf); |
| 7380 | if (!ret) |
| 7381 | i40e_rebuild(pf, reinit, lock_acquired); |
| 7382 | } |
| 7383 | |
| 7384 | /** |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7385 | * 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] | 7386 | * @pf: board private structure |
| 7387 | * |
| 7388 | * Close up the VFs and other things in prep for a Core Reset, |
| 7389 | * then get ready to rebuild the world. |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7390 | * @lock_acquired: indicates whether or not the lock has been acquired |
| 7391 | * before this function was called. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7392 | **/ |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7393 | 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] | 7394 | { |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 7395 | i40e_prep_for_reset(pf, lock_acquired); |
| 7396 | i40e_reset_and_rebuild(pf, false, lock_acquired); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7397 | } |
| 7398 | |
| 7399 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7400 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7401 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7402 | * |
| 7403 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 7404 | **/ |
| 7405 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 7406 | { |
| 7407 | struct i40e_hw *hw = &pf->hw; |
| 7408 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7409 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7410 | struct i40e_vf *vf; |
| 7411 | u32 reg; |
| 7412 | int i; |
| 7413 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7414 | if (!test_bit(__I40E_MDD_EVENT_PENDING, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7415 | return; |
| 7416 | |
| 7417 | /* find what triggered the MDD event */ |
| 7418 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 7419 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7420 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 7421 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7422 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7423 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7424 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7425 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7426 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 7427 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 7428 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7429 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7430 | 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] | 7431 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7432 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 7433 | mdd_detected = true; |
| 7434 | } |
| 7435 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 7436 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7437 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 7438 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7439 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7440 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7441 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 7442 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 7443 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7444 | if (netif_msg_rx_err(pf)) |
| 7445 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 7446 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7447 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 7448 | mdd_detected = true; |
| 7449 | } |
| 7450 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7451 | if (mdd_detected) { |
| 7452 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 7453 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 7454 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7455 | 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] | 7456 | pf_mdd_detected = true; |
| 7457 | } |
| 7458 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 7459 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 7460 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7461 | 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] | 7462 | pf_mdd_detected = true; |
| 7463 | } |
| 7464 | /* Queue belongs to the PF, initiate a reset */ |
| 7465 | if (pf_mdd_detected) { |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7466 | set_bit(__I40E_PF_RESET_REQUESTED, pf->state); |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7467 | i40e_service_event_schedule(pf); |
| 7468 | } |
| 7469 | } |
| 7470 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7471 | /* see if one of the VFs needs its hand slapped */ |
| 7472 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7473 | vf = &(pf->vf[i]); |
| 7474 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7475 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7476 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7477 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7478 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7479 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7480 | } |
| 7481 | |
| 7482 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7483 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7484 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7485 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7486 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7487 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7488 | } |
| 7489 | |
| 7490 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7491 | dev_info(&pf->pdev->dev, |
| 7492 | "Too many MDD events on VF %d, disabled\n", i); |
| 7493 | dev_info(&pf->pdev->dev, |
| 7494 | "Use PF Control I/F to re-enable the VF\n"); |
Jacob Keller | 6322e63 | 2017-04-13 04:45:54 -0400 | [diff] [blame] | 7495 | set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7496 | } |
| 7497 | } |
| 7498 | |
| 7499 | /* re-enable mdd interrupt cause */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7500 | clear_bit(__I40E_MDD_EVENT_PENDING, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7501 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7502 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7503 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7504 | i40e_flush(hw); |
| 7505 | } |
| 7506 | |
Jacob Keller | d8b2c70 | 2017-06-20 15:17:00 -0700 | [diff] [blame] | 7507 | static const char *i40e_tunnel_name(struct i40e_udp_port_config *port) |
| 7508 | { |
| 7509 | switch (port->type) { |
| 7510 | case UDP_TUNNEL_TYPE_VXLAN: |
| 7511 | return "vxlan"; |
| 7512 | case UDP_TUNNEL_TYPE_GENEVE: |
| 7513 | return "geneve"; |
| 7514 | default: |
| 7515 | return "unknown"; |
| 7516 | } |
| 7517 | } |
| 7518 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7519 | /** |
Alexander Duyck | 1f190d9 | 2017-04-19 09:25:51 -0400 | [diff] [blame] | 7520 | * i40e_sync_udp_filters - Trigger a sync event for existing UDP filters |
| 7521 | * @pf: board private structure |
| 7522 | **/ |
| 7523 | static void i40e_sync_udp_filters(struct i40e_pf *pf) |
| 7524 | { |
| 7525 | int i; |
| 7526 | |
| 7527 | /* loop through and set pending bit for all active UDP filters */ |
| 7528 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
| 7529 | if (pf->udp_ports[i].port) |
| 7530 | pf->pending_udp_bitmap |= BIT_ULL(i); |
| 7531 | } |
| 7532 | |
| 7533 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 7534 | } |
| 7535 | |
| 7536 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7537 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7538 | * @pf: board private structure |
| 7539 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7540 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7541 | { |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7542 | struct i40e_hw *hw = &pf->hw; |
| 7543 | i40e_status ret; |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 7544 | u16 port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7545 | int i; |
| 7546 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7547 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7548 | return; |
| 7549 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7550 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7551 | |
| 7552 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7553 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7554 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 7555 | port = pf->udp_ports[i].port; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7556 | if (port) |
Carolyn Wyborny | b3f5c7b | 2016-08-24 11:33:51 -0700 | [diff] [blame] | 7557 | ret = i40e_aq_add_udp_tunnel(hw, port, |
| 7558 | pf->udp_ports[i].type, |
| 7559 | NULL, NULL); |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7560 | else |
| 7561 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7562 | |
| 7563 | if (ret) { |
Jacob Keller | d8b2c70 | 2017-06-20 15:17:00 -0700 | [diff] [blame] | 7564 | dev_info(&pf->pdev->dev, |
| 7565 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 7566 | i40e_tunnel_name(&pf->udp_ports[i]), |
| 7567 | port ? "add" : "delete", |
| 7568 | port, i, |
| 7569 | i40e_stat_str(&pf->hw, ret), |
| 7570 | i40e_aq_str(&pf->hw, |
| 7571 | pf->hw.aq.asq_last_status)); |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 7572 | pf->udp_ports[i].port = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7573 | } |
| 7574 | } |
| 7575 | } |
| 7576 | } |
| 7577 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7578 | /** |
| 7579 | * i40e_service_task - Run the driver's async subtasks |
| 7580 | * @work: pointer to work_struct containing our data |
| 7581 | **/ |
| 7582 | static void i40e_service_task(struct work_struct *work) |
| 7583 | { |
| 7584 | struct i40e_pf *pf = container_of(work, |
| 7585 | struct i40e_pf, |
| 7586 | service_task); |
| 7587 | unsigned long start_time = jiffies; |
| 7588 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7589 | /* don't bother with service tasks if a reset is in progress */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7590 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7591 | return; |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7592 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7593 | if (test_and_set_bit(__I40E_SERVICE_SCHED, pf->state)) |
Mitch Williams | 9108903 | 2016-11-21 13:03:51 -0800 | [diff] [blame] | 7594 | return; |
| 7595 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7596 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 7597 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7598 | i40e_reset_subtask(pf); |
| 7599 | i40e_handle_mdd_event(pf); |
| 7600 | i40e_vc_process_vflr_event(pf); |
| 7601 | i40e_watchdog_subtask(pf); |
| 7602 | i40e_fdir_reinit_subtask(pf); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 7603 | if (pf->flags & I40E_FLAG_CLIENT_RESET) { |
| 7604 | /* Client subtask will reopen next time through. */ |
| 7605 | i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], true); |
| 7606 | pf->flags &= ~I40E_FLAG_CLIENT_RESET; |
| 7607 | } else { |
| 7608 | i40e_client_subtask(pf); |
| 7609 | if (pf->flags & I40E_FLAG_CLIENT_L2_CHANGE) { |
| 7610 | i40e_notify_client_of_l2_param_changes( |
| 7611 | pf->vsi[pf->lan_vsi]); |
| 7612 | pf->flags &= ~I40E_FLAG_CLIENT_L2_CHANGE; |
| 7613 | } |
| 7614 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7615 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7616 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7617 | i40e_clean_adminq_subtask(pf); |
| 7618 | |
Mitch Williams | 9108903 | 2016-11-21 13:03:51 -0800 | [diff] [blame] | 7619 | /* flush memory to make sure state is correct before next watchdog */ |
| 7620 | smp_mb__before_atomic(); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7621 | clear_bit(__I40E_SERVICE_SCHED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7622 | |
| 7623 | /* If the tasks have taken longer than one timer cycle or there |
| 7624 | * is more work to be done, reschedule the service task now |
| 7625 | * rather than wait for the timer to tick again. |
| 7626 | */ |
| 7627 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7628 | test_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state) || |
| 7629 | test_bit(__I40E_MDD_EVENT_PENDING, pf->state) || |
| 7630 | test_bit(__I40E_VFLR_EVENT_PENDING, pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7631 | i40e_service_event_schedule(pf); |
| 7632 | } |
| 7633 | |
| 7634 | /** |
| 7635 | * i40e_service_timer - timer callback |
| 7636 | * @data: pointer to PF struct |
| 7637 | **/ |
| 7638 | static void i40e_service_timer(unsigned long data) |
| 7639 | { |
| 7640 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7641 | |
| 7642 | mod_timer(&pf->service_timer, |
| 7643 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7644 | i40e_service_event_schedule(pf); |
| 7645 | } |
| 7646 | |
| 7647 | /** |
| 7648 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7649 | * @vsi: the VSI being configured |
| 7650 | **/ |
| 7651 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7652 | { |
| 7653 | struct i40e_pf *pf = vsi->back; |
| 7654 | |
| 7655 | switch (vsi->type) { |
| 7656 | case I40E_VSI_MAIN: |
| 7657 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7658 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7659 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7660 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7661 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7662 | else |
| 7663 | vsi->num_q_vectors = 1; |
| 7664 | |
| 7665 | break; |
| 7666 | |
| 7667 | case I40E_VSI_FDIR: |
| 7668 | vsi->alloc_queue_pairs = 1; |
| 7669 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7670 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7671 | vsi->num_q_vectors = pf->num_fdsb_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7672 | break; |
| 7673 | |
| 7674 | case I40E_VSI_VMDQ2: |
| 7675 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7676 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7677 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7678 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7679 | break; |
| 7680 | |
| 7681 | case I40E_VSI_SRIOV: |
| 7682 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7683 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7684 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7685 | break; |
| 7686 | |
| 7687 | default: |
| 7688 | WARN_ON(1); |
| 7689 | return -ENODATA; |
| 7690 | } |
| 7691 | |
| 7692 | return 0; |
| 7693 | } |
| 7694 | |
| 7695 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7696 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7697 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7698 | * @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] | 7699 | * |
| 7700 | * On error: returns error code (negative) |
| 7701 | * On success: returns 0 |
| 7702 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7703 | 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] | 7704 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7705 | struct i40e_ring **next_rings; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7706 | int size; |
| 7707 | int ret = 0; |
| 7708 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7709 | /* allocate memory for both Tx, XDP Tx and Rx ring pointers */ |
| 7710 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * |
| 7711 | (i40e_enabled_xdp_vsi(vsi) ? 3 : 2); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7712 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7713 | if (!vsi->tx_rings) |
| 7714 | return -ENOMEM; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7715 | next_rings = vsi->tx_rings + vsi->alloc_queue_pairs; |
| 7716 | if (i40e_enabled_xdp_vsi(vsi)) { |
| 7717 | vsi->xdp_rings = next_rings; |
| 7718 | next_rings += vsi->alloc_queue_pairs; |
| 7719 | } |
| 7720 | vsi->rx_rings = next_rings; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7721 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7722 | if (alloc_qvectors) { |
| 7723 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7724 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7725 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7726 | if (!vsi->q_vectors) { |
| 7727 | ret = -ENOMEM; |
| 7728 | goto err_vectors; |
| 7729 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7730 | } |
| 7731 | return ret; |
| 7732 | |
| 7733 | err_vectors: |
| 7734 | kfree(vsi->tx_rings); |
| 7735 | return ret; |
| 7736 | } |
| 7737 | |
| 7738 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7739 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7740 | * @pf: board private structure |
| 7741 | * @type: type of VSI |
| 7742 | * |
| 7743 | * On error: returns error code (negative) |
| 7744 | * On success: returns vsi index in PF (positive) |
| 7745 | **/ |
| 7746 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7747 | { |
| 7748 | int ret = -ENODEV; |
| 7749 | struct i40e_vsi *vsi; |
| 7750 | int vsi_idx; |
| 7751 | int i; |
| 7752 | |
| 7753 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7754 | mutex_lock(&pf->switch_mutex); |
| 7755 | |
| 7756 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7757 | * been happening. We can afford to do a quick scan to look |
| 7758 | * for any free VSIs in the list. |
| 7759 | * |
| 7760 | * find next empty vsi slot, looping back around if necessary |
| 7761 | */ |
| 7762 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7763 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7764 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7765 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7766 | i = 0; |
| 7767 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7768 | i++; |
| 7769 | } |
| 7770 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7771 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7772 | vsi_idx = i; /* Found one! */ |
| 7773 | } else { |
| 7774 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7775 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7776 | } |
| 7777 | pf->next_vsi = ++i; |
| 7778 | |
| 7779 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7780 | if (!vsi) { |
| 7781 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7782 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7783 | } |
| 7784 | vsi->type = type; |
| 7785 | vsi->back = pf; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 7786 | set_bit(__I40E_VSI_DOWN, vsi->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7787 | vsi->flags = 0; |
| 7788 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7789 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7790 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7791 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7792 | vsi->netdev_registered = false; |
| 7793 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 7794 | hash_init(vsi->mac_filter_hash); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7795 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7796 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7797 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7798 | if (ret) |
| 7799 | goto err_rings; |
| 7800 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7801 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7802 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7803 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7804 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7805 | /* Setup default MSIX irq handler for VSI */ |
| 7806 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7807 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7808 | /* Initialize VSI lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 7809 | spin_lock_init(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7810 | pf->vsi[vsi_idx] = vsi; |
| 7811 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7812 | goto unlock_pf; |
| 7813 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7814 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7815 | pf->next_vsi = i - 1; |
| 7816 | kfree(vsi); |
| 7817 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7818 | mutex_unlock(&pf->switch_mutex); |
| 7819 | return ret; |
| 7820 | } |
| 7821 | |
| 7822 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7823 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7824 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7825 | * @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] | 7826 | * |
| 7827 | * On error: returns error code (negative) |
| 7828 | * On success: returns 0 |
| 7829 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7830 | 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] | 7831 | { |
| 7832 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7833 | if (free_qvectors) { |
| 7834 | kfree(vsi->q_vectors); |
| 7835 | vsi->q_vectors = NULL; |
| 7836 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7837 | kfree(vsi->tx_rings); |
| 7838 | vsi->tx_rings = NULL; |
| 7839 | vsi->rx_rings = NULL; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7840 | vsi->xdp_rings = NULL; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7841 | } |
| 7842 | |
| 7843 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7844 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7845 | * and lookup table |
| 7846 | * @vsi: Pointer to VSI structure |
| 7847 | */ |
| 7848 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7849 | { |
| 7850 | if (!vsi) |
| 7851 | return; |
| 7852 | |
| 7853 | kfree(vsi->rss_hkey_user); |
| 7854 | vsi->rss_hkey_user = NULL; |
| 7855 | |
| 7856 | kfree(vsi->rss_lut_user); |
| 7857 | vsi->rss_lut_user = NULL; |
| 7858 | } |
| 7859 | |
| 7860 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7861 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7862 | * @vsi: the VSI being un-configured |
| 7863 | **/ |
| 7864 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7865 | { |
| 7866 | struct i40e_pf *pf; |
| 7867 | |
| 7868 | if (!vsi) |
| 7869 | return 0; |
| 7870 | |
| 7871 | if (!vsi->back) |
| 7872 | goto free_vsi; |
| 7873 | pf = vsi->back; |
| 7874 | |
| 7875 | mutex_lock(&pf->switch_mutex); |
| 7876 | if (!pf->vsi[vsi->idx]) { |
| 7877 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7878 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7879 | goto unlock_vsi; |
| 7880 | } |
| 7881 | |
| 7882 | if (pf->vsi[vsi->idx] != vsi) { |
| 7883 | dev_err(&pf->pdev->dev, |
| 7884 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7885 | pf->vsi[vsi->idx]->idx, |
| 7886 | pf->vsi[vsi->idx], |
| 7887 | pf->vsi[vsi->idx]->type, |
| 7888 | vsi->idx, vsi, vsi->type); |
| 7889 | goto unlock_vsi; |
| 7890 | } |
| 7891 | |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7892 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7893 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7894 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7895 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7896 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7897 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7898 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7899 | pf->vsi[vsi->idx] = NULL; |
| 7900 | if (vsi->idx < pf->next_vsi) |
| 7901 | pf->next_vsi = vsi->idx; |
| 7902 | |
| 7903 | unlock_vsi: |
| 7904 | mutex_unlock(&pf->switch_mutex); |
| 7905 | free_vsi: |
| 7906 | kfree(vsi); |
| 7907 | |
| 7908 | return 0; |
| 7909 | } |
| 7910 | |
| 7911 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7912 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7913 | * @vsi: the VSI being cleaned |
| 7914 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7915 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7916 | { |
| 7917 | int i; |
| 7918 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7919 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7920 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7921 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7922 | vsi->tx_rings[i] = NULL; |
| 7923 | vsi->rx_rings[i] = NULL; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7924 | if (vsi->xdp_rings) |
| 7925 | vsi->xdp_rings[i] = NULL; |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7926 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7927 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7928 | } |
| 7929 | |
| 7930 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7931 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7932 | * @vsi: the VSI being configured |
| 7933 | **/ |
| 7934 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7935 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7936 | int i, qpv = i40e_enabled_xdp_vsi(vsi) ? 3 : 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7937 | struct i40e_pf *pf = vsi->back; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7938 | struct i40e_ring *ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7939 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7940 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7941 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7942 | /* allocate space for both Tx and Rx in one shot */ |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7943 | ring = kcalloc(qpv, sizeof(struct i40e_ring), GFP_KERNEL); |
| 7944 | if (!ring) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7945 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7946 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7947 | ring->queue_index = i; |
| 7948 | ring->reg_idx = vsi->base_queue + i; |
| 7949 | ring->ring_active = false; |
| 7950 | ring->vsi = vsi; |
| 7951 | ring->netdev = vsi->netdev; |
| 7952 | ring->dev = &pf->pdev->dev; |
| 7953 | ring->count = vsi->num_desc; |
| 7954 | ring->size = 0; |
| 7955 | ring->dcb_tc = 0; |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 7956 | 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] | 7957 | ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
| 7958 | ring->tx_itr_setting = pf->tx_itr_default; |
| 7959 | vsi->tx_rings[i] = ring++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7960 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 7961 | if (!i40e_enabled_xdp_vsi(vsi)) |
| 7962 | goto setup_rx; |
| 7963 | |
| 7964 | ring->queue_index = vsi->alloc_queue_pairs + i; |
| 7965 | ring->reg_idx = vsi->base_queue + ring->queue_index; |
| 7966 | ring->ring_active = false; |
| 7967 | ring->vsi = vsi; |
| 7968 | ring->netdev = NULL; |
| 7969 | ring->dev = &pf->pdev->dev; |
| 7970 | ring->count = vsi->num_desc; |
| 7971 | ring->size = 0; |
| 7972 | ring->dcb_tc = 0; |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 7973 | 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] | 7974 | ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
| 7975 | set_ring_xdp(ring); |
| 7976 | ring->tx_itr_setting = pf->tx_itr_default; |
| 7977 | vsi->xdp_rings[i] = ring++; |
| 7978 | |
| 7979 | setup_rx: |
| 7980 | ring->queue_index = i; |
| 7981 | ring->reg_idx = vsi->base_queue + i; |
| 7982 | ring->ring_active = false; |
| 7983 | ring->vsi = vsi; |
| 7984 | ring->netdev = vsi->netdev; |
| 7985 | ring->dev = &pf->pdev->dev; |
| 7986 | ring->count = vsi->num_desc; |
| 7987 | ring->size = 0; |
| 7988 | ring->dcb_tc = 0; |
| 7989 | ring->rx_itr_setting = pf->rx_itr_default; |
| 7990 | vsi->rx_rings[i] = ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7991 | } |
| 7992 | |
| 7993 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7994 | |
| 7995 | err_out: |
| 7996 | i40e_vsi_clear_rings(vsi); |
| 7997 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7998 | } |
| 7999 | |
| 8000 | /** |
| 8001 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 8002 | * @pf: board private structure |
| 8003 | * @vectors: the number of MSI-X vectors to request |
| 8004 | * |
| 8005 | * Returns the number of vectors reserved, or error |
| 8006 | **/ |
| 8007 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 8008 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 8009 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 8010 | I40E_MIN_MSIX, vectors); |
| 8011 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8012 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 8013 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8014 | vectors = 0; |
| 8015 | } |
| 8016 | |
| 8017 | return vectors; |
| 8018 | } |
| 8019 | |
| 8020 | /** |
| 8021 | * i40e_init_msix - Setup the MSIX capability |
| 8022 | * @pf: board private structure |
| 8023 | * |
| 8024 | * Work with the OS to set up the MSIX vectors needed. |
| 8025 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8026 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8027 | **/ |
| 8028 | static int i40e_init_msix(struct i40e_pf *pf) |
| 8029 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8030 | struct i40e_hw *hw = &pf->hw; |
Jacob Keller | c0cf70a | 2017-01-24 10:24:01 -0800 | [diff] [blame] | 8031 | int cpus, extra_vectors; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8032 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8033 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8034 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8035 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8036 | |
| 8037 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 8038 | return -ENODEV; |
| 8039 | |
| 8040 | /* The number of vectors we'll request will be comprised of: |
| 8041 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 8042 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8043 | * - Queues being used for RSS. |
| 8044 | * We don't need as many as max_rss_size vectors. |
| 8045 | * use rss_size instead in the calculation since that |
| 8046 | * is governed by number of cpus in the system. |
| 8047 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8048 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8049 | * - The CPU count within the NUMA node if iWARP is enabled |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8050 | * Once we count this up, try the request. |
| 8051 | * |
| 8052 | * If we can't get what we want, we'll simplify to nearly nothing |
| 8053 | * and try again. If that still fails, we punt. |
| 8054 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8055 | vectors_left = hw->func_caps.num_msix_vectors; |
| 8056 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8057 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8058 | /* reserve one vector for miscellaneous handler */ |
| 8059 | if (vectors_left) { |
| 8060 | v_budget++; |
| 8061 | vectors_left--; |
| 8062 | } |
| 8063 | |
Jacob Keller | c0cf70a | 2017-01-24 10:24:01 -0800 | [diff] [blame] | 8064 | /* reserve some vectors for the main PF traffic queues. Initially we |
| 8065 | * only reserve at most 50% of the available vectors, in the case that |
| 8066 | * the number of online CPUs is large. This ensures that we can enable |
| 8067 | * extra features as well. Once we've enabled the other features, we |
| 8068 | * will use any remaining vectors to reach as close as we can to the |
| 8069 | * number of online CPUs. |
| 8070 | */ |
| 8071 | cpus = num_online_cpus(); |
| 8072 | pf->num_lan_msix = min_t(int, cpus, vectors_left / 2); |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8073 | vectors_left -= pf->num_lan_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8074 | |
| 8075 | /* reserve one vector for sideband flow director */ |
| 8076 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8077 | if (vectors_left) { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 8078 | pf->num_fdsb_msix = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8079 | v_budget++; |
| 8080 | vectors_left--; |
| 8081 | } else { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 8082 | pf->num_fdsb_msix = 0; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8083 | } |
| 8084 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 8085 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8086 | /* can we reserve enough for iWARP? */ |
| 8087 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 8088 | iwarp_requested = pf->num_iwarp_msix; |
| 8089 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8090 | if (!vectors_left) |
| 8091 | pf->num_iwarp_msix = 0; |
| 8092 | else if (vectors_left < pf->num_iwarp_msix) |
| 8093 | pf->num_iwarp_msix = 1; |
| 8094 | v_budget += pf->num_iwarp_msix; |
| 8095 | vectors_left -= pf->num_iwarp_msix; |
| 8096 | } |
| 8097 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8098 | /* any vectors left over go for VMDq support */ |
| 8099 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 8100 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 8101 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 8102 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 8103 | if (!vectors_left) { |
| 8104 | pf->num_vmdq_msix = 0; |
| 8105 | pf->num_vmdq_qps = 0; |
| 8106 | } else { |
| 8107 | /* if we're short on vectors for what's desired, we limit |
| 8108 | * the queues per vmdq. If this is still more than are |
| 8109 | * available, the user will need to change the number of |
| 8110 | * queues/vectors used by the PF later with the ethtool |
| 8111 | * channels command |
| 8112 | */ |
| 8113 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 8114 | pf->num_vmdq_qps = 1; |
| 8115 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8116 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 8117 | v_budget += vmdq_vecs; |
| 8118 | vectors_left -= vmdq_vecs; |
| 8119 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8120 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8121 | |
Jacob Keller | c0cf70a | 2017-01-24 10:24:01 -0800 | [diff] [blame] | 8122 | /* On systems with a large number of SMP cores, we previously limited |
| 8123 | * the number of vectors for num_lan_msix to be at most 50% of the |
| 8124 | * available vectors, to allow for other features. Now, we add back |
| 8125 | * the remaining vectors. However, we ensure that the total |
| 8126 | * num_lan_msix will not exceed num_online_cpus(). To do this, we |
| 8127 | * calculate the number of vectors we can add without going over the |
| 8128 | * cap of CPUs. For systems with a small number of CPUs this will be |
| 8129 | * zero. |
| 8130 | */ |
| 8131 | extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left); |
| 8132 | pf->num_lan_msix += extra_vectors; |
| 8133 | vectors_left -= extra_vectors; |
| 8134 | |
| 8135 | WARN(vectors_left < 0, |
| 8136 | "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n"); |
| 8137 | |
| 8138 | v_budget += pf->num_lan_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8139 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 8140 | GFP_KERNEL); |
| 8141 | if (!pf->msix_entries) |
| 8142 | return -ENOMEM; |
| 8143 | |
| 8144 | for (i = 0; i < v_budget; i++) |
| 8145 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8146 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 8147 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8148 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8149 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 8150 | kfree(pf->msix_entries); |
| 8151 | pf->msix_entries = NULL; |
Guilherme G Piccoli | 4c95aa5 | 2016-09-22 10:03:58 -0300 | [diff] [blame] | 8152 | pci_disable_msix(pf->pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8153 | return -ENODEV; |
| 8154 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8155 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8156 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8157 | pf->num_vmdq_vsis = 0; |
| 8158 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8159 | pf->num_lan_qps = 1; |
| 8160 | pf->num_lan_msix = 1; |
| 8161 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 8162 | } else if (!vectors_left) { |
| 8163 | /* If we have limited resources, we will start with no vectors |
| 8164 | * for the special features and then allocate vectors to some |
| 8165 | * of these features based on the policy and at the end disable |
| 8166 | * the features that did not get any vectors. |
| 8167 | */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8168 | int vec; |
| 8169 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 8170 | dev_info(&pf->pdev->dev, |
| 8171 | "MSI-X vector limit reached, attempting to redistribute vectors\n"); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 8172 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8173 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 8174 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8175 | /* Scale vector usage down */ |
| 8176 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 8177 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 8178 | pf->num_vmdq_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8179 | |
| 8180 | /* partition out the remaining vectors */ |
| 8181 | switch (vec) { |
| 8182 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8183 | pf->num_lan_msix = 1; |
| 8184 | break; |
| 8185 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8186 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 8187 | pf->num_lan_msix = 1; |
| 8188 | pf->num_iwarp_msix = 1; |
| 8189 | } else { |
| 8190 | pf->num_lan_msix = 2; |
| 8191 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8192 | break; |
| 8193 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8194 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 8195 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 8196 | iwarp_requested); |
| 8197 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 8198 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 8199 | } else { |
| 8200 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 8201 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 8202 | } |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 8203 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8204 | pf->num_fdsb_msix = 1; |
| 8205 | vec--; |
| 8206 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8207 | pf->num_lan_msix = min_t(int, |
| 8208 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 8209 | pf->num_lan_msix); |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 8210 | pf->num_lan_qps = pf->num_lan_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8211 | break; |
| 8212 | } |
| 8213 | } |
| 8214 | |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 8215 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 8216 | (pf->num_fdsb_msix == 0)) { |
| 8217 | dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n"); |
| 8218 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 8219 | } |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 8220 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 8221 | (pf->num_vmdq_msix == 0)) { |
| 8222 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 8223 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 8224 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8225 | |
| 8226 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 8227 | (pf->num_iwarp_msix == 0)) { |
| 8228 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 8229 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 8230 | } |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 8231 | i40e_debug(&pf->hw, I40E_DEBUG_INIT, |
| 8232 | "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n", |
| 8233 | pf->num_lan_msix, |
| 8234 | pf->num_vmdq_msix * pf->num_vmdq_vsis, |
| 8235 | pf->num_fdsb_msix, |
| 8236 | pf->num_iwarp_msix); |
| 8237 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8238 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8239 | } |
| 8240 | |
| 8241 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 8242 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8243 | * @vsi: the VSI being configured |
| 8244 | * @v_idx: index of the vector in the vsi struct |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8245 | * @cpu: cpu to be used on affinity_mask |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8246 | * |
| 8247 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 8248 | **/ |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8249 | 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] | 8250 | { |
| 8251 | struct i40e_q_vector *q_vector; |
| 8252 | |
| 8253 | /* allocate q_vector */ |
| 8254 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 8255 | if (!q_vector) |
| 8256 | return -ENOMEM; |
| 8257 | |
| 8258 | q_vector->vsi = vsi; |
| 8259 | q_vector->v_idx = v_idx; |
Jacob Keller | 759dc4a | 2017-07-14 09:10:10 -0400 | [diff] [blame] | 8260 | cpumask_copy(&q_vector->affinity_mask, cpu_possible_mask); |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8261 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8262 | if (vsi->netdev) |
| 8263 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 8264 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8265 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 8266 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 8267 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 8268 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8269 | /* tie q_vector and vsi together */ |
| 8270 | vsi->q_vectors[v_idx] = q_vector; |
| 8271 | |
| 8272 | return 0; |
| 8273 | } |
| 8274 | |
| 8275 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 8276 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8277 | * @vsi: the VSI being configured |
| 8278 | * |
| 8279 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 8280 | * return -ENOMEM. |
| 8281 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 8282 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8283 | { |
| 8284 | struct i40e_pf *pf = vsi->back; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8285 | int err, v_idx, num_q_vectors, current_cpu; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8286 | |
| 8287 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 8288 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 8289 | num_q_vectors = vsi->num_q_vectors; |
| 8290 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 8291 | num_q_vectors = 1; |
| 8292 | else |
| 8293 | return -EINVAL; |
| 8294 | |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8295 | current_cpu = cpumask_first(cpu_online_mask); |
| 8296 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8297 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8298 | err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8299 | if (err) |
| 8300 | goto err_out; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8301 | current_cpu = cpumask_next(current_cpu, cpu_online_mask); |
| 8302 | if (unlikely(current_cpu >= nr_cpu_ids)) |
| 8303 | current_cpu = cpumask_first(cpu_online_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8304 | } |
| 8305 | |
| 8306 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8307 | |
| 8308 | err_out: |
| 8309 | while (v_idx--) |
| 8310 | i40e_free_q_vector(vsi, v_idx); |
| 8311 | |
| 8312 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8313 | } |
| 8314 | |
| 8315 | /** |
| 8316 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 8317 | * @pf: board private structure to initialize |
| 8318 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8319 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8320 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8321 | int vectors = 0; |
| 8322 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8323 | |
| 8324 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8325 | vectors = i40e_init_msix(pf); |
| 8326 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 8327 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8328 | I40E_FLAG_IWARP_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 8329 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 8330 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 8331 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 8332 | I40E_FLAG_SRIOV_ENABLED | |
| 8333 | I40E_FLAG_FD_SB_ENABLED | |
| 8334 | I40E_FLAG_FD_ATR_ENABLED | |
| 8335 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8336 | |
| 8337 | /* rework the queue expectations without MSIX */ |
| 8338 | i40e_determine_queue_usage(pf); |
| 8339 | } |
| 8340 | } |
| 8341 | |
| 8342 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 8343 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8344 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8345 | vectors = pci_enable_msi(pf->pdev); |
| 8346 | if (vectors < 0) { |
| 8347 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 8348 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8349 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 8350 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8351 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8352 | } |
| 8353 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 8354 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8355 | 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] | 8356 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8357 | /* set up vector assignment tracking */ |
| 8358 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 8359 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8360 | if (!pf->irq_pile) { |
| 8361 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 8362 | return -ENOMEM; |
| 8363 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8364 | pf->irq_pile->num_entries = vectors; |
| 8365 | pf->irq_pile->search_hint = 0; |
| 8366 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8367 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8368 | (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] | 8369 | |
| 8370 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8371 | } |
| 8372 | |
Jacob Keller | b980c06 | 2017-07-14 09:27:06 -0400 | [diff] [blame] | 8373 | #ifdef CONFIG_PM |
| 8374 | /** |
| 8375 | * i40e_restore_interrupt_scheme - Restore the interrupt scheme |
| 8376 | * @pf: private board data structure |
| 8377 | * |
| 8378 | * Restore the interrupt scheme that was cleared when we suspended the |
| 8379 | * device. This should be called during resume to re-allocate the q_vectors |
| 8380 | * and reacquire IRQs. |
| 8381 | */ |
| 8382 | static int i40e_restore_interrupt_scheme(struct i40e_pf *pf) |
| 8383 | { |
| 8384 | int err, i; |
| 8385 | |
| 8386 | /* We cleared the MSI and MSI-X flags when disabling the old interrupt |
| 8387 | * scheme. We need to re-enabled them here in order to attempt to |
| 8388 | * re-acquire the MSI or MSI-X vectors |
| 8389 | */ |
| 8390 | pf->flags |= (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 8391 | |
| 8392 | err = i40e_init_interrupt_scheme(pf); |
| 8393 | if (err) |
| 8394 | return err; |
| 8395 | |
| 8396 | /* Now that we've re-acquired IRQs, we need to remap the vectors and |
| 8397 | * rings together again. |
| 8398 | */ |
| 8399 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
| 8400 | if (pf->vsi[i]) { |
| 8401 | err = i40e_vsi_alloc_q_vectors(pf->vsi[i]); |
| 8402 | if (err) |
| 8403 | goto err_unwind; |
| 8404 | i40e_vsi_map_rings_to_vectors(pf->vsi[i]); |
| 8405 | } |
| 8406 | } |
| 8407 | |
| 8408 | err = i40e_setup_misc_vector(pf); |
| 8409 | if (err) |
| 8410 | goto err_unwind; |
| 8411 | |
| 8412 | return 0; |
| 8413 | |
| 8414 | err_unwind: |
| 8415 | while (i--) { |
| 8416 | if (pf->vsi[i]) |
| 8417 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 8418 | } |
| 8419 | |
| 8420 | return err; |
| 8421 | } |
| 8422 | #endif /* CONFIG_PM */ |
| 8423 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8424 | /** |
| 8425 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 8426 | * @pf: board private structure |
| 8427 | * |
| 8428 | * This sets up the handler for MSIX 0, which is used to manage the |
| 8429 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 8430 | * when in MSI or Legacy interrupt mode. |
| 8431 | **/ |
| 8432 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 8433 | { |
| 8434 | struct i40e_hw *hw = &pf->hw; |
| 8435 | int err = 0; |
| 8436 | |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 8437 | /* Only request the IRQ once, the first time through. */ |
| 8438 | if (!test_and_set_bit(__I40E_MISC_IRQ_REQUESTED, pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8439 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8440 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8441 | if (err) { |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 8442 | clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8443 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8444 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8445 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8446 | return -EFAULT; |
| 8447 | } |
| 8448 | } |
| 8449 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 8450 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8451 | |
| 8452 | /* associate no queues to the misc vector */ |
| 8453 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 8454 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 8455 | |
| 8456 | i40e_flush(hw); |
| 8457 | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 8458 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8459 | |
| 8460 | return err; |
| 8461 | } |
| 8462 | |
| 8463 | /** |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8464 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 8465 | * @vsi: vsi structure |
| 8466 | * @seed: RSS hash seed |
| 8467 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8468 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8469 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8470 | { |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8471 | struct i40e_pf *pf = vsi->back; |
| 8472 | struct i40e_hw *hw = &pf->hw; |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8473 | int ret = 0; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8474 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8475 | if (seed) { |
| 8476 | struct i40e_aqc_get_set_rss_key_data *seed_dw = |
| 8477 | (struct i40e_aqc_get_set_rss_key_data *)seed; |
| 8478 | ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw); |
| 8479 | if (ret) { |
| 8480 | dev_info(&pf->pdev->dev, |
| 8481 | "Cannot set RSS key, err %s aq_err %s\n", |
| 8482 | i40e_stat_str(hw, ret), |
| 8483 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8484 | return ret; |
| 8485 | } |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8486 | } |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8487 | if (lut) { |
| 8488 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8489 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8490 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8491 | if (ret) { |
| 8492 | dev_info(&pf->pdev->dev, |
| 8493 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 8494 | i40e_stat_str(hw, ret), |
| 8495 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8496 | return ret; |
| 8497 | } |
| 8498 | } |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8499 | return ret; |
| 8500 | } |
| 8501 | |
| 8502 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8503 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 8504 | * @vsi: Pointer to vsi structure |
| 8505 | * @seed: Buffter to store the hash keys |
| 8506 | * @lut: Buffer to store the lookup table entries |
| 8507 | * @lut_size: Size of buffer to store the lookup table entries |
| 8508 | * |
| 8509 | * Return 0 on success, negative on failure |
| 8510 | */ |
| 8511 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8512 | u8 *lut, u16 lut_size) |
| 8513 | { |
| 8514 | struct i40e_pf *pf = vsi->back; |
| 8515 | struct i40e_hw *hw = &pf->hw; |
| 8516 | int ret = 0; |
| 8517 | |
| 8518 | if (seed) { |
| 8519 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 8520 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 8521 | if (ret) { |
| 8522 | dev_info(&pf->pdev->dev, |
| 8523 | "Cannot get RSS key, err %s aq_err %s\n", |
| 8524 | i40e_stat_str(&pf->hw, ret), |
| 8525 | i40e_aq_str(&pf->hw, |
| 8526 | pf->hw.aq.asq_last_status)); |
| 8527 | return ret; |
| 8528 | } |
| 8529 | } |
| 8530 | |
| 8531 | if (lut) { |
| 8532 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 8533 | |
| 8534 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8535 | if (ret) { |
| 8536 | dev_info(&pf->pdev->dev, |
| 8537 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 8538 | i40e_stat_str(&pf->hw, ret), |
| 8539 | i40e_aq_str(&pf->hw, |
| 8540 | pf->hw.aq.asq_last_status)); |
| 8541 | return ret; |
| 8542 | } |
| 8543 | } |
| 8544 | |
| 8545 | return ret; |
| 8546 | } |
| 8547 | |
| 8548 | /** |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8549 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 8550 | * @vsi: VSI structure |
| 8551 | **/ |
| 8552 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 8553 | { |
| 8554 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 8555 | struct i40e_pf *pf = vsi->back; |
| 8556 | u8 *lut; |
| 8557 | int ret; |
| 8558 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 8559 | if (!(pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)) |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8560 | return 0; |
| 8561 | |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8562 | if (!vsi->rss_size) |
| 8563 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8564 | vsi->num_queue_pairs); |
| 8565 | if (!vsi->rss_size) |
| 8566 | return -EINVAL; |
| 8567 | |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8568 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8569 | if (!lut) |
| 8570 | return -ENOMEM; |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8571 | /* Use the user configured hash keys and lookup table if there is one, |
| 8572 | * otherwise use default |
| 8573 | */ |
| 8574 | if (vsi->rss_lut_user) |
| 8575 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8576 | else |
| 8577 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
| 8578 | if (vsi->rss_hkey_user) |
| 8579 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8580 | else |
| 8581 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8582 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 8583 | kfree(lut); |
| 8584 | |
| 8585 | return ret; |
| 8586 | } |
| 8587 | |
| 8588 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8589 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8590 | * @vsi: Pointer to vsi structure |
| 8591 | * @seed: RSS hash seed |
| 8592 | * @lut: Lookup table |
| 8593 | * @lut_size: Lookup table size |
| 8594 | * |
| 8595 | * Returns 0 on success, negative on failure |
| 8596 | **/ |
| 8597 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8598 | const u8 *lut, u16 lut_size) |
| 8599 | { |
| 8600 | struct i40e_pf *pf = vsi->back; |
| 8601 | struct i40e_hw *hw = &pf->hw; |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8602 | u16 vf_id = vsi->vf_id; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8603 | u8 i; |
| 8604 | |
| 8605 | /* Fill out hash function seed */ |
| 8606 | if (seed) { |
| 8607 | u32 *seed_dw = (u32 *)seed; |
| 8608 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8609 | if (vsi->type == I40E_VSI_MAIN) { |
| 8610 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Lihong Yang | 26f77e5 | 2017-01-30 12:29:33 -0800 | [diff] [blame] | 8611 | wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]); |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8612 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8613 | for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++) |
Lihong Yang | 26f77e5 | 2017-01-30 12:29:33 -0800 | [diff] [blame] | 8614 | wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]); |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8615 | } else { |
| 8616 | dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n"); |
| 8617 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8618 | } |
| 8619 | |
| 8620 | if (lut) { |
| 8621 | u32 *lut_dw = (u32 *)lut; |
| 8622 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8623 | if (vsi->type == I40E_VSI_MAIN) { |
| 8624 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8625 | return -EINVAL; |
| 8626 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8627 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8628 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8629 | if (lut_size != I40E_VF_HLUT_ARRAY_SIZE) |
| 8630 | return -EINVAL; |
| 8631 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
Lihong Yang | 26f77e5 | 2017-01-30 12:29:33 -0800 | [diff] [blame] | 8632 | wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]); |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8633 | } else { |
| 8634 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8635 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8636 | } |
| 8637 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8638 | |
| 8639 | return 0; |
| 8640 | } |
| 8641 | |
| 8642 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8643 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8644 | * @vsi: Pointer to VSI structure |
| 8645 | * @seed: Buffer to store the keys |
| 8646 | * @lut: Buffer to store the lookup table entries |
| 8647 | * @lut_size: Size of buffer to store the lookup table entries |
| 8648 | * |
| 8649 | * Returns 0 on success, negative on failure |
| 8650 | */ |
| 8651 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8652 | u8 *lut, u16 lut_size) |
| 8653 | { |
| 8654 | struct i40e_pf *pf = vsi->back; |
| 8655 | struct i40e_hw *hw = &pf->hw; |
| 8656 | u16 i; |
| 8657 | |
| 8658 | if (seed) { |
| 8659 | u32 *seed_dw = (u32 *)seed; |
| 8660 | |
| 8661 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8662 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8663 | } |
| 8664 | if (lut) { |
| 8665 | u32 *lut_dw = (u32 *)lut; |
| 8666 | |
| 8667 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8668 | return -EINVAL; |
| 8669 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8670 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8671 | } |
| 8672 | |
| 8673 | return 0; |
| 8674 | } |
| 8675 | |
| 8676 | /** |
| 8677 | * i40e_config_rss - Configure RSS keys and lut |
| 8678 | * @vsi: Pointer to VSI structure |
| 8679 | * @seed: RSS hash seed |
| 8680 | * @lut: Lookup table |
| 8681 | * @lut_size: Lookup table size |
| 8682 | * |
| 8683 | * Returns 0 on success, negative on failure |
| 8684 | */ |
| 8685 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8686 | { |
| 8687 | struct i40e_pf *pf = vsi->back; |
| 8688 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 8689 | if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8690 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8691 | else |
| 8692 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8693 | } |
| 8694 | |
| 8695 | /** |
| 8696 | * i40e_get_rss - Get RSS keys and lut |
| 8697 | * @vsi: Pointer to VSI structure |
| 8698 | * @seed: Buffer to store the keys |
| 8699 | * @lut: Buffer to store the lookup table entries |
| 8700 | * lut_size: Size of buffer to store the lookup table entries |
| 8701 | * |
| 8702 | * Returns 0 on success, negative on failure |
| 8703 | */ |
| 8704 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8705 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8706 | struct i40e_pf *pf = vsi->back; |
| 8707 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 8708 | if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8709 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8710 | else |
| 8711 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8712 | } |
| 8713 | |
| 8714 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8715 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8716 | * @pf: Pointer to board private structure |
| 8717 | * @lut: Lookup table |
| 8718 | * @rss_table_size: Lookup table size |
| 8719 | * @rss_size: Range of queue number for hashing |
| 8720 | */ |
Alan Brady | f158235 | 2016-08-24 11:33:46 -0700 | [diff] [blame] | 8721 | void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8722 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8723 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8724 | u16 i; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8725 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8726 | for (i = 0; i < rss_table_size; i++) |
| 8727 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8728 | } |
| 8729 | |
| 8730 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8731 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8732 | * @pf: board private structure |
| 8733 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8734 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8735 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8736 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8737 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8738 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8739 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8740 | u32 reg_val; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8741 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8742 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8743 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8744 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8745 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 8746 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8747 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8748 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8749 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8750 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8751 | |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8752 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8753 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8754 | reg_val = (pf->rss_table_size == 512) ? |
| 8755 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8756 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8757 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8758 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8759 | /* Determine the RSS size of the VSI */ |
Harshitha Ramamurthy | f25571b | 2017-02-21 15:55:40 -0800 | [diff] [blame] | 8760 | if (!vsi->rss_size) { |
| 8761 | u16 qcount; |
| 8762 | |
| 8763 | qcount = vsi->num_queue_pairs / vsi->tc_config.numtc; |
| 8764 | vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount); |
| 8765 | } |
Mitch Williams | a4fa59c | 2016-09-12 14:18:43 -0700 | [diff] [blame] | 8766 | if (!vsi->rss_size) |
| 8767 | return -EINVAL; |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8768 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8769 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8770 | if (!lut) |
| 8771 | return -ENOMEM; |
| 8772 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8773 | /* Use user configured lut if there is one, otherwise use default */ |
| 8774 | if (vsi->rss_lut_user) |
| 8775 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8776 | else |
| 8777 | 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] | 8778 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8779 | /* Use user configured hash key if there is one, otherwise |
| 8780 | * use default. |
| 8781 | */ |
| 8782 | if (vsi->rss_hkey_user) |
| 8783 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8784 | else |
| 8785 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8786 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8787 | kfree(lut); |
| 8788 | |
| 8789 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8790 | } |
| 8791 | |
| 8792 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8793 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8794 | * @pf: board private structure |
| 8795 | * @queue_count: the requested queue count for rss. |
| 8796 | * |
| 8797 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8798 | * count which may be different from the requested queue count. |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8799 | * Note: expects to be called while under rtnl_lock() |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8800 | **/ |
| 8801 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8802 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8803 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8804 | int new_rss_size; |
| 8805 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8806 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8807 | return 0; |
| 8808 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8809 | 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] | 8810 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8811 | if (queue_count != vsi->num_queue_pairs) { |
Harshitha Ramamurthy | f25571b | 2017-02-21 15:55:40 -0800 | [diff] [blame] | 8812 | u16 qcount; |
| 8813 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8814 | vsi->req_queue_pairs = queue_count; |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8815 | i40e_prep_for_reset(pf, true); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8816 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8817 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8818 | |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 8819 | i40e_reset_and_rebuild(pf, true, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8820 | |
| 8821 | /* Discard the user configured hash keys and lut, if less |
| 8822 | * queues are enabled. |
| 8823 | */ |
| 8824 | if (queue_count < vsi->rss_size) { |
| 8825 | i40e_clear_rss_config_user(vsi); |
| 8826 | dev_dbg(&pf->pdev->dev, |
| 8827 | "discard user configured hash keys and lut\n"); |
| 8828 | } |
| 8829 | |
| 8830 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Harshitha Ramamurthy | f25571b | 2017-02-21 15:55:40 -0800 | [diff] [blame] | 8831 | qcount = vsi->num_queue_pairs / vsi->tc_config.numtc; |
| 8832 | vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8833 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8834 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8835 | } |
Lihong Yang | 1281505 | 2016-09-27 11:28:48 -0700 | [diff] [blame] | 8836 | dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n", |
| 8837 | vsi->req_queue_pairs, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8838 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8839 | } |
| 8840 | |
| 8841 | /** |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8842 | * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8843 | * @pf: board private structure |
| 8844 | **/ |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8845 | i40e_status i40e_get_partition_bw_setting(struct i40e_pf *pf) |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8846 | { |
| 8847 | i40e_status status; |
| 8848 | bool min_valid, max_valid; |
| 8849 | u32 max_bw, min_bw; |
| 8850 | |
| 8851 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8852 | &min_valid, &max_valid); |
| 8853 | |
| 8854 | if (!status) { |
| 8855 | if (min_valid) |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8856 | pf->min_bw = min_bw; |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8857 | if (max_valid) |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8858 | pf->max_bw = max_bw; |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8859 | } |
| 8860 | |
| 8861 | return status; |
| 8862 | } |
| 8863 | |
| 8864 | /** |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8865 | * i40e_set_partition_bw_setting - Set BW settings for this PF partition |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8866 | * @pf: board private structure |
| 8867 | **/ |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8868 | i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf) |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8869 | { |
| 8870 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8871 | i40e_status status; |
| 8872 | |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8873 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8874 | 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] | 8875 | bw_data.max_bw[pf->hw.pf_id] = pf->max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8876 | 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] | 8877 | |
| 8878 | /* Set the new bandwidths */ |
| 8879 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8880 | |
| 8881 | return status; |
| 8882 | } |
| 8883 | |
| 8884 | /** |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8885 | * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8886 | * @pf: board private structure |
| 8887 | **/ |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 8888 | i40e_status i40e_commit_partition_bw_setting(struct i40e_pf *pf) |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8889 | { |
| 8890 | /* Commit temporary BW setting to permanent NVM image */ |
| 8891 | enum i40e_admin_queue_err last_aq_status; |
| 8892 | i40e_status ret; |
| 8893 | u16 nvm_word; |
| 8894 | |
| 8895 | if (pf->hw.partition_id != 1) { |
| 8896 | dev_info(&pf->pdev->dev, |
| 8897 | "Commit BW only works on partition 1! This is partition %d", |
| 8898 | pf->hw.partition_id); |
| 8899 | ret = I40E_NOT_SUPPORTED; |
| 8900 | goto bw_commit_out; |
| 8901 | } |
| 8902 | |
| 8903 | /* Acquire NVM for read access */ |
| 8904 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8905 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8906 | if (ret) { |
| 8907 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8908 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8909 | i40e_stat_str(&pf->hw, ret), |
| 8910 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8911 | goto bw_commit_out; |
| 8912 | } |
| 8913 | |
| 8914 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8915 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8916 | I40E_SR_NVM_CONTROL_WORD, |
| 8917 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8918 | false, NULL); |
| 8919 | /* Save off last admin queue command status before releasing |
| 8920 | * the NVM |
| 8921 | */ |
| 8922 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8923 | i40e_release_nvm(&pf->hw); |
| 8924 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8925 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8926 | i40e_stat_str(&pf->hw, ret), |
| 8927 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8928 | goto bw_commit_out; |
| 8929 | } |
| 8930 | |
| 8931 | /* Wait a bit for NVM release to complete */ |
| 8932 | msleep(50); |
| 8933 | |
| 8934 | /* Acquire NVM for write access */ |
| 8935 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8936 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8937 | if (ret) { |
| 8938 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8939 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8940 | i40e_stat_str(&pf->hw, ret), |
| 8941 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8942 | goto bw_commit_out; |
| 8943 | } |
| 8944 | /* Write it back out unchanged to initiate update NVM, |
| 8945 | * which will force a write of the shadow (alt) RAM to |
| 8946 | * the NVM - thus storing the bandwidth values permanently. |
| 8947 | */ |
| 8948 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8949 | I40E_SR_NVM_CONTROL_WORD, |
| 8950 | 0x10, sizeof(nvm_word), |
| 8951 | &nvm_word, true, NULL); |
| 8952 | /* Save off last admin queue command status before releasing |
| 8953 | * the NVM |
| 8954 | */ |
| 8955 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8956 | i40e_release_nvm(&pf->hw); |
| 8957 | if (ret) |
| 8958 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8959 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8960 | i40e_stat_str(&pf->hw, ret), |
| 8961 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8962 | bw_commit_out: |
| 8963 | |
| 8964 | return ret; |
| 8965 | } |
| 8966 | |
| 8967 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8968 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8969 | * @pf: board private structure to initialize |
| 8970 | * |
| 8971 | * i40e_sw_init initializes the Adapter private data structure. |
| 8972 | * Fields are initialized based on PCI device information and |
| 8973 | * OS network device settings (MTU size). |
| 8974 | **/ |
| 8975 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8976 | { |
| 8977 | int err = 0; |
| 8978 | int size; |
| 8979 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8980 | /* Set default capability flags */ |
| 8981 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8982 | I40E_FLAG_MSI_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8983 | I40E_FLAG_MSIX_ENABLED; |
| 8984 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8985 | /* Set default ITR */ |
| 8986 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8987 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8988 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8989 | /* Depending on PF configurations, it is possible that the RSS |
| 8990 | * maximum might end up larger than the available queues |
| 8991 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8992 | 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] | 8993 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8994 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8995 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8996 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8997 | if (pf->hw.func_caps.rss) { |
| 8998 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8999 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 9000 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9001 | } |
| 9002 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 9003 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 9004 | 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] | 9005 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 9006 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 9007 | if (i40e_get_partition_bw_setting(pf)) { |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 9008 | dev_warn(&pf->pdev->dev, |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 9009 | "Could not get partition bw settings\n"); |
| 9010 | } else { |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 9011 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 4fc8c67 | 2017-06-07 05:43:08 -0400 | [diff] [blame] | 9012 | "Partition BW Min = %8.8x, Max = %8.8x\n", |
| 9013 | pf->min_bw, pf->max_bw); |
| 9014 | |
| 9015 | /* nudge the Tx scheduler */ |
| 9016 | i40e_set_partition_bw_setting(pf); |
| 9017 | } |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 9018 | } |
| 9019 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9020 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 9021 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 9022 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 9023 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 9024 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 9025 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9026 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 9027 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 9028 | else |
| 9029 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9030 | pf->fdir_pf_filter_count = |
| 9031 | pf->hw.func_caps.fd_filters_guaranteed; |
| 9032 | pf->hw.fdir_shared_filter_count = |
| 9033 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9034 | } |
| 9035 | |
Anjali Singhai Jain | 5a43319 | 2017-06-23 04:24:45 -0400 | [diff] [blame] | 9036 | if (pf->hw.mac.type == I40E_MAC_X722) { |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9037 | pf->hw_features |= (I40E_HW_RSS_AQ_CAPABLE | |
| 9038 | I40E_HW_128_QP_RSS_CAPABLE | |
| 9039 | I40E_HW_ATR_EVICT_CAPABLE | |
| 9040 | I40E_HW_WB_ON_ITR_CAPABLE | |
| 9041 | I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
| 9042 | I40E_HW_NO_PCI_LINK_CHECK | |
| 9043 | I40E_HW_USE_SET_LLDP_MIB | |
| 9044 | I40E_HW_GENEVE_OFFLOAD_CAPABLE | |
| 9045 | I40E_HW_PTP_L4_CAPABLE | |
| 9046 | I40E_HW_WOL_MC_MAGIC_PKT_WAKE | |
| 9047 | I40E_HW_OUTER_UDP_CSUM_CAPABLE); |
Anjali Singhai Jain | 10a955f | 2017-06-23 04:24:48 -0400 | [diff] [blame] | 9048 | |
| 9049 | #define I40E_FDEVICT_PCTYPE_DEFAULT 0xc03 |
| 9050 | if (rd32(&pf->hw, I40E_GLQF_FDEVICTENA(1)) != |
| 9051 | I40E_FDEVICT_PCTYPE_DEFAULT) { |
| 9052 | dev_warn(&pf->pdev->dev, |
| 9053 | "FD EVICT PCTYPES are not right, disable FD HW EVICT\n"); |
| 9054 | pf->hw_features &= ~I40E_HW_ATR_EVICT_CAPABLE; |
| 9055 | } |
Anjali Singhai Jain | 5a43319 | 2017-06-23 04:24:45 -0400 | [diff] [blame] | 9056 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 9057 | ((pf->hw.aq.api_maj_ver == 1) && |
| 9058 | (pf->hw.aq.api_min_ver > 4))) { |
| 9059 | /* Supported in FW API version higher than 1.4 */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9060 | pf->hw_features |= I40E_HW_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | 5a43319 | 2017-06-23 04:24:45 -0400 | [diff] [blame] | 9061 | } |
| 9062 | |
| 9063 | /* Enable HW ATR eviction if possible */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9064 | if (pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE) |
Anjali Singhai Jain | 5a43319 | 2017-06-23 04:24:45 -0400 | [diff] [blame] | 9065 | pf->flags |= I40E_FLAG_HW_ATR_EVICT_ENABLED; |
| 9066 | |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 9067 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 9068 | (((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] | 9069 | (pf->hw.aq.fw_maj_ver < 4))) { |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9070 | pf->hw_features |= I40E_HW_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 9071 | /* No DCB support for FW < v4.33 */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9072 | pf->hw_features |= I40E_HW_NO_DCB_SUPPORT; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 9073 | } |
| 9074 | |
| 9075 | /* Disable FW LLDP if FW < v4.3 */ |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 9076 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 9077 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 9078 | (pf->hw.aq.fw_maj_ver < 4))) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9079 | pf->hw_features |= I40E_HW_STOP_FW_LLDP; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 9080 | |
| 9081 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 9082 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 9083 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 9084 | (pf->hw.aq.fw_maj_ver >= 5))) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9085 | pf->hw_features |= I40E_HW_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 9086 | |
Alan Brady | c3d26b7 | 2017-08-29 05:32:32 -0400 | [diff] [blame] | 9087 | /* Enable PTP L4 if FW > v6.0 */ |
| 9088 | if (pf->hw.mac.type == I40E_MAC_XL710 && |
| 9089 | pf->hw.aq.fw_maj_ver >= 6) |
| 9090 | pf->hw_features |= I40E_HW_PTP_L4_CAPABLE; |
| 9091 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9092 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9093 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9094 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 9095 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9096 | } |
| 9097 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9098 | if (pf->hw.func_caps.iwarp) { |
| 9099 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 9100 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 9101 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 9102 | } |
| 9103 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9104 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 9105 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9106 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 9107 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 9108 | pf->num_req_vfs = min_t(int, |
| 9109 | pf->hw.func_caps.num_vfs, |
| 9110 | I40E_MAX_VF_COUNT); |
| 9111 | } |
| 9112 | #endif /* CONFIG_PCI_IOV */ |
| 9113 | pf->eeprom_version = 0xDEAD; |
| 9114 | pf->lan_veb = I40E_NO_VEB; |
| 9115 | pf->lan_vsi = I40E_NO_VSI; |
| 9116 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 9117 | /* By default FW has this off for performance reasons */ |
| 9118 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 9119 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9120 | /* set up queue assignment tracking */ |
| 9121 | size = sizeof(struct i40e_lump_tracking) |
| 9122 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 9123 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 9124 | if (!pf->qp_pile) { |
| 9125 | err = -ENOMEM; |
| 9126 | goto sw_init_done; |
| 9127 | } |
| 9128 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 9129 | pf->qp_pile->search_hint = 0; |
| 9130 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 9131 | pf->tx_timeout_recovery_level = 1; |
| 9132 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9133 | mutex_init(&pf->switch_mutex); |
| 9134 | |
| 9135 | sw_init_done: |
| 9136 | return err; |
| 9137 | } |
| 9138 | |
| 9139 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 9140 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 9141 | * @pf: board private structure to initialize |
| 9142 | * @features: the feature set that the stack is suggesting |
| 9143 | * |
| 9144 | * returns a bool to indicate if reset needs to happen |
| 9145 | **/ |
| 9146 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 9147 | { |
| 9148 | bool need_reset = false; |
| 9149 | |
| 9150 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 9151 | * the state changed, we need to reset. |
| 9152 | */ |
| 9153 | if (features & NETIF_F_NTUPLE) { |
| 9154 | /* Enable filters and mark for reset */ |
| 9155 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 9156 | need_reset = true; |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 9157 | /* enable FD_SB only if there is MSI-X vector */ |
| 9158 | if (pf->num_fdsb_msix > 0) |
| 9159 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 9160 | } else { |
| 9161 | /* turn off filters, mark for reset and clear SW filter list */ |
| 9162 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 9163 | need_reset = true; |
| 9164 | i40e_fdir_filter_exit(pf); |
| 9165 | } |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 9166 | pf->flags &= ~(I40E_FLAG_FD_SB_ENABLED | |
| 9167 | I40E_FLAG_FD_SB_AUTO_DISABLED); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 9168 | /* reset fd counters */ |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 9169 | pf->fd_add_err = 0; |
| 9170 | pf->fd_atr_cnt = 0; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 9171 | /* if ATR was auto disabled it can be re-enabled. */ |
Jacob Keller | 47994c1 | 2017-04-19 09:25:57 -0400 | [diff] [blame] | 9172 | if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) { |
| 9173 | pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED; |
| 9174 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 9175 | (I40E_DEBUG_FD & pf->hw.debug_mask)) |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 9176 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
| 9177 | } |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 9178 | } |
| 9179 | return need_reset; |
| 9180 | } |
| 9181 | |
| 9182 | /** |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 9183 | * i40e_clear_rss_lut - clear the rx hash lookup table |
| 9184 | * @vsi: the VSI being configured |
| 9185 | **/ |
| 9186 | static void i40e_clear_rss_lut(struct i40e_vsi *vsi) |
| 9187 | { |
| 9188 | struct i40e_pf *pf = vsi->back; |
| 9189 | struct i40e_hw *hw = &pf->hw; |
| 9190 | u16 vf_id = vsi->vf_id; |
| 9191 | u8 i; |
| 9192 | |
| 9193 | if (vsi->type == I40E_VSI_MAIN) { |
| 9194 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 9195 | wr32(hw, I40E_PFQF_HLUT(i), 0); |
| 9196 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 9197 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 9198 | i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0); |
| 9199 | } else { |
| 9200 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 9201 | } |
| 9202 | } |
| 9203 | |
| 9204 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9205 | * i40e_set_features - set the netdev feature flags |
| 9206 | * @netdev: ptr to the netdev being adjusted |
| 9207 | * @features: the feature set that the stack is suggesting |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 9208 | * Note: expects to be called while under rtnl_lock() |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9209 | **/ |
| 9210 | static int i40e_set_features(struct net_device *netdev, |
| 9211 | netdev_features_t features) |
| 9212 | { |
| 9213 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 9214 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 9215 | struct i40e_pf *pf = vsi->back; |
| 9216 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9217 | |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 9218 | if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH)) |
| 9219 | i40e_pf_config_rss(pf); |
| 9220 | else if (!(features & NETIF_F_RXHASH) && |
| 9221 | netdev->features & NETIF_F_RXHASH) |
| 9222 | i40e_clear_rss_lut(vsi); |
| 9223 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9224 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 9225 | i40e_vlan_stripping_enable(vsi); |
| 9226 | else |
| 9227 | i40e_vlan_stripping_disable(vsi); |
| 9228 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 9229 | need_reset = i40e_set_ntuple(pf, features); |
| 9230 | |
| 9231 | if (need_reset) |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 9232 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED), true); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 9233 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9234 | return 0; |
| 9235 | } |
| 9236 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9237 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9238 | * 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] | 9239 | * @pf: board private structure |
| 9240 | * @port: The UDP port to look up |
| 9241 | * |
| 9242 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 9243 | **/ |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 9244 | 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] | 9245 | { |
| 9246 | u8 i; |
| 9247 | |
| 9248 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 9249 | if (pf->udp_ports[i].port == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9250 | return i; |
| 9251 | } |
| 9252 | |
| 9253 | return i; |
| 9254 | } |
| 9255 | |
| 9256 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9257 | * 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] | 9258 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9259 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9260 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9261 | static void i40e_udp_tunnel_add(struct net_device *netdev, |
| 9262 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9263 | { |
| 9264 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 9265 | struct i40e_vsi *vsi = np->vsi; |
| 9266 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 9267 | u16 port = ntohs(ti->port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9268 | u8 next_idx; |
| 9269 | u8 idx; |
| 9270 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9271 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9272 | |
| 9273 | /* Check if port already exists */ |
| 9274 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 9275 | netdev_info(netdev, "port %d already offloaded\n", port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9276 | return; |
| 9277 | } |
| 9278 | |
| 9279 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9280 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9281 | |
| 9282 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9283 | 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] | 9284 | port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9285 | return; |
| 9286 | } |
| 9287 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9288 | switch (ti->type) { |
| 9289 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9290 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 9291 | break; |
| 9292 | case UDP_TUNNEL_TYPE_GENEVE: |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9293 | if (!(pf->hw_features & I40E_HW_GENEVE_OFFLOAD_CAPABLE)) |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9294 | return; |
| 9295 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 9296 | break; |
| 9297 | default: |
| 9298 | return; |
| 9299 | } |
| 9300 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9301 | /* New port: add it and mark its index in the bitmap */ |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 9302 | pf->udp_ports[next_idx].port = port; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9303 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 9304 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9305 | } |
| 9306 | |
| 9307 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9308 | * 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] | 9309 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9310 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9311 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9312 | static void i40e_udp_tunnel_del(struct net_device *netdev, |
| 9313 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9314 | { |
| 9315 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 9316 | struct i40e_vsi *vsi = np->vsi; |
| 9317 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 9318 | u16 port = ntohs(ti->port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9319 | u8 idx; |
| 9320 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9321 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9322 | |
| 9323 | /* Check if port already exists */ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9324 | if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS) |
| 9325 | goto not_found; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9326 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9327 | switch (ti->type) { |
| 9328 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9329 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN) |
| 9330 | goto not_found; |
| 9331 | break; |
| 9332 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9333 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE) |
| 9334 | goto not_found; |
| 9335 | break; |
| 9336 | default: |
| 9337 | goto not_found; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9338 | } |
| 9339 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9340 | /* if port exists, set it to 0 (mark for deletion) |
| 9341 | * and make it pending |
| 9342 | */ |
Jacob Keller | 27826fd | 2017-04-19 09:25:50 -0400 | [diff] [blame] | 9343 | pf->udp_ports[idx].port = 0; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9344 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9345 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 9346 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9347 | return; |
| 9348 | not_found: |
| 9349 | netdev_warn(netdev, "UDP port %d was not found, not deleting\n", |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 9350 | port); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9351 | } |
| 9352 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9353 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 9354 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9355 | { |
| 9356 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 9357 | struct i40e_pf *pf = np->vsi->back; |
| 9358 | struct i40e_hw *hw = &pf->hw; |
| 9359 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9360 | if (!(pf->hw_features & I40E_HW_PORT_ID_VALID)) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9361 | return -EOPNOTSUPP; |
| 9362 | |
| 9363 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 9364 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 9365 | |
| 9366 | return 0; |
| 9367 | } |
| 9368 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 9369 | /** |
| 9370 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 9371 | * @ndm: the input from the stack |
| 9372 | * @tb: pointer to array of nladdr (unused) |
| 9373 | * @dev: the net device pointer |
| 9374 | * @addr: the MAC address entry being added |
| 9375 | * @flags: instructions from stack about fdb operation |
| 9376 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9377 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 9378 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 9379 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9380 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9381 | { |
| 9382 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9383 | struct i40e_pf *pf = np->vsi->back; |
| 9384 | int err = 0; |
| 9385 | |
| 9386 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 9387 | return -EOPNOTSUPP; |
| 9388 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 9389 | if (vid) { |
| 9390 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 9391 | return -EINVAL; |
| 9392 | } |
| 9393 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9394 | /* Hardware does not support aging addresses so if a |
| 9395 | * ndm_state is given only allow permanent addresses |
| 9396 | */ |
| 9397 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 9398 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 9399 | return -EINVAL; |
| 9400 | } |
| 9401 | |
| 9402 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 9403 | err = dev_uc_add_excl(dev, addr); |
| 9404 | else if (is_multicast_ether_addr(addr)) |
| 9405 | err = dev_mc_add_excl(dev, addr); |
| 9406 | else |
| 9407 | err = -EINVAL; |
| 9408 | |
| 9409 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 9410 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 9411 | err = 0; |
| 9412 | |
| 9413 | return err; |
| 9414 | } |
| 9415 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9416 | /** |
| 9417 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 9418 | * @dev: the netdev being configured |
| 9419 | * @nlh: RTNL message |
| 9420 | * |
| 9421 | * Inserts a new hardware bridge if not already created and |
| 9422 | * enables the bridging mode requested (VEB or VEPA). If the |
| 9423 | * hardware bridge has already been inserted and the request |
| 9424 | * is to change the mode then that requires a PF reset to |
| 9425 | * allow rebuild of the components with required hardware |
| 9426 | * bridge mode enabled. |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 9427 | * |
| 9428 | * Note: expects to be called while under rtnl_lock() |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9429 | **/ |
| 9430 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 9431 | struct nlmsghdr *nlh, |
| 9432 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9433 | { |
| 9434 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9435 | struct i40e_vsi *vsi = np->vsi; |
| 9436 | struct i40e_pf *pf = vsi->back; |
| 9437 | struct i40e_veb *veb = NULL; |
| 9438 | struct nlattr *attr, *br_spec; |
| 9439 | int i, rem; |
| 9440 | |
| 9441 | /* Only for PF VSI for now */ |
| 9442 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9443 | return -EOPNOTSUPP; |
| 9444 | |
| 9445 | /* Find the HW bridge for PF VSI */ |
| 9446 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9447 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9448 | veb = pf->veb[i]; |
| 9449 | } |
| 9450 | |
| 9451 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 9452 | |
| 9453 | nla_for_each_nested(attr, br_spec, rem) { |
| 9454 | __u16 mode; |
| 9455 | |
| 9456 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 9457 | continue; |
| 9458 | |
| 9459 | mode = nla_get_u16(attr); |
| 9460 | if ((mode != BRIDGE_MODE_VEPA) && |
| 9461 | (mode != BRIDGE_MODE_VEB)) |
| 9462 | return -EINVAL; |
| 9463 | |
| 9464 | /* Insert a new HW bridge */ |
| 9465 | if (!veb) { |
| 9466 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9467 | vsi->tc_config.enabled_tc); |
| 9468 | if (veb) { |
| 9469 | veb->bridge_mode = mode; |
| 9470 | i40e_config_bridge_mode(veb); |
| 9471 | } else { |
| 9472 | /* No Bridge HW offload available */ |
| 9473 | return -ENOENT; |
| 9474 | } |
| 9475 | break; |
| 9476 | } else if (mode != veb->bridge_mode) { |
| 9477 | /* Existing HW bridge but different mode needs reset */ |
| 9478 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9479 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 9480 | if (mode == BRIDGE_MODE_VEB) |
| 9481 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 9482 | else |
| 9483 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 9484 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED), |
| 9485 | true); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9486 | break; |
| 9487 | } |
| 9488 | } |
| 9489 | |
| 9490 | return 0; |
| 9491 | } |
| 9492 | |
| 9493 | /** |
| 9494 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 9495 | * @skb: skb buff |
| 9496 | * @pid: process id |
| 9497 | * @seq: RTNL message seq # |
| 9498 | * @dev: the netdev being configured |
| 9499 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 9500 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9501 | * |
| 9502 | * Return the mode in which the hardware bridge is operating in |
| 9503 | * i.e VEB or VEPA. |
| 9504 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9505 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 9506 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 9507 | u32 __always_unused filter_mask, |
| 9508 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9509 | { |
| 9510 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9511 | struct i40e_vsi *vsi = np->vsi; |
| 9512 | struct i40e_pf *pf = vsi->back; |
| 9513 | struct i40e_veb *veb = NULL; |
| 9514 | int i; |
| 9515 | |
| 9516 | /* Only for PF VSI for now */ |
| 9517 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9518 | return -EOPNOTSUPP; |
| 9519 | |
| 9520 | /* Find the HW bridge for the PF VSI */ |
| 9521 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9522 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9523 | veb = pf->veb[i]; |
| 9524 | } |
| 9525 | |
| 9526 | if (!veb) |
| 9527 | return 0; |
| 9528 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9529 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Huaibin Wang | 599b076 | 2016-09-26 09:51:18 +0200 | [diff] [blame] | 9530 | 0, 0, nlflags, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9531 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9532 | |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9533 | /** |
| 9534 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 9535 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 9536 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9537 | * @features: Offload features that the stack believes apply |
| 9538 | **/ |
| 9539 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 9540 | struct net_device *dev, |
| 9541 | netdev_features_t features) |
| 9542 | { |
Alexander Duyck | f114dca | 2016-10-25 16:08:46 -0700 | [diff] [blame] | 9543 | size_t len; |
| 9544 | |
| 9545 | /* No point in doing any of this if neither checksum nor GSO are |
| 9546 | * being requested for this frame. We can rule out both by just |
| 9547 | * checking for CHECKSUM_PARTIAL |
| 9548 | */ |
| 9549 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 9550 | return features; |
| 9551 | |
| 9552 | /* We cannot support GSO if the MSS is going to be less than |
| 9553 | * 64 bytes. If it is then we need to drop support for GSO. |
| 9554 | */ |
| 9555 | if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64)) |
| 9556 | features &= ~NETIF_F_GSO_MASK; |
| 9557 | |
| 9558 | /* MACLEN can support at most 63 words */ |
| 9559 | len = skb_network_header(skb) - skb->data; |
| 9560 | if (len & ~(63 * 2)) |
| 9561 | goto out_err; |
| 9562 | |
| 9563 | /* IPLEN and EIPLEN can support at most 127 dwords */ |
| 9564 | len = skb_transport_header(skb) - skb_network_header(skb); |
| 9565 | if (len & ~(127 * 4)) |
| 9566 | goto out_err; |
| 9567 | |
| 9568 | if (skb->encapsulation) { |
| 9569 | /* L4TUNLEN can support 127 words */ |
| 9570 | len = skb_inner_network_header(skb) - skb_transport_header(skb); |
| 9571 | if (len & ~(127 * 2)) |
| 9572 | goto out_err; |
| 9573 | |
| 9574 | /* IPLEN can support at most 127 dwords */ |
| 9575 | len = skb_inner_transport_header(skb) - |
| 9576 | skb_inner_network_header(skb); |
| 9577 | if (len & ~(127 * 4)) |
| 9578 | goto out_err; |
| 9579 | } |
| 9580 | |
| 9581 | /* No need to validate L4LEN as TCP is the only protocol with a |
| 9582 | * a flexible value and we support all possible values supported |
| 9583 | * by TCP, which is at most 15 dwords |
| 9584 | */ |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9585 | |
| 9586 | return features; |
Alexander Duyck | f114dca | 2016-10-25 16:08:46 -0700 | [diff] [blame] | 9587 | out_err: |
| 9588 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9589 | } |
| 9590 | |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 9591 | /** |
| 9592 | * i40e_xdp_setup - add/remove an XDP program |
| 9593 | * @vsi: VSI to changed |
| 9594 | * @prog: XDP program |
| 9595 | **/ |
| 9596 | static int i40e_xdp_setup(struct i40e_vsi *vsi, |
| 9597 | struct bpf_prog *prog) |
| 9598 | { |
| 9599 | int frame_size = vsi->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
| 9600 | struct i40e_pf *pf = vsi->back; |
| 9601 | struct bpf_prog *old_prog; |
| 9602 | bool need_reset; |
| 9603 | int i; |
| 9604 | |
| 9605 | /* Don't allow frames that span over multiple buffers */ |
| 9606 | if (frame_size > vsi->rx_buf_len) |
| 9607 | return -EINVAL; |
| 9608 | |
| 9609 | if (!i40e_enabled_xdp_vsi(vsi) && !prog) |
| 9610 | return 0; |
| 9611 | |
| 9612 | /* When turning XDP on->off/off->on we reset and rebuild the rings. */ |
| 9613 | need_reset = (i40e_enabled_xdp_vsi(vsi) != !!prog); |
| 9614 | |
| 9615 | if (need_reset) |
| 9616 | i40e_prep_for_reset(pf, true); |
| 9617 | |
| 9618 | old_prog = xchg(&vsi->xdp_prog, prog); |
| 9619 | |
| 9620 | if (need_reset) |
| 9621 | i40e_reset_and_rebuild(pf, true, true); |
| 9622 | |
| 9623 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 9624 | WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog); |
| 9625 | |
| 9626 | if (old_prog) |
| 9627 | bpf_prog_put(old_prog); |
| 9628 | |
| 9629 | return 0; |
| 9630 | } |
| 9631 | |
| 9632 | /** |
| 9633 | * i40e_xdp - implements ndo_xdp for i40e |
| 9634 | * @dev: netdevice |
| 9635 | * @xdp: XDP command |
| 9636 | **/ |
| 9637 | static int i40e_xdp(struct net_device *dev, |
| 9638 | struct netdev_xdp *xdp) |
| 9639 | { |
| 9640 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9641 | struct i40e_vsi *vsi = np->vsi; |
| 9642 | |
| 9643 | if (vsi->type != I40E_VSI_MAIN) |
| 9644 | return -EINVAL; |
| 9645 | |
| 9646 | switch (xdp->command) { |
| 9647 | case XDP_SETUP_PROG: |
| 9648 | return i40e_xdp_setup(vsi, xdp->prog); |
| 9649 | case XDP_QUERY_PROG: |
| 9650 | xdp->prog_attached = i40e_enabled_xdp_vsi(vsi); |
Daniel Borkmann | eb23039 | 2017-06-24 21:13:52 +0200 | [diff] [blame] | 9651 | 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] | 9652 | return 0; |
| 9653 | default: |
| 9654 | return -EINVAL; |
| 9655 | } |
| 9656 | } |
| 9657 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 9658 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9659 | .ndo_open = i40e_open, |
| 9660 | .ndo_stop = i40e_close, |
| 9661 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 9662 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 9663 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 9664 | .ndo_validate_addr = eth_validate_addr, |
| 9665 | .ndo_set_mac_address = i40e_set_mac, |
| 9666 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 9667 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9668 | .ndo_tx_timeout = i40e_tx_timeout, |
| 9669 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 9670 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 9671 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9672 | .ndo_poll_controller = i40e_netpoll, |
| 9673 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9674 | .ndo_setup_tc = __i40e_setup_tc, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9675 | .ndo_set_features = i40e_set_features, |
| 9676 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 9677 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9678 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9679 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 9680 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 9681 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Anjali Singhai Jain | c3bbbd2 | 2016-04-01 03:56:07 -0700 | [diff] [blame] | 9682 | .ndo_set_vf_trust = i40e_ndo_set_vf_trust, |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9683 | .ndo_udp_tunnel_add = i40e_udp_tunnel_add, |
| 9684 | .ndo_udp_tunnel_del = i40e_udp_tunnel_del, |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9685 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9686 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9687 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9688 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 9689 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Björn Töpel | 0c8493d | 2017-05-24 07:55:34 +0200 | [diff] [blame] | 9690 | .ndo_xdp = i40e_xdp, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9691 | }; |
| 9692 | |
| 9693 | /** |
| 9694 | * i40e_config_netdev - Setup the netdev flags |
| 9695 | * @vsi: the VSI being configured |
| 9696 | * |
| 9697 | * Returns 0 on success, negative value on failure |
| 9698 | **/ |
| 9699 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 9700 | { |
| 9701 | struct i40e_pf *pf = vsi->back; |
| 9702 | struct i40e_hw *hw = &pf->hw; |
| 9703 | struct i40e_netdev_priv *np; |
| 9704 | struct net_device *netdev; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 9705 | u8 broadcast[ETH_ALEN]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9706 | u8 mac_addr[ETH_ALEN]; |
| 9707 | int etherdev_size; |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9708 | netdev_features_t hw_enc_features; |
| 9709 | netdev_features_t hw_features; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9710 | |
| 9711 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9712 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9713 | if (!netdev) |
| 9714 | return -ENOMEM; |
| 9715 | |
| 9716 | vsi->netdev = netdev; |
| 9717 | np = netdev_priv(netdev); |
| 9718 | np->vsi = vsi; |
| 9719 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9720 | hw_enc_features = NETIF_F_SG | |
| 9721 | NETIF_F_IP_CSUM | |
| 9722 | NETIF_F_IPV6_CSUM | |
| 9723 | NETIF_F_HIGHDMA | |
| 9724 | NETIF_F_SOFT_FEATURES | |
| 9725 | NETIF_F_TSO | |
| 9726 | NETIF_F_TSO_ECN | |
| 9727 | NETIF_F_TSO6 | |
| 9728 | NETIF_F_GSO_GRE | |
| 9729 | NETIF_F_GSO_GRE_CSUM | |
| 9730 | NETIF_F_GSO_PARTIAL | |
| 9731 | NETIF_F_GSO_UDP_TUNNEL | |
| 9732 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
| 9733 | NETIF_F_SCTP_CRC | |
| 9734 | NETIF_F_RXHASH | |
| 9735 | NETIF_F_RXCSUM | |
| 9736 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9737 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 9738 | if (!(pf->hw_features & I40E_HW_OUTER_UDP_CSUM_CAPABLE)) |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9739 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
| 9740 | |
| 9741 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9742 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9743 | netdev->hw_enc_features |= hw_enc_features; |
| 9744 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9745 | /* record features VLANs can make use of */ |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9746 | netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9747 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9748 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9749 | netdev->hw_features |= NETIF_F_NTUPLE; |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9750 | hw_features = hw_enc_features | |
| 9751 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9752 | NETIF_F_HW_VLAN_CTAG_RX; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9753 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9754 | netdev->hw_features |= hw_features; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9755 | |
Preethi Banala | bacd75c | 2017-03-27 14:43:18 -0700 | [diff] [blame] | 9756 | netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9757 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9758 | |
| 9759 | if (vsi->type == I40E_VSI_MAIN) { |
| 9760 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9761 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Jacob Keller | 41c4c2b | 2017-04-05 07:50:57 -0400 | [diff] [blame] | 9762 | /* The following steps are necessary for two reasons. First, |
| 9763 | * some older NVM configurations load a default MAC-VLAN |
| 9764 | * filter that will accept any tagged packet, and we want to |
| 9765 | * replace this with a normal filter. Additionally, it is |
| 9766 | * possible our MAC address was provided by the platform using |
| 9767 | * Open Firmware or similar. |
| 9768 | * |
| 9769 | * Thus, we need to remove the default filter and install one |
| 9770 | * specific to the MAC address. |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 9771 | */ |
| 9772 | i40e_rm_default_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9773 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 9774 | i40e_add_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9775 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9776 | } else { |
Jacob Keller | 8c9eb35 | 2017-07-12 05:46:12 -0400 | [diff] [blame] | 9777 | /* Relate the VSI_VMDQ name to the VSI_MAIN name. Note that we |
| 9778 | * are still limited by IFNAMSIZ, but we're adding 'v%d\0' to |
| 9779 | * the end, which is 4 bytes long, so force truncation of the |
| 9780 | * original name by IFNAMSIZ - 4 |
| 9781 | */ |
| 9782 | snprintf(netdev->name, IFNAMSIZ, "%.*sv%%d", |
| 9783 | IFNAMSIZ - 4, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9784 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9785 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9786 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9787 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 9788 | i40e_add_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9789 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9790 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9791 | |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 9792 | /* Add the broadcast filter so that we initially will receive |
| 9793 | * broadcast packets. Note that when a new VLAN is first added the |
| 9794 | * driver will convert all filters marked I40E_VLAN_ANY into VLAN |
| 9795 | * specific filters as part of transitioning into "vlan" operation. |
| 9796 | * When more VLANs are added, the driver will copy each existing MAC |
| 9797 | * filter and add it for the new VLAN. |
| 9798 | * |
| 9799 | * Broadcast filters are handled specially by |
| 9800 | * i40e_sync_filters_subtask, as the driver must to set the broadcast |
| 9801 | * promiscuous bit instead of adding this directly as a MAC/VLAN |
| 9802 | * filter. The subtask will update the correct broadcast promiscuous |
| 9803 | * bits as VLANs become active or inactive. |
| 9804 | */ |
| 9805 | eth_broadcast_addr(broadcast); |
| 9806 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 9807 | i40e_add_mac_filter(vsi, broadcast); |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 9808 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 9809 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9810 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9811 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9812 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9813 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9814 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9815 | /* Setup netdev TC information */ |
| 9816 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9817 | |
| 9818 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9819 | netdev->watchdog_timeo = 5 * HZ; |
| 9820 | i40e_set_ethtool_ops(netdev); |
| 9821 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 9822 | /* MTU range: 68 - 9706 */ |
| 9823 | netdev->min_mtu = ETH_MIN_MTU; |
Mitch Williams | 1e3a5fd | 2017-06-23 04:24:43 -0400 | [diff] [blame] | 9824 | netdev->max_mtu = I40E_MAX_RXBUFFER - I40E_PACKET_HDR_PAD; |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 9825 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9826 | return 0; |
| 9827 | } |
| 9828 | |
| 9829 | /** |
| 9830 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9831 | * @vsi: the VSI being removed |
| 9832 | * |
| 9833 | * Returns 0 on success, negative value on failure |
| 9834 | **/ |
| 9835 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9836 | { |
| 9837 | /* remove default VSI is not allowed */ |
| 9838 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9839 | return; |
| 9840 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9841 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9842 | } |
| 9843 | |
| 9844 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9845 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9846 | * @vsi: the VSI being queried |
| 9847 | * |
| 9848 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9849 | **/ |
| 9850 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9851 | { |
| 9852 | struct i40e_veb *veb; |
| 9853 | struct i40e_pf *pf = vsi->back; |
| 9854 | |
| 9855 | /* Uplink is not a bridge so default to VEB */ |
| 9856 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9857 | return 1; |
| 9858 | |
| 9859 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9860 | if (!veb) { |
| 9861 | dev_info(&pf->pdev->dev, |
| 9862 | "There is no veb associated with the bridge\n"); |
| 9863 | return -ENOENT; |
| 9864 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9865 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9866 | /* Uplink is a bridge in VEPA mode */ |
| 9867 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9868 | return 0; |
| 9869 | } else { |
| 9870 | /* Uplink is a bridge in VEB mode */ |
| 9871 | return 1; |
| 9872 | } |
| 9873 | |
| 9874 | /* VEPA is now default bridge, so return 0 */ |
| 9875 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9876 | } |
| 9877 | |
| 9878 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9879 | * i40e_add_vsi - Add a VSI to the switch |
| 9880 | * @vsi: the VSI being configured |
| 9881 | * |
| 9882 | * This initializes a VSI context depending on the VSI type to be added and |
| 9883 | * passes it down to the add_vsi aq command. |
| 9884 | **/ |
| 9885 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9886 | { |
| 9887 | int ret = -ENODEV; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9888 | struct i40e_pf *pf = vsi->back; |
| 9889 | struct i40e_hw *hw = &pf->hw; |
| 9890 | struct i40e_vsi_context ctxt; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9891 | struct i40e_mac_filter *f; |
| 9892 | struct hlist_node *h; |
| 9893 | int bkt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9894 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9895 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9896 | int f_count = 0; |
| 9897 | |
| 9898 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9899 | switch (vsi->type) { |
| 9900 | case I40E_VSI_MAIN: |
| 9901 | /* The PF's main VSI is already setup as part of the |
| 9902 | * device initialization, so we'll not bother with |
| 9903 | * the add_vsi call, but we will retrieve the current |
| 9904 | * VSI context. |
| 9905 | */ |
| 9906 | ctxt.seid = pf->main_vsi_seid; |
| 9907 | ctxt.pf_num = pf->hw.pf_id; |
| 9908 | ctxt.vf_num = 0; |
| 9909 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9910 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9911 | if (ret) { |
| 9912 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9913 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9914 | i40e_stat_str(&pf->hw, ret), |
| 9915 | i40e_aq_str(&pf->hw, |
| 9916 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9917 | return -ENOENT; |
| 9918 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9919 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9920 | vsi->info.valid_sections = 0; |
| 9921 | |
| 9922 | vsi->seid = ctxt.seid; |
| 9923 | vsi->id = ctxt.vsi_number; |
| 9924 | |
| 9925 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9926 | |
Mitch Williams | 64615b5 | 2017-08-29 05:32:30 -0400 | [diff] [blame] | 9927 | /* Source pruning is enabled by default, so the flag is |
| 9928 | * negative logic - if it's set, we need to fiddle with |
| 9929 | * the VSI to disable source pruning. |
| 9930 | */ |
| 9931 | if (pf->flags & I40E_FLAG_SOURCE_PRUNING_DISABLED) { |
| 9932 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9933 | ctxt.seid = pf->main_vsi_seid; |
| 9934 | ctxt.pf_num = pf->hw.pf_id; |
| 9935 | ctxt.vf_num = 0; |
| 9936 | ctxt.info.valid_sections |= |
| 9937 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9938 | ctxt.info.switch_id = |
| 9939 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB); |
| 9940 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9941 | if (ret) { |
| 9942 | dev_info(&pf->pdev->dev, |
| 9943 | "update vsi failed, err %s aq_err %s\n", |
| 9944 | i40e_stat_str(&pf->hw, ret), |
| 9945 | i40e_aq_str(&pf->hw, |
| 9946 | pf->hw.aq.asq_last_status)); |
| 9947 | ret = -ENOENT; |
| 9948 | goto err; |
| 9949 | } |
| 9950 | } |
| 9951 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9952 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9953 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9954 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9955 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9956 | ctxt.seid = pf->main_vsi_seid; |
| 9957 | ctxt.pf_num = pf->hw.pf_id; |
| 9958 | ctxt.vf_num = 0; |
| 9959 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9960 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9961 | if (ret) { |
| 9962 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9963 | "update vsi failed, err %s aq_err %s\n", |
| 9964 | i40e_stat_str(&pf->hw, ret), |
| 9965 | i40e_aq_str(&pf->hw, |
| 9966 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9967 | ret = -ENOENT; |
| 9968 | goto err; |
| 9969 | } |
| 9970 | /* update the local VSI info queue map */ |
| 9971 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9972 | vsi->info.valid_sections = 0; |
| 9973 | } else { |
| 9974 | /* Default/Main VSI is only enabled for TC0 |
| 9975 | * reconfigure it to enable all TCs that are |
| 9976 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9977 | * For MFP case the iSCSI PF would use this |
| 9978 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9979 | */ |
| 9980 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9981 | if (ret) { |
Carolyn Wyborny | 1927923 | 2017-07-14 09:10:07 -0400 | [diff] [blame] | 9982 | /* Single TC condition is not fatal, |
| 9983 | * message and continue |
| 9984 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9985 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9986 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9987 | enabled_tc, |
| 9988 | i40e_stat_str(&pf->hw, ret), |
| 9989 | i40e_aq_str(&pf->hw, |
| 9990 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9991 | } |
| 9992 | } |
| 9993 | break; |
| 9994 | |
| 9995 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9996 | ctxt.pf_num = hw->pf_id; |
| 9997 | ctxt.vf_num = 0; |
| 9998 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9999 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10000 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 10001 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 10002 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10003 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 10004 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10005 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 10006 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10007 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10008 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10009 | break; |
| 10010 | |
| 10011 | case I40E_VSI_VMDQ2: |
| 10012 | ctxt.pf_num = hw->pf_id; |
| 10013 | ctxt.vf_num = 0; |
| 10014 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 10015 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10016 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 10017 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10018 | /* This VSI is connected to VEB so the switch_id |
| 10019 | * should be set to zero by default. |
| 10020 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10021 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 10022 | ctxt.info.valid_sections |= |
| 10023 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 10024 | ctxt.info.switch_id = |
| 10025 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 10026 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10027 | |
| 10028 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 10029 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 10030 | break; |
| 10031 | |
| 10032 | case I40E_VSI_SRIOV: |
| 10033 | ctxt.pf_num = hw->pf_id; |
| 10034 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 10035 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 10036 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10037 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 10038 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10039 | /* This VSI is connected to VEB so the switch_id |
| 10040 | * should be set to zero by default. |
| 10041 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10042 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 10043 | ctxt.info.valid_sections |= |
| 10044 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 10045 | ctxt.info.switch_id = |
| 10046 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 10047 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10048 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10049 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 10050 | ctxt.info.valid_sections |= |
| 10051 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 10052 | ctxt.info.queueing_opt_flags |= |
Ashish Shah | 4b28cdb | 2016-05-03 15:13:17 -0700 | [diff] [blame] | 10053 | (I40E_AQ_VSI_QUE_OPT_TCP_ENA | |
| 10054 | I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10055 | } |
| 10056 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10057 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 10058 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 10059 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 10060 | ctxt.info.valid_sections |= |
| 10061 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 10062 | ctxt.info.sec_flags |= |
| 10063 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 10064 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 10065 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10066 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 10067 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 10068 | break; |
| 10069 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10070 | case I40E_VSI_IWARP: |
| 10071 | /* send down message to iWARP */ |
| 10072 | break; |
| 10073 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10074 | default: |
| 10075 | return -ENODEV; |
| 10076 | } |
| 10077 | |
| 10078 | if (vsi->type != I40E_VSI_MAIN) { |
| 10079 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 10080 | if (ret) { |
| 10081 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10082 | "add vsi failed, err %s aq_err %s\n", |
| 10083 | i40e_stat_str(&pf->hw, ret), |
| 10084 | i40e_aq_str(&pf->hw, |
| 10085 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10086 | ret = -ENOENT; |
| 10087 | goto err; |
| 10088 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 10089 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10090 | vsi->info.valid_sections = 0; |
| 10091 | vsi->seid = ctxt.seid; |
| 10092 | vsi->id = ctxt.vsi_number; |
| 10093 | } |
| 10094 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 10095 | vsi->active_filters = 0; |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 10096 | clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10097 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10098 | /* If macvlan filters already exist, force them to get loaded */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10099 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 10100 | f->state = I40E_FILTER_NEW; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10101 | f_count++; |
| 10102 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10103 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 10104 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10105 | if (f_count) { |
| 10106 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 10107 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 10108 | } |
| 10109 | |
| 10110 | /* Update VSI BW information */ |
| 10111 | ret = i40e_vsi_get_bw_info(vsi); |
| 10112 | if (ret) { |
| 10113 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10114 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 10115 | i40e_stat_str(&pf->hw, ret), |
| 10116 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10117 | /* VSI is already added so not tearing that up */ |
| 10118 | ret = 0; |
| 10119 | } |
| 10120 | |
| 10121 | err: |
| 10122 | return ret; |
| 10123 | } |
| 10124 | |
| 10125 | /** |
| 10126 | * i40e_vsi_release - Delete a VSI and free its resources |
| 10127 | * @vsi: the VSI being removed |
| 10128 | * |
| 10129 | * Returns 0 on success or < 0 on error |
| 10130 | **/ |
| 10131 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 10132 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10133 | struct i40e_mac_filter *f; |
| 10134 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10135 | struct i40e_veb *veb = NULL; |
| 10136 | struct i40e_pf *pf; |
| 10137 | u16 uplink_seid; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10138 | int i, n, bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10139 | |
| 10140 | pf = vsi->back; |
| 10141 | |
| 10142 | /* release of a VEB-owner or last VSI is not allowed */ |
| 10143 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 10144 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 10145 | vsi->seid, vsi->uplink_seid); |
| 10146 | return -ENODEV; |
| 10147 | } |
| 10148 | if (vsi == pf->vsi[pf->lan_vsi] && |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 10149 | !test_bit(__I40E_DOWN, pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10150 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 10151 | return -ENODEV; |
| 10152 | } |
| 10153 | |
| 10154 | uplink_seid = vsi->uplink_seid; |
| 10155 | if (vsi->type != I40E_VSI_SRIOV) { |
| 10156 | if (vsi->netdev_registered) { |
| 10157 | vsi->netdev_registered = false; |
| 10158 | if (vsi->netdev) { |
| 10159 | /* results in a call to i40e_close() */ |
| 10160 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10161 | } |
| 10162 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 10163 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10164 | } |
| 10165 | i40e_vsi_disable_irq(vsi); |
| 10166 | } |
| 10167 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10168 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 10169 | |
| 10170 | /* clear the sync flag on all filters */ |
| 10171 | if (vsi->netdev) { |
| 10172 | __dev_uc_unsync(vsi->netdev, NULL); |
| 10173 | __dev_mc_unsync(vsi->netdev, NULL); |
| 10174 | } |
| 10175 | |
| 10176 | /* make sure any remaining filters are marked for deletion */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10177 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 10178 | __i40e_del_filter(vsi, f); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 10179 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 10180 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 10181 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 10182 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10183 | |
| 10184 | i40e_vsi_delete(vsi); |
| 10185 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 10186 | if (vsi->netdev) { |
| 10187 | free_netdev(vsi->netdev); |
| 10188 | vsi->netdev = NULL; |
| 10189 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10190 | i40e_vsi_clear_rings(vsi); |
| 10191 | i40e_vsi_clear(vsi); |
| 10192 | |
| 10193 | /* If this was the last thing on the VEB, except for the |
| 10194 | * controlling VSI, remove the VEB, which puts the controlling |
| 10195 | * VSI onto the next level down in the switch. |
| 10196 | * |
| 10197 | * Well, okay, there's one more exception here: don't remove |
| 10198 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 10199 | * from up the network stack. |
| 10200 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10201 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10202 | if (pf->vsi[i] && |
| 10203 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 10204 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 10205 | n++; /* count the VSIs */ |
| 10206 | } |
| 10207 | } |
| 10208 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10209 | if (!pf->veb[i]) |
| 10210 | continue; |
| 10211 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 10212 | n++; /* count the VEBs */ |
| 10213 | if (pf->veb[i]->seid == uplink_seid) |
| 10214 | veb = pf->veb[i]; |
| 10215 | } |
| 10216 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 10217 | i40e_veb_release(veb); |
| 10218 | |
| 10219 | return 0; |
| 10220 | } |
| 10221 | |
| 10222 | /** |
| 10223 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 10224 | * @vsi: ptr to the VSI |
| 10225 | * |
| 10226 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 10227 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 10228 | * newly allocated VSI. |
| 10229 | * |
| 10230 | * Returns 0 on success or negative on failure |
| 10231 | **/ |
| 10232 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 10233 | { |
| 10234 | int ret = -ENOENT; |
| 10235 | struct i40e_pf *pf = vsi->back; |
| 10236 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 10237 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10238 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 10239 | vsi->seid); |
| 10240 | return -EEXIST; |
| 10241 | } |
| 10242 | |
| 10243 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 10244 | 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] | 10245 | vsi->seid, vsi->base_vector); |
| 10246 | return -EEXIST; |
| 10247 | } |
| 10248 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 10249 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10250 | if (ret) { |
| 10251 | dev_info(&pf->pdev->dev, |
| 10252 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 10253 | vsi->num_q_vectors, vsi->seid, ret); |
| 10254 | vsi->num_q_vectors = 0; |
| 10255 | goto vector_setup_out; |
| 10256 | } |
| 10257 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 10258 | /* In Legacy mode, we do not have to get any other vector since we |
| 10259 | * piggyback on the misc/ICR0 for queue interrupts. |
| 10260 | */ |
| 10261 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 10262 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 10263 | if (vsi->num_q_vectors) |
| 10264 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 10265 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10266 | if (vsi->base_vector < 0) { |
| 10267 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 10268 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 10269 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10270 | i40e_vsi_free_q_vectors(vsi); |
| 10271 | ret = -ENOENT; |
| 10272 | goto vector_setup_out; |
| 10273 | } |
| 10274 | |
| 10275 | vector_setup_out: |
| 10276 | return ret; |
| 10277 | } |
| 10278 | |
| 10279 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10280 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 10281 | * @vsi: pointer to the vsi. |
| 10282 | * |
| 10283 | * This re-allocates a vsi's queue resources. |
| 10284 | * |
| 10285 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 10286 | * on success, otherwise returns NULL on failure. |
| 10287 | **/ |
| 10288 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 10289 | { |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 10290 | u16 alloc_queue_pairs; |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 10291 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10292 | u8 enabled_tc; |
| 10293 | int ret; |
| 10294 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 10295 | if (!vsi) |
| 10296 | return NULL; |
| 10297 | |
| 10298 | pf = vsi->back; |
| 10299 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10300 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 10301 | i40e_vsi_clear_rings(vsi); |
| 10302 | |
| 10303 | i40e_vsi_free_arrays(vsi, false); |
| 10304 | i40e_set_num_rings_in_vsi(vsi); |
| 10305 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 10306 | if (ret) |
| 10307 | goto err_vsi; |
| 10308 | |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 10309 | alloc_queue_pairs = vsi->alloc_queue_pairs * |
| 10310 | (i40e_enabled_xdp_vsi(vsi) ? 2 : 1); |
| 10311 | |
| 10312 | 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] | 10313 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 10314 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10315 | "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] | 10316 | alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10317 | goto err_vsi; |
| 10318 | } |
| 10319 | vsi->base_queue = ret; |
| 10320 | |
| 10321 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 10322 | * layout configurations. |
| 10323 | */ |
| 10324 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 10325 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10326 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10327 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 10328 | if (vsi->type == I40E_VSI_MAIN) |
| 10329 | i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10330 | |
| 10331 | /* assign it some queues */ |
| 10332 | ret = i40e_alloc_rings(vsi); |
| 10333 | if (ret) |
| 10334 | goto err_rings; |
| 10335 | |
| 10336 | /* map all of the rings to the q_vectors */ |
| 10337 | i40e_vsi_map_rings_to_vectors(vsi); |
| 10338 | return vsi; |
| 10339 | |
| 10340 | err_rings: |
| 10341 | i40e_vsi_free_q_vectors(vsi); |
| 10342 | if (vsi->netdev_registered) { |
| 10343 | vsi->netdev_registered = false; |
| 10344 | unregister_netdev(vsi->netdev); |
| 10345 | free_netdev(vsi->netdev); |
| 10346 | vsi->netdev = NULL; |
| 10347 | } |
| 10348 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 10349 | err_vsi: |
| 10350 | i40e_vsi_clear(vsi); |
| 10351 | return NULL; |
| 10352 | } |
| 10353 | |
| 10354 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10355 | * i40e_vsi_setup - Set up a VSI by a given type |
| 10356 | * @pf: board private structure |
| 10357 | * @type: VSI type |
| 10358 | * @uplink_seid: the switch element to link to |
| 10359 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 10360 | * |
| 10361 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 10362 | * to the identified VEB. |
| 10363 | * |
| 10364 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 10365 | * success, otherwise returns NULL on failure. |
| 10366 | **/ |
| 10367 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 10368 | u16 uplink_seid, u32 param1) |
| 10369 | { |
| 10370 | struct i40e_vsi *vsi = NULL; |
| 10371 | struct i40e_veb *veb = NULL; |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 10372 | u16 alloc_queue_pairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10373 | int ret, i; |
| 10374 | int v_idx; |
| 10375 | |
| 10376 | /* The requested uplink_seid must be either |
| 10377 | * - the PF's port seid |
| 10378 | * no VEB is needed because this is the PF |
| 10379 | * or this is a Flow Director special case VSI |
| 10380 | * - seid of an existing VEB |
| 10381 | * - seid of a VSI that owns an existing VEB |
| 10382 | * - seid of a VSI that doesn't own a VEB |
| 10383 | * a new VEB is created and the VSI becomes the owner |
| 10384 | * - seid of the PF VSI, which is what creates the first VEB |
| 10385 | * this is a special case of the previous |
| 10386 | * |
| 10387 | * Find which uplink_seid we were given and create a new VEB if needed |
| 10388 | */ |
| 10389 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10390 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 10391 | veb = pf->veb[i]; |
| 10392 | break; |
| 10393 | } |
| 10394 | } |
| 10395 | |
| 10396 | if (!veb && uplink_seid != pf->mac_seid) { |
| 10397 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10398 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10399 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 10400 | vsi = pf->vsi[i]; |
| 10401 | break; |
| 10402 | } |
| 10403 | } |
| 10404 | if (!vsi) { |
| 10405 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 10406 | uplink_seid); |
| 10407 | return NULL; |
| 10408 | } |
| 10409 | |
| 10410 | if (vsi->uplink_seid == pf->mac_seid) |
| 10411 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 10412 | vsi->tc_config.enabled_tc); |
| 10413 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 10414 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 10415 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 10416 | if (veb) { |
| 10417 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 10418 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 10419 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 10420 | return NULL; |
| 10421 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 10422 | /* We come up by default in VEPA mode if SRIOV is not |
| 10423 | * already enabled, in which case we can't force VEPA |
| 10424 | * mode. |
| 10425 | */ |
| 10426 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 10427 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 10428 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 10429 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10430 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 10431 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10432 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 10433 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 10434 | veb = pf->veb[i]; |
| 10435 | } |
| 10436 | if (!veb) { |
| 10437 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 10438 | return NULL; |
| 10439 | } |
| 10440 | |
| 10441 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10442 | uplink_seid = veb->seid; |
| 10443 | } |
| 10444 | |
| 10445 | /* get vsi sw struct */ |
| 10446 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 10447 | if (v_idx < 0) |
| 10448 | goto err_alloc; |
| 10449 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10450 | if (!vsi) |
| 10451 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10452 | vsi->type = type; |
| 10453 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 10454 | |
| 10455 | if (type == I40E_VSI_MAIN) |
| 10456 | pf->lan_vsi = v_idx; |
| 10457 | else if (type == I40E_VSI_SRIOV) |
| 10458 | vsi->vf_id = param1; |
| 10459 | /* assign it some queues */ |
Björn Töpel | 74608d1 | 2017-05-24 07:55:35 +0200 | [diff] [blame] | 10460 | alloc_queue_pairs = vsi->alloc_queue_pairs * |
| 10461 | (i40e_enabled_xdp_vsi(vsi) ? 2 : 1); |
| 10462 | |
| 10463 | 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] | 10464 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 10465 | dev_info(&pf->pdev->dev, |
| 10466 | "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] | 10467 | alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10468 | goto err_vsi; |
| 10469 | } |
| 10470 | vsi->base_queue = ret; |
| 10471 | |
| 10472 | /* get a VSI from the hardware */ |
| 10473 | vsi->uplink_seid = uplink_seid; |
| 10474 | ret = i40e_add_vsi(vsi); |
| 10475 | if (ret) |
| 10476 | goto err_vsi; |
| 10477 | |
| 10478 | switch (vsi->type) { |
| 10479 | /* setup the netdev if needed */ |
| 10480 | case I40E_VSI_MAIN: |
| 10481 | case I40E_VSI_VMDQ2: |
| 10482 | ret = i40e_config_netdev(vsi); |
| 10483 | if (ret) |
| 10484 | goto err_netdev; |
| 10485 | ret = register_netdev(vsi->netdev); |
| 10486 | if (ret) |
| 10487 | goto err_netdev; |
| 10488 | vsi->netdev_registered = true; |
| 10489 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10490 | #ifdef CONFIG_I40E_DCB |
| 10491 | /* Setup DCB netlink interface */ |
| 10492 | i40e_dcbnl_setup(vsi); |
| 10493 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10494 | /* fall through */ |
| 10495 | |
| 10496 | case I40E_VSI_FDIR: |
| 10497 | /* set up vectors and rings if needed */ |
| 10498 | ret = i40e_vsi_setup_vectors(vsi); |
| 10499 | if (ret) |
| 10500 | goto err_msix; |
| 10501 | |
| 10502 | ret = i40e_alloc_rings(vsi); |
| 10503 | if (ret) |
| 10504 | goto err_rings; |
| 10505 | |
| 10506 | /* map all of the rings to the q_vectors */ |
| 10507 | i40e_vsi_map_rings_to_vectors(vsi); |
| 10508 | |
| 10509 | i40e_vsi_reset_stats(vsi); |
| 10510 | break; |
| 10511 | |
| 10512 | default: |
| 10513 | /* no netdev or rings for the other VSI types */ |
| 10514 | break; |
| 10515 | } |
| 10516 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 10517 | if ((pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) && |
Anjali Singhai Jain | e25d00b8 | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 10518 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 10519 | ret = i40e_vsi_config_rss(vsi); |
| 10520 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10521 | return vsi; |
| 10522 | |
| 10523 | err_rings: |
| 10524 | i40e_vsi_free_q_vectors(vsi); |
| 10525 | err_msix: |
| 10526 | if (vsi->netdev_registered) { |
| 10527 | vsi->netdev_registered = false; |
| 10528 | unregister_netdev(vsi->netdev); |
| 10529 | free_netdev(vsi->netdev); |
| 10530 | vsi->netdev = NULL; |
| 10531 | } |
| 10532 | err_netdev: |
| 10533 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 10534 | err_vsi: |
| 10535 | i40e_vsi_clear(vsi); |
| 10536 | err_alloc: |
| 10537 | return NULL; |
| 10538 | } |
| 10539 | |
| 10540 | /** |
| 10541 | * i40e_veb_get_bw_info - Query VEB BW information |
| 10542 | * @veb: the veb to query |
| 10543 | * |
| 10544 | * Query the Tx scheduler BW configuration data for given VEB |
| 10545 | **/ |
| 10546 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 10547 | { |
| 10548 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 10549 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 10550 | struct i40e_pf *pf = veb->pf; |
| 10551 | struct i40e_hw *hw = &pf->hw; |
| 10552 | u32 tc_bw_max; |
| 10553 | int ret = 0; |
| 10554 | int i; |
| 10555 | |
| 10556 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 10557 | &bw_data, NULL); |
| 10558 | if (ret) { |
| 10559 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10560 | "query veb bw config failed, err %s aq_err %s\n", |
| 10561 | i40e_stat_str(&pf->hw, ret), |
| 10562 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10563 | goto out; |
| 10564 | } |
| 10565 | |
| 10566 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 10567 | &ets_data, NULL); |
| 10568 | if (ret) { |
| 10569 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10570 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 10571 | i40e_stat_str(&pf->hw, ret), |
| 10572 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10573 | goto out; |
| 10574 | } |
| 10575 | |
| 10576 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 10577 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 10578 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 10579 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10580 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 10581 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 10582 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 10583 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 10584 | veb->bw_tc_limit_credits[i] = |
| 10585 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 10586 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 10587 | } |
| 10588 | |
| 10589 | out: |
| 10590 | return ret; |
| 10591 | } |
| 10592 | |
| 10593 | /** |
| 10594 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 10595 | * @pf: board private structure |
| 10596 | * |
| 10597 | * On error: returns error code (negative) |
| 10598 | * On success: returns vsi index in PF (positive) |
| 10599 | **/ |
| 10600 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 10601 | { |
| 10602 | int ret = -ENOENT; |
| 10603 | struct i40e_veb *veb; |
| 10604 | int i; |
| 10605 | |
| 10606 | /* Need to protect the allocation of switch elements at the PF level */ |
| 10607 | mutex_lock(&pf->switch_mutex); |
| 10608 | |
| 10609 | /* VEB list may be fragmented if VEB creation/destruction has |
| 10610 | * been happening. We can afford to do a quick scan to look |
| 10611 | * for any free slots in the list. |
| 10612 | * |
| 10613 | * find next empty veb slot, looping back around if necessary |
| 10614 | */ |
| 10615 | i = 0; |
| 10616 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 10617 | i++; |
| 10618 | if (i >= I40E_MAX_VEB) { |
| 10619 | ret = -ENOMEM; |
| 10620 | goto err_alloc_veb; /* out of VEB slots! */ |
| 10621 | } |
| 10622 | |
| 10623 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 10624 | if (!veb) { |
| 10625 | ret = -ENOMEM; |
| 10626 | goto err_alloc_veb; |
| 10627 | } |
| 10628 | veb->pf = pf; |
| 10629 | veb->idx = i; |
| 10630 | veb->enabled_tc = 1; |
| 10631 | |
| 10632 | pf->veb[i] = veb; |
| 10633 | ret = i; |
| 10634 | err_alloc_veb: |
| 10635 | mutex_unlock(&pf->switch_mutex); |
| 10636 | return ret; |
| 10637 | } |
| 10638 | |
| 10639 | /** |
| 10640 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 10641 | * @branch: where to start deleting |
| 10642 | * |
| 10643 | * This uses recursion to find the tips of the branch to be |
| 10644 | * removed, deleting until we get back to and can delete this VEB. |
| 10645 | **/ |
| 10646 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 10647 | { |
| 10648 | struct i40e_pf *pf = branch->pf; |
| 10649 | u16 branch_seid = branch->seid; |
| 10650 | u16 veb_idx = branch->idx; |
| 10651 | int i; |
| 10652 | |
| 10653 | /* release any VEBs on this VEB - RECURSION */ |
| 10654 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10655 | if (!pf->veb[i]) |
| 10656 | continue; |
| 10657 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 10658 | i40e_switch_branch_release(pf->veb[i]); |
| 10659 | } |
| 10660 | |
| 10661 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 10662 | * |
| 10663 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 10664 | * the VEB itself, so don't use (*branch) after this loop. |
| 10665 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10666 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10667 | if (!pf->vsi[i]) |
| 10668 | continue; |
| 10669 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 10670 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 10671 | i40e_vsi_release(pf->vsi[i]); |
| 10672 | } |
| 10673 | } |
| 10674 | |
| 10675 | /* There's one corner case where the VEB might not have been |
| 10676 | * removed, so double check it here and remove it if needed. |
| 10677 | * This case happens if the veb was created from the debugfs |
| 10678 | * commands and no VSIs were added to it. |
| 10679 | */ |
| 10680 | if (pf->veb[veb_idx]) |
| 10681 | i40e_veb_release(pf->veb[veb_idx]); |
| 10682 | } |
| 10683 | |
| 10684 | /** |
| 10685 | * i40e_veb_clear - remove veb struct |
| 10686 | * @veb: the veb to remove |
| 10687 | **/ |
| 10688 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 10689 | { |
| 10690 | if (!veb) |
| 10691 | return; |
| 10692 | |
| 10693 | if (veb->pf) { |
| 10694 | struct i40e_pf *pf = veb->pf; |
| 10695 | |
| 10696 | mutex_lock(&pf->switch_mutex); |
| 10697 | if (pf->veb[veb->idx] == veb) |
| 10698 | pf->veb[veb->idx] = NULL; |
| 10699 | mutex_unlock(&pf->switch_mutex); |
| 10700 | } |
| 10701 | |
| 10702 | kfree(veb); |
| 10703 | } |
| 10704 | |
| 10705 | /** |
| 10706 | * i40e_veb_release - Delete a VEB and free its resources |
| 10707 | * @veb: the VEB being removed |
| 10708 | **/ |
| 10709 | void i40e_veb_release(struct i40e_veb *veb) |
| 10710 | { |
| 10711 | struct i40e_vsi *vsi = NULL; |
| 10712 | struct i40e_pf *pf; |
| 10713 | int i, n = 0; |
| 10714 | |
| 10715 | pf = veb->pf; |
| 10716 | |
| 10717 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10718 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10719 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 10720 | n++; |
| 10721 | vsi = pf->vsi[i]; |
| 10722 | } |
| 10723 | } |
| 10724 | if (n != 1) { |
| 10725 | dev_info(&pf->pdev->dev, |
| 10726 | "can't remove VEB %d with %d VSIs left\n", |
| 10727 | veb->seid, n); |
| 10728 | return; |
| 10729 | } |
| 10730 | |
| 10731 | /* move the remaining VSI to uplink veb */ |
| 10732 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10733 | if (veb->uplink_seid) { |
| 10734 | vsi->uplink_seid = veb->uplink_seid; |
| 10735 | if (veb->uplink_seid == pf->mac_seid) |
| 10736 | vsi->veb_idx = I40E_NO_VEB; |
| 10737 | else |
| 10738 | vsi->veb_idx = veb->veb_idx; |
| 10739 | } else { |
| 10740 | /* floating VEB */ |
| 10741 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10742 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10743 | } |
| 10744 | |
| 10745 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10746 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10747 | } |
| 10748 | |
| 10749 | /** |
| 10750 | * i40e_add_veb - create the VEB in the switch |
| 10751 | * @veb: the VEB to be instantiated |
| 10752 | * @vsi: the controlling VSI |
| 10753 | **/ |
| 10754 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10755 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10756 | struct i40e_pf *pf = veb->pf; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10757 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10758 | int ret; |
| 10759 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10760 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10761 | veb->enabled_tc, false, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10762 | &veb->seid, enable_stats, NULL); |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10763 | |
| 10764 | /* get a VEB from the hardware */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10765 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10766 | dev_info(&pf->pdev->dev, |
| 10767 | "couldn't add VEB, err %s aq_err %s\n", |
| 10768 | i40e_stat_str(&pf->hw, ret), |
| 10769 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10770 | return -EPERM; |
| 10771 | } |
| 10772 | |
| 10773 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10774 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10775 | &veb->stats_idx, NULL, NULL, NULL); |
| 10776 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10777 | dev_info(&pf->pdev->dev, |
| 10778 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10779 | i40e_stat_str(&pf->hw, ret), |
| 10780 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10781 | return -EPERM; |
| 10782 | } |
| 10783 | ret = i40e_veb_get_bw_info(veb); |
| 10784 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10785 | dev_info(&pf->pdev->dev, |
| 10786 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10787 | i40e_stat_str(&pf->hw, ret), |
| 10788 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10789 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10790 | return -ENOENT; |
| 10791 | } |
| 10792 | |
| 10793 | vsi->uplink_seid = veb->seid; |
| 10794 | vsi->veb_idx = veb->idx; |
| 10795 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10796 | |
| 10797 | return 0; |
| 10798 | } |
| 10799 | |
| 10800 | /** |
| 10801 | * i40e_veb_setup - Set up a VEB |
| 10802 | * @pf: board private structure |
| 10803 | * @flags: VEB setup flags |
| 10804 | * @uplink_seid: the switch element to link to |
| 10805 | * @vsi_seid: the initial VSI seid |
| 10806 | * @enabled_tc: Enabled TC bit-map |
| 10807 | * |
| 10808 | * This allocates the sw VEB structure and links it into the switch |
| 10809 | * It is possible and legal for this to be a duplicate of an already |
| 10810 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10811 | * to be zero, in order to create a floating VEB. |
| 10812 | * |
| 10813 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10814 | * success, otherwise returns NULL on failure. |
| 10815 | **/ |
| 10816 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10817 | u16 uplink_seid, u16 vsi_seid, |
| 10818 | u8 enabled_tc) |
| 10819 | { |
| 10820 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10821 | int vsi_idx, veb_idx; |
| 10822 | int ret; |
| 10823 | |
| 10824 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10825 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10826 | (uplink_seid + vsi_seid != 0)) { |
| 10827 | dev_info(&pf->pdev->dev, |
| 10828 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10829 | uplink_seid, vsi_seid); |
| 10830 | return NULL; |
| 10831 | } |
| 10832 | |
| 10833 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10834 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10835 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10836 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10837 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10838 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10839 | vsi_seid); |
| 10840 | return NULL; |
| 10841 | } |
| 10842 | |
| 10843 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10844 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10845 | if (pf->veb[veb_idx] && |
| 10846 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10847 | uplink_veb = pf->veb[veb_idx]; |
| 10848 | break; |
| 10849 | } |
| 10850 | } |
| 10851 | if (!uplink_veb) { |
| 10852 | dev_info(&pf->pdev->dev, |
| 10853 | "uplink seid %d not found\n", uplink_seid); |
| 10854 | return NULL; |
| 10855 | } |
| 10856 | } |
| 10857 | |
| 10858 | /* get veb sw struct */ |
| 10859 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10860 | if (veb_idx < 0) |
| 10861 | goto err_alloc; |
| 10862 | veb = pf->veb[veb_idx]; |
| 10863 | veb->flags = flags; |
| 10864 | veb->uplink_seid = uplink_seid; |
| 10865 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10866 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10867 | |
| 10868 | /* create the VEB in the switch */ |
| 10869 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10870 | if (ret) |
| 10871 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10872 | if (vsi_idx == pf->lan_vsi) |
| 10873 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10874 | |
| 10875 | return veb; |
| 10876 | |
| 10877 | err_veb: |
| 10878 | i40e_veb_clear(veb); |
| 10879 | err_alloc: |
| 10880 | return NULL; |
| 10881 | } |
| 10882 | |
| 10883 | /** |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10884 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10885 | * @pf: board private structure |
| 10886 | * @ele: element we are building info from |
| 10887 | * @num_reported: total number of elements |
| 10888 | * @printconfig: should we print the contents |
| 10889 | * |
| 10890 | * helper function to assist in extracting a few useful SEID values. |
| 10891 | **/ |
| 10892 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10893 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10894 | u16 num_reported, bool printconfig) |
| 10895 | { |
| 10896 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10897 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10898 | u8 element_type = ele->element_type; |
| 10899 | u16 seid = le16_to_cpu(ele->seid); |
| 10900 | |
| 10901 | if (printconfig) |
| 10902 | dev_info(&pf->pdev->dev, |
| 10903 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10904 | element_type, seid, uplink_seid, downlink_seid); |
| 10905 | |
| 10906 | switch (element_type) { |
| 10907 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10908 | pf->mac_seid = seid; |
| 10909 | break; |
| 10910 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10911 | /* Main VEB? */ |
| 10912 | if (uplink_seid != pf->mac_seid) |
| 10913 | break; |
| 10914 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10915 | int v; |
| 10916 | |
| 10917 | /* find existing or else empty VEB */ |
| 10918 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10919 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10920 | pf->lan_veb = v; |
| 10921 | break; |
| 10922 | } |
| 10923 | } |
| 10924 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10925 | v = i40e_veb_mem_alloc(pf); |
| 10926 | if (v < 0) |
| 10927 | break; |
| 10928 | pf->lan_veb = v; |
| 10929 | } |
| 10930 | } |
| 10931 | |
| 10932 | pf->veb[pf->lan_veb]->seid = seid; |
| 10933 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10934 | pf->veb[pf->lan_veb]->pf = pf; |
| 10935 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10936 | break; |
| 10937 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10938 | if (num_reported != 1) |
| 10939 | break; |
| 10940 | /* This is immediately after a reset so we can assume this is |
| 10941 | * the PF's VSI |
| 10942 | */ |
| 10943 | pf->mac_seid = uplink_seid; |
| 10944 | pf->pf_seid = downlink_seid; |
| 10945 | pf->main_vsi_seid = seid; |
| 10946 | if (printconfig) |
| 10947 | dev_info(&pf->pdev->dev, |
| 10948 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10949 | pf->pf_seid, pf->main_vsi_seid); |
| 10950 | break; |
| 10951 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10952 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10953 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10954 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10955 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10956 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10957 | /* ignore these for now */ |
| 10958 | break; |
| 10959 | default: |
| 10960 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10961 | element_type, seid); |
| 10962 | break; |
| 10963 | } |
| 10964 | } |
| 10965 | |
| 10966 | /** |
| 10967 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10968 | * @pf: board private structure |
| 10969 | * @printconfig: should we print the contents |
| 10970 | * |
| 10971 | * Get the current switch configuration from the device and |
| 10972 | * extract a few useful SEID values. |
| 10973 | **/ |
| 10974 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10975 | { |
| 10976 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10977 | u16 next_seid = 0; |
| 10978 | int ret = 0; |
| 10979 | u8 *aq_buf; |
| 10980 | int i; |
| 10981 | |
| 10982 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10983 | if (!aq_buf) |
| 10984 | return -ENOMEM; |
| 10985 | |
| 10986 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10987 | do { |
| 10988 | u16 num_reported, num_total; |
| 10989 | |
| 10990 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10991 | I40E_AQ_LARGE_BUF, |
| 10992 | &next_seid, NULL); |
| 10993 | if (ret) { |
| 10994 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10995 | "get switch config failed err %s aq_err %s\n", |
| 10996 | i40e_stat_str(&pf->hw, ret), |
| 10997 | i40e_aq_str(&pf->hw, |
| 10998 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10999 | kfree(aq_buf); |
| 11000 | return -ENOENT; |
| 11001 | } |
| 11002 | |
| 11003 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 11004 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 11005 | |
| 11006 | if (printconfig) |
| 11007 | dev_info(&pf->pdev->dev, |
| 11008 | "header: %d reported %d total\n", |
| 11009 | num_reported, num_total); |
| 11010 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11011 | for (i = 0; i < num_reported; i++) { |
| 11012 | struct i40e_aqc_switch_config_element_resp *ele = |
| 11013 | &sw_config->element[i]; |
| 11014 | |
| 11015 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 11016 | printconfig); |
| 11017 | } |
| 11018 | } while (next_seid != 0); |
| 11019 | |
| 11020 | kfree(aq_buf); |
| 11021 | return ret; |
| 11022 | } |
| 11023 | |
| 11024 | /** |
| 11025 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 11026 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11027 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11028 | * |
| 11029 | * Returns 0 on success, negative value on failure |
| 11030 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11031 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11032 | { |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 11033 | u16 flags = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11034 | int ret; |
| 11035 | |
| 11036 | /* find out what's out there already */ |
| 11037 | ret = i40e_fetch_switch_configuration(pf, false); |
| 11038 | if (ret) { |
| 11039 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11040 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 11041 | i40e_stat_str(&pf->hw, ret), |
| 11042 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11043 | return ret; |
| 11044 | } |
| 11045 | i40e_pf_reset_stats(pf); |
| 11046 | |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 11047 | /* set the switch config bit for the whole device to |
| 11048 | * support limited promisc or true promisc |
| 11049 | * when user requests promisc. The default is limited |
| 11050 | * promisc. |
| 11051 | */ |
| 11052 | |
| 11053 | if ((pf->hw.pf_id == 0) && |
| 11054 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) |
| 11055 | flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 11056 | |
| 11057 | if (pf->hw.pf_id == 0) { |
| 11058 | u16 valid_flags; |
| 11059 | |
| 11060 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 11061 | ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, |
| 11062 | NULL); |
| 11063 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { |
| 11064 | dev_info(&pf->pdev->dev, |
| 11065 | "couldn't set switch config bits, err %s aq_err %s\n", |
| 11066 | i40e_stat_str(&pf->hw, ret), |
| 11067 | i40e_aq_str(&pf->hw, |
| 11068 | pf->hw.aq.asq_last_status)); |
| 11069 | /* not a fatal problem, just keep going */ |
| 11070 | } |
| 11071 | } |
| 11072 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11073 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11074 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11075 | struct i40e_vsi *vsi = NULL; |
| 11076 | u16 uplink_seid; |
| 11077 | |
| 11078 | /* Set up the PF VSI associated with the PF's main VSI |
| 11079 | * that is already in the HW switch |
| 11080 | */ |
| 11081 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 11082 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 11083 | else |
| 11084 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11085 | if (pf->lan_vsi == I40E_NO_VSI) |
| 11086 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 11087 | else if (reinit) |
| 11088 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11089 | if (!vsi) { |
| 11090 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 11091 | i40e_fdir_teardown(pf); |
| 11092 | return -EAGAIN; |
| 11093 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11094 | } else { |
| 11095 | /* force a reset of TC and queue layout configurations */ |
| 11096 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 11097 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11098 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 11099 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 11100 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 11101 | } |
| 11102 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 11103 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11104 | i40e_fdir_sb_setup(pf); |
| 11105 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11106 | /* Setup static PF queue filter control settings */ |
| 11107 | ret = i40e_setup_pf_filter_control(pf); |
| 11108 | if (ret) { |
| 11109 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 11110 | ret); |
| 11111 | /* Failure here should not stop continuing other steps */ |
| 11112 | } |
| 11113 | |
| 11114 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 11115 | * the hash |
| 11116 | */ |
| 11117 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 11118 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11119 | |
| 11120 | /* fill in link information and enable LSE reporting */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11121 | i40e_link_event(pf); |
| 11122 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 11123 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11124 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 11125 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 11126 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11127 | i40e_ptp_init(pf); |
| 11128 | |
Alexander Duyck | 1f190d9 | 2017-04-19 09:25:51 -0400 | [diff] [blame] | 11129 | /* repopulate tunnel port filters */ |
| 11130 | i40e_sync_udp_filters(pf); |
| 11131 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11132 | return ret; |
| 11133 | } |
| 11134 | |
| 11135 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11136 | * i40e_determine_queue_usage - Work out queue distribution |
| 11137 | * @pf: board private structure |
| 11138 | **/ |
| 11139 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 11140 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11141 | int queues_left; |
Shannon Nelson | e50d575 | 2017-07-24 18:17:42 -0700 | [diff] [blame] | 11142 | int q_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11143 | |
| 11144 | pf->num_lan_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11145 | |
| 11146 | /* Find the max queues to be put into basic use. We'll always be |
| 11147 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 11148 | * big RSS set. |
| 11149 | */ |
| 11150 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 11151 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11152 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 11153 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11154 | /* one qp for PF, no queues for anything else */ |
| 11155 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 11156 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11157 | |
| 11158 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 11159 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11160 | I40E_FLAG_IWARP_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 11161 | I40E_FLAG_FD_SB_ENABLED | |
| 11162 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 11163 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 11164 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 11165 | I40E_FLAG_SRIOV_ENABLED | |
| 11166 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 11167 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 11168 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 11169 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 11170 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 11171 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 11172 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 11173 | queues_left -= pf->num_lan_qps; |
| 11174 | |
| 11175 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11176 | I40E_FLAG_IWARP_ENABLED | |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 11177 | I40E_FLAG_FD_SB_ENABLED | |
| 11178 | I40E_FLAG_FD_ATR_ENABLED | |
| 11179 | I40E_FLAG_DCB_ENABLED | |
| 11180 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11181 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11182 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 11183 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11184 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 11185 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | |
| 11186 | I40E_FLAG_DCB_ENABLED); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11187 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 11188 | } |
Shannon Nelson | e50d575 | 2017-07-24 18:17:42 -0700 | [diff] [blame] | 11189 | |
| 11190 | /* limit lan qps to the smaller of qps, cpus or msix */ |
| 11191 | q_max = max_t(int, pf->rss_size_max, num_online_cpus()); |
| 11192 | q_max = min_t(int, q_max, pf->hw.func_caps.num_tx_qp); |
| 11193 | q_max = min_t(int, q_max, pf->hw.func_caps.num_msix_vectors); |
| 11194 | pf->num_lan_qps = q_max; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 11195 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11196 | queues_left -= pf->num_lan_qps; |
| 11197 | } |
| 11198 | |
| 11199 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 11200 | if (queues_left > 1) { |
| 11201 | queues_left -= 1; /* save 1 queue for FD */ |
| 11202 | } else { |
| 11203 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 11204 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 11205 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11206 | } |
| 11207 | |
| 11208 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 11209 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 11210 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 11211 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11212 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 11213 | } |
| 11214 | |
| 11215 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 11216 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 11217 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 11218 | (queues_left / pf->num_vmdq_qps)); |
| 11219 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 11220 | } |
| 11221 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 11222 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11223 | dev_dbg(&pf->pdev->dev, |
| 11224 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 11225 | pf->hw.func_caps.num_tx_qp, |
| 11226 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 11227 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 11228 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 11229 | queues_left); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11230 | } |
| 11231 | |
| 11232 | /** |
| 11233 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 11234 | * @pf: PF to be setup |
| 11235 | * |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 11236 | * 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] | 11237 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 11238 | * based filter sizes required for them. It also enables Flow director, |
| 11239 | * ethertype and macvlan type filter settings for the pf. |
| 11240 | * |
| 11241 | * Returns 0 on success, negative on failure |
| 11242 | **/ |
| 11243 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 11244 | { |
| 11245 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 11246 | |
| 11247 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 11248 | |
| 11249 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 11250 | 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] | 11251 | settings->enable_fdir = true; |
| 11252 | |
| 11253 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 11254 | settings->enable_ethtype = true; |
| 11255 | settings->enable_macvlan = true; |
| 11256 | |
| 11257 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 11258 | return -ENOENT; |
| 11259 | |
| 11260 | return 0; |
| 11261 | } |
| 11262 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11263 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 11264 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11265 | static void i40e_print_features(struct i40e_pf *pf) |
| 11266 | { |
| 11267 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11268 | char *buf; |
| 11269 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11270 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11271 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 11272 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11273 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11274 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11275 | 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] | 11276 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11277 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11278 | #endif |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 11279 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 11280 | pf->hw.func_caps.num_vsis, |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 11281 | pf->vsi[pf->lan_vsi]->num_queue_pairs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11282 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11283 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11284 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11285 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 11286 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11287 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 11288 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 11289 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 11290 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11291 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11292 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 11293 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11294 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11295 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 11296 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11297 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 11298 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11299 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11300 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 11301 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 11302 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 11303 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11304 | } |
| 11305 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11306 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 11307 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 11308 | * @pdev: PCI device information struct |
| 11309 | * @pf: board private structure |
| 11310 | * |
Jacob Keller | 41c4c2b | 2017-04-05 07:50:57 -0400 | [diff] [blame] | 11311 | * Look up the MAC address for the device. First we'll try |
| 11312 | * eth_platform_get_mac_address, which will check Open Firmware, or arch |
| 11313 | * specific fallback. Otherwise, we'll default to the stored value in |
| 11314 | * firmware. |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 11315 | **/ |
| 11316 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 11317 | { |
Jacob Keller | 41c4c2b | 2017-04-05 07:50:57 -0400 | [diff] [blame] | 11318 | if (eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
| 11319 | i40e_get_mac_addr(&pf->hw, pf->hw.mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 11320 | } |
| 11321 | |
| 11322 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11323 | * i40e_probe - Device initialization routine |
| 11324 | * @pdev: PCI device information struct |
| 11325 | * @ent: entry in i40e_pci_tbl |
| 11326 | * |
Jeff Kirsher | b40c82e6 | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 11327 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 11328 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11329 | * and a hardware reset occur. |
| 11330 | * |
| 11331 | * Returns 0 on success, negative on failure |
| 11332 | **/ |
| 11333 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 11334 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11335 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11336 | struct i40e_pf *pf; |
| 11337 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11338 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11339 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11340 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 11341 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11342 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11343 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11344 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11345 | |
| 11346 | err = pci_enable_device_mem(pdev); |
| 11347 | if (err) |
| 11348 | return err; |
| 11349 | |
| 11350 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 11351 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 11352 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 11353 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 11354 | if (err) { |
| 11355 | dev_err(&pdev->dev, |
| 11356 | "DMA configuration failed: 0x%x\n", err); |
| 11357 | goto err_dma; |
| 11358 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11359 | } |
| 11360 | |
| 11361 | /* set up pci connections */ |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11362 | err = pci_request_mem_regions(pdev, i40e_driver_name); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11363 | if (err) { |
| 11364 | dev_info(&pdev->dev, |
| 11365 | "pci_request_selected_regions failed %d\n", err); |
| 11366 | goto err_pci_reg; |
| 11367 | } |
| 11368 | |
| 11369 | pci_enable_pcie_error_reporting(pdev); |
| 11370 | pci_set_master(pdev); |
| 11371 | |
| 11372 | /* Now that we have a PCI connection, we need to do the |
| 11373 | * low level device setup. This is primarily setting up |
| 11374 | * the Admin Queue structures and then querying for the |
| 11375 | * device's current profile information. |
| 11376 | */ |
| 11377 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 11378 | if (!pf) { |
| 11379 | err = -ENOMEM; |
| 11380 | goto err_pf_alloc; |
| 11381 | } |
| 11382 | pf->next_vsi = 0; |
| 11383 | pf->pdev = pdev; |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 11384 | set_bit(__I40E_DOWN, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11385 | |
| 11386 | hw = &pf->hw; |
| 11387 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 11388 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 11389 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 11390 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 11391 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 11392 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11393 | if (!hw->hw_addr) { |
| 11394 | err = -EIO; |
| 11395 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 11396 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 11397 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11398 | goto err_ioremap; |
| 11399 | } |
| 11400 | hw->vendor_id = pdev->vendor; |
| 11401 | hw->device_id = pdev->device; |
| 11402 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 11403 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 11404 | hw->subsystem_device_id = pdev->subsystem_device; |
| 11405 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 11406 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Sudheer Mogilappagari | b3f028f | 2017-02-09 23:58:22 -0800 | [diff] [blame] | 11407 | hw->bus.bus_id = pdev->bus->number; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11408 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11409 | |
Scott Peterson | ab243ec | 2017-08-22 06:57:54 -0400 | [diff] [blame] | 11410 | /* Select something other than the 802.1ad ethertype for the |
| 11411 | * switch to use internally and drop on ingress. |
| 11412 | */ |
| 11413 | hw->switch_tag = 0xffff; |
| 11414 | hw->first_tag = ETH_P_8021AD; |
| 11415 | hw->second_tag = ETH_P_8021Q; |
| 11416 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame] | 11417 | INIT_LIST_HEAD(&pf->l3_flex_pit_list); |
| 11418 | INIT_LIST_HEAD(&pf->l4_flex_pit_list); |
| 11419 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 11420 | /* set up the locks for the AQ, do this only once in probe |
| 11421 | * and destroy them only once in remove |
| 11422 | */ |
| 11423 | mutex_init(&hw->aq.asq_mutex); |
| 11424 | mutex_init(&hw->aq.arq_mutex); |
| 11425 | |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 11426 | pf->msg_enable = netif_msg_init(debug, |
| 11427 | NETIF_MSG_DRV | |
| 11428 | NETIF_MSG_PROBE | |
| 11429 | NETIF_MSG_LINK); |
| 11430 | if (debug < -1) |
| 11431 | pf->hw.debug_mask = debug; |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 11432 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 11433 | /* do a special CORER for clearing PXE mode once at init */ |
| 11434 | if (hw->revision_id == 0 && |
| 11435 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 11436 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 11437 | i40e_flush(hw); |
| 11438 | msleep(200); |
| 11439 | pf->corer_count++; |
| 11440 | |
| 11441 | i40e_clear_pxe_mode(hw); |
| 11442 | } |
| 11443 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11444 | /* 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] | 11445 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11446 | err = i40e_pf_reset(hw); |
| 11447 | if (err) { |
| 11448 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 11449 | goto err_pf_reset; |
| 11450 | } |
| 11451 | pf->pfr_count++; |
| 11452 | |
| 11453 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 11454 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 11455 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 11456 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 11457 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 11458 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 11459 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 11460 | "%s-%s:misc", |
| 11461 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11462 | |
| 11463 | err = i40e_init_shared_code(hw); |
| 11464 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 11465 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 11466 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11467 | goto err_pf_reset; |
| 11468 | } |
| 11469 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 11470 | /* set up a default setting for link flow control */ |
| 11471 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 11472 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11473 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 11474 | if (err) { |
| 11475 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 11476 | dev_info(&pdev->dev, |
| 11477 | "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"); |
| 11478 | else |
| 11479 | dev_info(&pdev->dev, |
| 11480 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 11481 | |
| 11482 | goto err_pf_reset; |
| 11483 | } |
Filip Sadowski | 5bbb2e2 | 2017-06-07 05:43:09 -0400 | [diff] [blame] | 11484 | i40e_get_oem_version(hw); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 11485 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 11486 | /* provide nvm, fw, api versions */ |
| 11487 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 11488 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 11489 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 11490 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 11491 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 11492 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
Mitch Williams | 22b96551 | 2017-07-14 09:27:09 -0400 | [diff] [blame] | 11493 | hw->aq.api_min_ver > I40E_FW_MINOR_VERSION(hw)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 11494 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 11495 | "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] | 11496 | 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] | 11497 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 11498 | "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] | 11499 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11500 | i40e_verify_eeprom(pf); |
| 11501 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 11502 | /* Rev 0 hardware was never productized */ |
| 11503 | if (hw->revision_id < 1) |
| 11504 | 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"); |
| 11505 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 11506 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11507 | err = i40e_get_capabilities(pf); |
| 11508 | if (err) |
| 11509 | goto err_adminq_setup; |
| 11510 | |
| 11511 | err = i40e_sw_init(pf); |
| 11512 | if (err) { |
| 11513 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 11514 | goto err_sw_init; |
| 11515 | } |
| 11516 | |
| 11517 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
Alexander Duyck | c76cb6e | 2017-02-21 15:55:48 -0800 | [diff] [blame] | 11518 | hw->func_caps.num_rx_qp, 0, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11519 | if (err) { |
| 11520 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 11521 | goto err_init_lan_hmc; |
| 11522 | } |
| 11523 | |
| 11524 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 11525 | if (err) { |
| 11526 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 11527 | err = -ENOENT; |
| 11528 | goto err_configure_lan_hmc; |
| 11529 | } |
| 11530 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 11531 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 11532 | * Ignore error return codes because if it was already disabled via |
| 11533 | * hardware settings this will fail |
| 11534 | */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 11535 | if (pf->hw_features & I40E_HW_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 11536 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 11537 | i40e_aq_stop_lldp(hw, true, NULL); |
| 11538 | } |
| 11539 | |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 11540 | /* allow a platform config to override the HW addr */ |
| 11541 | i40e_get_platform_mac_addr(pdev, pf); |
Jacob Keller | 41c4c2b | 2017-04-05 07:50:57 -0400 | [diff] [blame] | 11542 | |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 11543 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11544 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 11545 | err = -EIO; |
| 11546 | goto err_mac_addr; |
| 11547 | } |
| 11548 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 11549 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 11550 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 11551 | if (is_valid_ether_addr(hw->mac.port_addr)) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 11552 | pf->hw_features |= I40E_HW_PORT_ID_VALID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11553 | |
| 11554 | pci_set_drvdata(pdev, pf); |
| 11555 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11556 | #ifdef CONFIG_I40E_DCB |
| 11557 | err = i40e_init_pf_dcb(pf); |
| 11558 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 11559 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
David Ertman | c17ef43 | 2016-09-30 01:36:21 -0700 | [diff] [blame] | 11560 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED); |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 11561 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11562 | } |
| 11563 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11564 | |
| 11565 | /* set up periodic task facility */ |
| 11566 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 11567 | pf->service_timer_period = HZ; |
| 11568 | |
| 11569 | INIT_WORK(&pf->service_task, i40e_service_task); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 11570 | clear_bit(__I40E_SERVICE_SCHED, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11571 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11572 | /* NVM bit on means WoL disabled for the port */ |
| 11573 | 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] | 11574 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11575 | pf->wol_en = false; |
| 11576 | else |
| 11577 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11578 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 11579 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11580 | /* set up the main switch operations */ |
| 11581 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 11582 | err = i40e_init_interrupt_scheme(pf); |
| 11583 | if (err) |
| 11584 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11585 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11586 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 11587 | * to us; HW supports far more and we share the remaining pool with |
| 11588 | * the other PFs. We allocate space for more than the guarantee with |
| 11589 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11590 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11591 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 11592 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 11593 | else |
| 11594 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 11595 | |
| 11596 | /* 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] | 11597 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 11598 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11599 | if (!pf->vsi) { |
| 11600 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11601 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11602 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11603 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 11604 | #ifdef CONFIG_PCI_IOV |
| 11605 | /* prep for VF support */ |
| 11606 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 11607 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 11608 | !test_bit(__I40E_BAD_EEPROM, pf->state)) { |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 11609 | if (pci_num_vf(pdev)) |
| 11610 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 11611 | } |
| 11612 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11613 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11614 | if (err) { |
| 11615 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 11616 | goto err_vsis; |
| 11617 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11618 | |
| 11619 | /* Make sure flow control is set according to current settings */ |
| 11620 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 11621 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 11622 | dev_dbg(&pf->pdev->dev, |
| 11623 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 11624 | i40e_stat_str(hw, err), |
| 11625 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11626 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 11627 | dev_dbg(&pf->pdev->dev, |
| 11628 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 11629 | i40e_stat_str(hw, err), |
| 11630 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11631 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 11632 | dev_dbg(&pf->pdev->dev, |
| 11633 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 11634 | i40e_stat_str(hw, err), |
| 11635 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11636 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11637 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11638 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11639 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 11640 | i40e_vsi_open(pf->vsi[i]); |
| 11641 | break; |
| 11642 | } |
| 11643 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11644 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11645 | /* The driver only wants link up/down and module qualification |
| 11646 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11647 | */ |
| 11648 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11649 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 11650 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11651 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11652 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11653 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 11654 | i40e_stat_str(&pf->hw, err), |
| 11655 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11656 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11657 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 11658 | * of TSO, so that we avoid the MDD being fired and causing |
| 11659 | * a reset in the case of small MSS+TSO. |
| 11660 | */ |
| 11661 | val = rd32(hw, I40E_REG_MSS); |
| 11662 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 11663 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 11664 | val |= I40E_64BYTE_MSS; |
| 11665 | wr32(hw, I40E_REG_MSS, val); |
| 11666 | } |
| 11667 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 11668 | if (pf->hw_features & I40E_HW_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 11669 | msleep(75); |
| 11670 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 11671 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11672 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 11673 | i40e_stat_str(&pf->hw, err), |
| 11674 | i40e_aq_str(&pf->hw, |
| 11675 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 11676 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11677 | /* The main driver is (mostly) up and happy. We need to set this state |
| 11678 | * before setting up the misc vector or we get a race and the vector |
| 11679 | * ends up disabled forever. |
| 11680 | */ |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 11681 | clear_bit(__I40E_DOWN, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11682 | |
| 11683 | /* In case of MSIX we are going to setup the misc vector right here |
| 11684 | * to handle admin queue events etc. In case of legacy and MSI |
| 11685 | * the misc functionality and queue processing is combined in |
| 11686 | * the same vector and that gets setup at open. |
| 11687 | */ |
| 11688 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 11689 | err = i40e_setup_misc_vector(pf); |
| 11690 | if (err) { |
| 11691 | dev_info(&pdev->dev, |
| 11692 | "setup of misc vector failed: %d\n", err); |
| 11693 | goto err_vsis; |
| 11694 | } |
| 11695 | } |
| 11696 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11697 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11698 | /* prep for VF support */ |
| 11699 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11700 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 11701 | !test_bit(__I40E_BAD_EEPROM, pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11702 | /* disable link interrupts for VFs */ |
| 11703 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11704 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11705 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11706 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11707 | |
| 11708 | if (pci_num_vf(pdev)) { |
| 11709 | dev_info(&pdev->dev, |
| 11710 | "Active VFs found, allocating resources.\n"); |
| 11711 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11712 | if (err) |
| 11713 | dev_info(&pdev->dev, |
| 11714 | "Error %d allocating resources for existing VFs\n", |
| 11715 | err); |
| 11716 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11717 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11718 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11719 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11720 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11721 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11722 | pf->num_iwarp_msix, |
| 11723 | I40E_IWARP_IRQ_PILE_ID); |
| 11724 | if (pf->iwarp_base_vector < 0) { |
| 11725 | dev_info(&pdev->dev, |
| 11726 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 11727 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 11728 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 11729 | } |
| 11730 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11731 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11732 | i40e_dbg_pf_init(pf); |
| 11733 | |
| 11734 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11735 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11736 | |
| 11737 | /* since everything's happy, start the service_task timer */ |
| 11738 | mod_timer(&pf->service_timer, |
| 11739 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11740 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11741 | /* 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] | 11742 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11743 | err = i40e_lan_add_device(pf); |
| 11744 | if (err) |
| 11745 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 11746 | err); |
| 11747 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11748 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11749 | #define PCI_SPEED_SIZE 8 |
| 11750 | #define PCI_WIDTH_SIZE 8 |
| 11751 | /* Devices on the IOSF bus do not have this information |
| 11752 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11753 | * checking them. |
| 11754 | */ |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 11755 | if (!(pf->hw_features & I40E_HW_NO_PCI_LINK_CHECK)) { |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11756 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11757 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11758 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11759 | /* Get the negotiated link width and speed from PCI config |
| 11760 | * space |
| 11761 | */ |
| 11762 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11763 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11764 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11765 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11766 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11767 | switch (hw->bus.speed) { |
| 11768 | case i40e_bus_speed_8000: |
| 11769 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11770 | case i40e_bus_speed_5000: |
| 11771 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11772 | case i40e_bus_speed_2500: |
| 11773 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11774 | default: |
| 11775 | break; |
| 11776 | } |
| 11777 | switch (hw->bus.width) { |
| 11778 | case i40e_bus_width_pcie_x8: |
| 11779 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11780 | case i40e_bus_width_pcie_x4: |
| 11781 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11782 | case i40e_bus_width_pcie_x2: |
| 11783 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11784 | case i40e_bus_width_pcie_x1: |
| 11785 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11786 | default: |
| 11787 | break; |
| 11788 | } |
| 11789 | |
| 11790 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11791 | speed, width); |
| 11792 | |
| 11793 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11794 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11795 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11796 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11797 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11798 | } |
| 11799 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11800 | /* get the requested speeds from the fw */ |
| 11801 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11802 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11803 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11804 | i40e_stat_str(&pf->hw, err), |
| 11805 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11806 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11807 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11808 | /* get the supported phy types from the fw */ |
| 11809 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11810 | if (err) |
| 11811 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11812 | i40e_stat_str(&pf->hw, err), |
| 11813 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11814 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11815 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11816 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11817 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11818 | * PF/VF VSIs. |
| 11819 | * The FW can still send Flow control frames if enabled. |
| 11820 | */ |
| 11821 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11822 | pf->main_vsi_seid); |
| 11823 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 11824 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
Henry Tieman | 4f9b430 | 2016-11-08 13:05:18 -0800 | [diff] [blame] | 11825 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 11826 | pf->hw_features |= I40E_HW_PHY_CONTROLS_LEDS; |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 11827 | if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722) |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 11828 | pf->hw_features |= I40E_HW_HAVE_CRT_RETIMER; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11829 | /* print a string summarizing features */ |
| 11830 | i40e_print_features(pf); |
| 11831 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11832 | return 0; |
| 11833 | |
| 11834 | /* Unwind what we've done if something failed in the setup */ |
| 11835 | err_vsis: |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 11836 | set_bit(__I40E_DOWN, pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11837 | i40e_clear_interrupt_scheme(pf); |
| 11838 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11839 | err_switch_setup: |
| 11840 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11841 | del_timer_sync(&pf->service_timer); |
| 11842 | err_mac_addr: |
| 11843 | err_configure_lan_hmc: |
| 11844 | (void)i40e_shutdown_lan_hmc(hw); |
| 11845 | err_init_lan_hmc: |
| 11846 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11847 | err_sw_init: |
| 11848 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11849 | err_pf_reset: |
| 11850 | iounmap(hw->hw_addr); |
| 11851 | err_ioremap: |
| 11852 | kfree(pf); |
| 11853 | err_pf_alloc: |
| 11854 | pci_disable_pcie_error_reporting(pdev); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11855 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11856 | err_pci_reg: |
| 11857 | err_dma: |
| 11858 | pci_disable_device(pdev); |
| 11859 | return err; |
| 11860 | } |
| 11861 | |
| 11862 | /** |
| 11863 | * i40e_remove - Device removal routine |
| 11864 | * @pdev: PCI device information struct |
| 11865 | * |
| 11866 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11867 | * that is should release a PCI device. This could be caused by a |
| 11868 | * Hot-Plug event, or because the driver is going to be removed from |
| 11869 | * memory. |
| 11870 | **/ |
| 11871 | static void i40e_remove(struct pci_dev *pdev) |
| 11872 | { |
| 11873 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11874 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11875 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11876 | int i; |
| 11877 | |
| 11878 | i40e_dbg_pf_exit(pf); |
| 11879 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11880 | i40e_ptp_stop(pf); |
| 11881 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11882 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 11883 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 11884 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11885 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11886 | /* no more scheduling of any task */ |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 11887 | set_bit(__I40E_SUSPENDED, pf->state); |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 11888 | set_bit(__I40E_DOWN, pf->state); |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 11889 | if (pf->service_timer.data) |
| 11890 | del_timer_sync(&pf->service_timer); |
| 11891 | if (pf->service_task.func) |
| 11892 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11893 | |
Mitch Williams | 921c467 | 2017-03-30 00:46:08 -0700 | [diff] [blame] | 11894 | /* Client close must be called explicitly here because the timer |
| 11895 | * has been stopped. |
| 11896 | */ |
| 11897 | i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false); |
| 11898 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11899 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11900 | i40e_free_vfs(pf); |
| 11901 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11902 | } |
| 11903 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11904 | i40e_fdir_teardown(pf); |
| 11905 | |
| 11906 | /* If there is a switch structure or any orphans, remove them. |
| 11907 | * This will leave only the PF's VSI remaining. |
| 11908 | */ |
| 11909 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11910 | if (!pf->veb[i]) |
| 11911 | continue; |
| 11912 | |
| 11913 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11914 | pf->veb[i]->uplink_seid == 0) |
| 11915 | i40e_switch_branch_release(pf->veb[i]); |
| 11916 | } |
| 11917 | |
| 11918 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11919 | * adminq and hmc. |
| 11920 | */ |
| 11921 | if (pf->vsi[pf->lan_vsi]) |
| 11922 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11923 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11924 | /* remove attached clients */ |
Mitch Williams | 004eb61 | 2017-04-04 12:40:16 -0700 | [diff] [blame] | 11925 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11926 | ret_code = i40e_lan_del_device(pf); |
| 11927 | if (ret_code) |
| 11928 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 11929 | ret_code); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11930 | } |
| 11931 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11932 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11933 | if (hw->hmc.hmc_obj) { |
| 11934 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11935 | if (ret_code) |
| 11936 | dev_warn(&pdev->dev, |
| 11937 | "Failed to destroy the HMC resources: %d\n", |
| 11938 | ret_code); |
| 11939 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11940 | |
| 11941 | /* shutdown the adminq */ |
Henry Tieman | ac9c5c6 | 2016-09-06 18:05:11 -0700 | [diff] [blame] | 11942 | i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11943 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11944 | /* destroy the locks only once, here */ |
| 11945 | mutex_destroy(&hw->aq.arq_mutex); |
| 11946 | mutex_destroy(&hw->aq.asq_mutex); |
| 11947 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11948 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11949 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11950 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11951 | if (pf->vsi[i]) { |
| 11952 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11953 | i40e_vsi_clear(pf->vsi[i]); |
| 11954 | pf->vsi[i] = NULL; |
| 11955 | } |
| 11956 | } |
| 11957 | |
| 11958 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11959 | kfree(pf->veb[i]); |
| 11960 | pf->veb[i] = NULL; |
| 11961 | } |
| 11962 | |
| 11963 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11964 | kfree(pf->vsi); |
| 11965 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11966 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11967 | kfree(pf); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11968 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11969 | |
| 11970 | pci_disable_pcie_error_reporting(pdev); |
| 11971 | pci_disable_device(pdev); |
| 11972 | } |
| 11973 | |
| 11974 | /** |
| 11975 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11976 | * @pdev: PCI device information struct |
| 11977 | * |
| 11978 | * Called to warn that something happened and the error handling steps |
| 11979 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11980 | * remediation. |
| 11981 | **/ |
| 11982 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11983 | enum pci_channel_state error) |
| 11984 | { |
| 11985 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11986 | |
| 11987 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11988 | |
Guilherme G Piccoli | edfc23ee | 2016-10-03 00:31:12 -0700 | [diff] [blame] | 11989 | if (!pf) { |
| 11990 | dev_info(&pdev->dev, |
| 11991 | "Cannot recover - error happened during device probe\n"); |
| 11992 | return PCI_ERS_RESULT_DISCONNECT; |
| 11993 | } |
| 11994 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11995 | /* shutdown all operations */ |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 11996 | if (!test_bit(__I40E_SUSPENDED, pf->state)) |
| 11997 | i40e_prep_for_reset(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11998 | |
| 11999 | /* Request a slot reset */ |
| 12000 | return PCI_ERS_RESULT_NEED_RESET; |
| 12001 | } |
| 12002 | |
| 12003 | /** |
| 12004 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 12005 | * @pdev: PCI device information struct |
| 12006 | * |
| 12007 | * Called to find if the driver can work with the device now that |
| 12008 | * the pci slot has been reset. If a basic connection seems good |
| 12009 | * (registers are readable and have sane content) then return a |
| 12010 | * happy little PCI_ERS_RESULT_xxx. |
| 12011 | **/ |
| 12012 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 12013 | { |
| 12014 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 12015 | pci_ers_result_t result; |
| 12016 | int err; |
| 12017 | u32 reg; |
| 12018 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 12019 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12020 | if (pci_enable_device_mem(pdev)) { |
| 12021 | dev_info(&pdev->dev, |
| 12022 | "Cannot re-enable PCI device after reset.\n"); |
| 12023 | result = PCI_ERS_RESULT_DISCONNECT; |
| 12024 | } else { |
| 12025 | pci_set_master(pdev); |
| 12026 | pci_restore_state(pdev); |
| 12027 | pci_save_state(pdev); |
| 12028 | pci_wake_from_d3(pdev, false); |
| 12029 | |
| 12030 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 12031 | if (reg == 0) |
| 12032 | result = PCI_ERS_RESULT_RECOVERED; |
| 12033 | else |
| 12034 | result = PCI_ERS_RESULT_DISCONNECT; |
| 12035 | } |
| 12036 | |
| 12037 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 12038 | if (err) { |
| 12039 | dev_info(&pdev->dev, |
| 12040 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 12041 | err); |
| 12042 | /* non-fatal, continue */ |
| 12043 | } |
| 12044 | |
| 12045 | return result; |
| 12046 | } |
| 12047 | |
| 12048 | /** |
Alan Brady | 19b7960 | 2017-08-29 05:32:39 -0400 | [diff] [blame^] | 12049 | * i40e_pci_error_reset_prepare - prepare device driver for pci reset |
| 12050 | * @pdev: PCI device information struct |
| 12051 | */ |
| 12052 | static void i40e_pci_error_reset_prepare(struct pci_dev *pdev) |
| 12053 | { |
| 12054 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 12055 | |
| 12056 | i40e_prep_for_reset(pf, false); |
| 12057 | } |
| 12058 | |
| 12059 | /** |
| 12060 | * i40e_pci_error_reset_done - pci reset done, device driver reset can begin |
| 12061 | * @pdev: PCI device information struct |
| 12062 | */ |
| 12063 | static void i40e_pci_error_reset_done(struct pci_dev *pdev) |
| 12064 | { |
| 12065 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 12066 | |
| 12067 | i40e_reset_and_rebuild(pf, false, false); |
| 12068 | } |
| 12069 | |
| 12070 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12071 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 12072 | * @pdev: PCI device information struct |
| 12073 | * |
| 12074 | * Called to allow the driver to bring things back up after PCI error |
| 12075 | * and/or reset recovery has finished. |
| 12076 | **/ |
| 12077 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 12078 | { |
| 12079 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 12080 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 12081 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 12082 | if (test_bit(__I40E_SUSPENDED, pf->state)) |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12083 | return; |
| 12084 | |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 12085 | i40e_handle_reset_warning(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12086 | } |
| 12087 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12088 | /** |
Joshua Hay | 1d68005 | 2016-12-12 15:44:08 -0800 | [diff] [blame] | 12089 | * i40e_enable_mc_magic_wake - enable multicast magic packet wake up |
| 12090 | * using the mac_address_write admin q function |
| 12091 | * @pf: pointer to i40e_pf struct |
| 12092 | **/ |
| 12093 | static void i40e_enable_mc_magic_wake(struct i40e_pf *pf) |
| 12094 | { |
| 12095 | struct i40e_hw *hw = &pf->hw; |
| 12096 | i40e_status ret; |
| 12097 | u8 mac_addr[6]; |
| 12098 | u16 flags = 0; |
| 12099 | |
| 12100 | /* Get current MAC address in case it's an LAA */ |
| 12101 | if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) { |
| 12102 | ether_addr_copy(mac_addr, |
| 12103 | pf->vsi[pf->lan_vsi]->netdev->dev_addr); |
| 12104 | } else { |
| 12105 | dev_err(&pf->pdev->dev, |
| 12106 | "Failed to retrieve MAC address; using default\n"); |
| 12107 | ether_addr_copy(mac_addr, hw->mac.addr); |
| 12108 | } |
| 12109 | |
| 12110 | /* The FW expects the mac address write cmd to first be called with |
| 12111 | * one of these flags before calling it again with the multicast |
| 12112 | * enable flags. |
| 12113 | */ |
| 12114 | flags = I40E_AQC_WRITE_TYPE_LAA_WOL; |
| 12115 | |
| 12116 | if (hw->func_caps.flex10_enable && hw->partition_id != 1) |
| 12117 | flags = I40E_AQC_WRITE_TYPE_LAA_ONLY; |
| 12118 | |
| 12119 | ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL); |
| 12120 | if (ret) { |
| 12121 | dev_err(&pf->pdev->dev, |
| 12122 | "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up"); |
| 12123 | return; |
| 12124 | } |
| 12125 | |
| 12126 | flags = I40E_AQC_MC_MAG_EN |
| 12127 | | I40E_AQC_WOL_PRESERVE_ON_PFR |
| 12128 | | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG; |
| 12129 | ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL); |
| 12130 | if (ret) |
| 12131 | dev_err(&pf->pdev->dev, |
| 12132 | "Failed to enable Multicast Magic Packet wake up\n"); |
| 12133 | } |
| 12134 | |
| 12135 | /** |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12136 | * i40e_shutdown - PCI callback for shutting down |
| 12137 | * @pdev: PCI device information struct |
| 12138 | **/ |
| 12139 | static void i40e_shutdown(struct pci_dev *pdev) |
| 12140 | { |
| 12141 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 12142 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12143 | |
Jacob Keller | 0da36b9 | 2017-04-19 09:25:55 -0400 | [diff] [blame] | 12144 | set_bit(__I40E_SUSPENDED, pf->state); |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 12145 | set_bit(__I40E_DOWN, pf->state); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12146 | rtnl_lock(); |
Maciej Sosin | 373149f | 2017-04-05 07:50:55 -0400 | [diff] [blame] | 12147 | i40e_prep_for_reset(pf, true); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12148 | rtnl_unlock(); |
| 12149 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 12150 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 12151 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 12152 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 12153 | del_timer_sync(&pf->service_timer); |
| 12154 | cancel_work_sync(&pf->service_task); |
| 12155 | i40e_fdir_teardown(pf); |
| 12156 | |
Mitch Williams | 921c467 | 2017-03-30 00:46:08 -0700 | [diff] [blame] | 12157 | /* Client close must be called explicitly here because the timer |
| 12158 | * has been stopped. |
| 12159 | */ |
| 12160 | i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false); |
| 12161 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 12162 | 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] | 12163 | i40e_enable_mc_magic_wake(pf); |
| 12164 | |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 12165 | i40e_prep_for_reset(pf, false); |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 12166 | |
| 12167 | wr32(hw, I40E_PFPM_APM, |
| 12168 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 12169 | wr32(hw, I40E_PFPM_WUFC, |
| 12170 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 12171 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 12172 | i40e_clear_interrupt_scheme(pf); |
| 12173 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12174 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 12175 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12176 | pci_set_power_state(pdev, PCI_D3hot); |
| 12177 | } |
| 12178 | } |
| 12179 | |
| 12180 | #ifdef CONFIG_PM |
| 12181 | /** |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 12182 | * i40e_suspend - PM callback for moving to D3 |
| 12183 | * @dev: generic device information structure |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12184 | **/ |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 12185 | static int i40e_suspend(struct device *dev) |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12186 | { |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 12187 | struct pci_dev *pdev = to_pci_dev(dev); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12188 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 12189 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12190 | |
Jacob Keller | 401586c | 2017-07-14 09:27:04 -0400 | [diff] [blame] | 12191 | /* If we're already suspended, then there is nothing to do */ |
| 12192 | if (test_and_set_bit(__I40E_SUSPENDED, pf->state)) |
| 12193 | return 0; |
| 12194 | |
Mauro S. M. Rodrigues | 9e6c9c0 | 2017-05-12 23:26:56 -0300 | [diff] [blame] | 12195 | set_bit(__I40E_DOWN, pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 12196 | |
Jacob Keller | 5c49922 | 2017-07-14 09:27:05 -0400 | [diff] [blame] | 12197 | /* Ensure service task will not be running */ |
| 12198 | del_timer_sync(&pf->service_timer); |
| 12199 | cancel_work_sync(&pf->service_task); |
| 12200 | |
Jacob Keller | d36e41d | 2017-06-23 04:24:46 -0400 | [diff] [blame] | 12201 | 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] | 12202 | i40e_enable_mc_magic_wake(pf); |
| 12203 | |
Jacob Keller | dfc4ff6 | 2017-06-07 05:43:13 -0400 | [diff] [blame] | 12204 | i40e_prep_for_reset(pf, false); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12205 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 12206 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 12207 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 12208 | |
Jacob Keller | b980c06 | 2017-07-14 09:27:06 -0400 | [diff] [blame] | 12209 | /* Clear the interrupt scheme and release our IRQs so that the system |
| 12210 | * can safely hibernate even when there are a large number of CPUs. |
| 12211 | * Otherwise hibernation might fail when mapping all the vectors back |
| 12212 | * to CPU0. |
| 12213 | */ |
| 12214 | i40e_clear_interrupt_scheme(pf); |
Jacob Keller | c17401a | 2017-07-14 09:27:02 -0400 | [diff] [blame] | 12215 | |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 12216 | return 0; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12217 | } |
| 12218 | |
| 12219 | /** |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 12220 | * i40e_resume - PM callback for waking up from D3 |
| 12221 | * @dev: generic device information structure |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12222 | **/ |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 12223 | static int i40e_resume(struct device *dev) |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12224 | { |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 12225 | struct pci_dev *pdev = to_pci_dev(dev); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12226 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Jacob Keller | b980c06 | 2017-07-14 09:27:06 -0400 | [diff] [blame] | 12227 | int err; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12228 | |
Jacob Keller | 401586c | 2017-07-14 09:27:04 -0400 | [diff] [blame] | 12229 | /* If we're not suspended, then there is nothing to do */ |
| 12230 | if (!test_bit(__I40E_SUSPENDED, pf->state)) |
| 12231 | return 0; |
| 12232 | |
Jacob Keller | b980c06 | 2017-07-14 09:27:06 -0400 | [diff] [blame] | 12233 | /* We cleared the interrupt scheme when we suspended, so we need to |
| 12234 | * restore it now to resume device functionality. |
| 12235 | */ |
| 12236 | err = i40e_restore_interrupt_scheme(pf); |
| 12237 | if (err) { |
| 12238 | dev_err(&pdev->dev, "Cannot restore interrupt scheme: %d\n", |
| 12239 | err); |
| 12240 | } |
| 12241 | |
Jacob Keller | 401586c | 2017-07-14 09:27:04 -0400 | [diff] [blame] | 12242 | clear_bit(__I40E_DOWN, pf->state); |
| 12243 | i40e_reset_and_rebuild(pf, false, false); |
| 12244 | |
| 12245 | /* Clear suspended state last after everything is recovered */ |
| 12246 | clear_bit(__I40E_SUSPENDED, pf->state); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12247 | |
Jacob Keller | 5c49922 | 2017-07-14 09:27:05 -0400 | [diff] [blame] | 12248 | /* Restart the service task */ |
| 12249 | mod_timer(&pf->service_timer, |
| 12250 | round_jiffies(jiffies + pf->service_timer_period)); |
| 12251 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12252 | return 0; |
| 12253 | } |
| 12254 | |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 12255 | #endif /* CONFIG_PM */ |
| 12256 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12257 | static const struct pci_error_handlers i40e_err_handler = { |
| 12258 | .error_detected = i40e_pci_error_detected, |
| 12259 | .slot_reset = i40e_pci_error_slot_reset, |
Alan Brady | 19b7960 | 2017-08-29 05:32:39 -0400 | [diff] [blame^] | 12260 | .reset_prepare = i40e_pci_error_reset_prepare, |
| 12261 | .reset_done = i40e_pci_error_reset_done, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12262 | .resume = i40e_pci_error_resume, |
| 12263 | }; |
| 12264 | |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 12265 | static SIMPLE_DEV_PM_OPS(i40e_pm_ops, i40e_suspend, i40e_resume); |
| 12266 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12267 | static struct pci_driver i40e_driver = { |
| 12268 | .name = i40e_driver_name, |
| 12269 | .id_table = i40e_pci_tbl, |
| 12270 | .probe = i40e_probe, |
| 12271 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12272 | #ifdef CONFIG_PM |
Jacob Keller | 0e5d3da | 2017-07-14 09:27:03 -0400 | [diff] [blame] | 12273 | .driver = { |
| 12274 | .pm = &i40e_pm_ops, |
| 12275 | }, |
| 12276 | #endif /* CONFIG_PM */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 12277 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12278 | .err_handler = &i40e_err_handler, |
| 12279 | .sriov_configure = i40e_pci_sriov_configure, |
| 12280 | }; |
| 12281 | |
| 12282 | /** |
| 12283 | * i40e_init_module - Driver registration routine |
| 12284 | * |
| 12285 | * i40e_init_module is the first routine called when the driver is |
| 12286 | * loaded. All it does is register with the PCI subsystem. |
| 12287 | **/ |
| 12288 | static int __init i40e_init_module(void) |
| 12289 | { |
| 12290 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 12291 | i40e_driver_string, i40e_driver_version_str); |
| 12292 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 12293 | |
Jacob Keller | 4d5957c | 2017-06-20 15:16:54 -0700 | [diff] [blame] | 12294 | /* There is no need to throttle the number of active tasks because |
| 12295 | * each device limits its own task using a state bit for scheduling |
| 12296 | * the service task, and the device tasks do not interfere with each |
| 12297 | * other, so we don't set a max task limit. We must set WQ_MEM_RECLAIM |
| 12298 | * since we need to be able to guarantee forward progress even under |
| 12299 | * memory pressure. |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 12300 | */ |
Jacob Keller | 4d5957c | 2017-06-20 15:16:54 -0700 | [diff] [blame] | 12301 | i40e_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, i40e_driver_name); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 12302 | if (!i40e_wq) { |
| 12303 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 12304 | return -ENOMEM; |
| 12305 | } |
| 12306 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12307 | i40e_dbg_init(); |
| 12308 | return pci_register_driver(&i40e_driver); |
| 12309 | } |
| 12310 | module_init(i40e_init_module); |
| 12311 | |
| 12312 | /** |
| 12313 | * i40e_exit_module - Driver exit cleanup routine |
| 12314 | * |
| 12315 | * i40e_exit_module is called just before the driver is removed |
| 12316 | * from memory. |
| 12317 | **/ |
| 12318 | static void __exit i40e_exit_module(void) |
| 12319 | { |
| 12320 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 12321 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12322 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 12323 | } |
| 12324 | module_exit(i40e_exit_module); |