Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2016 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> |
| 30 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 31 | /* Local includes */ |
| 32 | #include "i40e.h" |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 33 | #include "i40e_diag.h" |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 34 | #include <net/udp_tunnel.h> |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 35 | |
| 36 | const char i40e_driver_name[] = "i40e"; |
| 37 | static const char i40e_driver_string[] = |
| 38 | "Intel(R) Ethernet Connection XL710 Network Driver"; |
| 39 | |
| 40 | #define DRV_KERN "-k" |
| 41 | |
Bimmy Pujari | 1599083 | 2017-01-30 12:29:37 -0800 | [diff] [blame] | 42 | #define DRV_VERSION_MAJOR 2 |
| 43 | #define DRV_VERSION_MINOR 1 |
| 44 | #define DRV_VERSION_BUILD 7 |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 45 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 46 | __stringify(DRV_VERSION_MINOR) "." \ |
| 47 | __stringify(DRV_VERSION_BUILD) DRV_KERN |
| 48 | const char i40e_driver_version_str[] = DRV_VERSION; |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 49 | static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation."; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 50 | |
| 51 | /* a bit of forward declarations */ |
| 52 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); |
| 53 | static void i40e_handle_reset_warning(struct i40e_pf *pf); |
| 54 | static int i40e_add_vsi(struct i40e_vsi *vsi); |
| 55 | 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] | 56 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 57 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
| 58 | static void i40e_determine_queue_usage(struct i40e_pf *pf); |
| 59 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 60 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 61 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 62 | |
| 63 | /* i40e_pci_tbl - PCI Device ID Table |
| 64 | * |
| 65 | * Last entry must be all 0s |
| 66 | * |
| 67 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 68 | * Class, Class Mask, private data (not used) } |
| 69 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 70 | static const struct pci_device_id i40e_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 71 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 72 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 73 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, |
| 74 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 75 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, |
| 76 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, |
| 77 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 78 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0}, |
Shannon Nelson | bc5166b9 | 2015-08-26 15:14:10 -0400 | [diff] [blame] | 79 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0}, |
Anjali Singhai Jain | 35dae51 | 2015-12-22 14:25:03 -0800 | [diff] [blame] | 80 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0}, |
| 81 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame] | 82 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0}, |
| 83 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0}, |
| 84 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0}, |
Catherine Sullivan | d6bf58c | 2016-03-18 12:18:08 -0700 | [diff] [blame] | 85 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0}, |
Shannon Nelson | 48a3b51 | 2015-07-23 16:54:39 -0400 | [diff] [blame] | 86 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
| 87 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0}, |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 88 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_B), 0}, |
| 89 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_SFP28), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 90 | /* required last entry */ |
| 91 | {0, } |
| 92 | }; |
| 93 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 94 | |
| 95 | #define I40E_MAX_VF_COUNT 128 |
| 96 | static int debug = -1; |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 97 | module_param(debug, uint, 0); |
| 98 | 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] | 99 | |
| 100 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 101 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 102 | MODULE_LICENSE("GPL"); |
| 103 | MODULE_VERSION(DRV_VERSION); |
| 104 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 105 | static struct workqueue_struct *i40e_wq; |
| 106 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 107 | /** |
| 108 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 109 | * @hw: pointer to the HW structure |
| 110 | * @mem: ptr to mem struct to fill out |
| 111 | * @size: size of memory requested |
| 112 | * @alignment: what to align the allocation to |
| 113 | **/ |
| 114 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 115 | u64 size, u32 alignment) |
| 116 | { |
| 117 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 118 | |
| 119 | mem->size = ALIGN(size, alignment); |
| 120 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 121 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 122 | if (!mem->va) |
| 123 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 124 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 125 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /** |
| 129 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 130 | * @hw: pointer to the HW structure |
| 131 | * @mem: ptr to mem struct to free |
| 132 | **/ |
| 133 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 134 | { |
| 135 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 136 | |
| 137 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 138 | mem->va = NULL; |
| 139 | mem->pa = 0; |
| 140 | mem->size = 0; |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 147 | * @hw: pointer to the HW structure |
| 148 | * @mem: ptr to mem struct to fill out |
| 149 | * @size: size of memory requested |
| 150 | **/ |
| 151 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 152 | u32 size) |
| 153 | { |
| 154 | mem->size = size; |
| 155 | mem->va = kzalloc(size, GFP_KERNEL); |
| 156 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 157 | if (!mem->va) |
| 158 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 159 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 160 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /** |
| 164 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 165 | * @hw: pointer to the HW structure |
| 166 | * @mem: ptr to mem struct to free |
| 167 | **/ |
| 168 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 169 | { |
| 170 | /* it's ok to kfree a NULL pointer */ |
| 171 | kfree(mem->va); |
| 172 | mem->va = NULL; |
| 173 | mem->size = 0; |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * i40e_get_lump - find a lump of free generic resource |
| 180 | * @pf: board private structure |
| 181 | * @pile: the pile of resource to search |
| 182 | * @needed: the number of items needed |
| 183 | * @id: an owner id to stick on the items assigned |
| 184 | * |
| 185 | * Returns the base item index of the lump, or negative for error |
| 186 | * |
| 187 | * The search_hint trick and lack of advanced fit-finding only work |
| 188 | * because we're highly likely to have all the same size lump requests. |
| 189 | * Linear search time and any fragmentation should be minimal. |
| 190 | **/ |
| 191 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 192 | u16 needed, u16 id) |
| 193 | { |
| 194 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 195 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 196 | |
| 197 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 198 | dev_info(&pf->pdev->dev, |
| 199 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 200 | pile, needed, id); |
| 201 | return -EINVAL; |
| 202 | } |
| 203 | |
| 204 | /* start the linear search with an imperfect hint */ |
| 205 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 206 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 207 | /* skip already allocated entries */ |
| 208 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 209 | i++; |
| 210 | continue; |
| 211 | } |
| 212 | |
| 213 | /* do we have enough in this lump? */ |
| 214 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 215 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 216 | break; |
| 217 | } |
| 218 | |
| 219 | if (j == needed) { |
| 220 | /* there was enough, so assign it to the requestor */ |
| 221 | for (j = 0; j < needed; j++) |
| 222 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 223 | ret = i; |
| 224 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 225 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 226 | } |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 227 | |
| 228 | /* not enough, so skip over it and continue looking */ |
| 229 | i += j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | return ret; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * i40e_put_lump - return a lump of generic resource |
| 237 | * @pile: the pile of resource to search |
| 238 | * @index: the base item index |
| 239 | * @id: the owner id of the items assigned |
| 240 | * |
| 241 | * Returns the count of items in the lump |
| 242 | **/ |
| 243 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 244 | { |
| 245 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 246 | int count = 0; |
| 247 | int i; |
| 248 | |
| 249 | if (!pile || index >= pile->num_entries) |
| 250 | return -EINVAL; |
| 251 | |
| 252 | for (i = index; |
| 253 | i < pile->num_entries && pile->list[i] == valid_id; |
| 254 | i++) { |
| 255 | pile->list[i] = 0; |
| 256 | count++; |
| 257 | } |
| 258 | |
| 259 | if (count && index < pile->search_hint) |
| 260 | pile->search_hint = index; |
| 261 | |
| 262 | return count; |
| 263 | } |
| 264 | |
| 265 | /** |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 266 | * i40e_find_vsi_from_id - searches for the vsi with the given id |
| 267 | * @pf - the pf structure to search for the vsi |
| 268 | * @id - id of the vsi it is searching for |
| 269 | **/ |
| 270 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) |
| 271 | { |
| 272 | int i; |
| 273 | |
| 274 | for (i = 0; i < pf->num_alloc_vsi; i++) |
| 275 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) |
| 276 | return pf->vsi[i]; |
| 277 | |
| 278 | return NULL; |
| 279 | } |
| 280 | |
| 281 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 282 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 283 | * @pf: board private structure |
| 284 | * |
| 285 | * If not already scheduled, this puts the task into the work queue |
| 286 | **/ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 287 | void i40e_service_event_schedule(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 288 | { |
| 289 | if (!test_bit(__I40E_DOWN, &pf->state) && |
Mitch Williams | 9108903 | 2016-11-21 13:03:51 -0800 | [diff] [blame] | 290 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 291 | queue_work(i40e_wq, &pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /** |
| 295 | * i40e_tx_timeout - Respond to a Tx Hang |
| 296 | * @netdev: network interface device structure |
| 297 | * |
| 298 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 299 | * device is munged, not just the one netdev port, so go for the full |
| 300 | * reset. |
| 301 | **/ |
| 302 | static void i40e_tx_timeout(struct net_device *netdev) |
| 303 | { |
| 304 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 305 | struct i40e_vsi *vsi = np->vsi; |
| 306 | struct i40e_pf *pf = vsi->back; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 307 | struct i40e_ring *tx_ring = NULL; |
| 308 | unsigned int i, hung_queue = 0; |
| 309 | u32 head, val; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 310 | |
| 311 | pf->tx_timeout_count++; |
| 312 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 313 | /* find the stopped queue the same way the stack does */ |
| 314 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 315 | struct netdev_queue *q; |
| 316 | unsigned long trans_start; |
| 317 | |
| 318 | q = netdev_get_tx_queue(netdev, i); |
Florian Westphal | 9b36627 | 2016-05-03 16:33:14 +0200 | [diff] [blame] | 319 | trans_start = q->trans_start; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 320 | if (netif_xmit_stopped(q) && |
| 321 | time_after(jiffies, |
| 322 | (trans_start + netdev->watchdog_timeo))) { |
| 323 | hung_queue = i; |
| 324 | break; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | if (i == netdev->num_tx_queues) { |
| 329 | netdev_info(netdev, "tx_timeout: no netdev hung queue found\n"); |
| 330 | } else { |
| 331 | /* now that we have an index, find the tx_ring struct */ |
| 332 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 333 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 334 | if (hung_queue == |
| 335 | vsi->tx_rings[i]->queue_index) { |
| 336 | tx_ring = vsi->tx_rings[i]; |
| 337 | break; |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 343 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 344 | pf->tx_timeout_recovery_level = 1; /* reset after some time */ |
| 345 | else if (time_before(jiffies, |
| 346 | (pf->tx_timeout_last_recovery + netdev->watchdog_timeo))) |
| 347 | return; /* don't do any new action before the next timeout */ |
| 348 | |
| 349 | if (tx_ring) { |
| 350 | head = i40e_get_head(tx_ring); |
| 351 | /* Read interrupt register */ |
| 352 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 353 | val = rd32(&pf->hw, |
| 354 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 355 | tx_ring->vsi->base_vector - 1)); |
| 356 | else |
| 357 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 358 | |
| 359 | 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", |
| 360 | vsi->seid, hung_queue, tx_ring->next_to_clean, |
| 361 | head, tx_ring->next_to_use, |
| 362 | readl(tx_ring->tail), val); |
| 363 | } |
| 364 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 365 | pf->tx_timeout_last_recovery = jiffies; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 366 | netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n", |
| 367 | pf->tx_timeout_recovery_level, hung_queue); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 368 | |
| 369 | switch (pf->tx_timeout_recovery_level) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 370 | case 1: |
| 371 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 372 | break; |
| 373 | case 2: |
| 374 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 375 | break; |
| 376 | case 3: |
| 377 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 378 | break; |
| 379 | default: |
| 380 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 381 | break; |
| 382 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 383 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 384 | i40e_service_event_schedule(pf); |
| 385 | pf->tx_timeout_recovery_level++; |
| 386 | } |
| 387 | |
| 388 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 389 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 390 | * @vsi: the VSI we care about |
| 391 | * |
| 392 | * Returns the address of the device statistics structure. |
| 393 | * The statistics are actually updated from the service task. |
| 394 | **/ |
| 395 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 396 | { |
| 397 | return &vsi->net_stats; |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 402 | * @netdev: network interface device structure |
| 403 | * |
| 404 | * Returns the address of the device statistics structure. |
| 405 | * The statistics are actually updated from the service task. |
| 406 | **/ |
Alexander Duyck | 9eed69a | 2017-02-21 15:55:47 -0800 | [diff] [blame] | 407 | static void i40e_get_netdev_stats_struct(struct net_device *netdev, |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 408 | struct rtnl_link_stats64 *stats) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 409 | { |
| 410 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 411 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 412 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 413 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 414 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 415 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 416 | if (test_bit(__I40E_DOWN, &vsi->state)) |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 417 | return; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 418 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 419 | if (!vsi->tx_rings) |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 420 | return; |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 421 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 422 | rcu_read_lock(); |
| 423 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 424 | u64 bytes, packets; |
| 425 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 426 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 427 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 428 | if (!tx_ring) |
| 429 | continue; |
| 430 | |
| 431 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 432 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 433 | packets = tx_ring->stats.packets; |
| 434 | bytes = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 435 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 436 | |
| 437 | stats->tx_packets += packets; |
| 438 | stats->tx_bytes += bytes; |
| 439 | rx_ring = &tx_ring[1]; |
| 440 | |
| 441 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 442 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 443 | packets = rx_ring->stats.packets; |
| 444 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 445 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 446 | |
| 447 | stats->rx_packets += packets; |
| 448 | stats->rx_bytes += bytes; |
| 449 | } |
| 450 | rcu_read_unlock(); |
| 451 | |
Akeem G Abodunrin | a5282f4 | 2014-05-10 04:49:03 +0000 | [diff] [blame] | 452 | /* following stats updated by i40e_watchdog_subtask() */ |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 453 | stats->multicast = vsi_stats->multicast; |
| 454 | stats->tx_errors = vsi_stats->tx_errors; |
| 455 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 456 | stats->rx_errors = vsi_stats->rx_errors; |
Jesse Brandeburg | d8201e2 | 2015-07-23 16:54:35 -0400 | [diff] [blame] | 457 | stats->rx_dropped = vsi_stats->rx_dropped; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 458 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 459 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /** |
| 463 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 464 | * @vsi: the VSI to have its stats reset |
| 465 | **/ |
| 466 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 467 | { |
| 468 | struct rtnl_link_stats64 *ns; |
| 469 | int i; |
| 470 | |
| 471 | if (!vsi) |
| 472 | return; |
| 473 | |
| 474 | ns = i40e_get_vsi_stats_struct(vsi); |
| 475 | memset(ns, 0, sizeof(*ns)); |
| 476 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 477 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 478 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 479 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 480 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 481 | memset(&vsi->rx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 482 | sizeof(vsi->rx_rings[i]->stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 483 | memset(&vsi->rx_rings[i]->rx_stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 484 | sizeof(vsi->rx_rings[i]->rx_stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 485 | memset(&vsi->tx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 486 | sizeof(vsi->tx_rings[i]->stats)); |
| 487 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 488 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 489 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 490 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 491 | vsi->stat_offsets_loaded = false; |
| 492 | } |
| 493 | |
| 494 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 495 | * 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] | 496 | * @pf: the PF to be reset |
| 497 | **/ |
| 498 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 499 | { |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 500 | int i; |
| 501 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 502 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 503 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 504 | pf->stat_offsets_loaded = false; |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 505 | |
| 506 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 507 | if (pf->veb[i]) { |
| 508 | memset(&pf->veb[i]->stats, 0, |
| 509 | sizeof(pf->veb[i]->stats)); |
| 510 | memset(&pf->veb[i]->stats_offsets, 0, |
| 511 | sizeof(pf->veb[i]->stats_offsets)); |
| 512 | pf->veb[i]->stat_offsets_loaded = false; |
| 513 | } |
| 514 | } |
Catherine Sullivan | 42bce04 | 2016-07-27 12:02:32 -0700 | [diff] [blame] | 515 | pf->hw_csum_rx_error = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /** |
| 519 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 520 | * @hw: ptr to the hardware info |
| 521 | * @hireg: the high 32 bit reg to read |
| 522 | * @loreg: the low 32 bit reg to read |
| 523 | * @offset_loaded: has the initial offset been loaded yet |
| 524 | * @offset: ptr to current offset value |
| 525 | * @stat: ptr to the stat |
| 526 | * |
| 527 | * Since the device stats are not reset at PFReset, they likely will not |
| 528 | * be zeroed when the driver starts. We'll save the first values read |
| 529 | * and use them as offsets to be subtracted from the raw values in order |
| 530 | * to report stats that count from zero. In the process, we also manage |
| 531 | * the potential roll-over. |
| 532 | **/ |
| 533 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 534 | bool offset_loaded, u64 *offset, u64 *stat) |
| 535 | { |
| 536 | u64 new_data; |
| 537 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 538 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 539 | new_data = rd32(hw, loreg); |
| 540 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 541 | } else { |
| 542 | new_data = rd64(hw, loreg); |
| 543 | } |
| 544 | if (!offset_loaded) |
| 545 | *offset = new_data; |
| 546 | if (likely(new_data >= *offset)) |
| 547 | *stat = new_data - *offset; |
| 548 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 549 | *stat = (new_data + BIT_ULL(48)) - *offset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 550 | *stat &= 0xFFFFFFFFFFFFULL; |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 555 | * @hw: ptr to the hardware info |
| 556 | * @reg: the hw reg to read |
| 557 | * @offset_loaded: has the initial offset been loaded yet |
| 558 | * @offset: ptr to current offset value |
| 559 | * @stat: ptr to the stat |
| 560 | **/ |
| 561 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 562 | bool offset_loaded, u64 *offset, u64 *stat) |
| 563 | { |
| 564 | u32 new_data; |
| 565 | |
| 566 | new_data = rd32(hw, reg); |
| 567 | if (!offset_loaded) |
| 568 | *offset = new_data; |
| 569 | if (likely(new_data >= *offset)) |
| 570 | *stat = (u32)(new_data - *offset); |
| 571 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 572 | *stat = (u32)((new_data + BIT_ULL(32)) - *offset); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /** |
| 576 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 577 | * @vsi: the VSI to be updated |
| 578 | **/ |
| 579 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 580 | { |
| 581 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 582 | struct i40e_pf *pf = vsi->back; |
| 583 | struct i40e_hw *hw = &pf->hw; |
| 584 | struct i40e_eth_stats *oes; |
| 585 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 586 | |
| 587 | es = &vsi->eth_stats; |
| 588 | oes = &vsi->eth_stats_offsets; |
| 589 | |
| 590 | /* Gather up the stats that the hw collects */ |
| 591 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 592 | vsi->stat_offsets_loaded, |
| 593 | &oes->tx_errors, &es->tx_errors); |
| 594 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 595 | vsi->stat_offsets_loaded, |
| 596 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 597 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 598 | vsi->stat_offsets_loaded, |
| 599 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 600 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 601 | vsi->stat_offsets_loaded, |
| 602 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 603 | |
| 604 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 605 | I40E_GLV_GORCL(stat_idx), |
| 606 | vsi->stat_offsets_loaded, |
| 607 | &oes->rx_bytes, &es->rx_bytes); |
| 608 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 609 | I40E_GLV_UPRCL(stat_idx), |
| 610 | vsi->stat_offsets_loaded, |
| 611 | &oes->rx_unicast, &es->rx_unicast); |
| 612 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 613 | I40E_GLV_MPRCL(stat_idx), |
| 614 | vsi->stat_offsets_loaded, |
| 615 | &oes->rx_multicast, &es->rx_multicast); |
| 616 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 617 | I40E_GLV_BPRCL(stat_idx), |
| 618 | vsi->stat_offsets_loaded, |
| 619 | &oes->rx_broadcast, &es->rx_broadcast); |
| 620 | |
| 621 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 622 | I40E_GLV_GOTCL(stat_idx), |
| 623 | vsi->stat_offsets_loaded, |
| 624 | &oes->tx_bytes, &es->tx_bytes); |
| 625 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 626 | I40E_GLV_UPTCL(stat_idx), |
| 627 | vsi->stat_offsets_loaded, |
| 628 | &oes->tx_unicast, &es->tx_unicast); |
| 629 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 630 | I40E_GLV_MPTCL(stat_idx), |
| 631 | vsi->stat_offsets_loaded, |
| 632 | &oes->tx_multicast, &es->tx_multicast); |
| 633 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 634 | I40E_GLV_BPTCL(stat_idx), |
| 635 | vsi->stat_offsets_loaded, |
| 636 | &oes->tx_broadcast, &es->tx_broadcast); |
| 637 | vsi->stat_offsets_loaded = true; |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * i40e_update_veb_stats - Update Switch component statistics |
| 642 | * @veb: the VEB being updated |
| 643 | **/ |
| 644 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 645 | { |
| 646 | struct i40e_pf *pf = veb->pf; |
| 647 | struct i40e_hw *hw = &pf->hw; |
| 648 | struct i40e_eth_stats *oes; |
| 649 | struct i40e_eth_stats *es; /* device's eth stats */ |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 650 | struct i40e_veb_tc_stats *veb_oes; |
| 651 | struct i40e_veb_tc_stats *veb_es; |
| 652 | int i, idx = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 653 | |
| 654 | idx = veb->stats_idx; |
| 655 | es = &veb->stats; |
| 656 | oes = &veb->stats_offsets; |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 657 | veb_es = &veb->tc_stats; |
| 658 | veb_oes = &veb->tc_stats_offsets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 659 | |
| 660 | /* Gather up the stats that the hw collects */ |
| 661 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 662 | veb->stat_offsets_loaded, |
| 663 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 664 | if (hw->revision_id > 0) |
| 665 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 666 | veb->stat_offsets_loaded, |
| 667 | &oes->rx_unknown_protocol, |
| 668 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 669 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 670 | veb->stat_offsets_loaded, |
| 671 | &oes->rx_bytes, &es->rx_bytes); |
| 672 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 673 | veb->stat_offsets_loaded, |
| 674 | &oes->rx_unicast, &es->rx_unicast); |
| 675 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 676 | veb->stat_offsets_loaded, |
| 677 | &oes->rx_multicast, &es->rx_multicast); |
| 678 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 679 | veb->stat_offsets_loaded, |
| 680 | &oes->rx_broadcast, &es->rx_broadcast); |
| 681 | |
| 682 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 683 | veb->stat_offsets_loaded, |
| 684 | &oes->tx_bytes, &es->tx_bytes); |
| 685 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 686 | veb->stat_offsets_loaded, |
| 687 | &oes->tx_unicast, &es->tx_unicast); |
| 688 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 689 | veb->stat_offsets_loaded, |
| 690 | &oes->tx_multicast, &es->tx_multicast); |
| 691 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 692 | veb->stat_offsets_loaded, |
| 693 | &oes->tx_broadcast, &es->tx_broadcast); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 694 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 695 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), |
| 696 | I40E_GLVEBTC_RPCL(i, idx), |
| 697 | veb->stat_offsets_loaded, |
| 698 | &veb_oes->tc_rx_packets[i], |
| 699 | &veb_es->tc_rx_packets[i]); |
| 700 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), |
| 701 | I40E_GLVEBTC_RBCL(i, idx), |
| 702 | veb->stat_offsets_loaded, |
| 703 | &veb_oes->tc_rx_bytes[i], |
| 704 | &veb_es->tc_rx_bytes[i]); |
| 705 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), |
| 706 | I40E_GLVEBTC_TPCL(i, idx), |
| 707 | veb->stat_offsets_loaded, |
| 708 | &veb_oes->tc_tx_packets[i], |
| 709 | &veb_es->tc_tx_packets[i]); |
| 710 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), |
| 711 | I40E_GLVEBTC_TBCL(i, idx), |
| 712 | veb->stat_offsets_loaded, |
| 713 | &veb_oes->tc_tx_bytes[i], |
| 714 | &veb_es->tc_tx_bytes[i]); |
| 715 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 716 | veb->stat_offsets_loaded = true; |
| 717 | } |
| 718 | |
| 719 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 720 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 721 | * @vsi: the VSI to be updated |
| 722 | * |
| 723 | * There are a few instances where we store the same stat in a |
| 724 | * couple of different structs. This is partly because we have |
| 725 | * the netdev stats that need to be filled out, which is slightly |
| 726 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 727 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 728 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 729 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 730 | { |
| 731 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 732 | struct rtnl_link_stats64 *ons; |
| 733 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 734 | struct i40e_eth_stats *oes; |
| 735 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 736 | u32 tx_restart, tx_busy; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 737 | u64 tx_lost_interrupt; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 738 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 739 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 740 | u64 bytes, packets; |
| 741 | unsigned int start; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 742 | u64 tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 743 | u64 tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 744 | u64 rx_p, rx_b; |
| 745 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 746 | u16 q; |
| 747 | |
| 748 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 749 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 750 | return; |
| 751 | |
| 752 | ns = i40e_get_vsi_stats_struct(vsi); |
| 753 | ons = &vsi->net_stats_offsets; |
| 754 | es = &vsi->eth_stats; |
| 755 | oes = &vsi->eth_stats_offsets; |
| 756 | |
| 757 | /* Gather up the netdev and vsi stats that the driver collects |
| 758 | * on the fly during packet processing |
| 759 | */ |
| 760 | rx_b = rx_p = 0; |
| 761 | tx_b = tx_p = 0; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 762 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 763 | tx_lost_interrupt = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 764 | rx_page = 0; |
| 765 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 766 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 767 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 768 | /* locate Tx ring */ |
| 769 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 770 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 771 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 772 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 773 | packets = p->stats.packets; |
| 774 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 775 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 776 | tx_b += bytes; |
| 777 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 778 | tx_restart += p->tx_stats.restart_queue; |
| 779 | tx_busy += p->tx_stats.tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 780 | tx_linearize += p->tx_stats.tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 781 | tx_force_wb += p->tx_stats.tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 782 | tx_lost_interrupt += p->tx_stats.tx_lost_interrupt; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 783 | |
| 784 | /* Rx queue is part of the same block as Tx queue */ |
| 785 | p = &p[1]; |
| 786 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 787 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 788 | packets = p->stats.packets; |
| 789 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 790 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 791 | rx_b += bytes; |
| 792 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 793 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 794 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 795 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 796 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 797 | vsi->tx_restart = tx_restart; |
| 798 | vsi->tx_busy = tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 799 | vsi->tx_linearize = tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 800 | vsi->tx_force_wb = tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 801 | vsi->tx_lost_interrupt = tx_lost_interrupt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 802 | vsi->rx_page_failed = rx_page; |
| 803 | vsi->rx_buf_failed = rx_buf; |
| 804 | |
| 805 | ns->rx_packets = rx_p; |
| 806 | ns->rx_bytes = rx_b; |
| 807 | ns->tx_packets = tx_p; |
| 808 | ns->tx_bytes = tx_b; |
| 809 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 810 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 811 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 812 | ons->tx_errors = oes->tx_errors; |
| 813 | ns->tx_errors = es->tx_errors; |
| 814 | ons->multicast = oes->rx_multicast; |
| 815 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 816 | ons->rx_dropped = oes->rx_discards; |
| 817 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 818 | ons->tx_dropped = oes->tx_discards; |
| 819 | ns->tx_dropped = es->tx_discards; |
| 820 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 821 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 822 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 823 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 824 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 825 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 826 | } |
| 827 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 828 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 829 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 830 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 831 | * @pf: the PF to be updated |
| 832 | **/ |
| 833 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 834 | { |
| 835 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 836 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 837 | struct i40e_hw *hw = &pf->hw; |
| 838 | u32 val; |
| 839 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 840 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 841 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 842 | I40E_GLPRT_GORCL(hw->port), |
| 843 | pf->stat_offsets_loaded, |
| 844 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 845 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 846 | I40E_GLPRT_GOTCL(hw->port), |
| 847 | pf->stat_offsets_loaded, |
| 848 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 849 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 850 | pf->stat_offsets_loaded, |
| 851 | &osd->eth.rx_discards, |
| 852 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 853 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 854 | I40E_GLPRT_UPRCL(hw->port), |
| 855 | pf->stat_offsets_loaded, |
| 856 | &osd->eth.rx_unicast, |
| 857 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 858 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 859 | I40E_GLPRT_MPRCL(hw->port), |
| 860 | pf->stat_offsets_loaded, |
| 861 | &osd->eth.rx_multicast, |
| 862 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 863 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 864 | I40E_GLPRT_BPRCL(hw->port), |
| 865 | pf->stat_offsets_loaded, |
| 866 | &osd->eth.rx_broadcast, |
| 867 | &nsd->eth.rx_broadcast); |
| 868 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 869 | I40E_GLPRT_UPTCL(hw->port), |
| 870 | pf->stat_offsets_loaded, |
| 871 | &osd->eth.tx_unicast, |
| 872 | &nsd->eth.tx_unicast); |
| 873 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 874 | I40E_GLPRT_MPTCL(hw->port), |
| 875 | pf->stat_offsets_loaded, |
| 876 | &osd->eth.tx_multicast, |
| 877 | &nsd->eth.tx_multicast); |
| 878 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 879 | I40E_GLPRT_BPTCL(hw->port), |
| 880 | pf->stat_offsets_loaded, |
| 881 | &osd->eth.tx_broadcast, |
| 882 | &nsd->eth.tx_broadcast); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 883 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 884 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 885 | pf->stat_offsets_loaded, |
| 886 | &osd->tx_dropped_link_down, |
| 887 | &nsd->tx_dropped_link_down); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 888 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 889 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 890 | pf->stat_offsets_loaded, |
| 891 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 892 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 893 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 894 | pf->stat_offsets_loaded, |
| 895 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 896 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 897 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 898 | pf->stat_offsets_loaded, |
| 899 | &osd->mac_local_faults, |
| 900 | &nsd->mac_local_faults); |
| 901 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 902 | pf->stat_offsets_loaded, |
| 903 | &osd->mac_remote_faults, |
| 904 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 905 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 906 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 907 | pf->stat_offsets_loaded, |
| 908 | &osd->rx_length_errors, |
| 909 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 910 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 911 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 912 | pf->stat_offsets_loaded, |
| 913 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 914 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 915 | pf->stat_offsets_loaded, |
| 916 | &osd->link_xon_tx, &nsd->link_xon_tx); |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 917 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 918 | pf->stat_offsets_loaded, |
| 919 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 920 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 921 | pf->stat_offsets_loaded, |
| 922 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 923 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 924 | for (i = 0; i < 8; i++) { |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 925 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 926 | pf->stat_offsets_loaded, |
| 927 | &osd->priority_xoff_rx[i], |
| 928 | &nsd->priority_xoff_rx[i]); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 929 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 930 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 931 | &osd->priority_xon_rx[i], |
| 932 | &nsd->priority_xon_rx[i]); |
| 933 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 934 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 935 | &osd->priority_xon_tx[i], |
| 936 | &nsd->priority_xon_tx[i]); |
| 937 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 938 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 939 | &osd->priority_xoff_tx[i], |
| 940 | &nsd->priority_xoff_tx[i]); |
| 941 | i40e_stat_update32(hw, |
| 942 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 943 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 944 | &osd->priority_xon_2_xoff[i], |
| 945 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 946 | } |
| 947 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 948 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 949 | I40E_GLPRT_PRC64L(hw->port), |
| 950 | pf->stat_offsets_loaded, |
| 951 | &osd->rx_size_64, &nsd->rx_size_64); |
| 952 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 953 | I40E_GLPRT_PRC127L(hw->port), |
| 954 | pf->stat_offsets_loaded, |
| 955 | &osd->rx_size_127, &nsd->rx_size_127); |
| 956 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 957 | I40E_GLPRT_PRC255L(hw->port), |
| 958 | pf->stat_offsets_loaded, |
| 959 | &osd->rx_size_255, &nsd->rx_size_255); |
| 960 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 961 | I40E_GLPRT_PRC511L(hw->port), |
| 962 | pf->stat_offsets_loaded, |
| 963 | &osd->rx_size_511, &nsd->rx_size_511); |
| 964 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 965 | I40E_GLPRT_PRC1023L(hw->port), |
| 966 | pf->stat_offsets_loaded, |
| 967 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 968 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 969 | I40E_GLPRT_PRC1522L(hw->port), |
| 970 | pf->stat_offsets_loaded, |
| 971 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 972 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 973 | I40E_GLPRT_PRC9522L(hw->port), |
| 974 | pf->stat_offsets_loaded, |
| 975 | &osd->rx_size_big, &nsd->rx_size_big); |
| 976 | |
| 977 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 978 | I40E_GLPRT_PTC64L(hw->port), |
| 979 | pf->stat_offsets_loaded, |
| 980 | &osd->tx_size_64, &nsd->tx_size_64); |
| 981 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 982 | I40E_GLPRT_PTC127L(hw->port), |
| 983 | pf->stat_offsets_loaded, |
| 984 | &osd->tx_size_127, &nsd->tx_size_127); |
| 985 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 986 | I40E_GLPRT_PTC255L(hw->port), |
| 987 | pf->stat_offsets_loaded, |
| 988 | &osd->tx_size_255, &nsd->tx_size_255); |
| 989 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 990 | I40E_GLPRT_PTC511L(hw->port), |
| 991 | pf->stat_offsets_loaded, |
| 992 | &osd->tx_size_511, &nsd->tx_size_511); |
| 993 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 994 | I40E_GLPRT_PTC1023L(hw->port), |
| 995 | pf->stat_offsets_loaded, |
| 996 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 997 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 998 | I40E_GLPRT_PTC1522L(hw->port), |
| 999 | pf->stat_offsets_loaded, |
| 1000 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1001 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1002 | I40E_GLPRT_PTC9522L(hw->port), |
| 1003 | pf->stat_offsets_loaded, |
| 1004 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1005 | |
| 1006 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1007 | pf->stat_offsets_loaded, |
| 1008 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1009 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1010 | pf->stat_offsets_loaded, |
| 1011 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1012 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1013 | pf->stat_offsets_loaded, |
| 1014 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1015 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1016 | pf->stat_offsets_loaded, |
| 1017 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1018 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1019 | /* FDIR stats */ |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1020 | i40e_stat_update32(hw, |
| 1021 | I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)), |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1022 | pf->stat_offsets_loaded, |
| 1023 | &osd->fd_atr_match, &nsd->fd_atr_match); |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1024 | i40e_stat_update32(hw, |
| 1025 | I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)), |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1026 | pf->stat_offsets_loaded, |
| 1027 | &osd->fd_sb_match, &nsd->fd_sb_match); |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 1028 | i40e_stat_update32(hw, |
| 1029 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), |
| 1030 | pf->stat_offsets_loaded, |
| 1031 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1032 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1033 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1034 | nsd->tx_lpi_status = |
| 1035 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1036 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1037 | nsd->rx_lpi_status = |
| 1038 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1039 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1040 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1041 | pf->stat_offsets_loaded, |
| 1042 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1043 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1044 | pf->stat_offsets_loaded, |
| 1045 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1046 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1047 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 1048 | !(pf->hw_disabled_flags & I40E_FLAG_FD_SB_ENABLED)) |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1049 | nsd->fd_sb_status = true; |
| 1050 | else |
| 1051 | nsd->fd_sb_status = false; |
| 1052 | |
| 1053 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 1054 | !(pf->hw_disabled_flags & I40E_FLAG_FD_ATR_ENABLED)) |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1055 | nsd->fd_atr_status = true; |
| 1056 | else |
| 1057 | nsd->fd_atr_status = false; |
| 1058 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1059 | pf->stat_offsets_loaded = true; |
| 1060 | } |
| 1061 | |
| 1062 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1063 | * i40e_update_stats - Update the various statistics counters. |
| 1064 | * @vsi: the VSI to be updated |
| 1065 | * |
| 1066 | * Update the various stats for this VSI and its related entities. |
| 1067 | **/ |
| 1068 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1069 | { |
| 1070 | struct i40e_pf *pf = vsi->back; |
| 1071 | |
| 1072 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1073 | i40e_update_pf_stats(pf); |
| 1074 | |
| 1075 | i40e_update_vsi_stats(vsi); |
| 1076 | } |
| 1077 | |
| 1078 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1079 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1080 | * @vsi: the VSI to be searched |
| 1081 | * @macaddr: the MAC address |
| 1082 | * @vlan: the vlan |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1083 | * |
| 1084 | * Returns ptr to the filter object or NULL |
| 1085 | **/ |
| 1086 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1087 | const u8 *macaddr, s16 vlan) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1088 | { |
| 1089 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1090 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1091 | |
| 1092 | if (!vsi || !macaddr) |
| 1093 | return NULL; |
| 1094 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1095 | key = i40e_addr_to_hkey(macaddr); |
| 1096 | hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1097 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1098 | (vlan == f->vlan)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1099 | return f; |
| 1100 | } |
| 1101 | return NULL; |
| 1102 | } |
| 1103 | |
| 1104 | /** |
| 1105 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1106 | * @vsi: the VSI to be searched |
| 1107 | * @macaddr: the MAC address we are searching for |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1108 | * |
| 1109 | * Returns the first filter with the provided MAC address or NULL if |
| 1110 | * MAC address was not found |
| 1111 | **/ |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1112 | 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] | 1113 | { |
| 1114 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1115 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1116 | |
| 1117 | if (!vsi || !macaddr) |
| 1118 | return NULL; |
| 1119 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1120 | key = i40e_addr_to_hkey(macaddr); |
| 1121 | hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1122 | if ((ether_addr_equal(macaddr, f->macaddr))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1123 | return f; |
| 1124 | } |
| 1125 | return NULL; |
| 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1130 | * @vsi: the VSI to be searched |
| 1131 | * |
| 1132 | * Returns true if VSI is in vlan mode or false otherwise |
| 1133 | **/ |
| 1134 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1135 | { |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1136 | /* If we have a PVID, always operate in VLAN mode */ |
| 1137 | if (vsi->info.pvid) |
| 1138 | return true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1139 | |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1140 | /* We need to operate in VLAN mode whenever we have any filters with |
| 1141 | * a VLAN other than I40E_VLAN_ALL. We could check the table each |
| 1142 | * time, incurring search cost repeatedly. However, we can notice two |
| 1143 | * things: |
| 1144 | * |
| 1145 | * 1) the only place where we can gain a VLAN filter is in |
| 1146 | * i40e_add_filter. |
| 1147 | * |
| 1148 | * 2) the only place where filters are actually removed is in |
Jacob Keller | 0b7c8b5 | 2016-10-25 16:08:52 -0700 | [diff] [blame] | 1149 | * i40e_sync_filters_subtask. |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1150 | * |
| 1151 | * Thus, we can simply use a boolean value, has_vlan_filters which we |
| 1152 | * will set to true when we add a VLAN filter in i40e_add_filter. Then |
| 1153 | * we have to perform the full search after deleting filters in |
Jacob Keller | 0b7c8b5 | 2016-10-25 16:08:52 -0700 | [diff] [blame] | 1154 | * i40e_sync_filters_subtask, but we already have to search |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1155 | * filters here and can perform the check at the same time. This |
| 1156 | * results in avoiding embedding a loop for VLAN mode inside another |
| 1157 | * loop over all the filters, and should maintain correctness as noted |
| 1158 | * above. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1159 | */ |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1160 | return vsi->has_vlan_filter; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | /** |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1164 | * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary |
| 1165 | * @vsi: the VSI to configure |
| 1166 | * @tmp_add_list: list of filters ready to be added |
| 1167 | * @tmp_del_list: list of filters ready to be deleted |
| 1168 | * @vlan_filters: the number of active VLAN filters |
| 1169 | * |
| 1170 | * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they |
| 1171 | * behave as expected. If we have any active VLAN filters remaining or about |
| 1172 | * to be added then we need to update non-VLAN filters to be marked as VLAN=0 |
| 1173 | * so that they only match against untagged traffic. If we no longer have any |
| 1174 | * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1 |
| 1175 | * so that they match against both tagged and untagged traffic. In this way, |
| 1176 | * we ensure that we correctly receive the desired traffic. This ensures that |
| 1177 | * when we have an active VLAN we will receive only untagged traffic and |
| 1178 | * traffic matching active VLANs. If we have no active VLANs then we will |
| 1179 | * operate in non-VLAN mode and receive all traffic, tagged or untagged. |
| 1180 | * |
| 1181 | * Finally, in a similar fashion, this function also corrects filters when |
| 1182 | * there is an active PVID assigned to this VSI. |
| 1183 | * |
| 1184 | * In case of memory allocation failure return -ENOMEM. Otherwise, return 0. |
| 1185 | * |
| 1186 | * This function is only expected to be called from within |
| 1187 | * i40e_sync_vsi_filters. |
| 1188 | * |
| 1189 | * NOTE: This function expects to be called while under the |
| 1190 | * mac_filter_hash_lock |
| 1191 | */ |
| 1192 | static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi, |
| 1193 | struct hlist_head *tmp_add_list, |
| 1194 | struct hlist_head *tmp_del_list, |
| 1195 | int vlan_filters) |
| 1196 | { |
Jacob Keller | 5cb2590 | 2016-12-12 15:44:15 -0800 | [diff] [blame] | 1197 | s16 pvid = le16_to_cpu(vsi->info.pvid); |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1198 | struct i40e_mac_filter *f, *add_head; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1199 | struct i40e_new_mac_filter *new; |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1200 | struct hlist_node *h; |
| 1201 | int bkt, new_vlan; |
| 1202 | |
| 1203 | /* To determine if a particular filter needs to be replaced we |
| 1204 | * have the three following conditions: |
| 1205 | * |
| 1206 | * a) if we have a PVID assigned, then all filters which are |
| 1207 | * not marked as VLAN=PVID must be replaced with filters that |
| 1208 | * are. |
| 1209 | * b) otherwise, if we have any active VLANS, all filters |
| 1210 | * which are marked as VLAN=-1 must be replaced with |
| 1211 | * filters marked as VLAN=0 |
| 1212 | * c) finally, if we do not have any active VLANS, all filters |
| 1213 | * which are marked as VLAN=0 must be replaced with filters |
| 1214 | * marked as VLAN=-1 |
| 1215 | */ |
| 1216 | |
| 1217 | /* Update the filters about to be added in place */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1218 | hlist_for_each_entry(new, tmp_add_list, hlist) { |
Jacob Keller | 5cb2590 | 2016-12-12 15:44:15 -0800 | [diff] [blame] | 1219 | if (pvid && new->f->vlan != pvid) |
| 1220 | new->f->vlan = pvid; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1221 | else if (vlan_filters && new->f->vlan == I40E_VLAN_ANY) |
| 1222 | new->f->vlan = 0; |
| 1223 | else if (!vlan_filters && new->f->vlan == 0) |
| 1224 | new->f->vlan = I40E_VLAN_ANY; |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | /* Update the remaining active filters */ |
| 1228 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
| 1229 | /* Combine the checks for whether a filter needs to be changed |
| 1230 | * and then determine the new VLAN inside the if block, in |
| 1231 | * order to avoid duplicating code for adding the new filter |
| 1232 | * then deleting the old filter. |
| 1233 | */ |
Jacob Keller | 5cb2590 | 2016-12-12 15:44:15 -0800 | [diff] [blame] | 1234 | if ((pvid && f->vlan != pvid) || |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1235 | (vlan_filters && f->vlan == I40E_VLAN_ANY) || |
| 1236 | (!vlan_filters && f->vlan == 0)) { |
| 1237 | /* Determine the new vlan we will be adding */ |
Jacob Keller | 5cb2590 | 2016-12-12 15:44:15 -0800 | [diff] [blame] | 1238 | if (pvid) |
| 1239 | new_vlan = pvid; |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1240 | else if (vlan_filters) |
| 1241 | new_vlan = 0; |
| 1242 | else |
| 1243 | new_vlan = I40E_VLAN_ANY; |
| 1244 | |
| 1245 | /* Create the new filter */ |
| 1246 | add_head = i40e_add_filter(vsi, f->macaddr, new_vlan); |
| 1247 | if (!add_head) |
| 1248 | return -ENOMEM; |
| 1249 | |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1250 | /* Create a temporary i40e_new_mac_filter */ |
| 1251 | new = kzalloc(sizeof(*new), GFP_ATOMIC); |
| 1252 | if (!new) |
| 1253 | return -ENOMEM; |
| 1254 | |
| 1255 | new->f = add_head; |
| 1256 | new->state = add_head->state; |
| 1257 | |
| 1258 | /* Add the new filter to the tmp list */ |
| 1259 | hlist_add_head(&new->hlist, tmp_add_list); |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1260 | |
| 1261 | /* Put the original filter into the delete list */ |
| 1262 | f->state = I40E_FILTER_REMOVE; |
| 1263 | hash_del(&f->hlist); |
| 1264 | hlist_add_head(&f->hlist, tmp_del_list); |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | vsi->has_vlan_filter = !!vlan_filters; |
| 1269 | |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | /** |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 1274 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM |
| 1275 | * @vsi: the PF Main VSI - inappropriate for any other VSI |
| 1276 | * @macaddr: the MAC address |
| 1277 | * |
| 1278 | * Remove whatever filter the firmware set up so the driver can manage |
| 1279 | * its own filtering intelligently. |
| 1280 | **/ |
| 1281 | static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr) |
| 1282 | { |
| 1283 | struct i40e_aqc_remove_macvlan_element_data element; |
| 1284 | struct i40e_pf *pf = vsi->back; |
| 1285 | |
| 1286 | /* Only appropriate for the PF main VSI */ |
| 1287 | if (vsi->type != I40E_VSI_MAIN) |
| 1288 | return; |
| 1289 | |
| 1290 | memset(&element, 0, sizeof(element)); |
| 1291 | ether_addr_copy(element.mac_addr, macaddr); |
| 1292 | element.vlan_tag = 0; |
| 1293 | /* Ignore error returns, some firmware does it this way... */ |
| 1294 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1295 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1296 | |
| 1297 | memset(&element, 0, sizeof(element)); |
| 1298 | ether_addr_copy(element.mac_addr, macaddr); |
| 1299 | element.vlan_tag = 0; |
| 1300 | /* ...and some firmware does it this way. */ |
| 1301 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | |
| 1302 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
| 1303 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1304 | } |
| 1305 | |
| 1306 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1307 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1308 | * @vsi: the VSI to be searched |
| 1309 | * @macaddr: the MAC address |
| 1310 | * @vlan: the vlan |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1311 | * |
| 1312 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1313 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1314 | * 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] | 1315 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1316 | **/ |
| 1317 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1318 | const u8 *macaddr, s16 vlan) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1319 | { |
| 1320 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1321 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1322 | |
| 1323 | if (!vsi || !macaddr) |
| 1324 | return NULL; |
| 1325 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1326 | f = i40e_find_filter(vsi, macaddr, vlan); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1327 | if (!f) { |
| 1328 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1329 | if (!f) |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1330 | return NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1331 | |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1332 | /* Update the boolean indicating if we need to function in |
| 1333 | * VLAN mode. |
| 1334 | */ |
| 1335 | if (vlan >= 0) |
| 1336 | vsi->has_vlan_filter = true; |
| 1337 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1338 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1339 | f->vlan = vlan; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1340 | /* If we're in overflow promisc mode, set the state directly |
| 1341 | * to failed, so we don't bother to try sending the filter |
| 1342 | * to the hardware. |
| 1343 | */ |
| 1344 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state)) |
| 1345 | f->state = I40E_FILTER_FAILED; |
| 1346 | else |
| 1347 | f->state = I40E_FILTER_NEW; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1348 | INIT_HLIST_NODE(&f->hlist); |
| 1349 | |
| 1350 | key = i40e_addr_to_hkey(macaddr); |
| 1351 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1352 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1353 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1354 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1355 | } |
| 1356 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1357 | /* If we're asked to add a filter that has been marked for removal, it |
| 1358 | * is safe to simply restore it to active state. __i40e_del_filter |
| 1359 | * will have simply deleted any filters which were previously marked |
| 1360 | * NEW or FAILED, so if it is currently marked REMOVE it must have |
| 1361 | * previously been ACTIVE. Since we haven't yet run the sync filters |
| 1362 | * task, just restore this filter to the ACTIVE state so that the |
| 1363 | * sync task leaves it in place |
| 1364 | */ |
| 1365 | if (f->state == I40E_FILTER_REMOVE) |
| 1366 | f->state = I40E_FILTER_ACTIVE; |
| 1367 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1368 | return f; |
| 1369 | } |
| 1370 | |
| 1371 | /** |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1372 | * __i40e_del_filter - Remove a specific filter from the VSI |
| 1373 | * @vsi: VSI to remove from |
| 1374 | * @f: the filter to remove from the list |
| 1375 | * |
| 1376 | * This function should be called instead of i40e_del_filter only if you know |
| 1377 | * the exact filter you will remove already, such as via i40e_find_filter or |
| 1378 | * i40e_find_mac. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1379 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1380 | * 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] | 1381 | * being held. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1382 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1383 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1384 | * instead of list_for_each_entry(). |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1385 | **/ |
Jacob Keller | 148141b | 2016-11-11 12:39:36 -0800 | [diff] [blame] | 1386 | 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] | 1387 | { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1388 | if (!f) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1389 | return; |
| 1390 | |
Alan Brady | a410c82 | 2016-12-12 15:44:07 -0800 | [diff] [blame] | 1391 | /* If the filter was never added to firmware then we can just delete it |
| 1392 | * directly and we don't want to set the status to remove or else an |
| 1393 | * admin queue command will unnecessarily fire. |
| 1394 | */ |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1395 | if ((f->state == I40E_FILTER_FAILED) || |
| 1396 | (f->state == I40E_FILTER_NEW)) { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1397 | hash_del(&f->hlist); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1398 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1399 | } else { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1400 | f->state = I40E_FILTER_REMOVE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1401 | } |
Alan Brady | a410c82 | 2016-12-12 15:44:07 -0800 | [diff] [blame] | 1402 | |
| 1403 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1404 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | /** |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1408 | * i40e_del_filter - Remove a MAC/VLAN filter from the VSI |
| 1409 | * @vsi: the VSI to be searched |
| 1410 | * @macaddr: the MAC address |
| 1411 | * @vlan: the VLAN |
| 1412 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1413 | * 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] | 1414 | * being held. |
| 1415 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1416 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1417 | * instead of list_for_each_entry(). |
| 1418 | **/ |
| 1419 | void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan) |
| 1420 | { |
| 1421 | struct i40e_mac_filter *f; |
| 1422 | |
| 1423 | if (!vsi || !macaddr) |
| 1424 | return; |
| 1425 | |
| 1426 | f = i40e_find_filter(vsi, macaddr, vlan); |
| 1427 | __i40e_del_filter(vsi, f); |
| 1428 | } |
| 1429 | |
| 1430 | /** |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1431 | * i40e_add_mac_filter - Add a MAC filter for all active VLANs |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1432 | * @vsi: the VSI to be searched |
| 1433 | * @macaddr: the mac address to be filtered |
| 1434 | * |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1435 | * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise, |
| 1436 | * 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] | 1437 | * unique vlan that already exists. If a PVID has been assigned, instead only |
| 1438 | * add the macaddr to that VLAN. |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1439 | * |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1440 | * Returns last filter added on success, else NULL |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1441 | **/ |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1442 | struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi, |
| 1443 | const u8 *macaddr) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1444 | { |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1445 | struct i40e_mac_filter *f, *add = NULL; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1446 | struct hlist_node *h; |
| 1447 | int bkt; |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1448 | |
| 1449 | if (vsi->info.pvid) |
| 1450 | return i40e_add_filter(vsi, macaddr, |
| 1451 | le16_to_cpu(vsi->info.pvid)); |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1452 | |
Jacob Keller | 7aaf9536 | 2016-11-11 12:39:33 -0800 | [diff] [blame] | 1453 | if (!i40e_is_vsi_in_vlan(vsi)) |
| 1454 | return i40e_add_filter(vsi, macaddr, I40E_VLAN_ANY); |
| 1455 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1456 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 1457 | if (f->state == I40E_FILTER_REMOVE) |
| 1458 | continue; |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1459 | add = i40e_add_filter(vsi, macaddr, f->vlan); |
| 1460 | if (!add) |
| 1461 | return NULL; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1464 | return add; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | /** |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1468 | * i40e_del_mac_filter - Remove a MAC filter from all VLANs |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1469 | * @vsi: the VSI to be searched |
| 1470 | * @macaddr: the mac address to be removed |
| 1471 | * |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1472 | * Removes a given MAC address from a VSI regardless of what VLAN it has been |
| 1473 | * associated with. |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1474 | * |
| 1475 | * Returns 0 for success, or error |
| 1476 | **/ |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1477 | int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1478 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1479 | struct i40e_mac_filter *f; |
| 1480 | struct hlist_node *h; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1481 | bool found = false; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1482 | int bkt; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1483 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1484 | WARN(!spin_is_locked(&vsi->mac_filter_hash_lock), |
| 1485 | "Missing mac_filter_hash_lock\n"); |
| 1486 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1487 | if (ether_addr_equal(macaddr, f->macaddr)) { |
| 1488 | __i40e_del_filter(vsi, f); |
| 1489 | found = true; |
| 1490 | } |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1491 | } |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1492 | |
| 1493 | if (found) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1494 | return 0; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1495 | else |
| 1496 | return -ENOENT; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1500 | * i40e_set_mac - NDO callback to set mac address |
| 1501 | * @netdev: network interface device structure |
| 1502 | * @p: pointer to an address structure |
| 1503 | * |
| 1504 | * Returns 0 on success, negative on failure |
| 1505 | **/ |
| 1506 | static int i40e_set_mac(struct net_device *netdev, void *p) |
| 1507 | { |
| 1508 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1509 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1510 | struct i40e_pf *pf = vsi->back; |
| 1511 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1512 | struct sockaddr *addr = p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1513 | |
| 1514 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1515 | return -EADDRNOTAVAIL; |
| 1516 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1517 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1518 | netdev_info(netdev, "already using mac address %pM\n", |
| 1519 | addr->sa_data); |
| 1520 | return 0; |
| 1521 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1522 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1523 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1524 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1525 | return -EADDRNOTAVAIL; |
| 1526 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1527 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1528 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1529 | hw->mac.addr); |
| 1530 | else |
| 1531 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1532 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1533 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1534 | i40e_del_mac_filter(vsi, netdev->dev_addr); |
| 1535 | i40e_add_mac_filter(vsi, addr->sa_data); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1536 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1537 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1538 | if (vsi->type == I40E_VSI_MAIN) { |
| 1539 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1540 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1541 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1542 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1543 | addr->sa_data, NULL); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1544 | if (ret) |
| 1545 | netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n", |
| 1546 | i40e_stat_str(hw, ret), |
| 1547 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1550 | /* schedule our worker thread which will take care of |
| 1551 | * applying the new filter changes |
| 1552 | */ |
| 1553 | i40e_service_event_schedule(vsi->back); |
| 1554 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | /** |
| 1558 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1559 | * @vsi: the VSI being setup |
| 1560 | * @ctxt: VSI context structure |
| 1561 | * @enabled_tc: Enabled TCs bitmap |
| 1562 | * @is_add: True if called before Add VSI |
| 1563 | * |
| 1564 | * Setup VSI queue mapping for enabled traffic classes. |
| 1565 | **/ |
| 1566 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1567 | struct i40e_vsi_context *ctxt, |
| 1568 | u8 enabled_tc, |
| 1569 | bool is_add) |
| 1570 | { |
| 1571 | struct i40e_pf *pf = vsi->back; |
| 1572 | u16 sections = 0; |
| 1573 | u8 netdev_tc = 0; |
| 1574 | u16 numtc = 0; |
| 1575 | u16 qcount; |
| 1576 | u8 offset; |
| 1577 | u16 qmap; |
| 1578 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1579 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1580 | |
| 1581 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1582 | offset = 0; |
| 1583 | |
| 1584 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1585 | /* Find numtc from enabled TC bitmap */ |
| 1586 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1587 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1588 | numtc++; |
| 1589 | } |
| 1590 | if (!numtc) { |
| 1591 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1592 | numtc = 1; |
| 1593 | } |
| 1594 | } else { |
| 1595 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1596 | numtc = 1; |
| 1597 | } |
| 1598 | |
| 1599 | vsi->tc_config.numtc = numtc; |
| 1600 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1601 | /* Number of queues per enabled TC */ |
Catherine Sullivan | 7d64402 | 2016-05-16 10:26:41 -0700 | [diff] [blame] | 1602 | qcount = vsi->alloc_queue_pairs; |
| 1603 | |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1604 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1605 | 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] | 1606 | |
| 1607 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1608 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1609 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1610 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1611 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1612 | int pow, num_qps; |
| 1613 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1614 | switch (vsi->type) { |
| 1615 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1616 | qcount = min_t(int, pf->alloc_rss_size, |
| 1617 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1618 | break; |
| 1619 | case I40E_VSI_FDIR: |
| 1620 | case I40E_VSI_SRIOV: |
| 1621 | case I40E_VSI_VMDQ2: |
| 1622 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1623 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1624 | WARN_ON(i != 0); |
| 1625 | break; |
| 1626 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1627 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1628 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1629 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1630 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1631 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1632 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1633 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1634 | pow++; |
| 1635 | num_qps >>= 1; |
| 1636 | } |
| 1637 | |
| 1638 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1639 | qmap = |
| 1640 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1641 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1642 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1643 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1644 | } else { |
| 1645 | /* TC is not enabled so set the offset to |
| 1646 | * default queue and allocate one queue |
| 1647 | * for the given TC. |
| 1648 | */ |
| 1649 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1650 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1651 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1652 | |
| 1653 | qmap = 0; |
| 1654 | } |
| 1655 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1656 | } |
| 1657 | |
| 1658 | /* Set actual Tx/Rx queue pairs */ |
| 1659 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1660 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1661 | if (vsi->req_queue_pairs > 0) |
| 1662 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1663 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1664 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1665 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1666 | |
| 1667 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1668 | if (is_add) { |
| 1669 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1670 | |
| 1671 | ctxt->info.up_enable_bits = enabled_tc; |
| 1672 | } |
| 1673 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1674 | ctxt->info.mapping_flags |= |
| 1675 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1676 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1677 | ctxt->info.queue_mapping[i] = |
| 1678 | cpu_to_le16(vsi->base_queue + i); |
| 1679 | } else { |
| 1680 | ctxt->info.mapping_flags |= |
| 1681 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1682 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1683 | } |
| 1684 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1685 | } |
| 1686 | |
| 1687 | /** |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1688 | * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address |
| 1689 | * @netdev: the netdevice |
| 1690 | * @addr: address to add |
| 1691 | * |
| 1692 | * Called by __dev_(mc|uc)_sync when an address needs to be added. We call |
| 1693 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1694 | */ |
| 1695 | static int i40e_addr_sync(struct net_device *netdev, const u8 *addr) |
| 1696 | { |
| 1697 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1698 | struct i40e_vsi *vsi = np->vsi; |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1699 | |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1700 | if (i40e_add_mac_filter(vsi, addr)) |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1701 | return 0; |
| 1702 | else |
| 1703 | return -ENOMEM; |
| 1704 | } |
| 1705 | |
| 1706 | /** |
| 1707 | * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address |
| 1708 | * @netdev: the netdevice |
| 1709 | * @addr: address to add |
| 1710 | * |
| 1711 | * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call |
| 1712 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1713 | */ |
| 1714 | static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr) |
| 1715 | { |
| 1716 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1717 | struct i40e_vsi *vsi = np->vsi; |
| 1718 | |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1719 | i40e_del_mac_filter(vsi, addr); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1720 | |
| 1721 | return 0; |
| 1722 | } |
| 1723 | |
| 1724 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1725 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1726 | * @netdev: network interface device structure |
| 1727 | **/ |
| 1728 | static void i40e_set_rx_mode(struct net_device *netdev) |
| 1729 | { |
| 1730 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1731 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1732 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1733 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1734 | |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1735 | __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
| 1736 | __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1737 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1738 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1739 | |
| 1740 | /* check for other flag changes */ |
| 1741 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1742 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1743 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1744 | } |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1745 | |
| 1746 | /* schedule our worker thread which will take care of |
| 1747 | * applying the new filter changes |
| 1748 | */ |
| 1749 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | /** |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1753 | * 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] | 1754 | * @vsi: Pointer to VSI struct |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1755 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1756 | * those entries needs to be undone. |
| 1757 | * |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1758 | * MAC filter entries from this list were slated for deletion. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1759 | **/ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1760 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1761 | struct hlist_head *from) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1762 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1763 | struct i40e_mac_filter *f; |
| 1764 | struct hlist_node *h; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1765 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1766 | hlist_for_each_entry_safe(f, h, from, hlist) { |
| 1767 | u64 key = i40e_addr_to_hkey(f->macaddr); |
| 1768 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1769 | /* Move the element back into MAC filter list*/ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1770 | hlist_del(&f->hlist); |
| 1771 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | /** |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1776 | * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries |
| 1777 | * @vsi: Pointer to vsi struct |
| 1778 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1779 | * those entries needs to be undone. |
| 1780 | * |
| 1781 | * MAC filter entries from this list were slated for addition. |
| 1782 | **/ |
| 1783 | static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi, |
| 1784 | struct hlist_head *from) |
| 1785 | { |
| 1786 | struct i40e_new_mac_filter *new; |
| 1787 | struct hlist_node *h; |
| 1788 | |
| 1789 | hlist_for_each_entry_safe(new, h, from, hlist) { |
| 1790 | /* We can simply free the wrapper structure */ |
| 1791 | hlist_del(&new->hlist); |
| 1792 | kfree(new); |
| 1793 | } |
| 1794 | } |
| 1795 | |
| 1796 | /** |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1797 | * i40e_next_entry - Get the next non-broadcast filter from a list |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1798 | * @next: pointer to filter in list |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1799 | * |
| 1800 | * Returns the next non-broadcast filter in the list. Required so that we |
| 1801 | * ignore broadcast filters within the list, since these are not handled via |
| 1802 | * the normal firmware update path. |
| 1803 | */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1804 | static |
| 1805 | 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] | 1806 | { |
Jacob Keller | 584a887 | 2017-03-07 15:17:52 -0800 | [diff] [blame] | 1807 | hlist_for_each_entry_continue(next, hlist) { |
| 1808 | if (!is_broadcast_ether_addr(next->f->macaddr)) |
| 1809 | return next; |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1810 | } |
| 1811 | |
Jacob Keller | 584a887 | 2017-03-07 15:17:52 -0800 | [diff] [blame] | 1812 | return NULL; |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | /** |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1816 | * i40e_update_filter_state - Update filter state based on return data |
| 1817 | * from firmware |
| 1818 | * @count: Number of filters added |
| 1819 | * @add_list: return data from fw |
| 1820 | * @head: pointer to first filter in current batch |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1821 | * |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1822 | * MAC filter entries from list were slated to be added to device. Returns |
| 1823 | * number of successful filters. Note that 0 does NOT mean success! |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1824 | **/ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1825 | static int |
| 1826 | i40e_update_filter_state(int count, |
| 1827 | struct i40e_aqc_add_macvlan_element_data *add_list, |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1828 | struct i40e_new_mac_filter *add_head) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1829 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1830 | int retval = 0; |
| 1831 | int i; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1832 | |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1833 | for (i = 0; i < count; i++) { |
| 1834 | /* Always check status of each filter. We don't need to check |
| 1835 | * the firmware return status because we pre-set the filter |
| 1836 | * status to I40E_AQC_MM_ERR_NO_RES when sending the filter |
| 1837 | * request to the adminq. Thus, if it no longer matches then |
| 1838 | * we know the filter is active. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1839 | */ |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1840 | if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1841 | add_head->state = I40E_FILTER_FAILED; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1842 | } else { |
| 1843 | add_head->state = I40E_FILTER_ACTIVE; |
| 1844 | retval++; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1845 | } |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1846 | |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1847 | add_head = i40e_next_filter(add_head); |
| 1848 | if (!add_head) |
| 1849 | break; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1850 | } |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1851 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1852 | return retval; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | /** |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1856 | * i40e_aqc_del_filters - Request firmware to delete a set of filters |
| 1857 | * @vsi: ptr to the VSI |
| 1858 | * @vsi_name: name to display in messages |
| 1859 | * @list: the list of filters to send to firmware |
| 1860 | * @num_del: the number of filters to delete |
| 1861 | * @retval: Set to -EIO on failure to delete |
| 1862 | * |
| 1863 | * Send a request to firmware via AdminQ to delete a set of filters. Uses |
| 1864 | * *retval instead of a return value so that success does not force ret_val to |
| 1865 | * be set to 0. This ensures that a sequence of calls to this function |
| 1866 | * preserve the previous value of *retval on successful delete. |
| 1867 | */ |
| 1868 | static |
| 1869 | void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 1870 | struct i40e_aqc_remove_macvlan_element_data *list, |
| 1871 | int num_del, int *retval) |
| 1872 | { |
| 1873 | struct i40e_hw *hw = &vsi->back->hw; |
| 1874 | i40e_status aq_ret; |
| 1875 | int aq_err; |
| 1876 | |
| 1877 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL); |
| 1878 | aq_err = hw->aq.asq_last_status; |
| 1879 | |
| 1880 | /* Explicitly ignore and do not report when firmware returns ENOENT */ |
| 1881 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { |
| 1882 | *retval = -EIO; |
| 1883 | dev_info(&vsi->back->pdev->dev, |
| 1884 | "ignoring delete macvlan error on %s, err %s, aq_err %s\n", |
| 1885 | vsi_name, i40e_stat_str(hw, aq_ret), |
| 1886 | i40e_aq_str(hw, aq_err)); |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | /** |
| 1891 | * i40e_aqc_add_filters - Request firmware to add a set of filters |
| 1892 | * @vsi: ptr to the VSI |
| 1893 | * @vsi_name: name to display in messages |
| 1894 | * @list: the list of filters to send to firmware |
| 1895 | * @add_head: Position in the add hlist |
| 1896 | * @num_add: the number of filters to add |
| 1897 | * @promisc_change: set to true on exit if promiscuous mode was forced on |
| 1898 | * |
| 1899 | * Send a request to firmware via AdminQ to add a chunk of filters. Will set |
| 1900 | * promisc_changed to true if the firmware has run out of space for more |
| 1901 | * filters. |
| 1902 | */ |
| 1903 | static |
| 1904 | void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 1905 | struct i40e_aqc_add_macvlan_element_data *list, |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1906 | struct i40e_new_mac_filter *add_head, |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1907 | int num_add, bool *promisc_changed) |
| 1908 | { |
| 1909 | struct i40e_hw *hw = &vsi->back->hw; |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1910 | int aq_err, fcnt; |
| 1911 | |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1912 | i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1913 | aq_err = hw->aq.asq_last_status; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1914 | fcnt = i40e_update_filter_state(num_add, list, add_head); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1915 | |
| 1916 | if (fcnt != num_add) { |
| 1917 | *promisc_changed = true; |
| 1918 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1919 | dev_warn(&vsi->back->pdev->dev, |
| 1920 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", |
| 1921 | i40e_aq_str(hw, aq_err), |
| 1922 | vsi_name); |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | /** |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1927 | * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags |
| 1928 | * @vsi: pointer to the VSI |
| 1929 | * @f: filter data |
| 1930 | * |
| 1931 | * This function sets or clears the promiscuous broadcast flags for VLAN |
| 1932 | * filters in order to properly receive broadcast frames. Assumes that only |
| 1933 | * broadcast filters are passed. |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1934 | * |
| 1935 | * Returns status indicating success or failure; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1936 | **/ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1937 | static i40e_status |
| 1938 | i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name, |
| 1939 | struct i40e_mac_filter *f) |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1940 | { |
| 1941 | bool enable = f->state == I40E_FILTER_NEW; |
| 1942 | struct i40e_hw *hw = &vsi->back->hw; |
| 1943 | i40e_status aq_ret; |
| 1944 | |
| 1945 | if (f->vlan == I40E_VLAN_ANY) { |
| 1946 | aq_ret = i40e_aq_set_vsi_broadcast(hw, |
| 1947 | vsi->seid, |
| 1948 | enable, |
| 1949 | NULL); |
| 1950 | } else { |
| 1951 | aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw, |
| 1952 | vsi->seid, |
| 1953 | enable, |
| 1954 | f->vlan, |
| 1955 | NULL); |
| 1956 | } |
| 1957 | |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1958 | if (aq_ret) |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1959 | dev_warn(&vsi->back->pdev->dev, |
| 1960 | "Error %s setting broadcast promiscuous mode on %s\n", |
| 1961 | i40e_aq_str(hw, hw->aq.asq_last_status), |
| 1962 | vsi_name); |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1963 | |
| 1964 | return aq_ret; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1968 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1969 | * @vsi: ptr to the VSI |
| 1970 | * |
| 1971 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1972 | * |
| 1973 | * Returns 0 or error value |
| 1974 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 1975 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1976 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1977 | struct hlist_head tmp_add_list, tmp_del_list; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1978 | struct i40e_mac_filter *f; |
| 1979 | struct i40e_new_mac_filter *new, *add_head = NULL; |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1980 | struct i40e_hw *hw = &vsi->back->hw; |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 1981 | unsigned int failed_filters = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1982 | unsigned int vlan_filters = 0; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1983 | bool promisc_changed = false; |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1984 | char vsi_name[16] = "PF"; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1985 | int filter_list_len = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1986 | i40e_status aq_ret = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1987 | u32 changed_flags = 0; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1988 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1989 | struct i40e_pf *pf; |
| 1990 | int num_add = 0; |
| 1991 | int num_del = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1992 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1993 | u16 cmd_flags; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1994 | int list_size; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1995 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1996 | |
| 1997 | /* empty array typed pointers, kcalloc later */ |
| 1998 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1999 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 2000 | |
| 2001 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 2002 | usleep_range(1000, 2000); |
| 2003 | pf = vsi->back; |
| 2004 | |
| 2005 | if (vsi->netdev) { |
| 2006 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 2007 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 2008 | } |
| 2009 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2010 | INIT_HLIST_HEAD(&tmp_add_list); |
| 2011 | INIT_HLIST_HEAD(&tmp_del_list); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2012 | |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2013 | if (vsi->type == I40E_VSI_SRIOV) |
| 2014 | snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id); |
| 2015 | else if (vsi->type != I40E_VSI_MAIN) |
| 2016 | snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid); |
| 2017 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2018 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 2019 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 2020 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2021 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2022 | /* Create a list of filters to delete. */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2023 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2024 | if (f->state == I40E_FILTER_REMOVE) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2025 | /* Move the element into temporary del_list */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2026 | hash_del(&f->hlist); |
| 2027 | hlist_add_head(&f->hlist, &tmp_del_list); |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2028 | |
| 2029 | /* Avoid counting removed filters */ |
| 2030 | continue; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2031 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2032 | if (f->state == I40E_FILTER_NEW) { |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2033 | /* Create a temporary i40e_new_mac_filter */ |
| 2034 | new = kzalloc(sizeof(*new), GFP_ATOMIC); |
| 2035 | if (!new) |
| 2036 | goto err_no_memory_locked; |
| 2037 | |
| 2038 | /* Store pointer to the real filter */ |
| 2039 | new->f = f; |
| 2040 | new->state = f->state; |
| 2041 | |
| 2042 | /* Add it to the hash list */ |
| 2043 | hlist_add_head(&new->hlist, &tmp_add_list); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2044 | } |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2045 | |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2046 | /* Count the number of active (current and new) VLAN |
| 2047 | * filters we have now. Does not count filters which |
| 2048 | * are marked for deletion. |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2049 | */ |
| 2050 | if (f->vlan > 0) |
| 2051 | vlan_filters++; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2054 | retval = i40e_correct_mac_vlan_filters(vsi, |
| 2055 | &tmp_add_list, |
| 2056 | &tmp_del_list, |
| 2057 | vlan_filters); |
| 2058 | if (retval) |
| 2059 | goto err_no_memory_locked; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2060 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2061 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | /* Now process 'del_list' outside the lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2065 | if (!hlist_empty(&tmp_del_list)) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2066 | filter_list_len = hw->aq.asq_buf_size / |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2067 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2068 | list_size = filter_list_len * |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2069 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2070 | del_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2071 | if (!del_list) |
| 2072 | goto err_no_memory; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2073 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2074 | hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2075 | cmd_flags = 0; |
| 2076 | |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2077 | /* handle broadcast filters by updating the broadcast |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 2078 | * promiscuous flag and release filter list. |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2079 | */ |
| 2080 | if (is_broadcast_ether_addr(f->macaddr)) { |
| 2081 | i40e_aqc_broadcast_filter(vsi, vsi_name, f); |
| 2082 | |
| 2083 | hlist_del(&f->hlist); |
| 2084 | kfree(f); |
| 2085 | continue; |
| 2086 | } |
| 2087 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2088 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2089 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2090 | if (f->vlan == I40E_VLAN_ANY) { |
| 2091 | del_list[num_del].vlan_tag = 0; |
Alan Brady | a6cb914 | 2016-09-06 18:05:07 -0700 | [diff] [blame] | 2092 | cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2093 | } else { |
| 2094 | del_list[num_del].vlan_tag = |
| 2095 | cpu_to_le16((u16)(f->vlan)); |
| 2096 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2097 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2098 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 2099 | del_list[num_del].flags = cmd_flags; |
| 2100 | num_del++; |
| 2101 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2102 | /* flush a full buffer */ |
| 2103 | if (num_del == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2104 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2105 | num_del, &retval); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2106 | memset(del_list, 0, list_size); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2107 | num_del = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2108 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2109 | /* Release memory for MAC filter entries which were |
| 2110 | * synced up with HW. |
| 2111 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2112 | hlist_del(&f->hlist); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2113 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2114 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2115 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2116 | if (num_del) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2117 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2118 | num_del, &retval); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | kfree(del_list); |
| 2122 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2123 | } |
| 2124 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2125 | if (!hlist_empty(&tmp_add_list)) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2126 | /* Do all the adds now. */ |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2127 | filter_list_len = hw->aq.asq_buf_size / |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2128 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2129 | list_size = filter_list_len * |
| 2130 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
| 2131 | add_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2132 | if (!add_list) |
| 2133 | goto err_no_memory; |
| 2134 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2135 | num_add = 0; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2136 | hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2137 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2138 | &vsi->state)) { |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2139 | new->state = I40E_FILTER_FAILED; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2140 | continue; |
| 2141 | } |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2142 | |
| 2143 | /* handle broadcast filters by updating the broadcast |
| 2144 | * promiscuous flag instead of adding a MAC filter. |
| 2145 | */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2146 | if (is_broadcast_ether_addr(new->f->macaddr)) { |
| 2147 | if (i40e_aqc_broadcast_filter(vsi, vsi_name, |
| 2148 | new->f)) |
| 2149 | new->state = I40E_FILTER_FAILED; |
| 2150 | else |
| 2151 | new->state = I40E_FILTER_ACTIVE; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2152 | continue; |
| 2153 | } |
| 2154 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2155 | /* add to add array */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2156 | if (num_add == 0) |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2157 | add_head = new; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2158 | cmd_flags = 0; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2159 | ether_addr_copy(add_list[num_add].mac_addr, |
| 2160 | new->f->macaddr); |
| 2161 | if (new->f->vlan == I40E_VLAN_ANY) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2162 | add_list[num_add].vlan_tag = 0; |
| 2163 | cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; |
| 2164 | } else { |
| 2165 | add_list[num_add].vlan_tag = |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2166 | cpu_to_le16((u16)(new->f->vlan)); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2167 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2168 | add_list[num_add].queue_number = 0; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 2169 | /* set invalid match method for later detection */ |
Keller, Jacob E | 0266ac4 | 2016-12-09 13:39:21 -0800 | [diff] [blame] | 2170 | add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2171 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2172 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2173 | num_add++; |
| 2174 | |
| 2175 | /* flush a full buffer */ |
| 2176 | if (num_add == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2177 | i40e_aqc_add_filters(vsi, vsi_name, add_list, |
| 2178 | add_head, num_add, |
| 2179 | &promisc_changed); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2180 | memset(add_list, 0, list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2181 | num_add = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2182 | } |
| 2183 | } |
| 2184 | if (num_add) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2185 | i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head, |
| 2186 | num_add, &promisc_changed); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2187 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2188 | /* Now move all of the filters from the temp add list back to |
| 2189 | * the VSI's list. |
| 2190 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2191 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2192 | hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) { |
| 2193 | /* Only update the state if we're still NEW */ |
| 2194 | if (new->f->state == I40E_FILTER_NEW) |
| 2195 | new->f->state = new->state; |
| 2196 | hlist_del(&new->hlist); |
| 2197 | kfree(new); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2198 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2199 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2200 | kfree(add_list); |
| 2201 | add_list = NULL; |
| 2202 | } |
| 2203 | |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2204 | /* Determine the number of active and failed filters. */ |
| 2205 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2206 | vsi->active_filters = 0; |
| 2207 | hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) { |
| 2208 | if (f->state == I40E_FILTER_ACTIVE) |
| 2209 | vsi->active_filters++; |
| 2210 | else if (f->state == I40E_FILTER_FAILED) |
| 2211 | failed_filters++; |
| 2212 | } |
| 2213 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 2214 | |
| 2215 | /* If promiscuous mode has changed, we need to calculate a new |
| 2216 | * threshold for when we are safe to exit |
| 2217 | */ |
| 2218 | if (promisc_changed) |
| 2219 | vsi->promisc_threshold = (vsi->active_filters * 3) / 4; |
| 2220 | |
| 2221 | /* Check if we are able to exit overflow promiscuous mode. We can |
| 2222 | * safely exit if we didn't just enter, we no longer have any failed |
| 2223 | * filters, and we have reduced filters below the threshold value. |
| 2224 | */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2225 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) && |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2226 | !promisc_changed && !failed_filters && |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2227 | (vsi->active_filters < vsi->promisc_threshold)) { |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2228 | dev_info(&pf->pdev->dev, |
| 2229 | "filter logjam cleared on %s, leaving overflow promiscuous mode\n", |
| 2230 | vsi_name); |
| 2231 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2232 | promisc_changed = true; |
| 2233 | vsi->promisc_threshold = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2234 | } |
| 2235 | |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2236 | /* if the VF is not trusted do not do promisc */ |
| 2237 | if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) { |
| 2238 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2239 | goto out; |
| 2240 | } |
| 2241 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2242 | /* check for changes in promiscuous modes */ |
| 2243 | if (changed_flags & IFF_ALLMULTI) { |
| 2244 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2245 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2246 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2247 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2248 | vsi->seid, |
| 2249 | cur_multipromisc, |
| 2250 | NULL); |
| 2251 | if (aq_ret) { |
| 2252 | retval = i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2253 | hw->aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2254 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2255 | "set multi promisc failed on %s, err %s aq_err %s\n", |
| 2256 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2257 | i40e_stat_str(hw, aq_ret), |
| 2258 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2259 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2260 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2261 | if ((changed_flags & IFF_PROMISC) || |
| 2262 | (promisc_changed && |
| 2263 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2264 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2265 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2266 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 2267 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2268 | &vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2269 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2270 | (pf->lan_veb != I40E_NO_VEB) && |
| 2271 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2272 | /* set defport ON for Main VSI instead of true promisc |
| 2273 | * this way we will get all unicast/multicast and VLAN |
| 2274 | * promisc behavior but will not get VF or VMDq traffic |
| 2275 | * replicated on the Main VSI. |
| 2276 | */ |
| 2277 | if (pf->cur_promisc != cur_promisc) { |
| 2278 | pf->cur_promisc = cur_promisc; |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2279 | if (cur_promisc) |
| 2280 | aq_ret = |
| 2281 | i40e_aq_set_default_vsi(hw, |
| 2282 | vsi->seid, |
| 2283 | NULL); |
| 2284 | else |
| 2285 | aq_ret = |
| 2286 | i40e_aq_clear_default_vsi(hw, |
| 2287 | vsi->seid, |
| 2288 | NULL); |
| 2289 | if (aq_ret) { |
| 2290 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2291 | hw->aq.asq_last_status); |
| 2292 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2293 | "Set default VSI failed on %s, err %s, aq_err %s\n", |
| 2294 | vsi_name, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2295 | i40e_stat_str(hw, aq_ret), |
| 2296 | i40e_aq_str(hw, |
| 2297 | hw->aq.asq_last_status)); |
| 2298 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2299 | } |
| 2300 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2301 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2302 | hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2303 | vsi->seid, |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 2304 | cur_promisc, NULL, |
| 2305 | true); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2306 | if (aq_ret) { |
| 2307 | retval = |
| 2308 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2309 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2310 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2311 | "set unicast promisc failed on %s, err %s, aq_err %s\n", |
| 2312 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2313 | i40e_stat_str(hw, aq_ret), |
| 2314 | i40e_aq_str(hw, |
| 2315 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2316 | } |
| 2317 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2318 | hw, |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2319 | vsi->seid, |
| 2320 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2321 | if (aq_ret) { |
| 2322 | retval = |
| 2323 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2324 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2325 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2326 | "set multicast promisc failed on %s, err %s, aq_err %s\n", |
| 2327 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2328 | i40e_stat_str(hw, aq_ret), |
| 2329 | i40e_aq_str(hw, |
| 2330 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2331 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2332 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2333 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2334 | vsi->seid, |
| 2335 | cur_promisc, NULL); |
| 2336 | if (aq_ret) { |
| 2337 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2338 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2339 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2340 | "set brdcast promisc failed, err %s, aq_err %s\n", |
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 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2345 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2346 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2347 | /* if something went wrong then set the changed flag so we try again */ |
| 2348 | if (retval) |
| 2349 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2350 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2351 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2352 | return retval; |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2353 | |
| 2354 | err_no_memory: |
| 2355 | /* Restore elements on the temporary add and delete lists */ |
| 2356 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2357 | err_no_memory_locked: |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2358 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 2359 | i40e_undo_add_filter_entries(vsi, &tmp_add_list); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2360 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 2361 | |
| 2362 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2363 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
| 2364 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | /** |
| 2368 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2369 | * @pf: board private structure |
| 2370 | **/ |
| 2371 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2372 | { |
| 2373 | int v; |
| 2374 | |
| 2375 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2376 | return; |
| 2377 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2378 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2379 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2380 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2381 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2382 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2383 | |
| 2384 | if (ret) { |
| 2385 | /* come back and try again later */ |
| 2386 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2387 | break; |
| 2388 | } |
| 2389 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | /** |
| 2394 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2395 | * @netdev: network interface device structure |
| 2396 | * @new_mtu: new value for maximum frame size |
| 2397 | * |
| 2398 | * Returns 0 on success, negative on failure |
| 2399 | **/ |
| 2400 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2401 | { |
| 2402 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2403 | struct i40e_vsi *vsi = np->vsi; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 2404 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2405 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2406 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2407 | netdev->mtu, new_mtu); |
| 2408 | netdev->mtu = new_mtu; |
| 2409 | if (netif_running(netdev)) |
| 2410 | i40e_vsi_reinit_locked(vsi); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 2411 | pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED | |
| 2412 | I40E_FLAG_CLIENT_L2_CHANGE); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2413 | return 0; |
| 2414 | } |
| 2415 | |
| 2416 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2417 | * i40e_ioctl - Access the hwtstamp interface |
| 2418 | * @netdev: network interface device structure |
| 2419 | * @ifr: interface request data |
| 2420 | * @cmd: ioctl command |
| 2421 | **/ |
| 2422 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2423 | { |
| 2424 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2425 | struct i40e_pf *pf = np->vsi->back; |
| 2426 | |
| 2427 | switch (cmd) { |
| 2428 | case SIOCGHWTSTAMP: |
| 2429 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2430 | case SIOCSHWTSTAMP: |
| 2431 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2432 | default: |
| 2433 | return -EOPNOTSUPP; |
| 2434 | } |
| 2435 | } |
| 2436 | |
| 2437 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2438 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2439 | * @vsi: the vsi being adjusted |
| 2440 | **/ |
| 2441 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2442 | { |
| 2443 | struct i40e_vsi_context ctxt; |
| 2444 | i40e_status ret; |
| 2445 | |
| 2446 | if ((vsi->info.valid_sections & |
| 2447 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2448 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2449 | return; /* already enabled */ |
| 2450 | |
| 2451 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2452 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2453 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2454 | |
| 2455 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2456 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2457 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2458 | if (ret) { |
| 2459 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2460 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2461 | i40e_stat_str(&vsi->back->hw, ret), |
| 2462 | i40e_aq_str(&vsi->back->hw, |
| 2463 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2464 | } |
| 2465 | } |
| 2466 | |
| 2467 | /** |
| 2468 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2469 | * @vsi: the vsi being adjusted |
| 2470 | **/ |
| 2471 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2472 | { |
| 2473 | struct i40e_vsi_context ctxt; |
| 2474 | i40e_status ret; |
| 2475 | |
| 2476 | if ((vsi->info.valid_sections & |
| 2477 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2478 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2479 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2480 | return; /* already disabled */ |
| 2481 | |
| 2482 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2483 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2484 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2485 | |
| 2486 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2487 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2488 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2489 | if (ret) { |
| 2490 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2491 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2492 | i40e_stat_str(&vsi->back->hw, ret), |
| 2493 | i40e_aq_str(&vsi->back->hw, |
| 2494 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | /** |
| 2499 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2500 | * @netdev: network interface to be adjusted |
| 2501 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2502 | **/ |
| 2503 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2504 | { |
| 2505 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2506 | struct i40e_vsi *vsi = np->vsi; |
| 2507 | |
| 2508 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2509 | i40e_vlan_stripping_enable(vsi); |
| 2510 | else |
| 2511 | i40e_vlan_stripping_disable(vsi); |
| 2512 | } |
| 2513 | |
| 2514 | /** |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2515 | * 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] | 2516 | * @vsi: the vsi being configured |
| 2517 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2518 | * |
| 2519 | * This is a helper function for adding a new MAC/VLAN filter with the |
| 2520 | * specified VLAN for each existing MAC address already in the hash table. |
| 2521 | * This function does *not* perform any accounting to update filters based on |
| 2522 | * VLAN mode. |
| 2523 | * |
| 2524 | * NOTE: this function expects to be called while under the |
| 2525 | * mac_filter_hash_lock |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2526 | **/ |
Jacob Keller | 9af52f6 | 2016-11-11 12:39:30 -0800 | [diff] [blame] | 2527 | int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2528 | { |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2529 | struct i40e_mac_filter *f, *add_f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2530 | struct hlist_node *h; |
| 2531 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2532 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2533 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 2534 | if (f->state == I40E_FILTER_REMOVE) |
| 2535 | continue; |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2536 | add_f = i40e_add_filter(vsi, f->macaddr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2537 | if (!add_f) { |
| 2538 | dev_info(&vsi->back->pdev->dev, |
| 2539 | "Could not add vlan filter %d for %pM\n", |
| 2540 | vid, f->macaddr); |
| 2541 | return -ENOMEM; |
| 2542 | } |
| 2543 | } |
| 2544 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2545 | return 0; |
| 2546 | } |
| 2547 | |
| 2548 | /** |
| 2549 | * i40e_vsi_add_vlan - Add VSI membership for given VLAN |
| 2550 | * @vsi: the VSI being configured |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2551 | * @vid: VLAN id to be added |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2552 | **/ |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2553 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2554 | { |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2555 | int err; |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2556 | |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2557 | if (!vid || vsi->info.pvid) |
| 2558 | return -EINVAL; |
| 2559 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2560 | /* Locked once because all functions invoked below iterates list*/ |
| 2561 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2562 | err = i40e_add_vlan_all_mac(vsi, vid); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2563 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2564 | if (err) |
| 2565 | return err; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2566 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2567 | /* schedule our worker thread which will take care of |
| 2568 | * applying the new filter changes |
| 2569 | */ |
| 2570 | i40e_service_event_schedule(vsi->back); |
| 2571 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | /** |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2575 | * 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] | 2576 | * @vsi: the vsi being configured |
| 2577 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2578 | * |
| 2579 | * This function should be used to remove all VLAN filters which match the |
| 2580 | * given VID. It does not schedule the service event and does not take the |
| 2581 | * mac_filter_hash_lock so it may be combined with other operations under |
| 2582 | * a single invocation of the mac_filter_hash_lock. |
| 2583 | * |
| 2584 | * NOTE: this function expects to be called while under the |
| 2585 | * mac_filter_hash_lock |
| 2586 | */ |
Jacob Keller | 9af52f6 | 2016-11-11 12:39:30 -0800 | [diff] [blame] | 2587 | void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2588 | { |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2589 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2590 | struct hlist_node *h; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2591 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2592 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2593 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 2594 | if (f->vlan == vid) |
| 2595 | __i40e_del_filter(vsi, f); |
| 2596 | } |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2597 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2598 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2599 | /** |
| 2600 | * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN |
| 2601 | * @vsi: the VSI being configured |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2602 | * @vid: VLAN id to be removed |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2603 | **/ |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2604 | void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2605 | { |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2606 | if (!vid || vsi->info.pvid) |
| 2607 | return; |
| 2608 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2609 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2610 | i40e_rm_vlan_all_mac(vsi, vid); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2611 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2612 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2613 | /* schedule our worker thread which will take care of |
| 2614 | * applying the new filter changes |
| 2615 | */ |
| 2616 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | /** |
| 2620 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2621 | * @netdev: network interface to be adjusted |
| 2622 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2623 | * |
| 2624 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2625 | **/ |
| 2626 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2627 | __always_unused __be16 proto, u16 vid) |
| 2628 | { |
| 2629 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2630 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2631 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2632 | |
Jacob Keller | 6a112785 | 2016-10-25 16:08:49 -0700 | [diff] [blame] | 2633 | if (vid >= VLAN_N_VID) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2634 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2635 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2636 | /* If the network stack called us with vid = 0 then |
| 2637 | * it is asking to receive priority tagged packets with |
| 2638 | * vlan id 0. Our HW receives them by default when configured |
| 2639 | * to receive untagged packets so there is no need to add an |
| 2640 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2641 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2642 | if (vid) |
| 2643 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2644 | |
Jacob Keller | 6a112785 | 2016-10-25 16:08:49 -0700 | [diff] [blame] | 2645 | if (!ret) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2646 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2647 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2648 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2649 | } |
| 2650 | |
| 2651 | /** |
| 2652 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2653 | * @netdev: network interface to be adjusted |
| 2654 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2655 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2656 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2657 | **/ |
| 2658 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2659 | __always_unused __be16 proto, u16 vid) |
| 2660 | { |
| 2661 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2662 | struct i40e_vsi *vsi = np->vsi; |
| 2663 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2664 | /* return code is ignored as there is nothing a user |
| 2665 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2666 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2667 | */ |
| 2668 | i40e_vsi_kill_vlan(vsi, vid); |
| 2669 | |
| 2670 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2671 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2672 | return 0; |
| 2673 | } |
| 2674 | |
| 2675 | /** |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 2676 | * i40e_macaddr_init - explicitly write the mac address filters |
| 2677 | * |
| 2678 | * @vsi: pointer to the vsi |
| 2679 | * @macaddr: the MAC address |
| 2680 | * |
| 2681 | * This is needed when the macaddr has been obtained by other |
| 2682 | * means than the default, e.g., from Open Firmware or IDPROM. |
| 2683 | * Returns 0 on success, negative on failure |
| 2684 | **/ |
| 2685 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) |
| 2686 | { |
| 2687 | int ret; |
| 2688 | struct i40e_aqc_add_macvlan_element_data element; |
| 2689 | |
| 2690 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 2691 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 2692 | macaddr, NULL); |
| 2693 | if (ret) { |
| 2694 | dev_info(&vsi->back->pdev->dev, |
| 2695 | "Addr change for VSI failed: %d\n", ret); |
| 2696 | return -EADDRNOTAVAIL; |
| 2697 | } |
| 2698 | |
| 2699 | memset(&element, 0, sizeof(element)); |
| 2700 | ether_addr_copy(element.mac_addr, macaddr); |
| 2701 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 2702 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); |
| 2703 | if (ret) { |
| 2704 | dev_info(&vsi->back->pdev->dev, |
| 2705 | "add filter failed err %s aq_err %s\n", |
| 2706 | i40e_stat_str(&vsi->back->hw, ret), |
| 2707 | i40e_aq_str(&vsi->back->hw, |
| 2708 | vsi->back->hw.aq.asq_last_status)); |
| 2709 | } |
| 2710 | return ret; |
| 2711 | } |
| 2712 | |
| 2713 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2714 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2715 | * @vsi: the vsi being brought back up |
| 2716 | **/ |
| 2717 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2718 | { |
| 2719 | u16 vid; |
| 2720 | |
| 2721 | if (!vsi->netdev) |
| 2722 | return; |
| 2723 | |
| 2724 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2725 | |
| 2726 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2727 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2728 | vid); |
| 2729 | } |
| 2730 | |
| 2731 | /** |
| 2732 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2733 | * @vsi: the vsi being adjusted |
| 2734 | * @vid: the vlan id to set as a PVID |
| 2735 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2736 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2737 | { |
| 2738 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2739 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2740 | |
| 2741 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2742 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2743 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2744 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2745 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2746 | |
| 2747 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2748 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2749 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2750 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2751 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2752 | "add pvid failed, err %s aq_err %s\n", |
| 2753 | i40e_stat_str(&vsi->back->hw, ret), |
| 2754 | i40e_aq_str(&vsi->back->hw, |
| 2755 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2756 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2757 | } |
| 2758 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2759 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | /** |
| 2763 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2764 | * @vsi: the vsi being adjusted |
| 2765 | * |
| 2766 | * Just use the vlan_rx_register() service to put it back to normal |
| 2767 | **/ |
| 2768 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2769 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2770 | i40e_vlan_stripping_disable(vsi); |
| 2771 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2772 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | /** |
| 2776 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2777 | * @vsi: ptr to the VSI |
| 2778 | * |
| 2779 | * If this function returns with an error, then it's possible one or |
| 2780 | * more of the rings is populated (while the rest are not). It is the |
| 2781 | * callers duty to clean those orphaned rings. |
| 2782 | * |
| 2783 | * Return 0 on success, negative on failure |
| 2784 | **/ |
| 2785 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2786 | { |
| 2787 | int i, err = 0; |
| 2788 | |
| 2789 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2790 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2791 | |
| 2792 | return err; |
| 2793 | } |
| 2794 | |
| 2795 | /** |
| 2796 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2797 | * @vsi: ptr to the VSI |
| 2798 | * |
| 2799 | * Free VSI's transmit software resources |
| 2800 | **/ |
| 2801 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2802 | { |
| 2803 | int i; |
| 2804 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2805 | if (!vsi->tx_rings) |
| 2806 | return; |
| 2807 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2808 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2809 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2810 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | /** |
| 2814 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2815 | * @vsi: ptr to the VSI |
| 2816 | * |
| 2817 | * If this function returns with an error, then it's possible one or |
| 2818 | * more of the rings is populated (while the rest are not). It is the |
| 2819 | * callers duty to clean those orphaned rings. |
| 2820 | * |
| 2821 | * Return 0 on success, negative on failure |
| 2822 | **/ |
| 2823 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2824 | { |
| 2825 | int i, err = 0; |
| 2826 | |
| 2827 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2828 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2829 | return err; |
| 2830 | } |
| 2831 | |
| 2832 | /** |
| 2833 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2834 | * @vsi: ptr to the VSI |
| 2835 | * |
| 2836 | * Free all receive software resources |
| 2837 | **/ |
| 2838 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2839 | { |
| 2840 | int i; |
| 2841 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2842 | if (!vsi->rx_rings) |
| 2843 | return; |
| 2844 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2845 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2846 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2847 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2851 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2852 | * @ring: The Tx ring to configure |
| 2853 | * |
| 2854 | * This enables/disables XPS for a given Tx descriptor ring |
| 2855 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2856 | **/ |
| 2857 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2858 | { |
| 2859 | struct i40e_vsi *vsi = ring->vsi; |
| 2860 | cpumask_var_t mask; |
| 2861 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2862 | if (!ring->q_vector || !ring->netdev) |
| 2863 | return; |
| 2864 | |
| 2865 | /* Single TC mode enable XPS */ |
| 2866 | if (vsi->tc_config.numtc <= 1) { |
| 2867 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2868 | netif_set_xps_queue(ring->netdev, |
| 2869 | &ring->q_vector->affinity_mask, |
| 2870 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2871 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2872 | /* Disable XPS to allow selection based on TC */ |
| 2873 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2874 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2875 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2876 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2877 | |
| 2878 | /* schedule our worker thread which will take care of |
| 2879 | * applying the new filter changes |
| 2880 | */ |
| 2881 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2882 | } |
| 2883 | |
| 2884 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2885 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2886 | * @ring: The Tx ring to configure |
| 2887 | * |
| 2888 | * Configure the Tx descriptor ring in the HMC context. |
| 2889 | **/ |
| 2890 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2891 | { |
| 2892 | struct i40e_vsi *vsi = ring->vsi; |
| 2893 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2894 | struct i40e_hw *hw = &vsi->back->hw; |
| 2895 | struct i40e_hmc_obj_txq tx_ctx; |
| 2896 | i40e_status err = 0; |
| 2897 | u32 qtx_ctl = 0; |
| 2898 | |
| 2899 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2900 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2901 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2902 | ring->atr_count = 0; |
| 2903 | } else { |
| 2904 | ring->atr_sample_rate = 0; |
| 2905 | } |
| 2906 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2907 | /* configure XPS */ |
| 2908 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2909 | |
| 2910 | /* clear the context structure first */ |
| 2911 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2912 | |
| 2913 | tx_ctx.new_context = 1; |
| 2914 | tx_ctx.base = (ring->dma / 128); |
| 2915 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2916 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2917 | I40E_FLAG_FD_ATR_ENABLED)); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2918 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2919 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2920 | if (vsi->type != I40E_VSI_FDIR) |
| 2921 | tx_ctx.head_wb_ena = 1; |
| 2922 | tx_ctx.head_wb_addr = ring->dma + |
| 2923 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2924 | |
| 2925 | /* As part of VSI creation/update, FW allocates certain |
| 2926 | * Tx arbitration queue sets for each TC enabled for |
| 2927 | * the VSI. The FW returns the handles to these queue |
| 2928 | * sets as part of the response buffer to Add VSI, |
| 2929 | * Update VSI, etc. AQ commands. It is expected that |
| 2930 | * these queue set handles be associated with the Tx |
| 2931 | * queues by the driver as part of the TX queue context |
| 2932 | * initialization. This has to be done regardless of |
| 2933 | * DCB as by default everything is mapped to TC0. |
| 2934 | */ |
| 2935 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2936 | tx_ctx.rdylist_act = 0; |
| 2937 | |
| 2938 | /* clear the context in the HMC */ |
| 2939 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2940 | if (err) { |
| 2941 | dev_info(&vsi->back->pdev->dev, |
| 2942 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2943 | ring->queue_index, pf_q, err); |
| 2944 | return -ENOMEM; |
| 2945 | } |
| 2946 | |
| 2947 | /* set the context in the HMC */ |
| 2948 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2949 | if (err) { |
| 2950 | dev_info(&vsi->back->pdev->dev, |
| 2951 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2952 | ring->queue_index, pf_q, err); |
| 2953 | return -ENOMEM; |
| 2954 | } |
| 2955 | |
| 2956 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2957 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2958 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2959 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2960 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2961 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2962 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2963 | } |
| 2964 | |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2965 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2966 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2967 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2968 | i40e_flush(hw); |
| 2969 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2970 | /* cache tail off for easier writes later */ |
| 2971 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2972 | |
| 2973 | return 0; |
| 2974 | } |
| 2975 | |
| 2976 | /** |
| 2977 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2978 | * @ring: The Rx ring to configure |
| 2979 | * |
| 2980 | * Configure the Rx descriptor ring in the HMC context. |
| 2981 | **/ |
| 2982 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2983 | { |
| 2984 | struct i40e_vsi *vsi = ring->vsi; |
| 2985 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2986 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2987 | struct i40e_hw *hw = &vsi->back->hw; |
| 2988 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2989 | i40e_status err = 0; |
| 2990 | |
| 2991 | ring->state = 0; |
| 2992 | |
| 2993 | /* clear the context structure first */ |
| 2994 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2995 | |
| 2996 | ring->rx_buf_len = vsi->rx_buf_len; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2997 | |
| 2998 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2999 | |
| 3000 | rx_ctx.base = (ring->dma / 128); |
| 3001 | rx_ctx.qlen = ring->count; |
| 3002 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 3003 | /* use 32 byte descriptors */ |
| 3004 | rx_ctx.dsize = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3005 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 3006 | /* descriptor type is always zero |
| 3007 | * rx_ctx.dtype = 0; |
| 3008 | */ |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 3009 | rx_ctx.hsplit_0 = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3010 | |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 3011 | 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] | 3012 | if (hw->revision_id == 0) |
| 3013 | rx_ctx.lrxqthresh = 0; |
| 3014 | else |
| 3015 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3016 | rx_ctx.crcstrip = 1; |
| 3017 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 3018 | /* this controls whether VLAN is stripped from inner headers */ |
| 3019 | rx_ctx.showiv = 0; |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 3020 | /* set the prefena field to 1 because the manual says to */ |
| 3021 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3022 | |
| 3023 | /* clear the context in the HMC */ |
| 3024 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 3025 | if (err) { |
| 3026 | dev_info(&vsi->back->pdev->dev, |
| 3027 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 3028 | ring->queue_index, pf_q, err); |
| 3029 | return -ENOMEM; |
| 3030 | } |
| 3031 | |
| 3032 | /* set the context in the HMC */ |
| 3033 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 3034 | if (err) { |
| 3035 | dev_info(&vsi->back->pdev->dev, |
| 3036 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 3037 | ring->queue_index, pf_q, err); |
| 3038 | return -ENOMEM; |
| 3039 | } |
| 3040 | |
| 3041 | /* cache tail for quicker writes, and clear the reg before use */ |
| 3042 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 3043 | writel(0, ring->tail); |
| 3044 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 3045 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3046 | |
| 3047 | return 0; |
| 3048 | } |
| 3049 | |
| 3050 | /** |
| 3051 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 3052 | * @vsi: VSI structure describing this set of rings and resources |
| 3053 | * |
| 3054 | * Configure the Tx VSI for operation. |
| 3055 | **/ |
| 3056 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 3057 | { |
| 3058 | int err = 0; |
| 3059 | u16 i; |
| 3060 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3061 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 3062 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3063 | |
| 3064 | return err; |
| 3065 | } |
| 3066 | |
| 3067 | /** |
| 3068 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 3069 | * @vsi: the VSI being configured |
| 3070 | * |
| 3071 | * Configure the Rx VSI for operation. |
| 3072 | **/ |
| 3073 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 3074 | { |
| 3075 | int err = 0; |
| 3076 | u16 i; |
| 3077 | |
| 3078 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 3079 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 3080 | + ETH_FCS_LEN + VLAN_HLEN; |
| 3081 | else |
| 3082 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 3083 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 3084 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3085 | |
| 3086 | /* round up for the chip's needs */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3087 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3088 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3089 | |
| 3090 | /* set up individual rings */ |
| 3091 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3092 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3093 | |
| 3094 | return err; |
| 3095 | } |
| 3096 | |
| 3097 | /** |
| 3098 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3099 | * @vsi: ptr to the VSI |
| 3100 | **/ |
| 3101 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3102 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3103 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3104 | u16 qoffset, qcount; |
| 3105 | int i, n; |
| 3106 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3107 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3108 | /* Reset the TC information */ |
| 3109 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3110 | rx_ring = vsi->rx_rings[i]; |
| 3111 | tx_ring = vsi->tx_rings[i]; |
| 3112 | rx_ring->dcb_tc = 0; |
| 3113 | tx_ring->dcb_tc = 0; |
| 3114 | } |
| 3115 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3116 | |
| 3117 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3118 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3119 | continue; |
| 3120 | |
| 3121 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3122 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3123 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3124 | rx_ring = vsi->rx_rings[i]; |
| 3125 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3126 | rx_ring->dcb_tc = n; |
| 3127 | tx_ring->dcb_tc = n; |
| 3128 | } |
| 3129 | } |
| 3130 | } |
| 3131 | |
| 3132 | /** |
| 3133 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3134 | * @vsi: ptr to the VSI |
| 3135 | **/ |
| 3136 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3137 | { |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 3138 | struct i40e_pf *pf = vsi->back; |
| 3139 | int err; |
| 3140 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3141 | if (vsi->netdev) |
| 3142 | i40e_set_rx_mode(vsi->netdev); |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 3143 | |
| 3144 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 3145 | err = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 3146 | if (err) { |
| 3147 | dev_warn(&pf->pdev->dev, |
| 3148 | "could not set up macaddr; err %d\n", err); |
| 3149 | } |
| 3150 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3154 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3155 | * @vsi: Pointer to the targeted VSI |
| 3156 | * |
| 3157 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3158 | * filters were saved. |
| 3159 | **/ |
| 3160 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3161 | { |
| 3162 | struct i40e_fdir_filter *filter; |
| 3163 | struct i40e_pf *pf = vsi->back; |
| 3164 | struct hlist_node *node; |
| 3165 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3166 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3167 | return; |
| 3168 | |
Jacob Keller | 6d06942 | 2017-02-06 14:38:44 -0800 | [diff] [blame] | 3169 | /* Reset FDir counters as we're replaying all existing filters */ |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 3170 | pf->fd_tcp4_filter_cnt = 0; |
| 3171 | pf->fd_udp4_filter_cnt = 0; |
Jacob Keller | f223c87 | 2017-02-06 14:38:51 -0800 | [diff] [blame] | 3172 | pf->fd_sctp4_filter_cnt = 0; |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 3173 | pf->fd_ip4_filter_cnt = 0; |
Jacob Keller | 6d06942 | 2017-02-06 14:38:44 -0800 | [diff] [blame] | 3174 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3175 | hlist_for_each_entry_safe(filter, node, |
| 3176 | &pf->fdir_filter_list, fdir_node) { |
| 3177 | i40e_add_del_fdir(vsi, filter, true); |
| 3178 | } |
| 3179 | } |
| 3180 | |
| 3181 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3182 | * i40e_vsi_configure - Set up the VSI for action |
| 3183 | * @vsi: the VSI being configured |
| 3184 | **/ |
| 3185 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3186 | { |
| 3187 | int err; |
| 3188 | |
| 3189 | i40e_set_vsi_rx_mode(vsi); |
| 3190 | i40e_restore_vlan(vsi); |
| 3191 | i40e_vsi_config_dcb_rings(vsi); |
| 3192 | err = i40e_vsi_configure_tx(vsi); |
| 3193 | if (!err) |
| 3194 | err = i40e_vsi_configure_rx(vsi); |
| 3195 | |
| 3196 | return err; |
| 3197 | } |
| 3198 | |
| 3199 | /** |
| 3200 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3201 | * @vsi: the VSI being configured |
| 3202 | **/ |
| 3203 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3204 | { |
| 3205 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3206 | struct i40e_hw *hw = &pf->hw; |
| 3207 | u16 vector; |
| 3208 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3209 | u32 qp; |
| 3210 | |
| 3211 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3212 | * and PFINT_LNKLSTn registers, e.g.: |
| 3213 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3214 | */ |
| 3215 | qp = vsi->base_queue; |
| 3216 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3217 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3218 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3219 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3220 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3221 | 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] | 3222 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3223 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3224 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3225 | 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] | 3226 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3227 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3228 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3229 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
Alan Brady | 1c0e6a3 | 2016-11-28 16:06:02 -0800 | [diff] [blame] | 3230 | i40e_intrl_usec_to_reg(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3231 | |
| 3232 | /* Linked list for the queuepairs assigned to this vector */ |
| 3233 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3234 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3235 | u32 val; |
| 3236 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3237 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3238 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3239 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3240 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 3241 | (I40E_QUEUE_TYPE_TX |
| 3242 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 3243 | |
| 3244 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3245 | |
| 3246 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3247 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3248 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3249 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 3250 | (I40E_QUEUE_TYPE_RX |
| 3251 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3252 | |
| 3253 | /* Terminate the linked list */ |
| 3254 | if (q == (q_vector->num_ringpairs - 1)) |
| 3255 | val |= (I40E_QUEUE_END_OF_LIST |
| 3256 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3257 | |
| 3258 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3259 | qp++; |
| 3260 | } |
| 3261 | } |
| 3262 | |
| 3263 | i40e_flush(hw); |
| 3264 | } |
| 3265 | |
| 3266 | /** |
| 3267 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3268 | * @hw: ptr to the hardware info |
| 3269 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3270 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3271 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3272 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3273 | u32 val; |
| 3274 | |
| 3275 | /* clear things first */ |
| 3276 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3277 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3278 | |
| 3279 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3280 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3281 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3282 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3283 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3284 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3285 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3286 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3287 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3288 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3289 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3290 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3291 | if (pf->flags & I40E_FLAG_PTP) |
| 3292 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3293 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3294 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3295 | |
| 3296 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3297 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3298 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3299 | |
| 3300 | /* OTHER_ITR_IDX = 0 */ |
| 3301 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3302 | } |
| 3303 | |
| 3304 | /** |
| 3305 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3306 | * @vsi: the VSI being configured |
| 3307 | **/ |
| 3308 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3309 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3310 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3311 | struct i40e_pf *pf = vsi->back; |
| 3312 | struct i40e_hw *hw = &pf->hw; |
| 3313 | u32 val; |
| 3314 | |
| 3315 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3316 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3317 | 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] | 3318 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3319 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3320 | 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] | 3321 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3322 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3323 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3324 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3325 | |
| 3326 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3327 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3328 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3329 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3330 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3331 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3332 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3333 | |
| 3334 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3335 | |
| 3336 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3337 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3338 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3339 | |
| 3340 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3341 | i40e_flush(hw); |
| 3342 | } |
| 3343 | |
| 3344 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3345 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3346 | * @pf: board private structure |
| 3347 | **/ |
| 3348 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3349 | { |
| 3350 | struct i40e_hw *hw = &pf->hw; |
| 3351 | |
| 3352 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3353 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3354 | i40e_flush(hw); |
| 3355 | } |
| 3356 | |
| 3357 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3358 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3359 | * @pf: board private structure |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3360 | * @clearpba: true when all pending interrupt events should be cleared |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3361 | **/ |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3362 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3363 | { |
| 3364 | struct i40e_hw *hw = &pf->hw; |
| 3365 | u32 val; |
| 3366 | |
| 3367 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3368 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3369 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3370 | |
| 3371 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3372 | i40e_flush(hw); |
| 3373 | } |
| 3374 | |
| 3375 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3376 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3377 | * @irq: interrupt number |
| 3378 | * @data: pointer to a q_vector |
| 3379 | **/ |
| 3380 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3381 | { |
| 3382 | struct i40e_q_vector *q_vector = data; |
| 3383 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3384 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3385 | return IRQ_HANDLED; |
| 3386 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3387 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3388 | |
| 3389 | return IRQ_HANDLED; |
| 3390 | } |
| 3391 | |
| 3392 | /** |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3393 | * i40e_irq_affinity_notify - Callback for affinity changes |
| 3394 | * @notify: context as to what irq was changed |
| 3395 | * @mask: the new affinity mask |
| 3396 | * |
| 3397 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3398 | * so that we may register to receive changes to the irq affinity masks. |
| 3399 | **/ |
| 3400 | static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify, |
| 3401 | const cpumask_t *mask) |
| 3402 | { |
| 3403 | struct i40e_q_vector *q_vector = |
| 3404 | container_of(notify, struct i40e_q_vector, affinity_notify); |
| 3405 | |
| 3406 | q_vector->affinity_mask = *mask; |
| 3407 | } |
| 3408 | |
| 3409 | /** |
| 3410 | * i40e_irq_affinity_release - Callback for affinity notifier release |
| 3411 | * @ref: internal core kernel usage |
| 3412 | * |
| 3413 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3414 | * to inform the current notification subscriber that they will no longer |
| 3415 | * receive notifications. |
| 3416 | **/ |
| 3417 | static void i40e_irq_affinity_release(struct kref *ref) {} |
| 3418 | |
| 3419 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3420 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3421 | * @vsi: the VSI being configured |
| 3422 | * @basename: name for the vector |
| 3423 | * |
| 3424 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3425 | **/ |
| 3426 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3427 | { |
| 3428 | int q_vectors = vsi->num_q_vectors; |
| 3429 | struct i40e_pf *pf = vsi->back; |
| 3430 | int base = vsi->base_vector; |
| 3431 | int rx_int_idx = 0; |
| 3432 | int tx_int_idx = 0; |
| 3433 | int vector, err; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3434 | int irq_num; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3435 | |
| 3436 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3437 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3438 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3439 | irq_num = pf->msix_entries[base + vector].vector; |
| 3440 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3441 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3442 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3443 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3444 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3445 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3446 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3447 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3448 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3449 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3450 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3451 | } else { |
| 3452 | /* skip this unused q_vector */ |
| 3453 | continue; |
| 3454 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3455 | err = request_irq(irq_num, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3456 | vsi->irq_handler, |
| 3457 | 0, |
| 3458 | q_vector->name, |
| 3459 | q_vector); |
| 3460 | if (err) { |
| 3461 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3462 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3463 | goto free_queue_irqs; |
| 3464 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3465 | |
| 3466 | /* register for affinity change notifications */ |
| 3467 | q_vector->affinity_notify.notify = i40e_irq_affinity_notify; |
| 3468 | q_vector->affinity_notify.release = i40e_irq_affinity_release; |
| 3469 | irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3470 | /* assign the mask for this irq */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3471 | irq_set_affinity_hint(irq_num, &q_vector->affinity_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3472 | } |
| 3473 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3474 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3475 | return 0; |
| 3476 | |
| 3477 | free_queue_irqs: |
| 3478 | while (vector) { |
| 3479 | vector--; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3480 | irq_num = pf->msix_entries[base + vector].vector; |
| 3481 | irq_set_affinity_notifier(irq_num, NULL); |
| 3482 | irq_set_affinity_hint(irq_num, NULL); |
| 3483 | free_irq(irq_num, &vsi->q_vectors[vector]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3484 | } |
| 3485 | return err; |
| 3486 | } |
| 3487 | |
| 3488 | /** |
| 3489 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3490 | * @vsi: the VSI being un-configured |
| 3491 | **/ |
| 3492 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3493 | { |
| 3494 | struct i40e_pf *pf = vsi->back; |
| 3495 | struct i40e_hw *hw = &pf->hw; |
| 3496 | int base = vsi->base_vector; |
| 3497 | int i; |
| 3498 | |
| 3499 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3500 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3501 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3505 | for (i = vsi->base_vector; |
| 3506 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3507 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3508 | |
| 3509 | i40e_flush(hw); |
| 3510 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3511 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3512 | } else { |
| 3513 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3514 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3515 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3516 | i40e_flush(hw); |
| 3517 | synchronize_irq(pf->pdev->irq); |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | /** |
| 3522 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3523 | * @vsi: the VSI being configured |
| 3524 | **/ |
| 3525 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3526 | { |
| 3527 | struct i40e_pf *pf = vsi->back; |
| 3528 | int i; |
| 3529 | |
| 3530 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3531 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3532 | i40e_irq_dynamic_enable(vsi, i); |
| 3533 | } else { |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3534 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3535 | } |
| 3536 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3537 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3538 | return 0; |
| 3539 | } |
| 3540 | |
| 3541 | /** |
| 3542 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3543 | * @pf: board private structure |
| 3544 | **/ |
| 3545 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3546 | { |
| 3547 | /* Disable ICR 0 */ |
| 3548 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3549 | i40e_flush(&pf->hw); |
| 3550 | } |
| 3551 | |
| 3552 | /** |
| 3553 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3554 | * @irq: interrupt number |
| 3555 | * @data: pointer to a q_vector |
| 3556 | * |
| 3557 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3558 | * with both queue and non-queue interrupts. This is also used in |
| 3559 | * MSIX mode to handle the non-queue interrupts. |
| 3560 | **/ |
| 3561 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3562 | { |
| 3563 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3564 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3565 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3566 | u32 icr0, icr0_remaining; |
| 3567 | u32 val, ena_mask; |
| 3568 | |
| 3569 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3570 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3571 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3572 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3573 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3574 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3575 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3576 | /* if interrupt but no bits showing, must be SWINT */ |
| 3577 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3578 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3579 | pf->sw_int_count++; |
| 3580 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3581 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 3582 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
| 3583 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3584 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
Carolyn Wyborny | 23bb6dc | 2016-11-08 13:05:12 -0800 | [diff] [blame] | 3585 | dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3586 | } |
| 3587 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3588 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3589 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3590 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3591 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3592 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3593 | /* We do not have a way to disarm Queue causes while leaving |
| 3594 | * interrupt enabled for all other causes, ideally |
| 3595 | * interrupt should be disabled while we are in NAPI but |
| 3596 | * this is not a performance path and napi_schedule() |
| 3597 | * can deal with rescheduling. |
| 3598 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3599 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3600 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3601 | } |
| 3602 | |
| 3603 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3604 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3605 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3606 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3607 | } |
| 3608 | |
| 3609 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3610 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3611 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3612 | } |
| 3613 | |
| 3614 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3615 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3616 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3617 | } |
| 3618 | |
| 3619 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3620 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3621 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3622 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3623 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3624 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3625 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3626 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3627 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3628 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3629 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3630 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3631 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3632 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3633 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3634 | } |
| 3635 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3636 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3637 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3638 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3639 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3640 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3641 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3642 | } |
| 3643 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3644 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3645 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3646 | |
| 3647 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3648 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3649 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3650 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3651 | } |
| 3652 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3653 | /* If a critical error is pending we have no choice but to reset the |
| 3654 | * device. |
| 3655 | * Report and mask out any remaining unexpected interrupts. |
| 3656 | */ |
| 3657 | icr0_remaining = icr0 & ena_mask; |
| 3658 | if (icr0_remaining) { |
| 3659 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3660 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3661 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3662 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3663 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3664 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3665 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3666 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3667 | } |
| 3668 | ena_mask &= ~icr0_remaining; |
| 3669 | } |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3670 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3671 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3672 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3673 | /* re-enable interrupt causes */ |
| 3674 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3675 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3676 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3677 | i40e_irq_dynamic_enable_icr0(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3678 | } |
| 3679 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3680 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3681 | } |
| 3682 | |
| 3683 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3684 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3685 | * @tx_ring: tx ring to clean |
| 3686 | * @budget: how many cleans we're allowed |
| 3687 | * |
| 3688 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3689 | **/ |
| 3690 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3691 | { |
| 3692 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3693 | u16 i = tx_ring->next_to_clean; |
| 3694 | struct i40e_tx_buffer *tx_buf; |
| 3695 | struct i40e_tx_desc *tx_desc; |
| 3696 | |
| 3697 | tx_buf = &tx_ring->tx_bi[i]; |
| 3698 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3699 | i -= tx_ring->count; |
| 3700 | |
| 3701 | do { |
| 3702 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3703 | |
| 3704 | /* if next_to_watch is not set then there is no work pending */ |
| 3705 | if (!eop_desc) |
| 3706 | break; |
| 3707 | |
| 3708 | /* prevent any other reads prior to eop_desc */ |
| 3709 | read_barrier_depends(); |
| 3710 | |
| 3711 | /* if the descriptor isn't done, no work yet to do */ |
| 3712 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3713 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3714 | break; |
| 3715 | |
| 3716 | /* clear next_to_watch to prevent false hangs */ |
| 3717 | tx_buf->next_to_watch = NULL; |
| 3718 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3719 | tx_desc->buffer_addr = 0; |
| 3720 | tx_desc->cmd_type_offset_bsz = 0; |
| 3721 | /* move past filter desc */ |
| 3722 | tx_buf++; |
| 3723 | tx_desc++; |
| 3724 | i++; |
| 3725 | if (unlikely(!i)) { |
| 3726 | i -= tx_ring->count; |
| 3727 | tx_buf = tx_ring->tx_bi; |
| 3728 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3729 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3730 | /* unmap skb header data */ |
| 3731 | dma_unmap_single(tx_ring->dev, |
| 3732 | dma_unmap_addr(tx_buf, dma), |
| 3733 | dma_unmap_len(tx_buf, len), |
| 3734 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3735 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3736 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3737 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3738 | tx_buf->raw_buf = NULL; |
| 3739 | tx_buf->tx_flags = 0; |
| 3740 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3741 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3742 | tx_desc->buffer_addr = 0; |
| 3743 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3744 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3745 | /* 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] | 3746 | tx_buf++; |
| 3747 | tx_desc++; |
| 3748 | i++; |
| 3749 | if (unlikely(!i)) { |
| 3750 | i -= tx_ring->count; |
| 3751 | tx_buf = tx_ring->tx_bi; |
| 3752 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3753 | } |
| 3754 | |
| 3755 | /* update budget accounting */ |
| 3756 | budget--; |
| 3757 | } while (likely(budget)); |
| 3758 | |
| 3759 | i += tx_ring->count; |
| 3760 | tx_ring->next_to_clean = i; |
| 3761 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3762 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3763 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3764 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3765 | return budget > 0; |
| 3766 | } |
| 3767 | |
| 3768 | /** |
| 3769 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3770 | * @irq: interrupt number |
| 3771 | * @data: pointer to a q_vector |
| 3772 | **/ |
| 3773 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3774 | { |
| 3775 | struct i40e_q_vector *q_vector = data; |
| 3776 | struct i40e_vsi *vsi; |
| 3777 | |
| 3778 | if (!q_vector->tx.ring) |
| 3779 | return IRQ_HANDLED; |
| 3780 | |
| 3781 | vsi = q_vector->tx.ring->vsi; |
| 3782 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3783 | |
| 3784 | return IRQ_HANDLED; |
| 3785 | } |
| 3786 | |
| 3787 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3788 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3789 | * @vsi: the VSI being configured |
| 3790 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3791 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3792 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3793 | 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] | 3794 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3795 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3796 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3797 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3798 | |
| 3799 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3800 | tx_ring->next = q_vector->tx.ring; |
| 3801 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3802 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3803 | |
| 3804 | rx_ring->q_vector = q_vector; |
| 3805 | rx_ring->next = q_vector->rx.ring; |
| 3806 | q_vector->rx.ring = rx_ring; |
| 3807 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | /** |
| 3811 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3812 | * @vsi: the VSI being configured |
| 3813 | * |
| 3814 | * This function maps descriptor rings to the queue-specific vectors |
| 3815 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3816 | * one vector per queue pair, but on a constrained vector budget, we |
| 3817 | * group the queue pairs as "efficiently" as possible. |
| 3818 | **/ |
| 3819 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3820 | { |
| 3821 | int qp_remaining = vsi->num_queue_pairs; |
| 3822 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3823 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3824 | int v_start = 0; |
| 3825 | int qp_idx = 0; |
| 3826 | |
| 3827 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3828 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3829 | * It is also important to go through all the vectors available to be |
| 3830 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3831 | * are cleared. This is especially important when decreasing the |
| 3832 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3833 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3834 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3835 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3836 | |
| 3837 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3838 | |
| 3839 | q_vector->num_ringpairs = num_ringpairs; |
| 3840 | |
| 3841 | q_vector->rx.count = 0; |
| 3842 | q_vector->tx.count = 0; |
| 3843 | q_vector->rx.ring = NULL; |
| 3844 | q_vector->tx.ring = NULL; |
| 3845 | |
| 3846 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3847 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3848 | qp_idx++; |
| 3849 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3850 | } |
| 3851 | } |
| 3852 | } |
| 3853 | |
| 3854 | /** |
| 3855 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3856 | * @vsi: the VSI being configured |
| 3857 | * @basename: name for the vector |
| 3858 | **/ |
| 3859 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3860 | { |
| 3861 | struct i40e_pf *pf = vsi->back; |
| 3862 | int err; |
| 3863 | |
| 3864 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3865 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3866 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3867 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3868 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3869 | else |
| 3870 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3871 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3872 | |
| 3873 | if (err) |
| 3874 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3875 | |
| 3876 | return err; |
| 3877 | } |
| 3878 | |
| 3879 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3880 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3881 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3882 | * @netdev: network interface device structure |
| 3883 | * |
| 3884 | * This is used by netconsole to send skbs without having to re-enable |
| 3885 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3886 | **/ |
| 3887 | static void i40e_netpoll(struct net_device *netdev) |
| 3888 | { |
| 3889 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3890 | struct i40e_vsi *vsi = np->vsi; |
| 3891 | struct i40e_pf *pf = vsi->back; |
| 3892 | int i; |
| 3893 | |
| 3894 | /* if interface is down do nothing */ |
| 3895 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3896 | return; |
| 3897 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3898 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3899 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3900 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3901 | } else { |
| 3902 | i40e_intr(pf->pdev->irq, netdev); |
| 3903 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3904 | } |
| 3905 | #endif |
| 3906 | |
| 3907 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3908 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3909 | * @pf: the PF being configured |
| 3910 | * @pf_q: the PF queue |
| 3911 | * @enable: enable or disable state of the queue |
| 3912 | * |
| 3913 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3914 | * enabled or disabled state. |
| 3915 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3916 | * multiple retries; else will return 0 in case of success. |
| 3917 | **/ |
| 3918 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3919 | { |
| 3920 | int i; |
| 3921 | u32 tx_reg; |
| 3922 | |
| 3923 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3924 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3925 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3926 | break; |
| 3927 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3928 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3929 | } |
| 3930 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3931 | return -ETIMEDOUT; |
| 3932 | |
| 3933 | return 0; |
| 3934 | } |
| 3935 | |
| 3936 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3937 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3938 | * @vsi: the VSI being configured |
| 3939 | * @enable: start or stop the rings |
| 3940 | **/ |
| 3941 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3942 | { |
| 3943 | struct i40e_pf *pf = vsi->back; |
| 3944 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3945 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3946 | u32 tx_reg; |
| 3947 | |
| 3948 | pf_q = vsi->base_queue; |
| 3949 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3950 | |
| 3951 | /* warn the TX unit of coming changes */ |
| 3952 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3953 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3954 | usleep_range(10, 20); |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3955 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3956 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3957 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3958 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3959 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3960 | break; |
| 3961 | usleep_range(1000, 2000); |
| 3962 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3963 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3964 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3965 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3966 | |
| 3967 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3968 | if (enable) { |
| 3969 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3970 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3971 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3972 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3973 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3974 | |
| 3975 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 3976 | /* No waiting for the Tx queue to disable */ |
| 3977 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3978 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3979 | |
| 3980 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3981 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 3982 | if (ret) { |
| 3983 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3984 | "VSI seid %d Tx ring %d %sable timeout\n", |
| 3985 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3986 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3987 | } |
| 3988 | } |
| 3989 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3990 | return ret; |
| 3991 | } |
| 3992 | |
| 3993 | /** |
| 3994 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 3995 | * @pf: the PF being configured |
| 3996 | * @pf_q: the PF queue |
| 3997 | * @enable: enable or disable state of the queue |
| 3998 | * |
| 3999 | * This routine will wait for the given Rx queue of the PF to reach the |
| 4000 | * enabled or disabled state. |
| 4001 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 4002 | * multiple retries; else will return 0 in case of success. |
| 4003 | **/ |
| 4004 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 4005 | { |
| 4006 | int i; |
| 4007 | u32 rx_reg; |
| 4008 | |
| 4009 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 4010 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 4011 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 4012 | break; |
| 4013 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 4014 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4015 | } |
| 4016 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 4017 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 4018 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4019 | return 0; |
| 4020 | } |
| 4021 | |
| 4022 | /** |
| 4023 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 4024 | * @vsi: the VSI being configured |
| 4025 | * @enable: start or stop the rings |
| 4026 | **/ |
| 4027 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 4028 | { |
| 4029 | struct i40e_pf *pf = vsi->back; |
| 4030 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4031 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4032 | u32 rx_reg; |
| 4033 | |
| 4034 | pf_q = vsi->base_queue; |
| 4035 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4036 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4037 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4038 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 4039 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 4040 | break; |
| 4041 | usleep_range(1000, 2000); |
| 4042 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4043 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 4044 | /* Skip if the queue is already in the requested state */ |
| 4045 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 4046 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4047 | |
| 4048 | /* turn on/off the queue */ |
| 4049 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4050 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4051 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4052 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4053 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4054 | /* No waiting for the Tx queue to disable */ |
| 4055 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 4056 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4057 | |
| 4058 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4059 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 4060 | if (ret) { |
| 4061 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4062 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 4063 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4064 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4065 | } |
| 4066 | } |
| 4067 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4068 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4069 | } |
| 4070 | |
| 4071 | /** |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4072 | * i40e_vsi_start_rings - Start a VSI's rings |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4073 | * @vsi: the VSI being configured |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4074 | **/ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4075 | int i40e_vsi_start_rings(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4076 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 4077 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4078 | |
| 4079 | /* do rx first for enable and last for disable */ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4080 | ret = i40e_vsi_control_rx(vsi, true); |
| 4081 | if (ret) |
| 4082 | return ret; |
| 4083 | ret = i40e_vsi_control_tx(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4084 | |
| 4085 | return ret; |
| 4086 | } |
| 4087 | |
| 4088 | /** |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4089 | * i40e_vsi_stop_rings - Stop a VSI's rings |
| 4090 | * @vsi: the VSI being configured |
| 4091 | **/ |
| 4092 | void i40e_vsi_stop_rings(struct i40e_vsi *vsi) |
| 4093 | { |
| 4094 | /* do rx first for enable and last for disable |
| 4095 | * Ignore return value, we need to shutdown whatever we can |
| 4096 | */ |
| 4097 | i40e_vsi_control_tx(vsi, false); |
| 4098 | i40e_vsi_control_rx(vsi, false); |
| 4099 | } |
| 4100 | |
| 4101 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4102 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 4103 | * @vsi: the VSI being configured |
| 4104 | **/ |
| 4105 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 4106 | { |
| 4107 | struct i40e_pf *pf = vsi->back; |
| 4108 | struct i40e_hw *hw = &pf->hw; |
| 4109 | int base = vsi->base_vector; |
| 4110 | u32 val, qp; |
| 4111 | int i; |
| 4112 | |
| 4113 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4114 | if (!vsi->q_vectors) |
| 4115 | return; |
| 4116 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 4117 | if (!vsi->irqs_ready) |
| 4118 | return; |
| 4119 | |
| 4120 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4121 | for (i = 0; i < vsi->num_q_vectors; i++) { |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4122 | int irq_num; |
| 4123 | u16 vector; |
| 4124 | |
| 4125 | vector = i + base; |
| 4126 | irq_num = pf->msix_entries[vector].vector; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4127 | |
| 4128 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 4129 | if (!vsi->q_vectors[i] || |
| 4130 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4131 | continue; |
| 4132 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4133 | /* clear the affinity notifier in the IRQ descriptor */ |
| 4134 | irq_set_affinity_notifier(irq_num, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4135 | /* clear the affinity_mask in the IRQ descriptor */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4136 | irq_set_affinity_hint(irq_num, NULL); |
| 4137 | synchronize_irq(irq_num); |
| 4138 | free_irq(irq_num, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4139 | |
| 4140 | /* Tear down the interrupt queue link list |
| 4141 | * |
| 4142 | * We know that they come in pairs and always |
| 4143 | * the Rx first, then the Tx. To clear the |
| 4144 | * link list, stick the EOL value into the |
| 4145 | * next_q field of the registers. |
| 4146 | */ |
| 4147 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4148 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4149 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4150 | val |= I40E_QUEUE_END_OF_LIST |
| 4151 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4152 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4153 | |
| 4154 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4155 | u32 next; |
| 4156 | |
| 4157 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4158 | |
| 4159 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4160 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4161 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4162 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4163 | |
| 4164 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4165 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4166 | |
| 4167 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4168 | |
| 4169 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4170 | |
| 4171 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4172 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4173 | |
| 4174 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4175 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4176 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4177 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4178 | |
| 4179 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4180 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4181 | |
| 4182 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4183 | qp = next; |
| 4184 | } |
| 4185 | } |
| 4186 | } else { |
| 4187 | free_irq(pf->pdev->irq, pf); |
| 4188 | |
| 4189 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4190 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4191 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4192 | val |= I40E_QUEUE_END_OF_LIST |
| 4193 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4194 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4195 | |
| 4196 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4197 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4198 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4199 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4200 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4201 | |
| 4202 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4203 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4204 | |
| 4205 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4206 | |
| 4207 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4208 | |
| 4209 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4210 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4211 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4212 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4213 | |
| 4214 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4215 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4216 | |
| 4217 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4218 | } |
| 4219 | } |
| 4220 | |
| 4221 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4222 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4223 | * @vsi: the VSI being configured |
| 4224 | * @v_idx: Index of vector to be freed |
| 4225 | * |
| 4226 | * This function frees the memory allocated to the q_vector. In addition if |
| 4227 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4228 | * to freeing the q_vector. |
| 4229 | **/ |
| 4230 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4231 | { |
| 4232 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4233 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4234 | |
| 4235 | if (!q_vector) |
| 4236 | return; |
| 4237 | |
| 4238 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4239 | i40e_for_each_ring(ring, q_vector->tx) |
| 4240 | ring->q_vector = NULL; |
| 4241 | |
| 4242 | i40e_for_each_ring(ring, q_vector->rx) |
| 4243 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4244 | |
| 4245 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4246 | if (vsi->netdev) |
| 4247 | netif_napi_del(&q_vector->napi); |
| 4248 | |
| 4249 | vsi->q_vectors[v_idx] = NULL; |
| 4250 | |
| 4251 | kfree_rcu(q_vector, rcu); |
| 4252 | } |
| 4253 | |
| 4254 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4255 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4256 | * @vsi: the VSI being un-configured |
| 4257 | * |
| 4258 | * This frees the memory allocated to the q_vectors and |
| 4259 | * deletes references to the NAPI struct. |
| 4260 | **/ |
| 4261 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4262 | { |
| 4263 | int v_idx; |
| 4264 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4265 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4266 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4267 | } |
| 4268 | |
| 4269 | /** |
| 4270 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4271 | * @pf: board private structure |
| 4272 | **/ |
| 4273 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4274 | { |
| 4275 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4276 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4277 | pci_disable_msix(pf->pdev); |
| 4278 | kfree(pf->msix_entries); |
| 4279 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4280 | kfree(pf->irq_pile); |
| 4281 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4282 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4283 | pci_disable_msi(pf->pdev); |
| 4284 | } |
| 4285 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4286 | } |
| 4287 | |
| 4288 | /** |
| 4289 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4290 | * @pf: board private structure |
| 4291 | * |
| 4292 | * We go through and clear interrupt specific resources and reset the structure |
| 4293 | * to pre-load conditions |
| 4294 | **/ |
| 4295 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4296 | { |
| 4297 | int i; |
| 4298 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4299 | i40e_stop_misc_vector(pf); |
Shannon Nelson | 6927839 | 2016-03-10 14:59:43 -0800 | [diff] [blame] | 4300 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4301 | synchronize_irq(pf->msix_entries[0].vector); |
| 4302 | free_irq(pf->msix_entries[0].vector, pf); |
| 4303 | } |
| 4304 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4305 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4306 | I40E_IWARP_IRQ_PILE_ID); |
| 4307 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4308 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4309 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4310 | if (pf->vsi[i]) |
| 4311 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4312 | i40e_reset_interrupt_capability(pf); |
| 4313 | } |
| 4314 | |
| 4315 | /** |
| 4316 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4317 | * @vsi: the VSI being configured |
| 4318 | **/ |
| 4319 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4320 | { |
| 4321 | int q_idx; |
| 4322 | |
| 4323 | if (!vsi->netdev) |
| 4324 | return; |
| 4325 | |
| 4326 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4327 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | /** |
| 4331 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4332 | * @vsi: the VSI being configured |
| 4333 | **/ |
| 4334 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4335 | { |
| 4336 | int q_idx; |
| 4337 | |
| 4338 | if (!vsi->netdev) |
| 4339 | return; |
| 4340 | |
| 4341 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4342 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4343 | } |
| 4344 | |
| 4345 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4346 | * i40e_vsi_close - Shut down a VSI |
| 4347 | * @vsi: the vsi to be quelled |
| 4348 | **/ |
| 4349 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4350 | { |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 4351 | struct i40e_pf *pf = vsi->back; |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4352 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4353 | i40e_down(vsi); |
| 4354 | i40e_vsi_free_irq(vsi); |
| 4355 | i40e_vsi_free_tx_resources(vsi); |
| 4356 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4357 | vsi->current_netdev_flags = 0; |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 4358 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
| 4359 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 4360 | pf->flags |= I40E_FLAG_CLIENT_RESET; |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4364 | * i40e_quiesce_vsi - Pause a given VSI |
| 4365 | * @vsi: the VSI being paused |
| 4366 | **/ |
| 4367 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4368 | { |
| 4369 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4370 | return; |
| 4371 | |
| 4372 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4373 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4374 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4375 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4376 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4377 | } |
| 4378 | |
| 4379 | /** |
| 4380 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4381 | * @vsi: the VSI being resumed |
| 4382 | **/ |
| 4383 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4384 | { |
| 4385 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 4386 | return; |
| 4387 | |
| 4388 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4389 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4390 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4391 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4392 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | /** |
| 4396 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4397 | * @pf: the PF |
| 4398 | **/ |
| 4399 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4400 | { |
| 4401 | int v; |
| 4402 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4403 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4404 | if (pf->vsi[v]) |
| 4405 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4406 | } |
| 4407 | } |
| 4408 | |
| 4409 | /** |
| 4410 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4411 | * @pf: the PF |
| 4412 | **/ |
| 4413 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4414 | { |
| 4415 | int v; |
| 4416 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4417 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4418 | if (pf->vsi[v]) |
| 4419 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4420 | } |
| 4421 | } |
| 4422 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4423 | #ifdef CONFIG_I40E_DCB |
| 4424 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4425 | * 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] | 4426 | * @vsi: the VSI being configured |
| 4427 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4428 | * This function waits for the given VSI's queues to be disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4429 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4430 | static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4431 | { |
| 4432 | struct i40e_pf *pf = vsi->back; |
| 4433 | int i, pf_q, ret; |
| 4434 | |
| 4435 | pf_q = vsi->base_queue; |
| 4436 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4437 | /* Check and wait for the disable status of the queue */ |
| 4438 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4439 | if (ret) { |
| 4440 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4441 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4442 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4443 | return ret; |
| 4444 | } |
| 4445 | } |
| 4446 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4447 | pf_q = vsi->base_queue; |
| 4448 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4449 | /* Check and wait for the disable status of the queue */ |
| 4450 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4451 | if (ret) { |
| 4452 | dev_info(&pf->pdev->dev, |
| 4453 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4454 | vsi->seid, pf_q); |
| 4455 | return ret; |
| 4456 | } |
| 4457 | } |
| 4458 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4459 | return 0; |
| 4460 | } |
| 4461 | |
| 4462 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4463 | * 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] | 4464 | * @pf: the PF |
| 4465 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4466 | * 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] | 4467 | * VSIs that are managed by this PF. |
| 4468 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4469 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4470 | { |
| 4471 | int v, ret = 0; |
| 4472 | |
| 4473 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Alexander Duyck | c76cb6e | 2017-02-21 15:55:48 -0800 | [diff] [blame^] | 4474 | if (pf->vsi[v]) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4475 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4476 | if (ret) |
| 4477 | break; |
| 4478 | } |
| 4479 | } |
| 4480 | |
| 4481 | return ret; |
| 4482 | } |
| 4483 | |
| 4484 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4485 | |
| 4486 | /** |
| 4487 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4488 | * @q_idx: TX queue number |
| 4489 | * @vsi: Pointer to VSI struct |
| 4490 | * |
| 4491 | * This function checks specified queue for given VSI. Detects hung condition. |
| 4492 | * Sets hung bit since it is two step process. Before next run of service task |
| 4493 | * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not, |
| 4494 | * hung condition remain unchanged and during subsequent run, this function |
| 4495 | * issues SW interrupt to recover from hung condition. |
| 4496 | **/ |
| 4497 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4498 | { |
| 4499 | struct i40e_ring *tx_ring = NULL; |
| 4500 | struct i40e_pf *pf; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4501 | u32 head, val, tx_pending_hw; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4502 | int i; |
| 4503 | |
| 4504 | pf = vsi->back; |
| 4505 | |
| 4506 | /* now that we have an index, find the tx_ring struct */ |
| 4507 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4508 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4509 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4510 | tx_ring = vsi->tx_rings[i]; |
| 4511 | break; |
| 4512 | } |
| 4513 | } |
| 4514 | } |
| 4515 | |
| 4516 | if (!tx_ring) |
| 4517 | return; |
| 4518 | |
| 4519 | /* Read interrupt register */ |
| 4520 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4521 | val = rd32(&pf->hw, |
| 4522 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4523 | tx_ring->vsi->base_vector - 1)); |
| 4524 | else |
| 4525 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4526 | |
| 4527 | head = i40e_get_head(tx_ring); |
| 4528 | |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4529 | tx_pending_hw = i40e_get_tx_pending(tx_ring, false); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4530 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4531 | /* HW is done executing descriptors, updated HEAD write back, |
| 4532 | * but SW hasn't processed those descriptors. If interrupt is |
| 4533 | * not generated from this point ON, it could result into |
| 4534 | * dev_watchdog detecting timeout on those netdev_queue, |
| 4535 | * hence proactively trigger SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4536 | */ |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4537 | if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4538 | /* NAPI Poll didn't run and clear since it was set */ |
| 4539 | if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4540 | &tx_ring->q_vector->hung_detected)) { |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4541 | netdev_info(vsi->netdev, "VSI_seid %d, Hung TX queue %d, tx_pending_hw: %d, NTC:0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x\n", |
| 4542 | vsi->seid, q_idx, tx_pending_hw, |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4543 | tx_ring->next_to_clean, head, |
| 4544 | tx_ring->next_to_use, |
| 4545 | readl(tx_ring->tail)); |
| 4546 | netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n", |
| 4547 | vsi->seid, q_idx, val); |
| 4548 | i40e_force_wb(vsi, tx_ring->q_vector); |
| 4549 | } else { |
| 4550 | /* First Chance - detected possible hung */ |
| 4551 | set_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4552 | &tx_ring->q_vector->hung_detected); |
| 4553 | } |
| 4554 | } |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4555 | |
| 4556 | /* This is the case where we have interrupts missing, |
| 4557 | * so the tx_pending in HW will most likely be 0, but we |
| 4558 | * will have tx_pending in SW since the WB happened but the |
| 4559 | * interrupt got lost. |
| 4560 | */ |
| 4561 | if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) && |
| 4562 | (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
Benjamin Poirier | 83a0c6e | 2017-01-12 17:04:14 -0800 | [diff] [blame] | 4563 | local_bh_disable(); |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4564 | if (napi_reschedule(&tx_ring->q_vector->napi)) |
| 4565 | tx_ring->tx_stats.tx_lost_interrupt++; |
Benjamin Poirier | 83a0c6e | 2017-01-12 17:04:14 -0800 | [diff] [blame] | 4566 | local_bh_enable(); |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4567 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4568 | } |
| 4569 | |
| 4570 | /** |
| 4571 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4572 | * @pf: pointer to PF struct |
| 4573 | * |
| 4574 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4575 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4576 | * SW interrupt. |
| 4577 | **/ |
| 4578 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4579 | { |
| 4580 | struct net_device *netdev; |
| 4581 | struct i40e_vsi *vsi; |
| 4582 | int i; |
| 4583 | |
| 4584 | /* Only for LAN VSI */ |
| 4585 | vsi = pf->vsi[pf->lan_vsi]; |
| 4586 | |
| 4587 | if (!vsi) |
| 4588 | return; |
| 4589 | |
| 4590 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
| 4591 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 4592 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4593 | return; |
| 4594 | |
| 4595 | /* Make sure type is MAIN VSI */ |
| 4596 | if (vsi->type != I40E_VSI_MAIN) |
| 4597 | return; |
| 4598 | |
| 4599 | netdev = vsi->netdev; |
| 4600 | if (!netdev) |
| 4601 | return; |
| 4602 | |
| 4603 | /* Bail out if netif_carrier is not OK */ |
| 4604 | if (!netif_carrier_ok(netdev)) |
| 4605 | return; |
| 4606 | |
| 4607 | /* Go thru' TX queues for netdev */ |
| 4608 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4609 | struct netdev_queue *q; |
| 4610 | |
| 4611 | q = netdev_get_tx_queue(netdev, i); |
| 4612 | if (q) |
| 4613 | i40e_detect_recover_hung_queue(i, vsi); |
| 4614 | } |
| 4615 | } |
| 4616 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4617 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4618 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4619 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4620 | * |
| 4621 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4622 | * and LAN TC. |
| 4623 | **/ |
| 4624 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4625 | { |
| 4626 | struct i40e_dcb_app_priority_table app; |
| 4627 | struct i40e_hw *hw = &pf->hw; |
| 4628 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4629 | u8 tc, i; |
| 4630 | /* Get the iSCSI APP TLV */ |
| 4631 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4632 | |
| 4633 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4634 | app = dcbcfg->app[i]; |
| 4635 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4636 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4637 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4638 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4639 | break; |
| 4640 | } |
| 4641 | } |
| 4642 | |
| 4643 | return enabled_tc; |
| 4644 | } |
| 4645 | |
| 4646 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4647 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4648 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4649 | * |
| 4650 | * Return the number of TCs from given DCBx configuration |
| 4651 | **/ |
| 4652 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4653 | { |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4654 | int i, tc_unused = 0; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4655 | u8 num_tc = 0; |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4656 | u8 ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4657 | |
| 4658 | /* Scan the ETS Config Priority Table to find |
| 4659 | * traffic class enabled for a given priority |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4660 | * and create a bitmask of enabled TCs |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4661 | */ |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4662 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) |
| 4663 | num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]); |
| 4664 | |
| 4665 | /* Now scan the bitmask to check for |
| 4666 | * contiguous TCs starting with TC0 |
| 4667 | */ |
| 4668 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4669 | if (num_tc & BIT(i)) { |
| 4670 | if (!tc_unused) { |
| 4671 | ret++; |
| 4672 | } else { |
| 4673 | pr_err("Non-contiguous TC - Disabling DCB\n"); |
| 4674 | return 1; |
| 4675 | } |
| 4676 | } else { |
| 4677 | tc_unused = 1; |
| 4678 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4679 | } |
| 4680 | |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4681 | /* There is always at least TC0 */ |
| 4682 | if (!ret) |
| 4683 | ret = 1; |
| 4684 | |
| 4685 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4686 | } |
| 4687 | |
| 4688 | /** |
| 4689 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4690 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4691 | * |
| 4692 | * Query the current DCB configuration and return the number of |
| 4693 | * traffic classes enabled from the given DCBX config |
| 4694 | **/ |
| 4695 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4696 | { |
| 4697 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4698 | u8 enabled_tc = 1; |
| 4699 | u8 i; |
| 4700 | |
| 4701 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4702 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4703 | |
| 4704 | return enabled_tc; |
| 4705 | } |
| 4706 | |
| 4707 | /** |
| 4708 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4709 | * @pf: PF being queried |
| 4710 | * |
| 4711 | * Return number of traffic classes enabled for the given PF |
| 4712 | **/ |
| 4713 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4714 | { |
| 4715 | struct i40e_hw *hw = &pf->hw; |
Dave Ertman | 52a08ca | 2016-07-27 12:02:34 -0700 | [diff] [blame] | 4716 | u8 i, enabled_tc = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4717 | u8 num_tc = 0; |
| 4718 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4719 | |
| 4720 | /* If DCB is not enabled then always in single TC */ |
| 4721 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4722 | return 1; |
| 4723 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4724 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4725 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4726 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4727 | |
| 4728 | /* MFP mode return count of enabled TCs for this PF */ |
| 4729 | if (pf->hw.func_caps.iscsi) |
| 4730 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4731 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4732 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4733 | |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4734 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4735 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4736 | num_tc++; |
| 4737 | } |
| 4738 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4739 | } |
| 4740 | |
| 4741 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4742 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4743 | * @pf: PF being queried |
| 4744 | * |
| 4745 | * Return a bitmap for enabled traffic classes for this PF. |
| 4746 | **/ |
| 4747 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4748 | { |
| 4749 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4750 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4751 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4752 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4753 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4754 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4755 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4756 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4757 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4758 | if (pf->hw.func_caps.iscsi) |
| 4759 | return i40e_get_iscsi_tc_map(pf); |
| 4760 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4761 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4762 | } |
| 4763 | |
| 4764 | /** |
| 4765 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4766 | * @vsi: the VSI being queried |
| 4767 | * |
| 4768 | * Returns 0 on success, negative value on failure |
| 4769 | **/ |
| 4770 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4771 | { |
| 4772 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4773 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4774 | struct i40e_pf *pf = vsi->back; |
| 4775 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4776 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4777 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4778 | int i; |
| 4779 | |
| 4780 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4781 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4782 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4783 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4784 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4785 | i40e_stat_str(&pf->hw, ret), |
| 4786 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4787 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4788 | } |
| 4789 | |
| 4790 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4791 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4792 | NULL); |
| 4793 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4794 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4795 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4796 | i40e_stat_str(&pf->hw, ret), |
| 4797 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4798 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4802 | dev_info(&pf->pdev->dev, |
| 4803 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4804 | bw_config.tc_valid_bits, |
| 4805 | bw_ets_config.tc_valid_bits); |
| 4806 | /* Still continuing */ |
| 4807 | } |
| 4808 | |
| 4809 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4810 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4811 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4812 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4813 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4814 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4815 | vsi->bw_ets_limit_credits[i] = |
| 4816 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4817 | /* 3 bits out of 4 for each TC */ |
| 4818 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4819 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4820 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4821 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4822 | } |
| 4823 | |
| 4824 | /** |
| 4825 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4826 | * @vsi: the VSI being configured |
| 4827 | * @enabled_tc: TC bitmap |
| 4828 | * @bw_credits: BW shared credits per TC |
| 4829 | * |
| 4830 | * Returns 0 on success, negative value on failure |
| 4831 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4832 | 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] | 4833 | u8 *bw_share) |
| 4834 | { |
| 4835 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4836 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4837 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4838 | |
| 4839 | bw_data.tc_valid_bits = enabled_tc; |
| 4840 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4841 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4842 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4843 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4844 | NULL); |
| 4845 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4846 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4847 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4848 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4849 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4850 | } |
| 4851 | |
| 4852 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4853 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4854 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4855 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4856 | } |
| 4857 | |
| 4858 | /** |
| 4859 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4860 | * @vsi: the VSI being configured |
| 4861 | * @enabled_tc: TC map to be enabled |
| 4862 | * |
| 4863 | **/ |
| 4864 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4865 | { |
| 4866 | struct net_device *netdev = vsi->netdev; |
| 4867 | struct i40e_pf *pf = vsi->back; |
| 4868 | struct i40e_hw *hw = &pf->hw; |
| 4869 | u8 netdev_tc = 0; |
| 4870 | int i; |
| 4871 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4872 | |
| 4873 | if (!netdev) |
| 4874 | return; |
| 4875 | |
| 4876 | if (!enabled_tc) { |
| 4877 | netdev_reset_tc(netdev); |
| 4878 | return; |
| 4879 | } |
| 4880 | |
| 4881 | /* Set up actual enabled TCs on the VSI */ |
| 4882 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 4883 | return; |
| 4884 | |
| 4885 | /* set per TC queues for the VSI */ |
| 4886 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4887 | /* Only set TC queues for enabled tcs |
| 4888 | * |
| 4889 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 4890 | * enabled_tc bitmap would be 0x00001001; the driver |
| 4891 | * will set the numtc for netdev as 2 that will be |
| 4892 | * referenced by the netdev layer as TC 0 and 1. |
| 4893 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4894 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4895 | netdev_set_tc_queue(netdev, |
| 4896 | vsi->tc_config.tc_info[i].netdev_tc, |
| 4897 | vsi->tc_config.tc_info[i].qcount, |
| 4898 | vsi->tc_config.tc_info[i].qoffset); |
| 4899 | } |
| 4900 | |
| 4901 | /* Assign UP2TC map for the VSI */ |
| 4902 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4903 | /* Get the actual TC# for the UP */ |
| 4904 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4905 | /* Get the mapped netdev TC# for the UP */ |
| 4906 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 4907 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 4908 | } |
| 4909 | } |
| 4910 | |
| 4911 | /** |
| 4912 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 4913 | * @vsi: the VSI being configured |
| 4914 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 4915 | **/ |
| 4916 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 4917 | struct i40e_vsi_context *ctxt) |
| 4918 | { |
| 4919 | /* copy just the sections touched not the entire info |
| 4920 | * since not all sections are valid as returned by |
| 4921 | * update vsi params |
| 4922 | */ |
| 4923 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 4924 | memcpy(&vsi->info.queue_mapping, |
| 4925 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 4926 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 4927 | sizeof(vsi->info.tc_mapping)); |
| 4928 | } |
| 4929 | |
| 4930 | /** |
| 4931 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 4932 | * @vsi: VSI to be configured |
| 4933 | * @enabled_tc: TC bitmap |
| 4934 | * |
| 4935 | * This configures a particular VSI for TCs that are mapped to the |
| 4936 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 4937 | * VSIs to configure TC for a particular VSI. |
| 4938 | * |
| 4939 | * NOTE: |
| 4940 | * It is expected that the VSI queues have been quisced before calling |
| 4941 | * this function. |
| 4942 | **/ |
| 4943 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4944 | { |
| 4945 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 4946 | struct i40e_vsi_context ctxt; |
| 4947 | int ret = 0; |
| 4948 | int i; |
| 4949 | |
| 4950 | /* Check if enabled_tc is same as existing or new TCs */ |
| 4951 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 4952 | return ret; |
| 4953 | |
| 4954 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 4955 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4956 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4957 | bw_share[i] = 1; |
| 4958 | } |
| 4959 | |
| 4960 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 4961 | if (ret) { |
| 4962 | dev_info(&vsi->back->pdev->dev, |
| 4963 | "Failed configuring TC map %d for VSI %d\n", |
| 4964 | enabled_tc, vsi->seid); |
| 4965 | goto out; |
| 4966 | } |
| 4967 | |
| 4968 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 4969 | ctxt.seid = vsi->seid; |
| 4970 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 4971 | ctxt.vf_num = 0; |
| 4972 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 4973 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4974 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 4975 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4976 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 4977 | ctxt.info.valid_sections |= |
| 4978 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 4979 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 4980 | } |
| 4981 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4982 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 4983 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 4984 | if (ret) { |
| 4985 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4986 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 4987 | i40e_stat_str(&vsi->back->hw, ret), |
| 4988 | i40e_aq_str(&vsi->back->hw, |
| 4989 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4990 | goto out; |
| 4991 | } |
| 4992 | /* update the local VSI info with updated queue map */ |
| 4993 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 4994 | vsi->info.valid_sections = 0; |
| 4995 | |
| 4996 | /* Update current VSI BW information */ |
| 4997 | ret = i40e_vsi_get_bw_info(vsi); |
| 4998 | if (ret) { |
| 4999 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5000 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 5001 | i40e_stat_str(&vsi->back->hw, ret), |
| 5002 | i40e_aq_str(&vsi->back->hw, |
| 5003 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5004 | goto out; |
| 5005 | } |
| 5006 | |
| 5007 | /* Update the netdev TC setup */ |
| 5008 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 5009 | out: |
| 5010 | return ret; |
| 5011 | } |
| 5012 | |
| 5013 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5014 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 5015 | * @veb: given VEB |
| 5016 | * @enabled_tc: TC bitmap |
| 5017 | * |
| 5018 | * Configures given TC bitmap for VEB (switching) element |
| 5019 | **/ |
| 5020 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 5021 | { |
| 5022 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 5023 | struct i40e_pf *pf = veb->pf; |
| 5024 | int ret = 0; |
| 5025 | int i; |
| 5026 | |
| 5027 | /* No TCs or already enabled TCs just return */ |
| 5028 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 5029 | return ret; |
| 5030 | |
| 5031 | bw_data.tc_valid_bits = enabled_tc; |
| 5032 | /* bw_data.absolute_credits is not set (relative) */ |
| 5033 | |
| 5034 | /* Enable ETS TCs with equal BW Share for now */ |
| 5035 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5036 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5037 | bw_data.tc_bw_share_credits[i] = 1; |
| 5038 | } |
| 5039 | |
| 5040 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 5041 | &bw_data, NULL); |
| 5042 | if (ret) { |
| 5043 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5044 | "VEB bw config failed, err %s aq_err %s\n", |
| 5045 | i40e_stat_str(&pf->hw, ret), |
| 5046 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5047 | goto out; |
| 5048 | } |
| 5049 | |
| 5050 | /* Update the BW information */ |
| 5051 | ret = i40e_veb_get_bw_info(veb); |
| 5052 | if (ret) { |
| 5053 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5054 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 5055 | i40e_stat_str(&pf->hw, ret), |
| 5056 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5057 | } |
| 5058 | |
| 5059 | out: |
| 5060 | return ret; |
| 5061 | } |
| 5062 | |
| 5063 | #ifdef CONFIG_I40E_DCB |
| 5064 | /** |
| 5065 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 5066 | * @pf: PF struct |
| 5067 | * |
| 5068 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 5069 | * the caller would've quiesce all the VSIs before calling |
| 5070 | * this function |
| 5071 | **/ |
| 5072 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 5073 | { |
| 5074 | u8 tc_map = 0; |
| 5075 | int ret; |
| 5076 | u8 v; |
| 5077 | |
| 5078 | /* Enable the TCs available on PF to all VEBs */ |
| 5079 | tc_map = i40e_pf_get_tc_map(pf); |
| 5080 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 5081 | if (!pf->veb[v]) |
| 5082 | continue; |
| 5083 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 5084 | if (ret) { |
| 5085 | dev_info(&pf->pdev->dev, |
| 5086 | "Failed configuring TC for VEB seid=%d\n", |
| 5087 | pf->veb[v]->seid); |
| 5088 | /* Will try to configure as many components */ |
| 5089 | } |
| 5090 | } |
| 5091 | |
| 5092 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5093 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5094 | if (!pf->vsi[v]) |
| 5095 | continue; |
| 5096 | |
| 5097 | /* - Enable all TCs for the LAN VSI |
| 5098 | * - For all others keep them at TC0 for now |
| 5099 | */ |
| 5100 | if (v == pf->lan_vsi) |
| 5101 | tc_map = i40e_pf_get_tc_map(pf); |
| 5102 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5103 | tc_map = I40E_DEFAULT_TRAFFIC_CLASS; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5104 | |
| 5105 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 5106 | if (ret) { |
| 5107 | dev_info(&pf->pdev->dev, |
| 5108 | "Failed configuring TC for VSI seid=%d\n", |
| 5109 | pf->vsi[v]->seid); |
| 5110 | /* Will try to configure as many components */ |
| 5111 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 5112 | /* Re-configure VSI vectors based on updated TC map */ |
| 5113 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5114 | if (pf->vsi[v]->netdev) |
| 5115 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 5116 | } |
| 5117 | } |
| 5118 | } |
| 5119 | |
| 5120 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5121 | * i40e_resume_port_tx - Resume port Tx |
| 5122 | * @pf: PF struct |
| 5123 | * |
| 5124 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 5125 | * resume. |
| 5126 | **/ |
| 5127 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 5128 | { |
| 5129 | struct i40e_hw *hw = &pf->hw; |
| 5130 | int ret; |
| 5131 | |
| 5132 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 5133 | if (ret) { |
| 5134 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5135 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 5136 | i40e_stat_str(&pf->hw, ret), |
| 5137 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5138 | /* Schedule PF reset to recover */ |
| 5139 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5140 | i40e_service_event_schedule(pf); |
| 5141 | } |
| 5142 | |
| 5143 | return ret; |
| 5144 | } |
| 5145 | |
| 5146 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5147 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 5148 | * @pf: PF being configured |
| 5149 | * |
| 5150 | * Query the current DCB configuration and cache it |
| 5151 | * in the hardware structure |
| 5152 | **/ |
| 5153 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 5154 | { |
| 5155 | struct i40e_hw *hw = &pf->hw; |
| 5156 | int err = 0; |
| 5157 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5158 | /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */ |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 5159 | if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5160 | goto out; |
| 5161 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5162 | /* Get the initial DCB configuration */ |
| 5163 | err = i40e_init_dcb(hw); |
| 5164 | if (!err) { |
| 5165 | /* Device/Function is not DCBX capable */ |
| 5166 | if ((!hw->func_caps.dcb) || |
| 5167 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5168 | dev_info(&pf->pdev->dev, |
| 5169 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 5170 | |
| 5171 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 5172 | goto out; |
| 5173 | |
| 5174 | } else { |
| 5175 | /* When status is not DISABLED then DCBX in FW */ |
| 5176 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5177 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5178 | |
| 5179 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5180 | /* Enable DCB tagging only when more than one TC |
| 5181 | * or explicitly disable if only one TC |
| 5182 | */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5183 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5184 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5185 | else |
| 5186 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5187 | dev_dbg(&pf->pdev->dev, |
| 5188 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5189 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5190 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5191 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5192 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5193 | i40e_stat_str(&pf->hw, err), |
| 5194 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | out: |
| 5198 | return err; |
| 5199 | } |
| 5200 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5201 | #define SPEED_SIZE 14 |
| 5202 | #define FC_SIZE 8 |
| 5203 | /** |
| 5204 | * i40e_print_link_message - print link up or down |
| 5205 | * @vsi: the VSI for which link needs a message |
| 5206 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5207 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5208 | { |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 5209 | enum i40e_aq_link_speed new_speed; |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5210 | char *speed = "Unknown"; |
| 5211 | char *fc = "Unknown"; |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5212 | char *fec = ""; |
| 5213 | char *an = ""; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5214 | |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 5215 | new_speed = vsi->back->hw.phy.link_info.link_speed; |
| 5216 | |
| 5217 | if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed)) |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5218 | return; |
| 5219 | vsi->current_isup = isup; |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 5220 | vsi->current_speed = new_speed; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5221 | if (!isup) { |
| 5222 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5223 | return; |
| 5224 | } |
| 5225 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5226 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5227 | * least 10GB |
| 5228 | */ |
| 5229 | if (vsi->back->hw.func_caps.npar_enable && |
| 5230 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5231 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5232 | netdev_warn(vsi->netdev, |
| 5233 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5234 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5235 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5236 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5237 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5238 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5239 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5240 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5241 | break; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 5242 | case I40E_LINK_SPEED_25GB: |
| 5243 | speed = "25 G"; |
| 5244 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5245 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5246 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5247 | break; |
| 5248 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5249 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5250 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5251 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5252 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5253 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5254 | default: |
| 5255 | break; |
| 5256 | } |
| 5257 | |
| 5258 | switch (vsi->back->hw.fc.current_mode) { |
| 5259 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5260 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5261 | break; |
| 5262 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5263 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5264 | break; |
| 5265 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5266 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5267 | break; |
| 5268 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5269 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5270 | break; |
| 5271 | } |
| 5272 | |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5273 | if (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) { |
| 5274 | fec = ", FEC: None"; |
| 5275 | an = ", Autoneg: False"; |
| 5276 | |
| 5277 | if (vsi->back->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED) |
| 5278 | an = ", Autoneg: True"; |
| 5279 | |
| 5280 | if (vsi->back->hw.phy.link_info.fec_info & |
| 5281 | I40E_AQ_CONFIG_FEC_KR_ENA) |
| 5282 | fec = ", FEC: CL74 FC-FEC/BASE-R"; |
| 5283 | else if (vsi->back->hw.phy.link_info.fec_info & |
| 5284 | I40E_AQ_CONFIG_FEC_RS_ENA) |
| 5285 | fec = ", FEC: CL108 RS-FEC"; |
| 5286 | } |
| 5287 | |
| 5288 | netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s, Flow Control: %s\n", |
| 5289 | speed, fec, an, fc); |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5290 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5291 | |
| 5292 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5293 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5294 | * @vsi: the VSI being configured |
| 5295 | **/ |
| 5296 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5297 | { |
| 5298 | struct i40e_pf *pf = vsi->back; |
| 5299 | int err; |
| 5300 | |
| 5301 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5302 | i40e_vsi_configure_msix(vsi); |
| 5303 | else |
| 5304 | i40e_configure_msi_and_legacy(vsi); |
| 5305 | |
| 5306 | /* start rings */ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 5307 | err = i40e_vsi_start_rings(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5308 | if (err) |
| 5309 | return err; |
| 5310 | |
| 5311 | clear_bit(__I40E_DOWN, &vsi->state); |
| 5312 | i40e_napi_enable_all(vsi); |
| 5313 | i40e_vsi_enable_irq(vsi); |
| 5314 | |
| 5315 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5316 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5317 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5318 | netif_tx_start_all_queues(vsi->netdev); |
| 5319 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5320 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5321 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5322 | /* need to check for qualified module here*/ |
| 5323 | if ((pf->hw.phy.link_info.link_info & |
| 5324 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5325 | (!(pf->hw.phy.link_info.an_info & |
| 5326 | I40E_AQ_QUALIFIED_MODULE))) |
| 5327 | netdev_err(vsi->netdev, |
| 5328 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5329 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5330 | |
| 5331 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5332 | if (vsi->type == I40E_VSI_FDIR) { |
| 5333 | /* reset fd counters */ |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5334 | pf->fd_add_err = 0; |
| 5335 | pf->fd_atr_cnt = 0; |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5336 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5337 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5338 | |
| 5339 | /* On the next run of the service_task, notify any clients of the new |
| 5340 | * opened netdev |
| 5341 | */ |
| 5342 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5343 | i40e_service_event_schedule(pf); |
| 5344 | |
| 5345 | return 0; |
| 5346 | } |
| 5347 | |
| 5348 | /** |
| 5349 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5350 | * @vsi: the VSI being configured |
| 5351 | * |
| 5352 | * Rebuild the ring structs after some configuration |
| 5353 | * has changed, e.g. MTU size. |
| 5354 | **/ |
| 5355 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5356 | { |
| 5357 | struct i40e_pf *pf = vsi->back; |
| 5358 | |
| 5359 | WARN_ON(in_interrupt()); |
| 5360 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5361 | usleep_range(1000, 2000); |
| 5362 | i40e_down(vsi); |
| 5363 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5364 | i40e_up(vsi); |
| 5365 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 5366 | } |
| 5367 | |
| 5368 | /** |
| 5369 | * i40e_up - Bring the connection back up after being down |
| 5370 | * @vsi: the VSI being configured |
| 5371 | **/ |
| 5372 | int i40e_up(struct i40e_vsi *vsi) |
| 5373 | { |
| 5374 | int err; |
| 5375 | |
| 5376 | err = i40e_vsi_configure(vsi); |
| 5377 | if (!err) |
| 5378 | err = i40e_up_complete(vsi); |
| 5379 | |
| 5380 | return err; |
| 5381 | } |
| 5382 | |
| 5383 | /** |
| 5384 | * i40e_down - Shutdown the connection processing |
| 5385 | * @vsi: the VSI being stopped |
| 5386 | **/ |
| 5387 | void i40e_down(struct i40e_vsi *vsi) |
| 5388 | { |
| 5389 | int i; |
| 5390 | |
| 5391 | /* It is assumed that the caller of this function |
| 5392 | * sets the vsi->state __I40E_DOWN bit. |
| 5393 | */ |
| 5394 | if (vsi->netdev) { |
| 5395 | netif_carrier_off(vsi->netdev); |
| 5396 | netif_tx_disable(vsi->netdev); |
| 5397 | } |
| 5398 | i40e_vsi_disable_irq(vsi); |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 5399 | i40e_vsi_stop_rings(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5400 | i40e_napi_disable_all(vsi); |
| 5401 | |
| 5402 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5403 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 5404 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5405 | } |
Catherine Sullivan | f980d44 | 2016-05-16 10:26:34 -0700 | [diff] [blame] | 5406 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5407 | } |
| 5408 | |
| 5409 | /** |
| 5410 | * i40e_setup_tc - configure multiple traffic classes |
| 5411 | * @netdev: net device to configure |
| 5412 | * @tc: number of traffic classes to enable |
| 5413 | **/ |
| 5414 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5415 | { |
| 5416 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5417 | struct i40e_vsi *vsi = np->vsi; |
| 5418 | struct i40e_pf *pf = vsi->back; |
| 5419 | u8 enabled_tc = 0; |
| 5420 | int ret = -EINVAL; |
| 5421 | int i; |
| 5422 | |
| 5423 | /* Check if DCB enabled to continue */ |
| 5424 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5425 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5426 | goto exit; |
| 5427 | } |
| 5428 | |
| 5429 | /* Check if MFP enabled */ |
| 5430 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5431 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5432 | goto exit; |
| 5433 | } |
| 5434 | |
| 5435 | /* Check whether tc count is within enabled limit */ |
| 5436 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5437 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5438 | goto exit; |
| 5439 | } |
| 5440 | |
| 5441 | /* Generate TC map for number of tc requested */ |
| 5442 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5443 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5444 | |
| 5445 | /* Requesting same TC configuration as already enabled */ |
| 5446 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5447 | return 0; |
| 5448 | |
| 5449 | /* Quiesce VSI queues */ |
| 5450 | i40e_quiesce_vsi(vsi); |
| 5451 | |
| 5452 | /* Configure VSI for enabled TCs */ |
| 5453 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5454 | if (ret) { |
| 5455 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5456 | vsi->seid); |
| 5457 | goto exit; |
| 5458 | } |
| 5459 | |
| 5460 | /* Unquiesce VSI */ |
| 5461 | i40e_unquiesce_vsi(vsi); |
| 5462 | |
| 5463 | exit: |
| 5464 | return ret; |
| 5465 | } |
| 5466 | |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5467 | static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5468 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5469 | { |
Amritha Nambiar | 56f36ac | 2017-03-15 10:39:25 -0700 | [diff] [blame] | 5470 | if (tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5471 | return -EINVAL; |
Amritha Nambiar | 56f36ac | 2017-03-15 10:39:25 -0700 | [diff] [blame] | 5472 | |
| 5473 | tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS; |
| 5474 | |
| 5475 | return i40e_setup_tc(netdev, tc->mqprio->num_tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5476 | } |
| 5477 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5478 | /** |
| 5479 | * i40e_open - Called when a network interface is made active |
| 5480 | * @netdev: network interface device structure |
| 5481 | * |
| 5482 | * The open entry point is called when a network interface is made |
| 5483 | * active by the system (IFF_UP). At this point all resources needed |
| 5484 | * for transmit and receive operations are allocated, the interrupt |
| 5485 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5486 | * enabled, and the stack is notified that the interface is ready. |
| 5487 | * |
| 5488 | * Returns 0 on success, negative value on failure |
| 5489 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5490 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5491 | { |
| 5492 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5493 | struct i40e_vsi *vsi = np->vsi; |
| 5494 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5495 | int err; |
| 5496 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5497 | /* disallow open during test or if eeprom is broken */ |
| 5498 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 5499 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5500 | return -EBUSY; |
| 5501 | |
| 5502 | netif_carrier_off(netdev); |
| 5503 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5504 | err = i40e_vsi_open(vsi); |
| 5505 | if (err) |
| 5506 | return err; |
| 5507 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5508 | /* configure global TSO hardware offload settings */ |
| 5509 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5510 | TCP_FLAG_FIN) >> 16); |
| 5511 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5512 | TCP_FLAG_FIN | |
| 5513 | TCP_FLAG_CWR) >> 16); |
| 5514 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5515 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 5516 | udp_tunnel_get_rx_info(netdev); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5517 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5518 | return 0; |
| 5519 | } |
| 5520 | |
| 5521 | /** |
| 5522 | * i40e_vsi_open - |
| 5523 | * @vsi: the VSI to open |
| 5524 | * |
| 5525 | * Finish initialization of the VSI. |
| 5526 | * |
| 5527 | * Returns 0 on success, negative value on failure |
| 5528 | **/ |
| 5529 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5530 | { |
| 5531 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5532 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5533 | int err; |
| 5534 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5535 | /* allocate descriptors */ |
| 5536 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5537 | if (err) |
| 5538 | goto err_setup_tx; |
| 5539 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5540 | if (err) |
| 5541 | goto err_setup_rx; |
| 5542 | |
| 5543 | err = i40e_vsi_configure(vsi); |
| 5544 | if (err) |
| 5545 | goto err_setup_rx; |
| 5546 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5547 | if (vsi->netdev) { |
| 5548 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5549 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5550 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5551 | if (err) |
| 5552 | goto err_setup_rx; |
| 5553 | |
| 5554 | /* Notify the stack of the actual queue counts. */ |
| 5555 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5556 | vsi->num_queue_pairs); |
| 5557 | if (err) |
| 5558 | goto err_set_queues; |
| 5559 | |
| 5560 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5561 | vsi->num_queue_pairs); |
| 5562 | if (err) |
| 5563 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5564 | |
| 5565 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5566 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5567 | dev_driver_string(&pf->pdev->dev), |
| 5568 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5569 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5570 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5571 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5572 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5573 | goto err_setup_rx; |
| 5574 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5575 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5576 | err = i40e_up_complete(vsi); |
| 5577 | if (err) |
| 5578 | goto err_up_complete; |
| 5579 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5580 | return 0; |
| 5581 | |
| 5582 | err_up_complete: |
| 5583 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5584 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5585 | i40e_vsi_free_irq(vsi); |
| 5586 | err_setup_rx: |
| 5587 | i40e_vsi_free_rx_resources(vsi); |
| 5588 | err_setup_tx: |
| 5589 | i40e_vsi_free_tx_resources(vsi); |
| 5590 | if (vsi == pf->vsi[pf->lan_vsi]) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5591 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5592 | |
| 5593 | return err; |
| 5594 | } |
| 5595 | |
| 5596 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5597 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5598 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5599 | * |
| 5600 | * This function destroys the hlist where all the Flow Director |
| 5601 | * filters were saved. |
| 5602 | **/ |
| 5603 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5604 | { |
| 5605 | struct i40e_fdir_filter *filter; |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame] | 5606 | struct i40e_flex_pit *pit_entry, *tmp; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5607 | struct hlist_node *node2; |
| 5608 | |
| 5609 | hlist_for_each_entry_safe(filter, node2, |
| 5610 | &pf->fdir_filter_list, fdir_node) { |
| 5611 | hlist_del(&filter->fdir_node); |
| 5612 | kfree(filter); |
| 5613 | } |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5614 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame] | 5615 | list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) { |
| 5616 | list_del(&pit_entry->list); |
| 5617 | kfree(pit_entry); |
| 5618 | } |
| 5619 | INIT_LIST_HEAD(&pf->l3_flex_pit_list); |
| 5620 | |
| 5621 | list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) { |
| 5622 | list_del(&pit_entry->list); |
| 5623 | kfree(pit_entry); |
| 5624 | } |
| 5625 | INIT_LIST_HEAD(&pf->l4_flex_pit_list); |
| 5626 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5627 | pf->fdir_pf_active_filters = 0; |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5628 | pf->fd_tcp4_filter_cnt = 0; |
| 5629 | pf->fd_udp4_filter_cnt = 0; |
Jacob Keller | f223c87 | 2017-02-06 14:38:51 -0800 | [diff] [blame] | 5630 | pf->fd_sctp4_filter_cnt = 0; |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5631 | pf->fd_ip4_filter_cnt = 0; |
Jacob Keller | 3bcee1e | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 5632 | |
| 5633 | /* Reprogram the default input set for TCP/IPv4 */ |
| 5634 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP, |
| 5635 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | |
| 5636 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); |
| 5637 | |
| 5638 | /* Reprogram the default input set for UDP/IPv4 */ |
| 5639 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP, |
| 5640 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | |
| 5641 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); |
| 5642 | |
| 5643 | /* Reprogram the default input set for SCTP/IPv4 */ |
| 5644 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP, |
| 5645 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | |
| 5646 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); |
| 5647 | |
| 5648 | /* Reprogram the default input set for Other/IPv4 */ |
| 5649 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER, |
| 5650 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5651 | } |
| 5652 | |
| 5653 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5654 | * i40e_close - Disables a network interface |
| 5655 | * @netdev: network interface device structure |
| 5656 | * |
| 5657 | * The close entry point is called when an interface is de-activated |
| 5658 | * by the OS. The hardware is still under the driver's control, but |
| 5659 | * this netdev interface is disabled. |
| 5660 | * |
| 5661 | * Returns 0, this is not allowed to fail |
| 5662 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5663 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5664 | { |
| 5665 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5666 | struct i40e_vsi *vsi = np->vsi; |
| 5667 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5668 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5669 | |
| 5670 | return 0; |
| 5671 | } |
| 5672 | |
| 5673 | /** |
| 5674 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5675 | * @pf: board private structure |
| 5676 | * @reset_flags: which reset is requested |
| 5677 | * |
| 5678 | * The essential difference in resets is that the PF Reset |
| 5679 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5680 | * firmware, and doesn't bother the other PFs on the chip. |
| 5681 | **/ |
| 5682 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5683 | { |
| 5684 | u32 val; |
| 5685 | |
| 5686 | WARN_ON(in_interrupt()); |
| 5687 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5688 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5689 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5690 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5691 | |
| 5692 | /* Request a Global Reset |
| 5693 | * |
| 5694 | * This will start the chip's countdown to the actual full |
| 5695 | * chip reset event, and a warning interrupt to be sent |
| 5696 | * to all PFs, including the requestor. Our handler |
| 5697 | * for the warning interrupt will deal with the shutdown |
| 5698 | * and recovery of the switch setup. |
| 5699 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5700 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5701 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5702 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5703 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5704 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5705 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5706 | |
| 5707 | /* Request a Core Reset |
| 5708 | * |
| 5709 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5710 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5711 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5712 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5713 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5714 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5715 | i40e_flush(&pf->hw); |
| 5716 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5717 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5718 | |
| 5719 | /* Request a PF Reset |
| 5720 | * |
| 5721 | * Resets only the PF-specific registers |
| 5722 | * |
| 5723 | * This goes directly to the tear-down and rebuild of |
| 5724 | * the switch, since we need to do all the recovery as |
| 5725 | * for the Core Reset. |
| 5726 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5727 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5728 | i40e_handle_reset_warning(pf); |
| 5729 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5730 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5731 | int v; |
| 5732 | |
| 5733 | /* Find the VSI(s) that requested a re-init */ |
| 5734 | dev_info(&pf->pdev->dev, |
| 5735 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5736 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5737 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5738 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5739 | if (vsi != NULL && |
| 5740 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5741 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5742 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5743 | } |
| 5744 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5745 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5746 | int v; |
| 5747 | |
| 5748 | /* Find the VSI(s) that needs to be brought down */ |
| 5749 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5750 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5751 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5752 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5753 | if (vsi != NULL && |
| 5754 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5755 | set_bit(__I40E_DOWN, &vsi->state); |
| 5756 | i40e_down(vsi); |
| 5757 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5758 | } |
| 5759 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5760 | } else { |
| 5761 | dev_info(&pf->pdev->dev, |
| 5762 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5763 | } |
| 5764 | } |
| 5765 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5766 | #ifdef CONFIG_I40E_DCB |
| 5767 | /** |
| 5768 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5769 | * @pf: board private structure |
| 5770 | * @old_cfg: current DCB config |
| 5771 | * @new_cfg: new DCB config |
| 5772 | **/ |
| 5773 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5774 | struct i40e_dcbx_config *old_cfg, |
| 5775 | struct i40e_dcbx_config *new_cfg) |
| 5776 | { |
| 5777 | bool need_reconfig = false; |
| 5778 | |
| 5779 | /* Check if ETS configuration has changed */ |
| 5780 | if (memcmp(&new_cfg->etscfg, |
| 5781 | &old_cfg->etscfg, |
| 5782 | sizeof(new_cfg->etscfg))) { |
| 5783 | /* If Priority Table has changed reconfig is needed */ |
| 5784 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5785 | &old_cfg->etscfg.prioritytable, |
| 5786 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5787 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5788 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5792 | &old_cfg->etscfg.tcbwtable, |
| 5793 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5794 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5795 | |
| 5796 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5797 | &old_cfg->etscfg.tsatable, |
| 5798 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5799 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5800 | } |
| 5801 | |
| 5802 | /* Check if PFC configuration has changed */ |
| 5803 | if (memcmp(&new_cfg->pfc, |
| 5804 | &old_cfg->pfc, |
| 5805 | sizeof(new_cfg->pfc))) { |
| 5806 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5807 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5808 | } |
| 5809 | |
| 5810 | /* Check if APP Table has changed */ |
| 5811 | if (memcmp(&new_cfg->app, |
| 5812 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5813 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5814 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5815 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5816 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5817 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5818 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5819 | return need_reconfig; |
| 5820 | } |
| 5821 | |
| 5822 | /** |
| 5823 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5824 | * @pf: board private structure |
| 5825 | * @e: event info posted on ARQ |
| 5826 | **/ |
| 5827 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5828 | struct i40e_arq_event_info *e) |
| 5829 | { |
| 5830 | struct i40e_aqc_lldp_get_mib *mib = |
| 5831 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5832 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5833 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5834 | bool need_reconfig = false; |
| 5835 | int ret = 0; |
| 5836 | u8 type; |
| 5837 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5838 | /* Not DCB capable or capability disabled */ |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5839 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5840 | return ret; |
| 5841 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5842 | /* Ignore if event is not for Nearest Bridge */ |
| 5843 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5844 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5845 | 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] | 5846 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5847 | return ret; |
| 5848 | |
| 5849 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5850 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5851 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5852 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5853 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5854 | /* Update the remote cached instance and return */ |
| 5855 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5856 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5857 | &hw->remote_dcbx_config); |
| 5858 | goto exit; |
| 5859 | } |
| 5860 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5861 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5862 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5863 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5864 | /* Reset the old DCBx configuration data */ |
| 5865 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5866 | /* Get updated DCBX data from firmware */ |
| 5867 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5868 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5869 | dev_info(&pf->pdev->dev, |
| 5870 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 5871 | i40e_stat_str(&pf->hw, ret), |
| 5872 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5873 | goto exit; |
| 5874 | } |
| 5875 | |
| 5876 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5877 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5878 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5879 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5880 | goto exit; |
| 5881 | } |
| 5882 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5883 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5884 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5885 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5886 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5887 | |
| 5888 | if (!need_reconfig) |
| 5889 | goto exit; |
| 5890 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5891 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5892 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5893 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5894 | else |
| 5895 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5896 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5897 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5898 | /* Reconfiguration needed quiesce all VSIs */ |
| 5899 | i40e_pf_quiesce_all_vsi(pf); |
| 5900 | |
| 5901 | /* Changes in configuration update VEB/VSI */ |
| 5902 | i40e_dcb_reconfigure(pf); |
| 5903 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5904 | ret = i40e_resume_port_tx(pf); |
| 5905 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5906 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5907 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5908 | if (ret) |
| 5909 | goto exit; |
| 5910 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 5911 | /* Wait for the PF's queues to be disabled */ |
| 5912 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5913 | if (ret) { |
| 5914 | /* Schedule PF reset to recover */ |
| 5915 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5916 | i40e_service_event_schedule(pf); |
| 5917 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5918 | i40e_pf_unquiesce_all_vsi(pf); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 5919 | pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED | |
| 5920 | I40E_FLAG_CLIENT_L2_CHANGE); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5921 | } |
| 5922 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5923 | exit: |
| 5924 | return ret; |
| 5925 | } |
| 5926 | #endif /* CONFIG_I40E_DCB */ |
| 5927 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5928 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5929 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 5930 | * @pf: board private structure |
| 5931 | * @reset_flags: which reset is requested |
| 5932 | * |
| 5933 | **/ |
| 5934 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 5935 | { |
| 5936 | rtnl_lock(); |
| 5937 | i40e_do_reset(pf, reset_flags); |
| 5938 | rtnl_unlock(); |
| 5939 | } |
| 5940 | |
| 5941 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5942 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 5943 | * @pf: board private structure |
| 5944 | * @e: event info posted on ARQ |
| 5945 | * |
| 5946 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 5947 | * and VF queues |
| 5948 | **/ |
| 5949 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 5950 | struct i40e_arq_event_info *e) |
| 5951 | { |
| 5952 | struct i40e_aqc_lan_overflow *data = |
| 5953 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 5954 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 5955 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 5956 | struct i40e_hw *hw = &pf->hw; |
| 5957 | struct i40e_vf *vf; |
| 5958 | u16 vf_id; |
| 5959 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5960 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 5961 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5962 | |
| 5963 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 5964 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 5965 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 5966 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 5967 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 5968 | vf_id -= hw->func_caps.vf_base_id; |
| 5969 | vf = &pf->vf[vf_id]; |
| 5970 | i40e_vc_notify_vf_reset(vf); |
| 5971 | /* Allow VF to process pending reset notification */ |
| 5972 | msleep(20); |
| 5973 | i40e_reset_vf(vf, false); |
| 5974 | } |
| 5975 | } |
| 5976 | |
| 5977 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5978 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 5979 | * @pf: board private structure |
| 5980 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5981 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5982 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5983 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5984 | |
| 5985 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5986 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 5987 | return fcnt_prog; |
| 5988 | } |
| 5989 | |
| 5990 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5991 | * 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] | 5992 | * @pf: board private structure |
| 5993 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5994 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5995 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5996 | u32 val, fcnt_prog; |
| 5997 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5998 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5999 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 6000 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 6001 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 6002 | return fcnt_prog; |
| 6003 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6004 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6005 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6006 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 6007 | * @pf: board private structure |
| 6008 | **/ |
| 6009 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 6010 | { |
| 6011 | u32 val, fcnt_prog; |
| 6012 | |
| 6013 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 6014 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 6015 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 6016 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 6017 | return fcnt_prog; |
| 6018 | } |
| 6019 | |
| 6020 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6021 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 6022 | * @pf: board private structure |
| 6023 | **/ |
| 6024 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 6025 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6026 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6027 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6028 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6029 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6030 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 6031 | return; |
| 6032 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6033 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 6034 | * to re-enable |
| 6035 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6036 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6037 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6038 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 6039 | (pf->fd_add_err == 0) || |
| 6040 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6041 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 6042 | (pf->hw_disabled_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 6043 | pf->hw_disabled_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 6044 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6045 | 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] | 6046 | } |
| 6047 | } |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6048 | |
| 6049 | /* Wait for some more space to be available to turn on ATR. We also |
| 6050 | * must check that no existing ntuple rules for TCP are in effect |
| 6051 | */ |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6052 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 6053 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 6054 | (pf->hw_disabled_flags & I40E_FLAG_FD_ATR_ENABLED) && |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 6055 | (pf->fd_tcp4_filter_cnt == 0)) { |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 6056 | pf->hw_disabled_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 6057 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6058 | 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] | 6059 | } |
| 6060 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6061 | |
| 6062 | /* if hw had a problem adding a filter, delete it */ |
| 6063 | if (pf->fd_inv > 0) { |
| 6064 | hlist_for_each_entry_safe(filter, node, |
| 6065 | &pf->fdir_filter_list, fdir_node) { |
| 6066 | if (filter->fd_id == pf->fd_inv) { |
| 6067 | hlist_del(&filter->fdir_node); |
| 6068 | kfree(filter); |
| 6069 | pf->fdir_pf_active_filters--; |
| 6070 | } |
| 6071 | } |
| 6072 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6073 | } |
| 6074 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6075 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6076 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6077 | /** |
| 6078 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 6079 | * @pf: board private structure |
| 6080 | **/ |
| 6081 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 6082 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6083 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6084 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6085 | bool disable_atr = false; |
| 6086 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6087 | int reg; |
| 6088 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6089 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 6090 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 6091 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6092 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6093 | /* If the flush is happening too quick and we have mostly SB rules we |
| 6094 | * should not re-enable ATR for some time. |
| 6095 | */ |
| 6096 | min_flush_time = pf->fd_flush_timestamp + |
| 6097 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 6098 | 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] | 6099 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6100 | if (!(time_after(jiffies, min_flush_time)) && |
| 6101 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 6102 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6103 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 6104 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6105 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6106 | |
| 6107 | pf->fd_flush_timestamp = jiffies; |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 6108 | pf->hw_disabled_flags |= I40E_FLAG_FD_ATR_ENABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6109 | /* flush all filters */ |
| 6110 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 6111 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 6112 | i40e_flush(&pf->hw); |
| 6113 | pf->fd_flush_cnt++; |
| 6114 | pf->fd_add_err = 0; |
| 6115 | do { |
| 6116 | /* Check FD flush status every 5-6msec */ |
| 6117 | usleep_range(5000, 6000); |
| 6118 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 6119 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 6120 | break; |
| 6121 | } while (flush_wait_retry--); |
| 6122 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 6123 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 6124 | } else { |
| 6125 | /* replay sideband filters */ |
| 6126 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 6127 | if (!disable_atr && !pf->fd_tcp4_filter_cnt) |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 6128 | pf->hw_disabled_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6129 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
| 6130 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6131 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 6132 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6133 | } |
| 6134 | |
| 6135 | /** |
| 6136 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 6137 | * @pf: board private structure |
| 6138 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6139 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6140 | { |
| 6141 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 6142 | } |
| 6143 | |
| 6144 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 6145 | * being applied really fast; before we see the first |
| 6146 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 6147 | * reacting will make sure we don't cause flush too often. |
| 6148 | */ |
| 6149 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 6150 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6151 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6152 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 6153 | * @pf: board private structure |
| 6154 | **/ |
| 6155 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 6156 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6157 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6158 | /* if interface is down do nothing */ |
| 6159 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 6160 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6161 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6162 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6163 | i40e_fdir_flush_and_replay(pf); |
| 6164 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6165 | i40e_fdir_check_and_reenable(pf); |
| 6166 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6167 | } |
| 6168 | |
| 6169 | /** |
| 6170 | * i40e_vsi_link_event - notify VSI of a link event |
| 6171 | * @vsi: vsi to be notified |
| 6172 | * @link_up: link up or down |
| 6173 | **/ |
| 6174 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 6175 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 6176 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6177 | return; |
| 6178 | |
| 6179 | switch (vsi->type) { |
| 6180 | case I40E_VSI_MAIN: |
| 6181 | if (!vsi->netdev || !vsi->netdev_registered) |
| 6182 | break; |
| 6183 | |
| 6184 | if (link_up) { |
| 6185 | netif_carrier_on(vsi->netdev); |
| 6186 | netif_tx_wake_all_queues(vsi->netdev); |
| 6187 | } else { |
| 6188 | netif_carrier_off(vsi->netdev); |
| 6189 | netif_tx_stop_all_queues(vsi->netdev); |
| 6190 | } |
| 6191 | break; |
| 6192 | |
| 6193 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6194 | case I40E_VSI_VMDQ2: |
| 6195 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6196 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6197 | case I40E_VSI_MIRROR: |
| 6198 | default: |
| 6199 | /* there is no notification for other VSIs */ |
| 6200 | break; |
| 6201 | } |
| 6202 | } |
| 6203 | |
| 6204 | /** |
| 6205 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6206 | * @veb: veb to be notified |
| 6207 | * @link_up: link up or down |
| 6208 | **/ |
| 6209 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6210 | { |
| 6211 | struct i40e_pf *pf; |
| 6212 | int i; |
| 6213 | |
| 6214 | if (!veb || !veb->pf) |
| 6215 | return; |
| 6216 | pf = veb->pf; |
| 6217 | |
| 6218 | /* depth first... */ |
| 6219 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6220 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6221 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6222 | |
| 6223 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6224 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6225 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6226 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6227 | } |
| 6228 | |
| 6229 | /** |
| 6230 | * i40e_link_event - Update netif_carrier status |
| 6231 | * @pf: board private structure |
| 6232 | **/ |
| 6233 | static void i40e_link_event(struct i40e_pf *pf) |
| 6234 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6235 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6236 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6237 | i40e_status status; |
| 6238 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6239 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6240 | /* save off old link status information */ |
| 6241 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6242 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6243 | /* set this to force the get_link_status call to refresh state */ |
| 6244 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6245 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6246 | 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] | 6247 | |
| 6248 | status = i40e_get_link_status(&pf->hw, &new_link); |
Harshitha Ramamurthy | ae13670 | 2016-12-12 15:44:16 -0800 | [diff] [blame] | 6249 | |
| 6250 | /* On success, disable temp link polling */ |
| 6251 | if (status == I40E_SUCCESS) { |
| 6252 | if (pf->flags & I40E_FLAG_TEMP_LINK_POLLING) |
| 6253 | pf->flags &= ~I40E_FLAG_TEMP_LINK_POLLING; |
| 6254 | } else { |
| 6255 | /* Enable link polling temporarily until i40e_get_link_status |
| 6256 | * returns I40E_SUCCESS |
| 6257 | */ |
| 6258 | pf->flags |= I40E_FLAG_TEMP_LINK_POLLING; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6259 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6260 | status); |
| 6261 | return; |
| 6262 | } |
| 6263 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6264 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6265 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6266 | |
| 6267 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6268 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6269 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 6270 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6271 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6272 | |
| 6273 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 6274 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6275 | |
| 6276 | /* Notify the base of the switch tree connected to |
| 6277 | * the link. Floating VEBs are not notified. |
| 6278 | */ |
| 6279 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6280 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6281 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6282 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6283 | |
| 6284 | if (pf->vf) |
| 6285 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6286 | |
| 6287 | if (pf->flags & I40E_FLAG_PTP) |
| 6288 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6289 | } |
| 6290 | |
| 6291 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6292 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6293 | * @pf: board private structure |
| 6294 | **/ |
| 6295 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6296 | { |
| 6297 | int i; |
| 6298 | |
| 6299 | /* if interface is down do nothing */ |
| 6300 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 6301 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6302 | return; |
| 6303 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6304 | /* make sure we don't do these things too often */ |
| 6305 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6306 | pf->service_timer_period))) |
| 6307 | return; |
| 6308 | pf->service_timer_previous = jiffies; |
| 6309 | |
Harshitha Ramamurthy | ae13670 | 2016-12-12 15:44:16 -0800 | [diff] [blame] | 6310 | if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) || |
| 6311 | (pf->flags & I40E_FLAG_TEMP_LINK_POLLING)) |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6312 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6313 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6314 | /* Update the stats for active netdevs so the network stack |
| 6315 | * can look at updated numbers whenever it cares to |
| 6316 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6317 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6318 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6319 | i40e_update_stats(pf->vsi[i]); |
| 6320 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6321 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6322 | /* Update the stats for the active switching components */ |
| 6323 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6324 | if (pf->veb[i]) |
| 6325 | i40e_update_veb_stats(pf->veb[i]); |
| 6326 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6327 | |
| 6328 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6329 | } |
| 6330 | |
| 6331 | /** |
| 6332 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6333 | * @pf: board private structure |
| 6334 | **/ |
| 6335 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6336 | { |
| 6337 | u32 reset_flags = 0; |
| 6338 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6339 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6340 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6341 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6342 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 6343 | } |
| 6344 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6345 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6346 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6347 | } |
| 6348 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6349 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6350 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 6351 | } |
| 6352 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6353 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6354 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 6355 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6356 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6357 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6358 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 6359 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6360 | |
| 6361 | /* If there's a recovery already waiting, it takes |
| 6362 | * precedence before starting a new reset sequence. |
| 6363 | */ |
| 6364 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 6365 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6366 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6367 | } |
| 6368 | |
| 6369 | /* If we're already down or resetting, just bail */ |
| 6370 | if (reset_flags && |
| 6371 | !test_bit(__I40E_DOWN, &pf->state) && |
| 6372 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6373 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6374 | |
| 6375 | unlock: |
| 6376 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6377 | } |
| 6378 | |
| 6379 | /** |
| 6380 | * i40e_handle_link_event - Handle link event |
| 6381 | * @pf: board private structure |
| 6382 | * @e: event info posted on ARQ |
| 6383 | **/ |
| 6384 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6385 | struct i40e_arq_event_info *e) |
| 6386 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6387 | struct i40e_aqc_get_link_status *status = |
| 6388 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6389 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6390 | /* Do a new status request to re-enable LSE reporting |
| 6391 | * and load new status information into the hw struct |
| 6392 | * This completely ignores any state information |
| 6393 | * in the ARQ event info, instead choosing to always |
| 6394 | * issue the AQ update link status command. |
| 6395 | */ |
| 6396 | i40e_link_event(pf); |
| 6397 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6398 | /* check for unqualified module, if link is down */ |
| 6399 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6400 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6401 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6402 | dev_err(&pf->pdev->dev, |
| 6403 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6404 | } |
| 6405 | |
| 6406 | /** |
| 6407 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6408 | * @pf: board private structure |
| 6409 | **/ |
| 6410 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6411 | { |
| 6412 | struct i40e_arq_event_info event; |
| 6413 | struct i40e_hw *hw = &pf->hw; |
| 6414 | u16 pending, i = 0; |
| 6415 | i40e_status ret; |
| 6416 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6417 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6418 | u32 val; |
| 6419 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6420 | /* Do not run clean AQ when PF reset fails */ |
| 6421 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 6422 | return; |
| 6423 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6424 | /* check for error indications */ |
| 6425 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6426 | oldval = val; |
| 6427 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6428 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6429 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6430 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6431 | } |
| 6432 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6433 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6434 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6435 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6436 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6437 | } |
| 6438 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6439 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6440 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6441 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6442 | } |
| 6443 | if (oldval != val) |
| 6444 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6445 | |
| 6446 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6447 | oldval = val; |
| 6448 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6449 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6450 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6451 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6452 | } |
| 6453 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6454 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6455 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6456 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6457 | } |
| 6458 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6459 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6460 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6461 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6462 | } |
| 6463 | if (oldval != val) |
| 6464 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6465 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6466 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6467 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6468 | if (!event.msg_buf) |
| 6469 | return; |
| 6470 | |
| 6471 | do { |
| 6472 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6473 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6474 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6475 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6476 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6477 | break; |
| 6478 | } |
| 6479 | |
| 6480 | opcode = le16_to_cpu(event.desc.opcode); |
| 6481 | switch (opcode) { |
| 6482 | |
| 6483 | case i40e_aqc_opc_get_link_status: |
| 6484 | i40e_handle_link_event(pf, &event); |
| 6485 | break; |
| 6486 | case i40e_aqc_opc_send_msg_to_pf: |
| 6487 | ret = i40e_vc_process_vf_msg(pf, |
| 6488 | le16_to_cpu(event.desc.retval), |
| 6489 | le32_to_cpu(event.desc.cookie_high), |
| 6490 | le32_to_cpu(event.desc.cookie_low), |
| 6491 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6492 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6493 | break; |
| 6494 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6495 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6496 | #ifdef CONFIG_I40E_DCB |
| 6497 | rtnl_lock(); |
| 6498 | ret = i40e_handle_lldp_event(pf, &event); |
| 6499 | rtnl_unlock(); |
| 6500 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6501 | break; |
| 6502 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6503 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6504 | i40e_handle_lan_overflow_event(pf, &event); |
| 6505 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6506 | case i40e_aqc_opc_send_msg_to_peer: |
| 6507 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6508 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6509 | case i40e_aqc_opc_nvm_erase: |
| 6510 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6511 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 6512 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 6513 | "ARQ NVM operation 0x%04x completed\n", |
| 6514 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6515 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6516 | default: |
| 6517 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 6518 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6519 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6520 | break; |
| 6521 | } |
| 6522 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 6523 | |
| 6524 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 6525 | /* re-enable Admin queue interrupt cause */ |
| 6526 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6527 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6528 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6529 | i40e_flush(hw); |
| 6530 | |
| 6531 | kfree(event.msg_buf); |
| 6532 | } |
| 6533 | |
| 6534 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6535 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6536 | * @pf: board private structure |
| 6537 | **/ |
| 6538 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6539 | { |
| 6540 | int err; |
| 6541 | |
| 6542 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6543 | if (err) { |
| 6544 | /* retry in case of garbage read */ |
| 6545 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6546 | if (err) { |
| 6547 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6548 | err); |
| 6549 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6550 | } |
| 6551 | } |
| 6552 | |
| 6553 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 6554 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 6555 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6556 | } |
| 6557 | } |
| 6558 | |
| 6559 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6560 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6561 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6562 | * |
| 6563 | * enable switch loop back or die - no point in a return value |
| 6564 | **/ |
| 6565 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6566 | { |
| 6567 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6568 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6569 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6570 | |
| 6571 | ctxt.seid = pf->main_vsi_seid; |
| 6572 | ctxt.pf_num = pf->hw.pf_id; |
| 6573 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6574 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6575 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6576 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6577 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6578 | i40e_stat_str(&pf->hw, ret), |
| 6579 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6580 | return; |
| 6581 | } |
| 6582 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6583 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6584 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6585 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6586 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6587 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6588 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6589 | "update vsi switch failed, err %s aq_err %s\n", |
| 6590 | i40e_stat_str(&pf->hw, ret), |
| 6591 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6592 | } |
| 6593 | } |
| 6594 | |
| 6595 | /** |
| 6596 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6597 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6598 | * |
| 6599 | * disable switch loop back or die - no point in a return value |
| 6600 | **/ |
| 6601 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6602 | { |
| 6603 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6604 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6605 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6606 | |
| 6607 | ctxt.seid = pf->main_vsi_seid; |
| 6608 | ctxt.pf_num = pf->hw.pf_id; |
| 6609 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6610 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6611 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6612 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6613 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6614 | i40e_stat_str(&pf->hw, ret), |
| 6615 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6616 | return; |
| 6617 | } |
| 6618 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6619 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6620 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6621 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6622 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6623 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6624 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6625 | "update vsi switch failed, err %s aq_err %s\n", |
| 6626 | i40e_stat_str(&pf->hw, ret), |
| 6627 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6628 | } |
| 6629 | } |
| 6630 | |
| 6631 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6632 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6633 | * @veb: pointer to the bridge instance |
| 6634 | * |
| 6635 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6636 | * specified HW bridge instance. It is expected this function is called |
| 6637 | * when a new HW bridge is instantiated. |
| 6638 | **/ |
| 6639 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6640 | { |
| 6641 | struct i40e_pf *pf = veb->pf; |
| 6642 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6643 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6644 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6645 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6646 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6647 | i40e_disable_pf_switch_lb(pf); |
| 6648 | else |
| 6649 | i40e_enable_pf_switch_lb(pf); |
| 6650 | } |
| 6651 | |
| 6652 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6653 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6654 | * @veb: pointer to the VEB instance |
| 6655 | * |
| 6656 | * This is a recursive function that first builds the attached VSIs then |
| 6657 | * recurses in to build the next layer of VEB. We track the connections |
| 6658 | * through our own index numbers because the seid's from the HW could |
| 6659 | * change across the reset. |
| 6660 | **/ |
| 6661 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6662 | { |
| 6663 | struct i40e_vsi *ctl_vsi = NULL; |
| 6664 | struct i40e_pf *pf = veb->pf; |
| 6665 | int v, veb_idx; |
| 6666 | int ret; |
| 6667 | |
| 6668 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6669 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6670 | if (pf->vsi[v] && |
| 6671 | pf->vsi[v]->veb_idx == veb->idx && |
| 6672 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6673 | ctl_vsi = pf->vsi[v]; |
| 6674 | break; |
| 6675 | } |
| 6676 | } |
| 6677 | if (!ctl_vsi) { |
| 6678 | dev_info(&pf->pdev->dev, |
| 6679 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6680 | ret = -ENOENT; |
| 6681 | goto end_reconstitute; |
| 6682 | } |
| 6683 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6684 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6685 | ret = i40e_add_vsi(ctl_vsi); |
| 6686 | if (ret) { |
| 6687 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6688 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6689 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6690 | goto end_reconstitute; |
| 6691 | } |
| 6692 | i40e_vsi_reset_stats(ctl_vsi); |
| 6693 | |
| 6694 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6695 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6696 | if (ret) |
| 6697 | goto end_reconstitute; |
| 6698 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6699 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6700 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6701 | else |
| 6702 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6703 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6704 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6705 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6706 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6707 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6708 | continue; |
| 6709 | |
| 6710 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6711 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6712 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6713 | vsi->uplink_seid = veb->seid; |
| 6714 | ret = i40e_add_vsi(vsi); |
| 6715 | if (ret) { |
| 6716 | dev_info(&pf->pdev->dev, |
| 6717 | "rebuild of vsi_idx %d failed: %d\n", |
| 6718 | v, ret); |
| 6719 | goto end_reconstitute; |
| 6720 | } |
| 6721 | i40e_vsi_reset_stats(vsi); |
| 6722 | } |
| 6723 | } |
| 6724 | |
| 6725 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6726 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6727 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6728 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6729 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6730 | if (ret) |
| 6731 | break; |
| 6732 | } |
| 6733 | } |
| 6734 | |
| 6735 | end_reconstitute: |
| 6736 | return ret; |
| 6737 | } |
| 6738 | |
| 6739 | /** |
| 6740 | * i40e_get_capabilities - get info about the HW |
| 6741 | * @pf: the PF struct |
| 6742 | **/ |
| 6743 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6744 | { |
| 6745 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6746 | u16 data_size; |
| 6747 | int buf_len; |
| 6748 | int err; |
| 6749 | |
| 6750 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6751 | do { |
| 6752 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6753 | if (!cap_buf) |
| 6754 | return -ENOMEM; |
| 6755 | |
| 6756 | /* this loads the data into the hw struct for us */ |
| 6757 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6758 | &data_size, |
| 6759 | i40e_aqc_opc_list_func_capabilities, |
| 6760 | NULL); |
| 6761 | /* data loaded, buffer no longer needed */ |
| 6762 | kfree(cap_buf); |
| 6763 | |
| 6764 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6765 | /* retry with a larger buffer */ |
| 6766 | buf_len = data_size; |
| 6767 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6768 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6769 | "capability discovery failed, err %s aq_err %s\n", |
| 6770 | i40e_stat_str(&pf->hw, err), |
| 6771 | i40e_aq_str(&pf->hw, |
| 6772 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6773 | return -ENODEV; |
| 6774 | } |
| 6775 | } while (err); |
| 6776 | |
| 6777 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6778 | dev_info(&pf->pdev->dev, |
| 6779 | "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", |
| 6780 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6781 | pf->hw.func_caps.num_msix_vectors, |
| 6782 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6783 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6784 | pf->hw.func_caps.fd_filters_best_effort, |
| 6785 | pf->hw.func_caps.num_tx_qp, |
| 6786 | pf->hw.func_caps.num_vsis); |
| 6787 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6788 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6789 | + pf->hw.func_caps.num_vfs) |
| 6790 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6791 | dev_info(&pf->pdev->dev, |
| 6792 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6793 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6794 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6795 | } |
| 6796 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6797 | return 0; |
| 6798 | } |
| 6799 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6800 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6801 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6802 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6803 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6804 | * @pf: board private structure |
| 6805 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6806 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6807 | { |
| 6808 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6809 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6810 | /* quick workaround for an NVM issue that leaves a critical register |
| 6811 | * uninitialized |
| 6812 | */ |
| 6813 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6814 | static const u32 hkey[] = { |
| 6815 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6816 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6817 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6818 | 0x95b3a76d}; |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6819 | int i; |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6820 | |
| 6821 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6822 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6823 | } |
| 6824 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6825 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6826 | return; |
| 6827 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6828 | /* find existing VSI and see if it needs configuring */ |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6829 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6830 | |
| 6831 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6832 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6833 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6834 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6835 | if (!vsi) { |
| 6836 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6837 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6838 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6839 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6840 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6841 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6842 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6843 | } |
| 6844 | |
| 6845 | /** |
| 6846 | * i40e_fdir_teardown - release the Flow Director resources |
| 6847 | * @pf: board private structure |
| 6848 | **/ |
| 6849 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6850 | { |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6851 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6852 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6853 | i40e_fdir_filter_exit(pf); |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6854 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
| 6855 | if (vsi) |
| 6856 | i40e_vsi_release(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6857 | } |
| 6858 | |
| 6859 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6860 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6861 | * @pf: board private structure |
| 6862 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6863 | * 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] | 6864 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6865 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6866 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6867 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6868 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6869 | u32 v; |
| 6870 | |
| 6871 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6872 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6873 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 6874 | if (i40e_check_asq_alive(&pf->hw)) |
| 6875 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6876 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6877 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6878 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6879 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6880 | i40e_pf_quiesce_all_vsi(pf); |
| 6881 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6882 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6883 | if (pf->vsi[v]) |
| 6884 | pf->vsi[v]->seid = 0; |
| 6885 | } |
| 6886 | |
| 6887 | i40e_shutdown_adminq(&pf->hw); |
| 6888 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6889 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6890 | if (hw->hmc.hmc_obj) { |
| 6891 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6892 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6893 | dev_warn(&pf->pdev->dev, |
| 6894 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6895 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6896 | } |
| 6897 | |
| 6898 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6899 | * i40e_send_version - update firmware with driver version |
| 6900 | * @pf: PF struct |
| 6901 | */ |
| 6902 | static void i40e_send_version(struct i40e_pf *pf) |
| 6903 | { |
| 6904 | struct i40e_driver_version dv; |
| 6905 | |
| 6906 | dv.major_version = DRV_VERSION_MAJOR; |
| 6907 | dv.minor_version = DRV_VERSION_MINOR; |
| 6908 | dv.build_version = DRV_VERSION_BUILD; |
| 6909 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 6910 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6911 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 6912 | } |
| 6913 | |
| 6914 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 6915 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6916 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6917 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6918 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6919 | static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit) |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6920 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6921 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6922 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6923 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6924 | u32 val; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6925 | u32 v; |
| 6926 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6927 | /* Now we wait for GRST to settle out. |
| 6928 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 6929 | * because the reset will make them disappear. |
| 6930 | */ |
| 6931 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6932 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6933 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6934 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 6935 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6936 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6937 | pf->pfr_count++; |
| 6938 | |
| 6939 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6940 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6941 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6942 | |
| 6943 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 6944 | ret = i40e_init_adminq(&pf->hw); |
| 6945 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6946 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 6947 | i40e_stat_str(&pf->hw, ret), |
| 6948 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6949 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6950 | } |
| 6951 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6952 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 6953 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6954 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6955 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 6956 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6957 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6958 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6959 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6960 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6961 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
Alexander Duyck | c76cb6e | 2017-02-21 15:55:48 -0800 | [diff] [blame^] | 6962 | hw->func_caps.num_rx_qp, 0, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6963 | if (ret) { |
| 6964 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 6965 | goto end_core_reset; |
| 6966 | } |
| 6967 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 6968 | if (ret) { |
| 6969 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 6970 | goto end_core_reset; |
| 6971 | } |
| 6972 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6973 | #ifdef CONFIG_I40E_DCB |
| 6974 | ret = i40e_init_pf_dcb(pf); |
| 6975 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6976 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 6977 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 6978 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6979 | } |
| 6980 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6981 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6982 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6983 | if (ret) |
| 6984 | goto end_core_reset; |
| 6985 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6986 | /* The driver only wants link up/down and module qualification |
| 6987 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6988 | */ |
| 6989 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6990 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 6991 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6992 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6993 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6994 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 6995 | i40e_stat_str(&pf->hw, ret), |
| 6996 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6997 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6998 | /* make sure our flow control settings are restored */ |
| 6999 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 7000 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 7001 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 7002 | i40e_stat_str(&pf->hw, ret), |
| 7003 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7004 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7005 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 7006 | * They are still in our local switch element arrays, so only |
| 7007 | * need to rebuild the switch model in the HW. |
| 7008 | * |
| 7009 | * If there were VEBs but the reconstitution failed, we'll try |
| 7010 | * try to recover minimal use by getting the basic PF VSI working. |
| 7011 | */ |
| 7012 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7013 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7014 | /* find the one VEB connected to the MAC, and find orphans */ |
| 7015 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 7016 | if (!pf->veb[v]) |
| 7017 | continue; |
| 7018 | |
| 7019 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 7020 | pf->veb[v]->uplink_seid == 0) { |
| 7021 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 7022 | |
| 7023 | if (!ret) |
| 7024 | continue; |
| 7025 | |
| 7026 | /* If Main VEB failed, we're in deep doodoo, |
| 7027 | * so give up rebuilding the switch and set up |
| 7028 | * for minimal rebuild of PF VSI. |
| 7029 | * If orphan failed, we'll report the error |
| 7030 | * but try to keep going. |
| 7031 | */ |
| 7032 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 7033 | dev_info(&pf->pdev->dev, |
| 7034 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 7035 | ret); |
| 7036 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 7037 | = pf->mac_seid; |
| 7038 | break; |
| 7039 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 7040 | dev_info(&pf->pdev->dev, |
| 7041 | "rebuild of orphan VEB failed: %d\n", |
| 7042 | ret); |
| 7043 | } |
| 7044 | } |
| 7045 | } |
| 7046 | } |
| 7047 | |
| 7048 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 7049 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7050 | /* no VEB, so rebuild only the Main VSI */ |
| 7051 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 7052 | if (ret) { |
| 7053 | dev_info(&pf->pdev->dev, |
| 7054 | "rebuild of Main VSI failed: %d\n", ret); |
| 7055 | goto end_core_reset; |
| 7056 | } |
| 7057 | } |
| 7058 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 7059 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 7060 | * of TSO, so that we avoid the MDD being fired and causing |
| 7061 | * a reset in the case of small MSS+TSO. |
| 7062 | */ |
| 7063 | #define I40E_REG_MSS 0x000E64DC |
| 7064 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 7065 | #define I40E_64BYTE_MSS 0x400000 |
| 7066 | val = rd32(hw, I40E_REG_MSS); |
| 7067 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 7068 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 7069 | val |= I40E_64BYTE_MSS; |
| 7070 | wr32(hw, I40E_REG_MSS, val); |
| 7071 | } |
| 7072 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 7073 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 7074 | msleep(75); |
| 7075 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 7076 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7077 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 7078 | i40e_stat_str(&pf->hw, ret), |
| 7079 | i40e_aq_str(&pf->hw, |
| 7080 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7081 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7082 | /* reinit the misc interrupt */ |
| 7083 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7084 | ret = i40e_setup_misc_vector(pf); |
| 7085 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 7086 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 7087 | * transmitted. By doing so we stop a malicious VF from sending out |
| 7088 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 7089 | * PF/VF VSIs. |
| 7090 | * The FW can still send Flow control frames if enabled. |
| 7091 | */ |
| 7092 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 7093 | pf->main_vsi_seid); |
| 7094 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7095 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 7096 | i40e_pf_unquiesce_all_vsi(pf); |
| 7097 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 7098 | if (pf->num_alloc_vfs) { |
| 7099 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 7100 | i40e_reset_vf(&pf->vf[v], true); |
| 7101 | } |
| 7102 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7103 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 7104 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7105 | |
| 7106 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7107 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 7108 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7109 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 7110 | } |
| 7111 | |
| 7112 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7113 | * 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] | 7114 | * @pf: board private structure |
| 7115 | * |
| 7116 | * Close up the VFs and other things in prep for a Core Reset, |
| 7117 | * then get ready to rebuild the world. |
| 7118 | **/ |
| 7119 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 7120 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 7121 | i40e_prep_for_reset(pf); |
| 7122 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7123 | } |
| 7124 | |
| 7125 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7126 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7127 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7128 | * |
| 7129 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 7130 | **/ |
| 7131 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 7132 | { |
| 7133 | struct i40e_hw *hw = &pf->hw; |
| 7134 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7135 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7136 | struct i40e_vf *vf; |
| 7137 | u32 reg; |
| 7138 | int i; |
| 7139 | |
| 7140 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 7141 | return; |
| 7142 | |
| 7143 | /* find what triggered the MDD event */ |
| 7144 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 7145 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7146 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 7147 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7148 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7149 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7150 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7151 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7152 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 7153 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 7154 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7155 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7156 | 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] | 7157 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7158 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 7159 | mdd_detected = true; |
| 7160 | } |
| 7161 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 7162 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7163 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 7164 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7165 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7166 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7167 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 7168 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 7169 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7170 | if (netif_msg_rx_err(pf)) |
| 7171 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 7172 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7173 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 7174 | mdd_detected = true; |
| 7175 | } |
| 7176 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7177 | if (mdd_detected) { |
| 7178 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 7179 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 7180 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7181 | 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] | 7182 | pf_mdd_detected = true; |
| 7183 | } |
| 7184 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 7185 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 7186 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7187 | 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] | 7188 | pf_mdd_detected = true; |
| 7189 | } |
| 7190 | /* Queue belongs to the PF, initiate a reset */ |
| 7191 | if (pf_mdd_detected) { |
| 7192 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 7193 | i40e_service_event_schedule(pf); |
| 7194 | } |
| 7195 | } |
| 7196 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7197 | /* see if one of the VFs needs its hand slapped */ |
| 7198 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7199 | vf = &(pf->vf[i]); |
| 7200 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7201 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7202 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7203 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7204 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7205 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7206 | } |
| 7207 | |
| 7208 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7209 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7210 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7211 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7212 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7213 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7214 | } |
| 7215 | |
| 7216 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7217 | dev_info(&pf->pdev->dev, |
| 7218 | "Too many MDD events on VF %d, disabled\n", i); |
| 7219 | dev_info(&pf->pdev->dev, |
| 7220 | "Use PF Control I/F to re-enable the VF\n"); |
| 7221 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 7222 | } |
| 7223 | } |
| 7224 | |
| 7225 | /* re-enable mdd interrupt cause */ |
| 7226 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 7227 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7228 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7229 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7230 | i40e_flush(hw); |
| 7231 | } |
| 7232 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7233 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7234 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7235 | * @pf: board private structure |
| 7236 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7237 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7238 | { |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7239 | struct i40e_hw *hw = &pf->hw; |
| 7240 | i40e_status ret; |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 7241 | u16 port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7242 | int i; |
| 7243 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7244 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7245 | return; |
| 7246 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7247 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7248 | |
| 7249 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7250 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7251 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
| 7252 | port = pf->udp_ports[i].index; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7253 | if (port) |
Carolyn Wyborny | b3f5c7b | 2016-08-24 11:33:51 -0700 | [diff] [blame] | 7254 | ret = i40e_aq_add_udp_tunnel(hw, port, |
| 7255 | pf->udp_ports[i].type, |
| 7256 | NULL, NULL); |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7257 | else |
| 7258 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7259 | |
| 7260 | if (ret) { |
Carolyn Wyborny | 730a8f8 | 2016-02-17 16:12:16 -0800 | [diff] [blame] | 7261 | dev_dbg(&pf->pdev->dev, |
| 7262 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 7263 | pf->udp_ports[i].type ? "vxlan" : "geneve", |
| 7264 | port ? "add" : "delete", |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 7265 | port, i, |
Carolyn Wyborny | 730a8f8 | 2016-02-17 16:12:16 -0800 | [diff] [blame] | 7266 | i40e_stat_str(&pf->hw, ret), |
| 7267 | i40e_aq_str(&pf->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7268 | pf->hw.aq.asq_last_status)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7269 | pf->udp_ports[i].index = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7270 | } |
| 7271 | } |
| 7272 | } |
| 7273 | } |
| 7274 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7275 | /** |
| 7276 | * i40e_service_task - Run the driver's async subtasks |
| 7277 | * @work: pointer to work_struct containing our data |
| 7278 | **/ |
| 7279 | static void i40e_service_task(struct work_struct *work) |
| 7280 | { |
| 7281 | struct i40e_pf *pf = container_of(work, |
| 7282 | struct i40e_pf, |
| 7283 | service_task); |
| 7284 | unsigned long start_time = jiffies; |
| 7285 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7286 | /* don't bother with service tasks if a reset is in progress */ |
| 7287 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7288 | return; |
| 7289 | } |
| 7290 | |
Mitch Williams | 9108903 | 2016-11-21 13:03:51 -0800 | [diff] [blame] | 7291 | if (test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
| 7292 | return; |
| 7293 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7294 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 7295 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7296 | i40e_reset_subtask(pf); |
| 7297 | i40e_handle_mdd_event(pf); |
| 7298 | i40e_vc_process_vflr_event(pf); |
| 7299 | i40e_watchdog_subtask(pf); |
| 7300 | i40e_fdir_reinit_subtask(pf); |
Mitch Williams | 0ef2d5a | 2017-01-24 10:24:00 -0800 | [diff] [blame] | 7301 | if (pf->flags & I40E_FLAG_CLIENT_RESET) { |
| 7302 | /* Client subtask will reopen next time through. */ |
| 7303 | i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], true); |
| 7304 | pf->flags &= ~I40E_FLAG_CLIENT_RESET; |
| 7305 | } else { |
| 7306 | i40e_client_subtask(pf); |
| 7307 | if (pf->flags & I40E_FLAG_CLIENT_L2_CHANGE) { |
| 7308 | i40e_notify_client_of_l2_param_changes( |
| 7309 | pf->vsi[pf->lan_vsi]); |
| 7310 | pf->flags &= ~I40E_FLAG_CLIENT_L2_CHANGE; |
| 7311 | } |
| 7312 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7313 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7314 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7315 | i40e_clean_adminq_subtask(pf); |
| 7316 | |
Mitch Williams | 9108903 | 2016-11-21 13:03:51 -0800 | [diff] [blame] | 7317 | /* flush memory to make sure state is correct before next watchdog */ |
| 7318 | smp_mb__before_atomic(); |
| 7319 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7320 | |
| 7321 | /* If the tasks have taken longer than one timer cycle or there |
| 7322 | * is more work to be done, reschedule the service task now |
| 7323 | * rather than wait for the timer to tick again. |
| 7324 | */ |
| 7325 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 7326 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 7327 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 7328 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 7329 | i40e_service_event_schedule(pf); |
| 7330 | } |
| 7331 | |
| 7332 | /** |
| 7333 | * i40e_service_timer - timer callback |
| 7334 | * @data: pointer to PF struct |
| 7335 | **/ |
| 7336 | static void i40e_service_timer(unsigned long data) |
| 7337 | { |
| 7338 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7339 | |
| 7340 | mod_timer(&pf->service_timer, |
| 7341 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7342 | i40e_service_event_schedule(pf); |
| 7343 | } |
| 7344 | |
| 7345 | /** |
| 7346 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7347 | * @vsi: the VSI being configured |
| 7348 | **/ |
| 7349 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7350 | { |
| 7351 | struct i40e_pf *pf = vsi->back; |
| 7352 | |
| 7353 | switch (vsi->type) { |
| 7354 | case I40E_VSI_MAIN: |
| 7355 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7356 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7357 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7358 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7359 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7360 | else |
| 7361 | vsi->num_q_vectors = 1; |
| 7362 | |
| 7363 | break; |
| 7364 | |
| 7365 | case I40E_VSI_FDIR: |
| 7366 | vsi->alloc_queue_pairs = 1; |
| 7367 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7368 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7369 | vsi->num_q_vectors = pf->num_fdsb_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7370 | break; |
| 7371 | |
| 7372 | case I40E_VSI_VMDQ2: |
| 7373 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7374 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7375 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7376 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7377 | break; |
| 7378 | |
| 7379 | case I40E_VSI_SRIOV: |
| 7380 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7381 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7382 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7383 | break; |
| 7384 | |
| 7385 | default: |
| 7386 | WARN_ON(1); |
| 7387 | return -ENODATA; |
| 7388 | } |
| 7389 | |
| 7390 | return 0; |
| 7391 | } |
| 7392 | |
| 7393 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7394 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7395 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7396 | * @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] | 7397 | * |
| 7398 | * On error: returns error code (negative) |
| 7399 | * On success: returns 0 |
| 7400 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7401 | 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] | 7402 | { |
| 7403 | int size; |
| 7404 | int ret = 0; |
| 7405 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7406 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7407 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 7408 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7409 | if (!vsi->tx_rings) |
| 7410 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7411 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 7412 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7413 | if (alloc_qvectors) { |
| 7414 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7415 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7416 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7417 | if (!vsi->q_vectors) { |
| 7418 | ret = -ENOMEM; |
| 7419 | goto err_vectors; |
| 7420 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7421 | } |
| 7422 | return ret; |
| 7423 | |
| 7424 | err_vectors: |
| 7425 | kfree(vsi->tx_rings); |
| 7426 | return ret; |
| 7427 | } |
| 7428 | |
| 7429 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7430 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7431 | * @pf: board private structure |
| 7432 | * @type: type of VSI |
| 7433 | * |
| 7434 | * On error: returns error code (negative) |
| 7435 | * On success: returns vsi index in PF (positive) |
| 7436 | **/ |
| 7437 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7438 | { |
| 7439 | int ret = -ENODEV; |
| 7440 | struct i40e_vsi *vsi; |
| 7441 | int vsi_idx; |
| 7442 | int i; |
| 7443 | |
| 7444 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7445 | mutex_lock(&pf->switch_mutex); |
| 7446 | |
| 7447 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7448 | * been happening. We can afford to do a quick scan to look |
| 7449 | * for any free VSIs in the list. |
| 7450 | * |
| 7451 | * find next empty vsi slot, looping back around if necessary |
| 7452 | */ |
| 7453 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7454 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7455 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7456 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7457 | i = 0; |
| 7458 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7459 | i++; |
| 7460 | } |
| 7461 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7462 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7463 | vsi_idx = i; /* Found one! */ |
| 7464 | } else { |
| 7465 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7466 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7467 | } |
| 7468 | pf->next_vsi = ++i; |
| 7469 | |
| 7470 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7471 | if (!vsi) { |
| 7472 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7473 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7474 | } |
| 7475 | vsi->type = type; |
| 7476 | vsi->back = pf; |
| 7477 | set_bit(__I40E_DOWN, &vsi->state); |
| 7478 | vsi->flags = 0; |
| 7479 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7480 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7481 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7482 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7483 | vsi->netdev_registered = false; |
| 7484 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 7485 | hash_init(vsi->mac_filter_hash); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7486 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7487 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7488 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7489 | if (ret) |
| 7490 | goto err_rings; |
| 7491 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7492 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7493 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7494 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7495 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7496 | /* Setup default MSIX irq handler for VSI */ |
| 7497 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7498 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7499 | /* Initialize VSI lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 7500 | spin_lock_init(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7501 | pf->vsi[vsi_idx] = vsi; |
| 7502 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7503 | goto unlock_pf; |
| 7504 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7505 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7506 | pf->next_vsi = i - 1; |
| 7507 | kfree(vsi); |
| 7508 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7509 | mutex_unlock(&pf->switch_mutex); |
| 7510 | return ret; |
| 7511 | } |
| 7512 | |
| 7513 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7514 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7515 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7516 | * @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] | 7517 | * |
| 7518 | * On error: returns error code (negative) |
| 7519 | * On success: returns 0 |
| 7520 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7521 | 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] | 7522 | { |
| 7523 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7524 | if (free_qvectors) { |
| 7525 | kfree(vsi->q_vectors); |
| 7526 | vsi->q_vectors = NULL; |
| 7527 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7528 | kfree(vsi->tx_rings); |
| 7529 | vsi->tx_rings = NULL; |
| 7530 | vsi->rx_rings = NULL; |
| 7531 | } |
| 7532 | |
| 7533 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7534 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7535 | * and lookup table |
| 7536 | * @vsi: Pointer to VSI structure |
| 7537 | */ |
| 7538 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7539 | { |
| 7540 | if (!vsi) |
| 7541 | return; |
| 7542 | |
| 7543 | kfree(vsi->rss_hkey_user); |
| 7544 | vsi->rss_hkey_user = NULL; |
| 7545 | |
| 7546 | kfree(vsi->rss_lut_user); |
| 7547 | vsi->rss_lut_user = NULL; |
| 7548 | } |
| 7549 | |
| 7550 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7551 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7552 | * @vsi: the VSI being un-configured |
| 7553 | **/ |
| 7554 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7555 | { |
| 7556 | struct i40e_pf *pf; |
| 7557 | |
| 7558 | if (!vsi) |
| 7559 | return 0; |
| 7560 | |
| 7561 | if (!vsi->back) |
| 7562 | goto free_vsi; |
| 7563 | pf = vsi->back; |
| 7564 | |
| 7565 | mutex_lock(&pf->switch_mutex); |
| 7566 | if (!pf->vsi[vsi->idx]) { |
| 7567 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7568 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7569 | goto unlock_vsi; |
| 7570 | } |
| 7571 | |
| 7572 | if (pf->vsi[vsi->idx] != vsi) { |
| 7573 | dev_err(&pf->pdev->dev, |
| 7574 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7575 | pf->vsi[vsi->idx]->idx, |
| 7576 | pf->vsi[vsi->idx], |
| 7577 | pf->vsi[vsi->idx]->type, |
| 7578 | vsi->idx, vsi, vsi->type); |
| 7579 | goto unlock_vsi; |
| 7580 | } |
| 7581 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7582 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7583 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7584 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7585 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7586 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7587 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7588 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7589 | pf->vsi[vsi->idx] = NULL; |
| 7590 | if (vsi->idx < pf->next_vsi) |
| 7591 | pf->next_vsi = vsi->idx; |
| 7592 | |
| 7593 | unlock_vsi: |
| 7594 | mutex_unlock(&pf->switch_mutex); |
| 7595 | free_vsi: |
| 7596 | kfree(vsi); |
| 7597 | |
| 7598 | return 0; |
| 7599 | } |
| 7600 | |
| 7601 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7602 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7603 | * @vsi: the VSI being cleaned |
| 7604 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7605 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7606 | { |
| 7607 | int i; |
| 7608 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7609 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7610 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7611 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7612 | vsi->tx_rings[i] = NULL; |
| 7613 | vsi->rx_rings[i] = NULL; |
| 7614 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7615 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7616 | } |
| 7617 | |
| 7618 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7619 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7620 | * @vsi: the VSI being configured |
| 7621 | **/ |
| 7622 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7623 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7624 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7625 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7626 | int i; |
| 7627 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7628 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7629 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7630 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7631 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7632 | if (!tx_ring) |
| 7633 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7634 | |
| 7635 | tx_ring->queue_index = i; |
| 7636 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7637 | tx_ring->ring_active = false; |
| 7638 | tx_ring->vsi = vsi; |
| 7639 | tx_ring->netdev = vsi->netdev; |
| 7640 | tx_ring->dev = &pf->pdev->dev; |
| 7641 | tx_ring->count = vsi->num_desc; |
| 7642 | tx_ring->size = 0; |
| 7643 | tx_ring->dcb_tc = 0; |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 7644 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 7645 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7646 | tx_ring->tx_itr_setting = pf->tx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7647 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7648 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7649 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7650 | rx_ring->queue_index = i; |
| 7651 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7652 | rx_ring->ring_active = false; |
| 7653 | rx_ring->vsi = vsi; |
| 7654 | rx_ring->netdev = vsi->netdev; |
| 7655 | rx_ring->dev = &pf->pdev->dev; |
| 7656 | rx_ring->count = vsi->num_desc; |
| 7657 | rx_ring->size = 0; |
| 7658 | rx_ring->dcb_tc = 0; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7659 | rx_ring->rx_itr_setting = pf->rx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7660 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7661 | } |
| 7662 | |
| 7663 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7664 | |
| 7665 | err_out: |
| 7666 | i40e_vsi_clear_rings(vsi); |
| 7667 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7668 | } |
| 7669 | |
| 7670 | /** |
| 7671 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7672 | * @pf: board private structure |
| 7673 | * @vectors: the number of MSI-X vectors to request |
| 7674 | * |
| 7675 | * Returns the number of vectors reserved, or error |
| 7676 | **/ |
| 7677 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7678 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7679 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7680 | I40E_MIN_MSIX, vectors); |
| 7681 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7682 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7683 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7684 | vectors = 0; |
| 7685 | } |
| 7686 | |
| 7687 | return vectors; |
| 7688 | } |
| 7689 | |
| 7690 | /** |
| 7691 | * i40e_init_msix - Setup the MSIX capability |
| 7692 | * @pf: board private structure |
| 7693 | * |
| 7694 | * Work with the OS to set up the MSIX vectors needed. |
| 7695 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7696 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7697 | **/ |
| 7698 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7699 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7700 | struct i40e_hw *hw = &pf->hw; |
Jacob Keller | c0cf70a | 2017-01-24 10:24:01 -0800 | [diff] [blame] | 7701 | int cpus, extra_vectors; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7702 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7703 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7704 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7705 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7706 | |
| 7707 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7708 | return -ENODEV; |
| 7709 | |
| 7710 | /* The number of vectors we'll request will be comprised of: |
| 7711 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7712 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7713 | * - Queues being used for RSS. |
| 7714 | * We don't need as many as max_rss_size vectors. |
| 7715 | * use rss_size instead in the calculation since that |
| 7716 | * is governed by number of cpus in the system. |
| 7717 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7718 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7719 | * - The CPU count within the NUMA node if iWARP is enabled |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7720 | * Once we count this up, try the request. |
| 7721 | * |
| 7722 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7723 | * and try again. If that still fails, we punt. |
| 7724 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7725 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7726 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7727 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7728 | /* reserve one vector for miscellaneous handler */ |
| 7729 | if (vectors_left) { |
| 7730 | v_budget++; |
| 7731 | vectors_left--; |
| 7732 | } |
| 7733 | |
Jacob Keller | c0cf70a | 2017-01-24 10:24:01 -0800 | [diff] [blame] | 7734 | /* reserve some vectors for the main PF traffic queues. Initially we |
| 7735 | * only reserve at most 50% of the available vectors, in the case that |
| 7736 | * the number of online CPUs is large. This ensures that we can enable |
| 7737 | * extra features as well. Once we've enabled the other features, we |
| 7738 | * will use any remaining vectors to reach as close as we can to the |
| 7739 | * number of online CPUs. |
| 7740 | */ |
| 7741 | cpus = num_online_cpus(); |
| 7742 | pf->num_lan_msix = min_t(int, cpus, vectors_left / 2); |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7743 | vectors_left -= pf->num_lan_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7744 | |
| 7745 | /* reserve one vector for sideband flow director */ |
| 7746 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7747 | if (vectors_left) { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7748 | pf->num_fdsb_msix = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7749 | v_budget++; |
| 7750 | vectors_left--; |
| 7751 | } else { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7752 | pf->num_fdsb_msix = 0; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7753 | } |
| 7754 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7755 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7756 | /* can we reserve enough for iWARP? */ |
| 7757 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7758 | iwarp_requested = pf->num_iwarp_msix; |
| 7759 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7760 | if (!vectors_left) |
| 7761 | pf->num_iwarp_msix = 0; |
| 7762 | else if (vectors_left < pf->num_iwarp_msix) |
| 7763 | pf->num_iwarp_msix = 1; |
| 7764 | v_budget += pf->num_iwarp_msix; |
| 7765 | vectors_left -= pf->num_iwarp_msix; |
| 7766 | } |
| 7767 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7768 | /* any vectors left over go for VMDq support */ |
| 7769 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7770 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7771 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7772 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 7773 | if (!vectors_left) { |
| 7774 | pf->num_vmdq_msix = 0; |
| 7775 | pf->num_vmdq_qps = 0; |
| 7776 | } else { |
| 7777 | /* if we're short on vectors for what's desired, we limit |
| 7778 | * the queues per vmdq. If this is still more than are |
| 7779 | * available, the user will need to change the number of |
| 7780 | * queues/vectors used by the PF later with the ethtool |
| 7781 | * channels command |
| 7782 | */ |
| 7783 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7784 | pf->num_vmdq_qps = 1; |
| 7785 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7786 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 7787 | v_budget += vmdq_vecs; |
| 7788 | vectors_left -= vmdq_vecs; |
| 7789 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7790 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7791 | |
Jacob Keller | c0cf70a | 2017-01-24 10:24:01 -0800 | [diff] [blame] | 7792 | /* On systems with a large number of SMP cores, we previously limited |
| 7793 | * the number of vectors for num_lan_msix to be at most 50% of the |
| 7794 | * available vectors, to allow for other features. Now, we add back |
| 7795 | * the remaining vectors. However, we ensure that the total |
| 7796 | * num_lan_msix will not exceed num_online_cpus(). To do this, we |
| 7797 | * calculate the number of vectors we can add without going over the |
| 7798 | * cap of CPUs. For systems with a small number of CPUs this will be |
| 7799 | * zero. |
| 7800 | */ |
| 7801 | extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left); |
| 7802 | pf->num_lan_msix += extra_vectors; |
| 7803 | vectors_left -= extra_vectors; |
| 7804 | |
| 7805 | WARN(vectors_left < 0, |
| 7806 | "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n"); |
| 7807 | |
| 7808 | v_budget += pf->num_lan_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7809 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7810 | GFP_KERNEL); |
| 7811 | if (!pf->msix_entries) |
| 7812 | return -ENOMEM; |
| 7813 | |
| 7814 | for (i = 0; i < v_budget; i++) |
| 7815 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7816 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7817 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7818 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7819 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7820 | kfree(pf->msix_entries); |
| 7821 | pf->msix_entries = NULL; |
Guilherme G Piccoli | 4c95aa5 | 2016-09-22 10:03:58 -0300 | [diff] [blame] | 7822 | pci_disable_msix(pf->pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7823 | return -ENODEV; |
| 7824 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7825 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7826 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7827 | pf->num_vmdq_vsis = 0; |
| 7828 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7829 | pf->num_lan_qps = 1; |
| 7830 | pf->num_lan_msix = 1; |
| 7831 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7832 | } else if (!vectors_left) { |
| 7833 | /* If we have limited resources, we will start with no vectors |
| 7834 | * for the special features and then allocate vectors to some |
| 7835 | * of these features based on the policy and at the end disable |
| 7836 | * the features that did not get any vectors. |
| 7837 | */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7838 | int vec; |
| 7839 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7840 | dev_info(&pf->pdev->dev, |
| 7841 | "MSI-X vector limit reached, attempting to redistribute vectors\n"); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7842 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7843 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7844 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7845 | /* Scale vector usage down */ |
| 7846 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7847 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7848 | pf->num_vmdq_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7849 | |
| 7850 | /* partition out the remaining vectors */ |
| 7851 | switch (vec) { |
| 7852 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7853 | pf->num_lan_msix = 1; |
| 7854 | break; |
| 7855 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7856 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7857 | pf->num_lan_msix = 1; |
| 7858 | pf->num_iwarp_msix = 1; |
| 7859 | } else { |
| 7860 | pf->num_lan_msix = 2; |
| 7861 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7862 | break; |
| 7863 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7864 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7865 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 7866 | iwarp_requested); |
| 7867 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 7868 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7869 | } else { |
| 7870 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 7871 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7872 | } |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 7873 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7874 | pf->num_fdsb_msix = 1; |
| 7875 | vec--; |
| 7876 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7877 | pf->num_lan_msix = min_t(int, |
| 7878 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 7879 | pf->num_lan_msix); |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7880 | pf->num_lan_qps = pf->num_lan_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7881 | break; |
| 7882 | } |
| 7883 | } |
| 7884 | |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 7885 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 7886 | (pf->num_fdsb_msix == 0)) { |
| 7887 | dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n"); |
| 7888 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7889 | } |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7890 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7891 | (pf->num_vmdq_msix == 0)) { |
| 7892 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 7893 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 7894 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7895 | |
| 7896 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 7897 | (pf->num_iwarp_msix == 0)) { |
| 7898 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 7899 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 7900 | } |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7901 | i40e_debug(&pf->hw, I40E_DEBUG_INIT, |
| 7902 | "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n", |
| 7903 | pf->num_lan_msix, |
| 7904 | pf->num_vmdq_msix * pf->num_vmdq_vsis, |
| 7905 | pf->num_fdsb_msix, |
| 7906 | pf->num_iwarp_msix); |
| 7907 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7908 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7909 | } |
| 7910 | |
| 7911 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7912 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7913 | * @vsi: the VSI being configured |
| 7914 | * @v_idx: index of the vector in the vsi struct |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7915 | * @cpu: cpu to be used on affinity_mask |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7916 | * |
| 7917 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 7918 | **/ |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7919 | 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] | 7920 | { |
| 7921 | struct i40e_q_vector *q_vector; |
| 7922 | |
| 7923 | /* allocate q_vector */ |
| 7924 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 7925 | if (!q_vector) |
| 7926 | return -ENOMEM; |
| 7927 | |
| 7928 | q_vector->vsi = vsi; |
| 7929 | q_vector->v_idx = v_idx; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7930 | cpumask_set_cpu(cpu, &q_vector->affinity_mask); |
| 7931 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7932 | if (vsi->netdev) |
| 7933 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 7934 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7935 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 7936 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 7937 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 7938 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7939 | /* tie q_vector and vsi together */ |
| 7940 | vsi->q_vectors[v_idx] = q_vector; |
| 7941 | |
| 7942 | return 0; |
| 7943 | } |
| 7944 | |
| 7945 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7946 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7947 | * @vsi: the VSI being configured |
| 7948 | * |
| 7949 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 7950 | * return -ENOMEM. |
| 7951 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7952 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7953 | { |
| 7954 | struct i40e_pf *pf = vsi->back; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7955 | int err, v_idx, num_q_vectors, current_cpu; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7956 | |
| 7957 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 7958 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7959 | num_q_vectors = vsi->num_q_vectors; |
| 7960 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 7961 | num_q_vectors = 1; |
| 7962 | else |
| 7963 | return -EINVAL; |
| 7964 | |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7965 | current_cpu = cpumask_first(cpu_online_mask); |
| 7966 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7967 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7968 | err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7969 | if (err) |
| 7970 | goto err_out; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7971 | current_cpu = cpumask_next(current_cpu, cpu_online_mask); |
| 7972 | if (unlikely(current_cpu >= nr_cpu_ids)) |
| 7973 | current_cpu = cpumask_first(cpu_online_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7974 | } |
| 7975 | |
| 7976 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7977 | |
| 7978 | err_out: |
| 7979 | while (v_idx--) |
| 7980 | i40e_free_q_vector(vsi, v_idx); |
| 7981 | |
| 7982 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7983 | } |
| 7984 | |
| 7985 | /** |
| 7986 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 7987 | * @pf: board private structure to initialize |
| 7988 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7989 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7990 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7991 | int vectors = 0; |
| 7992 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7993 | |
| 7994 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7995 | vectors = i40e_init_msix(pf); |
| 7996 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7997 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7998 | I40E_FLAG_IWARP_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7999 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 8000 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 8001 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 8002 | I40E_FLAG_SRIOV_ENABLED | |
| 8003 | I40E_FLAG_FD_SB_ENABLED | |
| 8004 | I40E_FLAG_FD_ATR_ENABLED | |
| 8005 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8006 | |
| 8007 | /* rework the queue expectations without MSIX */ |
| 8008 | i40e_determine_queue_usage(pf); |
| 8009 | } |
| 8010 | } |
| 8011 | |
| 8012 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 8013 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8014 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8015 | vectors = pci_enable_msi(pf->pdev); |
| 8016 | if (vectors < 0) { |
| 8017 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 8018 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8019 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 8020 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8021 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8022 | } |
| 8023 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 8024 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8025 | 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] | 8026 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8027 | /* set up vector assignment tracking */ |
| 8028 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 8029 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8030 | if (!pf->irq_pile) { |
| 8031 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 8032 | return -ENOMEM; |
| 8033 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8034 | pf->irq_pile->num_entries = vectors; |
| 8035 | pf->irq_pile->search_hint = 0; |
| 8036 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8037 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8038 | (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] | 8039 | |
| 8040 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8041 | } |
| 8042 | |
| 8043 | /** |
| 8044 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 8045 | * @pf: board private structure |
| 8046 | * |
| 8047 | * This sets up the handler for MSIX 0, which is used to manage the |
| 8048 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 8049 | * when in MSI or Legacy interrupt mode. |
| 8050 | **/ |
| 8051 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 8052 | { |
| 8053 | struct i40e_hw *hw = &pf->hw; |
| 8054 | int err = 0; |
| 8055 | |
| 8056 | /* Only request the irq if this is the first time through, and |
| 8057 | * not when we're rebuilding after a Reset |
| 8058 | */ |
| 8059 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 8060 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8061 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8062 | if (err) { |
| 8063 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8064 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8065 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8066 | return -EFAULT; |
| 8067 | } |
| 8068 | } |
| 8069 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 8070 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8071 | |
| 8072 | /* associate no queues to the misc vector */ |
| 8073 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 8074 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 8075 | |
| 8076 | i40e_flush(hw); |
| 8077 | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 8078 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8079 | |
| 8080 | return err; |
| 8081 | } |
| 8082 | |
| 8083 | /** |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8084 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 8085 | * @vsi: vsi structure |
| 8086 | * @seed: RSS hash seed |
| 8087 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8088 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8089 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8090 | { |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8091 | struct i40e_pf *pf = vsi->back; |
| 8092 | struct i40e_hw *hw = &pf->hw; |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8093 | int ret = 0; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8094 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8095 | if (seed) { |
| 8096 | struct i40e_aqc_get_set_rss_key_data *seed_dw = |
| 8097 | (struct i40e_aqc_get_set_rss_key_data *)seed; |
| 8098 | ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw); |
| 8099 | if (ret) { |
| 8100 | dev_info(&pf->pdev->dev, |
| 8101 | "Cannot set RSS key, err %s aq_err %s\n", |
| 8102 | i40e_stat_str(hw, ret), |
| 8103 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8104 | return ret; |
| 8105 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8106 | } |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8107 | if (lut) { |
| 8108 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8109 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8110 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8111 | if (ret) { |
| 8112 | dev_info(&pf->pdev->dev, |
| 8113 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 8114 | i40e_stat_str(hw, ret), |
| 8115 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8116 | return ret; |
| 8117 | } |
| 8118 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8119 | return ret; |
| 8120 | } |
| 8121 | |
| 8122 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8123 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 8124 | * @vsi: Pointer to vsi structure |
| 8125 | * @seed: Buffter to store the hash keys |
| 8126 | * @lut: Buffer to store the lookup table entries |
| 8127 | * @lut_size: Size of buffer to store the lookup table entries |
| 8128 | * |
| 8129 | * Return 0 on success, negative on failure |
| 8130 | */ |
| 8131 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8132 | u8 *lut, u16 lut_size) |
| 8133 | { |
| 8134 | struct i40e_pf *pf = vsi->back; |
| 8135 | struct i40e_hw *hw = &pf->hw; |
| 8136 | int ret = 0; |
| 8137 | |
| 8138 | if (seed) { |
| 8139 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 8140 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 8141 | if (ret) { |
| 8142 | dev_info(&pf->pdev->dev, |
| 8143 | "Cannot get RSS key, err %s aq_err %s\n", |
| 8144 | i40e_stat_str(&pf->hw, ret), |
| 8145 | i40e_aq_str(&pf->hw, |
| 8146 | pf->hw.aq.asq_last_status)); |
| 8147 | return ret; |
| 8148 | } |
| 8149 | } |
| 8150 | |
| 8151 | if (lut) { |
| 8152 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 8153 | |
| 8154 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8155 | if (ret) { |
| 8156 | dev_info(&pf->pdev->dev, |
| 8157 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 8158 | i40e_stat_str(&pf->hw, ret), |
| 8159 | i40e_aq_str(&pf->hw, |
| 8160 | pf->hw.aq.asq_last_status)); |
| 8161 | return ret; |
| 8162 | } |
| 8163 | } |
| 8164 | |
| 8165 | return ret; |
| 8166 | } |
| 8167 | |
| 8168 | /** |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8169 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 8170 | * @vsi: VSI structure |
| 8171 | **/ |
| 8172 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 8173 | { |
| 8174 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 8175 | struct i40e_pf *pf = vsi->back; |
| 8176 | u8 *lut; |
| 8177 | int ret; |
| 8178 | |
| 8179 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) |
| 8180 | return 0; |
| 8181 | |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8182 | if (!vsi->rss_size) |
| 8183 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8184 | vsi->num_queue_pairs); |
| 8185 | if (!vsi->rss_size) |
| 8186 | return -EINVAL; |
| 8187 | |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8188 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8189 | if (!lut) |
| 8190 | return -ENOMEM; |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8191 | /* Use the user configured hash keys and lookup table if there is one, |
| 8192 | * otherwise use default |
| 8193 | */ |
| 8194 | if (vsi->rss_lut_user) |
| 8195 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8196 | else |
| 8197 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
| 8198 | if (vsi->rss_hkey_user) |
| 8199 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8200 | else |
| 8201 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8202 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 8203 | kfree(lut); |
| 8204 | |
| 8205 | return ret; |
| 8206 | } |
| 8207 | |
| 8208 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8209 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8210 | * @vsi: Pointer to vsi structure |
| 8211 | * @seed: RSS hash seed |
| 8212 | * @lut: Lookup table |
| 8213 | * @lut_size: Lookup table size |
| 8214 | * |
| 8215 | * Returns 0 on success, negative on failure |
| 8216 | **/ |
| 8217 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8218 | const u8 *lut, u16 lut_size) |
| 8219 | { |
| 8220 | struct i40e_pf *pf = vsi->back; |
| 8221 | struct i40e_hw *hw = &pf->hw; |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8222 | u16 vf_id = vsi->vf_id; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8223 | u8 i; |
| 8224 | |
| 8225 | /* Fill out hash function seed */ |
| 8226 | if (seed) { |
| 8227 | u32 *seed_dw = (u32 *)seed; |
| 8228 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8229 | if (vsi->type == I40E_VSI_MAIN) { |
| 8230 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Lihong Yang | 26f77e5 | 2017-01-30 12:29:33 -0800 | [diff] [blame] | 8231 | wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]); |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8232 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8233 | for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++) |
Lihong Yang | 26f77e5 | 2017-01-30 12:29:33 -0800 | [diff] [blame] | 8234 | wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]); |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8235 | } else { |
| 8236 | dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n"); |
| 8237 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8238 | } |
| 8239 | |
| 8240 | if (lut) { |
| 8241 | u32 *lut_dw = (u32 *)lut; |
| 8242 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8243 | if (vsi->type == I40E_VSI_MAIN) { |
| 8244 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8245 | return -EINVAL; |
| 8246 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8247 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8248 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8249 | if (lut_size != I40E_VF_HLUT_ARRAY_SIZE) |
| 8250 | return -EINVAL; |
| 8251 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
Lihong Yang | 26f77e5 | 2017-01-30 12:29:33 -0800 | [diff] [blame] | 8252 | wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]); |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8253 | } else { |
| 8254 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8255 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8256 | } |
| 8257 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8258 | |
| 8259 | return 0; |
| 8260 | } |
| 8261 | |
| 8262 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8263 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8264 | * @vsi: Pointer to VSI structure |
| 8265 | * @seed: Buffer to store the keys |
| 8266 | * @lut: Buffer to store the lookup table entries |
| 8267 | * @lut_size: Size of buffer to store the lookup table entries |
| 8268 | * |
| 8269 | * Returns 0 on success, negative on failure |
| 8270 | */ |
| 8271 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8272 | u8 *lut, u16 lut_size) |
| 8273 | { |
| 8274 | struct i40e_pf *pf = vsi->back; |
| 8275 | struct i40e_hw *hw = &pf->hw; |
| 8276 | u16 i; |
| 8277 | |
| 8278 | if (seed) { |
| 8279 | u32 *seed_dw = (u32 *)seed; |
| 8280 | |
| 8281 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8282 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8283 | } |
| 8284 | if (lut) { |
| 8285 | u32 *lut_dw = (u32 *)lut; |
| 8286 | |
| 8287 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8288 | return -EINVAL; |
| 8289 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8290 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8291 | } |
| 8292 | |
| 8293 | return 0; |
| 8294 | } |
| 8295 | |
| 8296 | /** |
| 8297 | * i40e_config_rss - Configure RSS keys and lut |
| 8298 | * @vsi: Pointer to VSI structure |
| 8299 | * @seed: RSS hash seed |
| 8300 | * @lut: Lookup table |
| 8301 | * @lut_size: Lookup table size |
| 8302 | * |
| 8303 | * Returns 0 on success, negative on failure |
| 8304 | */ |
| 8305 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8306 | { |
| 8307 | struct i40e_pf *pf = vsi->back; |
| 8308 | |
| 8309 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8310 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8311 | else |
| 8312 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8313 | } |
| 8314 | |
| 8315 | /** |
| 8316 | * i40e_get_rss - Get RSS keys and lut |
| 8317 | * @vsi: Pointer to VSI structure |
| 8318 | * @seed: Buffer to store the keys |
| 8319 | * @lut: Buffer to store the lookup table entries |
| 8320 | * lut_size: Size of buffer to store the lookup table entries |
| 8321 | * |
| 8322 | * Returns 0 on success, negative on failure |
| 8323 | */ |
| 8324 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8325 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8326 | struct i40e_pf *pf = vsi->back; |
| 8327 | |
| 8328 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8329 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8330 | else |
| 8331 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8332 | } |
| 8333 | |
| 8334 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8335 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8336 | * @pf: Pointer to board private structure |
| 8337 | * @lut: Lookup table |
| 8338 | * @rss_table_size: Lookup table size |
| 8339 | * @rss_size: Range of queue number for hashing |
| 8340 | */ |
Alan Brady | f158235 | 2016-08-24 11:33:46 -0700 | [diff] [blame] | 8341 | void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8342 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8343 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8344 | u16 i; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8345 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8346 | for (i = 0; i < rss_table_size; i++) |
| 8347 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8348 | } |
| 8349 | |
| 8350 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8351 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8352 | * @pf: board private structure |
| 8353 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8354 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8355 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8356 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8357 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8358 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8359 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8360 | u32 reg_val; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8361 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8362 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8363 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8364 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8365 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 8366 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8367 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8368 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8369 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8370 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8371 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8372 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8373 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8374 | reg_val = (pf->rss_table_size == 512) ? |
| 8375 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8376 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8377 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8378 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8379 | /* Determine the RSS size of the VSI */ |
Harshitha Ramamurthy | f25571b | 2017-02-21 15:55:40 -0800 | [diff] [blame] | 8380 | if (!vsi->rss_size) { |
| 8381 | u16 qcount; |
| 8382 | |
| 8383 | qcount = vsi->num_queue_pairs / vsi->tc_config.numtc; |
| 8384 | vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount); |
| 8385 | } |
Mitch Williams | a4fa59c | 2016-09-12 14:18:43 -0700 | [diff] [blame] | 8386 | if (!vsi->rss_size) |
| 8387 | return -EINVAL; |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8388 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8389 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8390 | if (!lut) |
| 8391 | return -ENOMEM; |
| 8392 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8393 | /* Use user configured lut if there is one, otherwise use default */ |
| 8394 | if (vsi->rss_lut_user) |
| 8395 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8396 | else |
| 8397 | 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] | 8398 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8399 | /* Use user configured hash key if there is one, otherwise |
| 8400 | * use default. |
| 8401 | */ |
| 8402 | if (vsi->rss_hkey_user) |
| 8403 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8404 | else |
| 8405 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8406 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8407 | kfree(lut); |
| 8408 | |
| 8409 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8410 | } |
| 8411 | |
| 8412 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8413 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8414 | * @pf: board private structure |
| 8415 | * @queue_count: the requested queue count for rss. |
| 8416 | * |
| 8417 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8418 | * count which may be different from the requested queue count. |
| 8419 | **/ |
| 8420 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8421 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8422 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8423 | int new_rss_size; |
| 8424 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8425 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8426 | return 0; |
| 8427 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8428 | 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] | 8429 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8430 | if (queue_count != vsi->num_queue_pairs) { |
Harshitha Ramamurthy | f25571b | 2017-02-21 15:55:40 -0800 | [diff] [blame] | 8431 | u16 qcount; |
| 8432 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8433 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8434 | i40e_prep_for_reset(pf); |
| 8435 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8436 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8437 | |
| 8438 | i40e_reset_and_rebuild(pf, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8439 | |
| 8440 | /* Discard the user configured hash keys and lut, if less |
| 8441 | * queues are enabled. |
| 8442 | */ |
| 8443 | if (queue_count < vsi->rss_size) { |
| 8444 | i40e_clear_rss_config_user(vsi); |
| 8445 | dev_dbg(&pf->pdev->dev, |
| 8446 | "discard user configured hash keys and lut\n"); |
| 8447 | } |
| 8448 | |
| 8449 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Harshitha Ramamurthy | f25571b | 2017-02-21 15:55:40 -0800 | [diff] [blame] | 8450 | qcount = vsi->num_queue_pairs / vsi->tc_config.numtc; |
| 8451 | vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8452 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8453 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8454 | } |
Lihong Yang | 1281505 | 2016-09-27 11:28:48 -0700 | [diff] [blame] | 8455 | dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n", |
| 8456 | vsi->req_queue_pairs, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8457 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8458 | } |
| 8459 | |
| 8460 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8461 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 8462 | * @pf: board private structure |
| 8463 | **/ |
| 8464 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 8465 | { |
| 8466 | i40e_status status; |
| 8467 | bool min_valid, max_valid; |
| 8468 | u32 max_bw, min_bw; |
| 8469 | |
| 8470 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8471 | &min_valid, &max_valid); |
| 8472 | |
| 8473 | if (!status) { |
| 8474 | if (min_valid) |
| 8475 | pf->npar_min_bw = min_bw; |
| 8476 | if (max_valid) |
| 8477 | pf->npar_max_bw = max_bw; |
| 8478 | } |
| 8479 | |
| 8480 | return status; |
| 8481 | } |
| 8482 | |
| 8483 | /** |
| 8484 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 8485 | * @pf: board private structure |
| 8486 | **/ |
| 8487 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 8488 | { |
| 8489 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8490 | i40e_status status; |
| 8491 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8492 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8493 | bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8494 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8495 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 8496 | |
| 8497 | /* Set the new bandwidths */ |
| 8498 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8499 | |
| 8500 | return status; |
| 8501 | } |
| 8502 | |
| 8503 | /** |
| 8504 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 8505 | * @pf: board private structure |
| 8506 | **/ |
| 8507 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 8508 | { |
| 8509 | /* Commit temporary BW setting to permanent NVM image */ |
| 8510 | enum i40e_admin_queue_err last_aq_status; |
| 8511 | i40e_status ret; |
| 8512 | u16 nvm_word; |
| 8513 | |
| 8514 | if (pf->hw.partition_id != 1) { |
| 8515 | dev_info(&pf->pdev->dev, |
| 8516 | "Commit BW only works on partition 1! This is partition %d", |
| 8517 | pf->hw.partition_id); |
| 8518 | ret = I40E_NOT_SUPPORTED; |
| 8519 | goto bw_commit_out; |
| 8520 | } |
| 8521 | |
| 8522 | /* Acquire NVM for read access */ |
| 8523 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8524 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8525 | if (ret) { |
| 8526 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8527 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8528 | i40e_stat_str(&pf->hw, ret), |
| 8529 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8530 | goto bw_commit_out; |
| 8531 | } |
| 8532 | |
| 8533 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8534 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8535 | I40E_SR_NVM_CONTROL_WORD, |
| 8536 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8537 | false, NULL); |
| 8538 | /* Save off last admin queue command status before releasing |
| 8539 | * the NVM |
| 8540 | */ |
| 8541 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8542 | i40e_release_nvm(&pf->hw); |
| 8543 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8544 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8545 | i40e_stat_str(&pf->hw, ret), |
| 8546 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8547 | goto bw_commit_out; |
| 8548 | } |
| 8549 | |
| 8550 | /* Wait a bit for NVM release to complete */ |
| 8551 | msleep(50); |
| 8552 | |
| 8553 | /* Acquire NVM for write access */ |
| 8554 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8555 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8556 | if (ret) { |
| 8557 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8558 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8559 | i40e_stat_str(&pf->hw, ret), |
| 8560 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8561 | goto bw_commit_out; |
| 8562 | } |
| 8563 | /* Write it back out unchanged to initiate update NVM, |
| 8564 | * which will force a write of the shadow (alt) RAM to |
| 8565 | * the NVM - thus storing the bandwidth values permanently. |
| 8566 | */ |
| 8567 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8568 | I40E_SR_NVM_CONTROL_WORD, |
| 8569 | 0x10, sizeof(nvm_word), |
| 8570 | &nvm_word, true, NULL); |
| 8571 | /* Save off last admin queue command status before releasing |
| 8572 | * the NVM |
| 8573 | */ |
| 8574 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8575 | i40e_release_nvm(&pf->hw); |
| 8576 | if (ret) |
| 8577 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8578 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8579 | i40e_stat_str(&pf->hw, ret), |
| 8580 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8581 | bw_commit_out: |
| 8582 | |
| 8583 | return ret; |
| 8584 | } |
| 8585 | |
| 8586 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8587 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8588 | * @pf: board private structure to initialize |
| 8589 | * |
| 8590 | * i40e_sw_init initializes the Adapter private data structure. |
| 8591 | * Fields are initialized based on PCI device information and |
| 8592 | * OS network device settings (MTU size). |
| 8593 | **/ |
| 8594 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8595 | { |
| 8596 | int err = 0; |
| 8597 | int size; |
| 8598 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8599 | /* Set default capability flags */ |
| 8600 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8601 | I40E_FLAG_MSI_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8602 | I40E_FLAG_MSIX_ENABLED; |
| 8603 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8604 | /* Set default ITR */ |
| 8605 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8606 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8607 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8608 | /* Depending on PF configurations, it is possible that the RSS |
| 8609 | * maximum might end up larger than the available queues |
| 8610 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8611 | 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] | 8612 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8613 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8614 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8615 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8616 | if (pf->hw.func_caps.rss) { |
| 8617 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8618 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8619 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8620 | } |
| 8621 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8622 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8623 | 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] | 8624 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8625 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8626 | if (i40e_get_npar_bw_setting(pf)) |
| 8627 | dev_warn(&pf->pdev->dev, |
| 8628 | "Could not get NPAR bw settings\n"); |
| 8629 | else |
| 8630 | dev_info(&pf->pdev->dev, |
| 8631 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 8632 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8633 | } |
| 8634 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8635 | /* FW/NVM is not yet fixed in this regard */ |
| 8636 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8637 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8638 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8639 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8640 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8641 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8642 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8643 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8644 | else |
| 8645 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8646 | pf->fdir_pf_filter_count = |
| 8647 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8648 | pf->hw.fdir_shared_filter_count = |
| 8649 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8650 | } |
| 8651 | |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 8652 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8653 | (((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] | 8654 | (pf->hw.aq.fw_maj_ver < 4))) { |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8655 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8656 | /* No DCB support for FW < v4.33 */ |
| 8657 | pf->flags |= I40E_FLAG_NO_DCB_SUPPORT; |
| 8658 | } |
| 8659 | |
| 8660 | /* Disable FW LLDP if FW < v4.3 */ |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 8661 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8662 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 8663 | (pf->hw.aq.fw_maj_ver < 4))) |
| 8664 | pf->flags |= I40E_FLAG_STOP_FW_LLDP; |
| 8665 | |
| 8666 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 8667 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8668 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 8669 | (pf->hw.aq.fw_maj_ver >= 5))) |
| 8670 | pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8671 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8672 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8673 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8674 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 8675 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8676 | } |
| 8677 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8678 | if (pf->hw.func_caps.iwarp) { |
| 8679 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 8680 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 8681 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 8682 | } |
| 8683 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8684 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 8685 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8686 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 8687 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 8688 | pf->num_req_vfs = min_t(int, |
| 8689 | pf->hw.func_caps.num_vfs, |
| 8690 | I40E_MAX_VF_COUNT); |
| 8691 | } |
| 8692 | #endif /* CONFIG_PCI_IOV */ |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8693 | if (pf->hw.mac.type == I40E_MAC_X722) { |
Joshua Hay | 1d68005 | 2016-12-12 15:44:08 -0800 | [diff] [blame] | 8694 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE |
| 8695 | | I40E_FLAG_128_QP_RSS_CAPABLE |
| 8696 | | I40E_FLAG_HW_ATR_EVICT_CAPABLE |
| 8697 | | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE |
| 8698 | | I40E_FLAG_WB_ON_ITR_CAPABLE |
| 8699 | | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE |
| 8700 | | I40E_FLAG_NO_PCI_LINK_CHECK |
| 8701 | | I40E_FLAG_USE_SET_LLDP_MIB |
| 8702 | | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE |
| 8703 | | I40E_FLAG_PTP_L4_CAPABLE |
| 8704 | | I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE; |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8705 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 8706 | ((pf->hw.aq.api_maj_ver == 1) && |
| 8707 | (pf->hw.aq.api_min_ver > 4))) { |
| 8708 | /* Supported in FW API version higher than 1.4 */ |
| 8709 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 8710 | pf->hw_disabled_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 8711 | } else { |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 8712 | pf->hw_disabled_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8713 | } |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8714 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8715 | pf->eeprom_version = 0xDEAD; |
| 8716 | pf->lan_veb = I40E_NO_VEB; |
| 8717 | pf->lan_vsi = I40E_NO_VSI; |
| 8718 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 8719 | /* By default FW has this off for performance reasons */ |
| 8720 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 8721 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8722 | /* set up queue assignment tracking */ |
| 8723 | size = sizeof(struct i40e_lump_tracking) |
| 8724 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 8725 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 8726 | if (!pf->qp_pile) { |
| 8727 | err = -ENOMEM; |
| 8728 | goto sw_init_done; |
| 8729 | } |
| 8730 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 8731 | pf->qp_pile->search_hint = 0; |
| 8732 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 8733 | pf->tx_timeout_recovery_level = 1; |
| 8734 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8735 | mutex_init(&pf->switch_mutex); |
| 8736 | |
Greg Rose | c668a12 | 2015-02-26 16:10:39 +0000 | [diff] [blame] | 8737 | /* If NPAR is enabled nudge the Tx scheduler */ |
| 8738 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) |
| 8739 | i40e_set_npar_bw_setting(pf); |
| 8740 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8741 | sw_init_done: |
| 8742 | return err; |
| 8743 | } |
| 8744 | |
| 8745 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8746 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 8747 | * @pf: board private structure to initialize |
| 8748 | * @features: the feature set that the stack is suggesting |
| 8749 | * |
| 8750 | * returns a bool to indicate if reset needs to happen |
| 8751 | **/ |
| 8752 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 8753 | { |
| 8754 | bool need_reset = false; |
| 8755 | |
| 8756 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 8757 | * the state changed, we need to reset. |
| 8758 | */ |
| 8759 | if (features & NETIF_F_NTUPLE) { |
| 8760 | /* Enable filters and mark for reset */ |
| 8761 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 8762 | need_reset = true; |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 8763 | /* enable FD_SB only if there is MSI-X vector */ |
| 8764 | if (pf->num_fdsb_msix > 0) |
| 8765 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8766 | } else { |
| 8767 | /* turn off filters, mark for reset and clear SW filter list */ |
| 8768 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8769 | need_reset = true; |
| 8770 | i40e_fdir_filter_exit(pf); |
| 8771 | } |
| 8772 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 8773 | pf->hw_disabled_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 8774 | /* reset fd counters */ |
Jacob Keller | 097dbf5 | 2017-02-06 14:38:46 -0800 | [diff] [blame] | 8775 | pf->fd_add_err = 0; |
| 8776 | pf->fd_atr_cnt = 0; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8777 | /* if ATR was auto disabled it can be re-enabled. */ |
| 8778 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 8779 | (pf->hw_disabled_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
| 8780 | pf->hw_disabled_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 8781 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 8782 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
| 8783 | } |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8784 | } |
| 8785 | return need_reset; |
| 8786 | } |
| 8787 | |
| 8788 | /** |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8789 | * i40e_clear_rss_lut - clear the rx hash lookup table |
| 8790 | * @vsi: the VSI being configured |
| 8791 | **/ |
| 8792 | static void i40e_clear_rss_lut(struct i40e_vsi *vsi) |
| 8793 | { |
| 8794 | struct i40e_pf *pf = vsi->back; |
| 8795 | struct i40e_hw *hw = &pf->hw; |
| 8796 | u16 vf_id = vsi->vf_id; |
| 8797 | u8 i; |
| 8798 | |
| 8799 | if (vsi->type == I40E_VSI_MAIN) { |
| 8800 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8801 | wr32(hw, I40E_PFQF_HLUT(i), 0); |
| 8802 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8803 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8804 | i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0); |
| 8805 | } else { |
| 8806 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8807 | } |
| 8808 | } |
| 8809 | |
| 8810 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8811 | * i40e_set_features - set the netdev feature flags |
| 8812 | * @netdev: ptr to the netdev being adjusted |
| 8813 | * @features: the feature set that the stack is suggesting |
| 8814 | **/ |
| 8815 | static int i40e_set_features(struct net_device *netdev, |
| 8816 | netdev_features_t features) |
| 8817 | { |
| 8818 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8819 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8820 | struct i40e_pf *pf = vsi->back; |
| 8821 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8822 | |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8823 | if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH)) |
| 8824 | i40e_pf_config_rss(pf); |
| 8825 | else if (!(features & NETIF_F_RXHASH) && |
| 8826 | netdev->features & NETIF_F_RXHASH) |
| 8827 | i40e_clear_rss_lut(vsi); |
| 8828 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8829 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8830 | i40e_vlan_stripping_enable(vsi); |
| 8831 | else |
| 8832 | i40e_vlan_stripping_disable(vsi); |
| 8833 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8834 | need_reset = i40e_set_ntuple(pf, features); |
| 8835 | |
| 8836 | if (need_reset) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8837 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8838 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8839 | return 0; |
| 8840 | } |
| 8841 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8842 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8843 | * 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] | 8844 | * @pf: board private structure |
| 8845 | * @port: The UDP port to look up |
| 8846 | * |
| 8847 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 8848 | **/ |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 8849 | 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] | 8850 | { |
| 8851 | u8 i; |
| 8852 | |
| 8853 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8854 | if (pf->udp_ports[i].index == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8855 | return i; |
| 8856 | } |
| 8857 | |
| 8858 | return i; |
| 8859 | } |
| 8860 | |
| 8861 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8862 | * 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] | 8863 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8864 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8865 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8866 | static void i40e_udp_tunnel_add(struct net_device *netdev, |
| 8867 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8868 | { |
| 8869 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8870 | struct i40e_vsi *vsi = np->vsi; |
| 8871 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 8872 | u16 port = ntohs(ti->port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8873 | u8 next_idx; |
| 8874 | u8 idx; |
| 8875 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8876 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8877 | |
| 8878 | /* Check if port already exists */ |
| 8879 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 8880 | netdev_info(netdev, "port %d already offloaded\n", port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8881 | return; |
| 8882 | } |
| 8883 | |
| 8884 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8885 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8886 | |
| 8887 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8888 | 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] | 8889 | port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8890 | return; |
| 8891 | } |
| 8892 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8893 | switch (ti->type) { |
| 8894 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8895 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 8896 | break; |
| 8897 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8898 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8899 | return; |
| 8900 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 8901 | break; |
| 8902 | default: |
| 8903 | return; |
| 8904 | } |
| 8905 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8906 | /* New port: add it and mark its index in the bitmap */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8907 | pf->udp_ports[next_idx].index = port; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8908 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8909 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8910 | } |
| 8911 | |
| 8912 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8913 | * 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] | 8914 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8915 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8916 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8917 | static void i40e_udp_tunnel_del(struct net_device *netdev, |
| 8918 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8919 | { |
| 8920 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8921 | struct i40e_vsi *vsi = np->vsi; |
| 8922 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 8923 | u16 port = ntohs(ti->port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8924 | u8 idx; |
| 8925 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8926 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8927 | |
| 8928 | /* Check if port already exists */ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8929 | if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS) |
| 8930 | goto not_found; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8931 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8932 | switch (ti->type) { |
| 8933 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8934 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN) |
| 8935 | goto not_found; |
| 8936 | break; |
| 8937 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8938 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE) |
| 8939 | goto not_found; |
| 8940 | break; |
| 8941 | default: |
| 8942 | goto not_found; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8943 | } |
| 8944 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8945 | /* if port exists, set it to 0 (mark for deletion) |
| 8946 | * and make it pending |
| 8947 | */ |
| 8948 | pf->udp_ports[idx].index = 0; |
| 8949 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8950 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8951 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8952 | return; |
| 8953 | not_found: |
| 8954 | netdev_warn(netdev, "UDP port %d was not found, not deleting\n", |
Jacob Keller | fe0b0cd | 2017-02-06 14:38:38 -0800 | [diff] [blame] | 8955 | port); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8956 | } |
| 8957 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8958 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 8959 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8960 | { |
| 8961 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8962 | struct i40e_pf *pf = np->vsi->back; |
| 8963 | struct i40e_hw *hw = &pf->hw; |
| 8964 | |
| 8965 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 8966 | return -EOPNOTSUPP; |
| 8967 | |
| 8968 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 8969 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 8970 | |
| 8971 | return 0; |
| 8972 | } |
| 8973 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 8974 | /** |
| 8975 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 8976 | * @ndm: the input from the stack |
| 8977 | * @tb: pointer to array of nladdr (unused) |
| 8978 | * @dev: the net device pointer |
| 8979 | * @addr: the MAC address entry being added |
| 8980 | * @flags: instructions from stack about fdb operation |
| 8981 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8982 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 8983 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8984 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8985 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8986 | { |
| 8987 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8988 | struct i40e_pf *pf = np->vsi->back; |
| 8989 | int err = 0; |
| 8990 | |
| 8991 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 8992 | return -EOPNOTSUPP; |
| 8993 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 8994 | if (vid) { |
| 8995 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 8996 | return -EINVAL; |
| 8997 | } |
| 8998 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8999 | /* Hardware does not support aging addresses so if a |
| 9000 | * ndm_state is given only allow permanent addresses |
| 9001 | */ |
| 9002 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 9003 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 9004 | return -EINVAL; |
| 9005 | } |
| 9006 | |
| 9007 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 9008 | err = dev_uc_add_excl(dev, addr); |
| 9009 | else if (is_multicast_ether_addr(addr)) |
| 9010 | err = dev_mc_add_excl(dev, addr); |
| 9011 | else |
| 9012 | err = -EINVAL; |
| 9013 | |
| 9014 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 9015 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 9016 | err = 0; |
| 9017 | |
| 9018 | return err; |
| 9019 | } |
| 9020 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9021 | /** |
| 9022 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 9023 | * @dev: the netdev being configured |
| 9024 | * @nlh: RTNL message |
| 9025 | * |
| 9026 | * Inserts a new hardware bridge if not already created and |
| 9027 | * enables the bridging mode requested (VEB or VEPA). If the |
| 9028 | * hardware bridge has already been inserted and the request |
| 9029 | * is to change the mode then that requires a PF reset to |
| 9030 | * allow rebuild of the components with required hardware |
| 9031 | * bridge mode enabled. |
| 9032 | **/ |
| 9033 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 9034 | struct nlmsghdr *nlh, |
| 9035 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9036 | { |
| 9037 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9038 | struct i40e_vsi *vsi = np->vsi; |
| 9039 | struct i40e_pf *pf = vsi->back; |
| 9040 | struct i40e_veb *veb = NULL; |
| 9041 | struct nlattr *attr, *br_spec; |
| 9042 | int i, rem; |
| 9043 | |
| 9044 | /* Only for PF VSI for now */ |
| 9045 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9046 | return -EOPNOTSUPP; |
| 9047 | |
| 9048 | /* Find the HW bridge for PF VSI */ |
| 9049 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9050 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9051 | veb = pf->veb[i]; |
| 9052 | } |
| 9053 | |
| 9054 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 9055 | |
| 9056 | nla_for_each_nested(attr, br_spec, rem) { |
| 9057 | __u16 mode; |
| 9058 | |
| 9059 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 9060 | continue; |
| 9061 | |
| 9062 | mode = nla_get_u16(attr); |
| 9063 | if ((mode != BRIDGE_MODE_VEPA) && |
| 9064 | (mode != BRIDGE_MODE_VEB)) |
| 9065 | return -EINVAL; |
| 9066 | |
| 9067 | /* Insert a new HW bridge */ |
| 9068 | if (!veb) { |
| 9069 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9070 | vsi->tc_config.enabled_tc); |
| 9071 | if (veb) { |
| 9072 | veb->bridge_mode = mode; |
| 9073 | i40e_config_bridge_mode(veb); |
| 9074 | } else { |
| 9075 | /* No Bridge HW offload available */ |
| 9076 | return -ENOENT; |
| 9077 | } |
| 9078 | break; |
| 9079 | } else if (mode != veb->bridge_mode) { |
| 9080 | /* Existing HW bridge but different mode needs reset */ |
| 9081 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9082 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 9083 | if (mode == BRIDGE_MODE_VEB) |
| 9084 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 9085 | else |
| 9086 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9087 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9088 | break; |
| 9089 | } |
| 9090 | } |
| 9091 | |
| 9092 | return 0; |
| 9093 | } |
| 9094 | |
| 9095 | /** |
| 9096 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 9097 | * @skb: skb buff |
| 9098 | * @pid: process id |
| 9099 | * @seq: RTNL message seq # |
| 9100 | * @dev: the netdev being configured |
| 9101 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 9102 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9103 | * |
| 9104 | * Return the mode in which the hardware bridge is operating in |
| 9105 | * i.e VEB or VEPA. |
| 9106 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9107 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 9108 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 9109 | u32 __always_unused filter_mask, |
| 9110 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9111 | { |
| 9112 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9113 | struct i40e_vsi *vsi = np->vsi; |
| 9114 | struct i40e_pf *pf = vsi->back; |
| 9115 | struct i40e_veb *veb = NULL; |
| 9116 | int i; |
| 9117 | |
| 9118 | /* Only for PF VSI for now */ |
| 9119 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9120 | return -EOPNOTSUPP; |
| 9121 | |
| 9122 | /* Find the HW bridge for the PF VSI */ |
| 9123 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9124 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9125 | veb = pf->veb[i]; |
| 9126 | } |
| 9127 | |
| 9128 | if (!veb) |
| 9129 | return 0; |
| 9130 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9131 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Huaibin Wang | 599b076 | 2016-09-26 09:51:18 +0200 | [diff] [blame] | 9132 | 0, 0, nlflags, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9133 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9134 | |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9135 | /** |
| 9136 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 9137 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 9138 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9139 | * @features: Offload features that the stack believes apply |
| 9140 | **/ |
| 9141 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 9142 | struct net_device *dev, |
| 9143 | netdev_features_t features) |
| 9144 | { |
Alexander Duyck | f114dca | 2016-10-25 16:08:46 -0700 | [diff] [blame] | 9145 | size_t len; |
| 9146 | |
| 9147 | /* No point in doing any of this if neither checksum nor GSO are |
| 9148 | * being requested for this frame. We can rule out both by just |
| 9149 | * checking for CHECKSUM_PARTIAL |
| 9150 | */ |
| 9151 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 9152 | return features; |
| 9153 | |
| 9154 | /* We cannot support GSO if the MSS is going to be less than |
| 9155 | * 64 bytes. If it is then we need to drop support for GSO. |
| 9156 | */ |
| 9157 | if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64)) |
| 9158 | features &= ~NETIF_F_GSO_MASK; |
| 9159 | |
| 9160 | /* MACLEN can support at most 63 words */ |
| 9161 | len = skb_network_header(skb) - skb->data; |
| 9162 | if (len & ~(63 * 2)) |
| 9163 | goto out_err; |
| 9164 | |
| 9165 | /* IPLEN and EIPLEN can support at most 127 dwords */ |
| 9166 | len = skb_transport_header(skb) - skb_network_header(skb); |
| 9167 | if (len & ~(127 * 4)) |
| 9168 | goto out_err; |
| 9169 | |
| 9170 | if (skb->encapsulation) { |
| 9171 | /* L4TUNLEN can support 127 words */ |
| 9172 | len = skb_inner_network_header(skb) - skb_transport_header(skb); |
| 9173 | if (len & ~(127 * 2)) |
| 9174 | goto out_err; |
| 9175 | |
| 9176 | /* IPLEN can support at most 127 dwords */ |
| 9177 | len = skb_inner_transport_header(skb) - |
| 9178 | skb_inner_network_header(skb); |
| 9179 | if (len & ~(127 * 4)) |
| 9180 | goto out_err; |
| 9181 | } |
| 9182 | |
| 9183 | /* No need to validate L4LEN as TCP is the only protocol with a |
| 9184 | * a flexible value and we support all possible values supported |
| 9185 | * by TCP, which is at most 15 dwords |
| 9186 | */ |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9187 | |
| 9188 | return features; |
Alexander Duyck | f114dca | 2016-10-25 16:08:46 -0700 | [diff] [blame] | 9189 | out_err: |
| 9190 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9191 | } |
| 9192 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 9193 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9194 | .ndo_open = i40e_open, |
| 9195 | .ndo_stop = i40e_close, |
| 9196 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 9197 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 9198 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 9199 | .ndo_validate_addr = eth_validate_addr, |
| 9200 | .ndo_set_mac_address = i40e_set_mac, |
| 9201 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 9202 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9203 | .ndo_tx_timeout = i40e_tx_timeout, |
| 9204 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 9205 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 9206 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9207 | .ndo_poll_controller = i40e_netpoll, |
| 9208 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9209 | .ndo_setup_tc = __i40e_setup_tc, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9210 | .ndo_set_features = i40e_set_features, |
| 9211 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 9212 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9213 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9214 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 9215 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 9216 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Anjali Singhai Jain | c3bbbd2 | 2016-04-01 03:56:07 -0700 | [diff] [blame] | 9217 | .ndo_set_vf_trust = i40e_ndo_set_vf_trust, |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9218 | .ndo_udp_tunnel_add = i40e_udp_tunnel_add, |
| 9219 | .ndo_udp_tunnel_del = i40e_udp_tunnel_del, |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9220 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9221 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9222 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9223 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 9224 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9225 | }; |
| 9226 | |
| 9227 | /** |
| 9228 | * i40e_config_netdev - Setup the netdev flags |
| 9229 | * @vsi: the VSI being configured |
| 9230 | * |
| 9231 | * Returns 0 on success, negative value on failure |
| 9232 | **/ |
| 9233 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 9234 | { |
| 9235 | struct i40e_pf *pf = vsi->back; |
| 9236 | struct i40e_hw *hw = &pf->hw; |
| 9237 | struct i40e_netdev_priv *np; |
| 9238 | struct net_device *netdev; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 9239 | u8 broadcast[ETH_ALEN]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9240 | u8 mac_addr[ETH_ALEN]; |
| 9241 | int etherdev_size; |
| 9242 | |
| 9243 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9244 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9245 | if (!netdev) |
| 9246 | return -ENOMEM; |
| 9247 | |
| 9248 | vsi->netdev = netdev; |
| 9249 | np = netdev_priv(netdev); |
| 9250 | np->vsi = vsi; |
| 9251 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9252 | netdev->hw_enc_features |= NETIF_F_SG | |
| 9253 | NETIF_F_IP_CSUM | |
| 9254 | NETIF_F_IPV6_CSUM | |
| 9255 | NETIF_F_HIGHDMA | |
| 9256 | NETIF_F_SOFT_FEATURES | |
| 9257 | NETIF_F_TSO | |
| 9258 | NETIF_F_TSO_ECN | |
| 9259 | NETIF_F_TSO6 | |
| 9260 | NETIF_F_GSO_GRE | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9261 | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 9262 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 9263 | NETIF_F_GSO_IPXIP6 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9264 | NETIF_F_GSO_UDP_TUNNEL | |
| 9265 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9266 | NETIF_F_GSO_PARTIAL | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9267 | NETIF_F_SCTP_CRC | |
| 9268 | NETIF_F_RXHASH | |
| 9269 | NETIF_F_RXCSUM | |
Jesse Brandeburg | 5afdaaa | 2015-12-10 11:38:50 -0800 | [diff] [blame] | 9270 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9271 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9272 | if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)) |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9273 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
| 9274 | |
| 9275 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9276 | |
| 9277 | /* record features VLANs can make use of */ |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9278 | netdev->vlan_features |= netdev->hw_enc_features | |
| 9279 | NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9280 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9281 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9282 | netdev->hw_features |= NETIF_F_NTUPLE; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9283 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9284 | netdev->hw_features |= netdev->hw_enc_features | |
| 9285 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9286 | NETIF_F_HW_VLAN_CTAG_RX; |
| 9287 | |
| 9288 | netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9289 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9290 | |
| 9291 | if (vsi->type == I40E_VSI_MAIN) { |
| 9292 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9293 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Filip Sadowski | 3954b39 | 2017-01-30 12:29:34 -0800 | [diff] [blame] | 9294 | /* The following steps are necessary to properly keep track of |
| 9295 | * MAC-VLAN filters loaded into firmware - first we remove |
| 9296 | * filter that is automatically generated by firmware and then |
| 9297 | * add new filter both to the driver hash table and firmware. |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 9298 | */ |
| 9299 | i40e_rm_default_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9300 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 9301 | i40e_add_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9302 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9303 | } else { |
| 9304 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 9305 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 9306 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9307 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9308 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9309 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 9310 | i40e_add_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9311 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9312 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9313 | |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 9314 | /* Add the broadcast filter so that we initially will receive |
| 9315 | * broadcast packets. Note that when a new VLAN is first added the |
| 9316 | * driver will convert all filters marked I40E_VLAN_ANY into VLAN |
| 9317 | * specific filters as part of transitioning into "vlan" operation. |
| 9318 | * When more VLANs are added, the driver will copy each existing MAC |
| 9319 | * filter and add it for the new VLAN. |
| 9320 | * |
| 9321 | * Broadcast filters are handled specially by |
| 9322 | * i40e_sync_filters_subtask, as the driver must to set the broadcast |
| 9323 | * promiscuous bit instead of adding this directly as a MAC/VLAN |
| 9324 | * filter. The subtask will update the correct broadcast promiscuous |
| 9325 | * bits as VLANs become active or inactive. |
| 9326 | */ |
| 9327 | eth_broadcast_addr(broadcast); |
| 9328 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 9329 | i40e_add_mac_filter(vsi, broadcast); |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 9330 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 9331 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9332 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9333 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9334 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9335 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9336 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9337 | /* Setup netdev TC information */ |
| 9338 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9339 | |
| 9340 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9341 | netdev->watchdog_timeo = 5 * HZ; |
| 9342 | i40e_set_ethtool_ops(netdev); |
| 9343 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 9344 | /* MTU range: 68 - 9706 */ |
| 9345 | netdev->min_mtu = ETH_MIN_MTU; |
| 9346 | netdev->max_mtu = I40E_MAX_RXBUFFER - |
| 9347 | (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
| 9348 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9349 | return 0; |
| 9350 | } |
| 9351 | |
| 9352 | /** |
| 9353 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9354 | * @vsi: the VSI being removed |
| 9355 | * |
| 9356 | * Returns 0 on success, negative value on failure |
| 9357 | **/ |
| 9358 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9359 | { |
| 9360 | /* remove default VSI is not allowed */ |
| 9361 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9362 | return; |
| 9363 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9364 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9365 | } |
| 9366 | |
| 9367 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9368 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9369 | * @vsi: the VSI being queried |
| 9370 | * |
| 9371 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9372 | **/ |
| 9373 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9374 | { |
| 9375 | struct i40e_veb *veb; |
| 9376 | struct i40e_pf *pf = vsi->back; |
| 9377 | |
| 9378 | /* Uplink is not a bridge so default to VEB */ |
| 9379 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9380 | return 1; |
| 9381 | |
| 9382 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9383 | if (!veb) { |
| 9384 | dev_info(&pf->pdev->dev, |
| 9385 | "There is no veb associated with the bridge\n"); |
| 9386 | return -ENOENT; |
| 9387 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9388 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9389 | /* Uplink is a bridge in VEPA mode */ |
| 9390 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9391 | return 0; |
| 9392 | } else { |
| 9393 | /* Uplink is a bridge in VEB mode */ |
| 9394 | return 1; |
| 9395 | } |
| 9396 | |
| 9397 | /* VEPA is now default bridge, so return 0 */ |
| 9398 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9399 | } |
| 9400 | |
| 9401 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9402 | * i40e_add_vsi - Add a VSI to the switch |
| 9403 | * @vsi: the VSI being configured |
| 9404 | * |
| 9405 | * This initializes a VSI context depending on the VSI type to be added and |
| 9406 | * passes it down to the add_vsi aq command. |
| 9407 | **/ |
| 9408 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9409 | { |
| 9410 | int ret = -ENODEV; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9411 | struct i40e_pf *pf = vsi->back; |
| 9412 | struct i40e_hw *hw = &pf->hw; |
| 9413 | struct i40e_vsi_context ctxt; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9414 | struct i40e_mac_filter *f; |
| 9415 | struct hlist_node *h; |
| 9416 | int bkt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9417 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9418 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9419 | int f_count = 0; |
| 9420 | |
| 9421 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9422 | switch (vsi->type) { |
| 9423 | case I40E_VSI_MAIN: |
| 9424 | /* The PF's main VSI is already setup as part of the |
| 9425 | * device initialization, so we'll not bother with |
| 9426 | * the add_vsi call, but we will retrieve the current |
| 9427 | * VSI context. |
| 9428 | */ |
| 9429 | ctxt.seid = pf->main_vsi_seid; |
| 9430 | ctxt.pf_num = pf->hw.pf_id; |
| 9431 | ctxt.vf_num = 0; |
| 9432 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9433 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9434 | if (ret) { |
| 9435 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9436 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9437 | i40e_stat_str(&pf->hw, ret), |
| 9438 | i40e_aq_str(&pf->hw, |
| 9439 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9440 | return -ENOENT; |
| 9441 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9442 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9443 | vsi->info.valid_sections = 0; |
| 9444 | |
| 9445 | vsi->seid = ctxt.seid; |
| 9446 | vsi->id = ctxt.vsi_number; |
| 9447 | |
| 9448 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9449 | |
| 9450 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9451 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9452 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9453 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9454 | ctxt.seid = pf->main_vsi_seid; |
| 9455 | ctxt.pf_num = pf->hw.pf_id; |
| 9456 | ctxt.vf_num = 0; |
| 9457 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9458 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9459 | if (ret) { |
| 9460 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9461 | "update vsi failed, err %s aq_err %s\n", |
| 9462 | i40e_stat_str(&pf->hw, ret), |
| 9463 | i40e_aq_str(&pf->hw, |
| 9464 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9465 | ret = -ENOENT; |
| 9466 | goto err; |
| 9467 | } |
| 9468 | /* update the local VSI info queue map */ |
| 9469 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9470 | vsi->info.valid_sections = 0; |
| 9471 | } else { |
| 9472 | /* Default/Main VSI is only enabled for TC0 |
| 9473 | * reconfigure it to enable all TCs that are |
| 9474 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9475 | * For MFP case the iSCSI PF would use this |
| 9476 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9477 | */ |
| 9478 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9479 | if (ret) { |
| 9480 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9481 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9482 | enabled_tc, |
| 9483 | i40e_stat_str(&pf->hw, ret), |
| 9484 | i40e_aq_str(&pf->hw, |
| 9485 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9486 | ret = -ENOENT; |
| 9487 | } |
| 9488 | } |
| 9489 | break; |
| 9490 | |
| 9491 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9492 | ctxt.pf_num = hw->pf_id; |
| 9493 | ctxt.vf_num = 0; |
| 9494 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9495 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9496 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9497 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9498 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9499 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9500 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9501 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9502 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9503 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9504 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9505 | break; |
| 9506 | |
| 9507 | case I40E_VSI_VMDQ2: |
| 9508 | ctxt.pf_num = hw->pf_id; |
| 9509 | ctxt.vf_num = 0; |
| 9510 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9511 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9512 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9513 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9514 | /* This VSI is connected to VEB so the switch_id |
| 9515 | * should be set to zero by default. |
| 9516 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9517 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9518 | ctxt.info.valid_sections |= |
| 9519 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9520 | ctxt.info.switch_id = |
| 9521 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9522 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9523 | |
| 9524 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9525 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9526 | break; |
| 9527 | |
| 9528 | case I40E_VSI_SRIOV: |
| 9529 | ctxt.pf_num = hw->pf_id; |
| 9530 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9531 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9532 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9533 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9534 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9535 | /* This VSI is connected to VEB so the switch_id |
| 9536 | * should be set to zero by default. |
| 9537 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9538 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9539 | ctxt.info.valid_sections |= |
| 9540 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9541 | ctxt.info.switch_id = |
| 9542 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9543 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9544 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9545 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9546 | ctxt.info.valid_sections |= |
| 9547 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 9548 | ctxt.info.queueing_opt_flags |= |
Ashish Shah | 4b28cdb | 2016-05-03 15:13:17 -0700 | [diff] [blame] | 9549 | (I40E_AQ_VSI_QUE_OPT_TCP_ENA | |
| 9550 | I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9551 | } |
| 9552 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9553 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9554 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9555 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9556 | ctxt.info.valid_sections |= |
| 9557 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9558 | ctxt.info.sec_flags |= |
| 9559 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9560 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9561 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9562 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9563 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9564 | break; |
| 9565 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9566 | case I40E_VSI_IWARP: |
| 9567 | /* send down message to iWARP */ |
| 9568 | break; |
| 9569 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9570 | default: |
| 9571 | return -ENODEV; |
| 9572 | } |
| 9573 | |
| 9574 | if (vsi->type != I40E_VSI_MAIN) { |
| 9575 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9576 | if (ret) { |
| 9577 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9578 | "add vsi failed, err %s aq_err %s\n", |
| 9579 | i40e_stat_str(&pf->hw, ret), |
| 9580 | i40e_aq_str(&pf->hw, |
| 9581 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9582 | ret = -ENOENT; |
| 9583 | goto err; |
| 9584 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9585 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9586 | vsi->info.valid_sections = 0; |
| 9587 | vsi->seid = ctxt.seid; |
| 9588 | vsi->id = ctxt.vsi_number; |
| 9589 | } |
| 9590 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9591 | vsi->active_filters = 0; |
| 9592 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9593 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9594 | /* If macvlan filters already exist, force them to get loaded */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9595 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9596 | f->state = I40E_FILTER_NEW; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9597 | f_count++; |
| 9598 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9599 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9600 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9601 | if (f_count) { |
| 9602 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 9603 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 9604 | } |
| 9605 | |
| 9606 | /* Update VSI BW information */ |
| 9607 | ret = i40e_vsi_get_bw_info(vsi); |
| 9608 | if (ret) { |
| 9609 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9610 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 9611 | i40e_stat_str(&pf->hw, ret), |
| 9612 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9613 | /* VSI is already added so not tearing that up */ |
| 9614 | ret = 0; |
| 9615 | } |
| 9616 | |
| 9617 | err: |
| 9618 | return ret; |
| 9619 | } |
| 9620 | |
| 9621 | /** |
| 9622 | * i40e_vsi_release - Delete a VSI and free its resources |
| 9623 | * @vsi: the VSI being removed |
| 9624 | * |
| 9625 | * Returns 0 on success or < 0 on error |
| 9626 | **/ |
| 9627 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 9628 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9629 | struct i40e_mac_filter *f; |
| 9630 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9631 | struct i40e_veb *veb = NULL; |
| 9632 | struct i40e_pf *pf; |
| 9633 | u16 uplink_seid; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9634 | int i, n, bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9635 | |
| 9636 | pf = vsi->back; |
| 9637 | |
| 9638 | /* release of a VEB-owner or last VSI is not allowed */ |
| 9639 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 9640 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 9641 | vsi->seid, vsi->uplink_seid); |
| 9642 | return -ENODEV; |
| 9643 | } |
| 9644 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 9645 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 9646 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 9647 | return -ENODEV; |
| 9648 | } |
| 9649 | |
| 9650 | uplink_seid = vsi->uplink_seid; |
| 9651 | if (vsi->type != I40E_VSI_SRIOV) { |
| 9652 | if (vsi->netdev_registered) { |
| 9653 | vsi->netdev_registered = false; |
| 9654 | if (vsi->netdev) { |
| 9655 | /* results in a call to i40e_close() */ |
| 9656 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9657 | } |
| 9658 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 9659 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9660 | } |
| 9661 | i40e_vsi_disable_irq(vsi); |
| 9662 | } |
| 9663 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9664 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 9665 | |
| 9666 | /* clear the sync flag on all filters */ |
| 9667 | if (vsi->netdev) { |
| 9668 | __dev_uc_unsync(vsi->netdev, NULL); |
| 9669 | __dev_mc_unsync(vsi->netdev, NULL); |
| 9670 | } |
| 9671 | |
| 9672 | /* make sure any remaining filters are marked for deletion */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9673 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 9674 | __i40e_del_filter(vsi, f); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 9675 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9676 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9677 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 9678 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9679 | |
| 9680 | i40e_vsi_delete(vsi); |
| 9681 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 9682 | if (vsi->netdev) { |
| 9683 | free_netdev(vsi->netdev); |
| 9684 | vsi->netdev = NULL; |
| 9685 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9686 | i40e_vsi_clear_rings(vsi); |
| 9687 | i40e_vsi_clear(vsi); |
| 9688 | |
| 9689 | /* If this was the last thing on the VEB, except for the |
| 9690 | * controlling VSI, remove the VEB, which puts the controlling |
| 9691 | * VSI onto the next level down in the switch. |
| 9692 | * |
| 9693 | * Well, okay, there's one more exception here: don't remove |
| 9694 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 9695 | * from up the network stack. |
| 9696 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9697 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9698 | if (pf->vsi[i] && |
| 9699 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 9700 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9701 | n++; /* count the VSIs */ |
| 9702 | } |
| 9703 | } |
| 9704 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9705 | if (!pf->veb[i]) |
| 9706 | continue; |
| 9707 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 9708 | n++; /* count the VEBs */ |
| 9709 | if (pf->veb[i]->seid == uplink_seid) |
| 9710 | veb = pf->veb[i]; |
| 9711 | } |
| 9712 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 9713 | i40e_veb_release(veb); |
| 9714 | |
| 9715 | return 0; |
| 9716 | } |
| 9717 | |
| 9718 | /** |
| 9719 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 9720 | * @vsi: ptr to the VSI |
| 9721 | * |
| 9722 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 9723 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 9724 | * newly allocated VSI. |
| 9725 | * |
| 9726 | * Returns 0 on success or negative on failure |
| 9727 | **/ |
| 9728 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 9729 | { |
| 9730 | int ret = -ENOENT; |
| 9731 | struct i40e_pf *pf = vsi->back; |
| 9732 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9733 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9734 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 9735 | vsi->seid); |
| 9736 | return -EEXIST; |
| 9737 | } |
| 9738 | |
| 9739 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 9740 | 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] | 9741 | vsi->seid, vsi->base_vector); |
| 9742 | return -EEXIST; |
| 9743 | } |
| 9744 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9745 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9746 | if (ret) { |
| 9747 | dev_info(&pf->pdev->dev, |
| 9748 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 9749 | vsi->num_q_vectors, vsi->seid, ret); |
| 9750 | vsi->num_q_vectors = 0; |
| 9751 | goto vector_setup_out; |
| 9752 | } |
| 9753 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 9754 | /* In Legacy mode, we do not have to get any other vector since we |
| 9755 | * piggyback on the misc/ICR0 for queue interrupts. |
| 9756 | */ |
| 9757 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9758 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9759 | if (vsi->num_q_vectors) |
| 9760 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 9761 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9762 | if (vsi->base_vector < 0) { |
| 9763 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9764 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 9765 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9766 | i40e_vsi_free_q_vectors(vsi); |
| 9767 | ret = -ENOENT; |
| 9768 | goto vector_setup_out; |
| 9769 | } |
| 9770 | |
| 9771 | vector_setup_out: |
| 9772 | return ret; |
| 9773 | } |
| 9774 | |
| 9775 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9776 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 9777 | * @vsi: pointer to the vsi. |
| 9778 | * |
| 9779 | * This re-allocates a vsi's queue resources. |
| 9780 | * |
| 9781 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 9782 | * on success, otherwise returns NULL on failure. |
| 9783 | **/ |
| 9784 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 9785 | { |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9786 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9787 | u8 enabled_tc; |
| 9788 | int ret; |
| 9789 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9790 | if (!vsi) |
| 9791 | return NULL; |
| 9792 | |
| 9793 | pf = vsi->back; |
| 9794 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9795 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9796 | i40e_vsi_clear_rings(vsi); |
| 9797 | |
| 9798 | i40e_vsi_free_arrays(vsi, false); |
| 9799 | i40e_set_num_rings_in_vsi(vsi); |
| 9800 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 9801 | if (ret) |
| 9802 | goto err_vsi; |
| 9803 | |
| 9804 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 9805 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9806 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9807 | "failed to get tracking for %d queues for VSI %d err %d\n", |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9808 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9809 | goto err_vsi; |
| 9810 | } |
| 9811 | vsi->base_queue = ret; |
| 9812 | |
| 9813 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 9814 | * layout configurations. |
| 9815 | */ |
| 9816 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9817 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9818 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9819 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 9820 | if (vsi->type == I40E_VSI_MAIN) |
| 9821 | i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9822 | |
| 9823 | /* assign it some queues */ |
| 9824 | ret = i40e_alloc_rings(vsi); |
| 9825 | if (ret) |
| 9826 | goto err_rings; |
| 9827 | |
| 9828 | /* map all of the rings to the q_vectors */ |
| 9829 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9830 | return vsi; |
| 9831 | |
| 9832 | err_rings: |
| 9833 | i40e_vsi_free_q_vectors(vsi); |
| 9834 | if (vsi->netdev_registered) { |
| 9835 | vsi->netdev_registered = false; |
| 9836 | unregister_netdev(vsi->netdev); |
| 9837 | free_netdev(vsi->netdev); |
| 9838 | vsi->netdev = NULL; |
| 9839 | } |
| 9840 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9841 | err_vsi: |
| 9842 | i40e_vsi_clear(vsi); |
| 9843 | return NULL; |
| 9844 | } |
| 9845 | |
| 9846 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9847 | * i40e_vsi_setup - Set up a VSI by a given type |
| 9848 | * @pf: board private structure |
| 9849 | * @type: VSI type |
| 9850 | * @uplink_seid: the switch element to link to |
| 9851 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 9852 | * |
| 9853 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 9854 | * to the identified VEB. |
| 9855 | * |
| 9856 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 9857 | * success, otherwise returns NULL on failure. |
| 9858 | **/ |
| 9859 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 9860 | u16 uplink_seid, u32 param1) |
| 9861 | { |
| 9862 | struct i40e_vsi *vsi = NULL; |
| 9863 | struct i40e_veb *veb = NULL; |
| 9864 | int ret, i; |
| 9865 | int v_idx; |
| 9866 | |
| 9867 | /* The requested uplink_seid must be either |
| 9868 | * - the PF's port seid |
| 9869 | * no VEB is needed because this is the PF |
| 9870 | * or this is a Flow Director special case VSI |
| 9871 | * - seid of an existing VEB |
| 9872 | * - seid of a VSI that owns an existing VEB |
| 9873 | * - seid of a VSI that doesn't own a VEB |
| 9874 | * a new VEB is created and the VSI becomes the owner |
| 9875 | * - seid of the PF VSI, which is what creates the first VEB |
| 9876 | * this is a special case of the previous |
| 9877 | * |
| 9878 | * Find which uplink_seid we were given and create a new VEB if needed |
| 9879 | */ |
| 9880 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9881 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 9882 | veb = pf->veb[i]; |
| 9883 | break; |
| 9884 | } |
| 9885 | } |
| 9886 | |
| 9887 | if (!veb && uplink_seid != pf->mac_seid) { |
| 9888 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9889 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9890 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 9891 | vsi = pf->vsi[i]; |
| 9892 | break; |
| 9893 | } |
| 9894 | } |
| 9895 | if (!vsi) { |
| 9896 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 9897 | uplink_seid); |
| 9898 | return NULL; |
| 9899 | } |
| 9900 | |
| 9901 | if (vsi->uplink_seid == pf->mac_seid) |
| 9902 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 9903 | vsi->tc_config.enabled_tc); |
| 9904 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 9905 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9906 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9907 | if (veb) { |
| 9908 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 9909 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 9910 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9911 | return NULL; |
| 9912 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 9913 | /* We come up by default in VEPA mode if SRIOV is not |
| 9914 | * already enabled, in which case we can't force VEPA |
| 9915 | * mode. |
| 9916 | */ |
| 9917 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 9918 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 9919 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9920 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9921 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9922 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9923 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9924 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9925 | veb = pf->veb[i]; |
| 9926 | } |
| 9927 | if (!veb) { |
| 9928 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 9929 | return NULL; |
| 9930 | } |
| 9931 | |
| 9932 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 9933 | uplink_seid = veb->seid; |
| 9934 | } |
| 9935 | |
| 9936 | /* get vsi sw struct */ |
| 9937 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 9938 | if (v_idx < 0) |
| 9939 | goto err_alloc; |
| 9940 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9941 | if (!vsi) |
| 9942 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9943 | vsi->type = type; |
| 9944 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 9945 | |
| 9946 | if (type == I40E_VSI_MAIN) |
| 9947 | pf->lan_vsi = v_idx; |
| 9948 | else if (type == I40E_VSI_SRIOV) |
| 9949 | vsi->vf_id = param1; |
| 9950 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9951 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 9952 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9953 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9954 | dev_info(&pf->pdev->dev, |
| 9955 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 9956 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9957 | goto err_vsi; |
| 9958 | } |
| 9959 | vsi->base_queue = ret; |
| 9960 | |
| 9961 | /* get a VSI from the hardware */ |
| 9962 | vsi->uplink_seid = uplink_seid; |
| 9963 | ret = i40e_add_vsi(vsi); |
| 9964 | if (ret) |
| 9965 | goto err_vsi; |
| 9966 | |
| 9967 | switch (vsi->type) { |
| 9968 | /* setup the netdev if needed */ |
| 9969 | case I40E_VSI_MAIN: |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9970 | /* Apply relevant filters if a platform-specific mac |
| 9971 | * address was selected. |
| 9972 | */ |
| 9973 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 9974 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 9975 | if (ret) { |
| 9976 | dev_warn(&pf->pdev->dev, |
| 9977 | "could not set up macaddr; err %d\n", |
| 9978 | ret); |
| 9979 | } |
| 9980 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9981 | case I40E_VSI_VMDQ2: |
| 9982 | ret = i40e_config_netdev(vsi); |
| 9983 | if (ret) |
| 9984 | goto err_netdev; |
| 9985 | ret = register_netdev(vsi->netdev); |
| 9986 | if (ret) |
| 9987 | goto err_netdev; |
| 9988 | vsi->netdev_registered = true; |
| 9989 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9990 | #ifdef CONFIG_I40E_DCB |
| 9991 | /* Setup DCB netlink interface */ |
| 9992 | i40e_dcbnl_setup(vsi); |
| 9993 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9994 | /* fall through */ |
| 9995 | |
| 9996 | case I40E_VSI_FDIR: |
| 9997 | /* set up vectors and rings if needed */ |
| 9998 | ret = i40e_vsi_setup_vectors(vsi); |
| 9999 | if (ret) |
| 10000 | goto err_msix; |
| 10001 | |
| 10002 | ret = i40e_alloc_rings(vsi); |
| 10003 | if (ret) |
| 10004 | goto err_rings; |
| 10005 | |
| 10006 | /* map all of the rings to the q_vectors */ |
| 10007 | i40e_vsi_map_rings_to_vectors(vsi); |
| 10008 | |
| 10009 | i40e_vsi_reset_stats(vsi); |
| 10010 | break; |
| 10011 | |
| 10012 | default: |
| 10013 | /* no netdev or rings for the other VSI types */ |
| 10014 | break; |
| 10015 | } |
| 10016 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 10017 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
| 10018 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 10019 | ret = i40e_vsi_config_rss(vsi); |
| 10020 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10021 | return vsi; |
| 10022 | |
| 10023 | err_rings: |
| 10024 | i40e_vsi_free_q_vectors(vsi); |
| 10025 | err_msix: |
| 10026 | if (vsi->netdev_registered) { |
| 10027 | vsi->netdev_registered = false; |
| 10028 | unregister_netdev(vsi->netdev); |
| 10029 | free_netdev(vsi->netdev); |
| 10030 | vsi->netdev = NULL; |
| 10031 | } |
| 10032 | err_netdev: |
| 10033 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 10034 | err_vsi: |
| 10035 | i40e_vsi_clear(vsi); |
| 10036 | err_alloc: |
| 10037 | return NULL; |
| 10038 | } |
| 10039 | |
| 10040 | /** |
| 10041 | * i40e_veb_get_bw_info - Query VEB BW information |
| 10042 | * @veb: the veb to query |
| 10043 | * |
| 10044 | * Query the Tx scheduler BW configuration data for given VEB |
| 10045 | **/ |
| 10046 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 10047 | { |
| 10048 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 10049 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 10050 | struct i40e_pf *pf = veb->pf; |
| 10051 | struct i40e_hw *hw = &pf->hw; |
| 10052 | u32 tc_bw_max; |
| 10053 | int ret = 0; |
| 10054 | int i; |
| 10055 | |
| 10056 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 10057 | &bw_data, NULL); |
| 10058 | if (ret) { |
| 10059 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10060 | "query veb bw config failed, err %s aq_err %s\n", |
| 10061 | i40e_stat_str(&pf->hw, ret), |
| 10062 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10063 | goto out; |
| 10064 | } |
| 10065 | |
| 10066 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 10067 | &ets_data, NULL); |
| 10068 | if (ret) { |
| 10069 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10070 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 10071 | i40e_stat_str(&pf->hw, ret), |
| 10072 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10073 | goto out; |
| 10074 | } |
| 10075 | |
| 10076 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 10077 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 10078 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 10079 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10080 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 10081 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 10082 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 10083 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 10084 | veb->bw_tc_limit_credits[i] = |
| 10085 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 10086 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 10087 | } |
| 10088 | |
| 10089 | out: |
| 10090 | return ret; |
| 10091 | } |
| 10092 | |
| 10093 | /** |
| 10094 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 10095 | * @pf: board private structure |
| 10096 | * |
| 10097 | * On error: returns error code (negative) |
| 10098 | * On success: returns vsi index in PF (positive) |
| 10099 | **/ |
| 10100 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 10101 | { |
| 10102 | int ret = -ENOENT; |
| 10103 | struct i40e_veb *veb; |
| 10104 | int i; |
| 10105 | |
| 10106 | /* Need to protect the allocation of switch elements at the PF level */ |
| 10107 | mutex_lock(&pf->switch_mutex); |
| 10108 | |
| 10109 | /* VEB list may be fragmented if VEB creation/destruction has |
| 10110 | * been happening. We can afford to do a quick scan to look |
| 10111 | * for any free slots in the list. |
| 10112 | * |
| 10113 | * find next empty veb slot, looping back around if necessary |
| 10114 | */ |
| 10115 | i = 0; |
| 10116 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 10117 | i++; |
| 10118 | if (i >= I40E_MAX_VEB) { |
| 10119 | ret = -ENOMEM; |
| 10120 | goto err_alloc_veb; /* out of VEB slots! */ |
| 10121 | } |
| 10122 | |
| 10123 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 10124 | if (!veb) { |
| 10125 | ret = -ENOMEM; |
| 10126 | goto err_alloc_veb; |
| 10127 | } |
| 10128 | veb->pf = pf; |
| 10129 | veb->idx = i; |
| 10130 | veb->enabled_tc = 1; |
| 10131 | |
| 10132 | pf->veb[i] = veb; |
| 10133 | ret = i; |
| 10134 | err_alloc_veb: |
| 10135 | mutex_unlock(&pf->switch_mutex); |
| 10136 | return ret; |
| 10137 | } |
| 10138 | |
| 10139 | /** |
| 10140 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 10141 | * @branch: where to start deleting |
| 10142 | * |
| 10143 | * This uses recursion to find the tips of the branch to be |
| 10144 | * removed, deleting until we get back to and can delete this VEB. |
| 10145 | **/ |
| 10146 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 10147 | { |
| 10148 | struct i40e_pf *pf = branch->pf; |
| 10149 | u16 branch_seid = branch->seid; |
| 10150 | u16 veb_idx = branch->idx; |
| 10151 | int i; |
| 10152 | |
| 10153 | /* release any VEBs on this VEB - RECURSION */ |
| 10154 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10155 | if (!pf->veb[i]) |
| 10156 | continue; |
| 10157 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 10158 | i40e_switch_branch_release(pf->veb[i]); |
| 10159 | } |
| 10160 | |
| 10161 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 10162 | * |
| 10163 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 10164 | * the VEB itself, so don't use (*branch) after this loop. |
| 10165 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10166 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10167 | if (!pf->vsi[i]) |
| 10168 | continue; |
| 10169 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 10170 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 10171 | i40e_vsi_release(pf->vsi[i]); |
| 10172 | } |
| 10173 | } |
| 10174 | |
| 10175 | /* There's one corner case where the VEB might not have been |
| 10176 | * removed, so double check it here and remove it if needed. |
| 10177 | * This case happens if the veb was created from the debugfs |
| 10178 | * commands and no VSIs were added to it. |
| 10179 | */ |
| 10180 | if (pf->veb[veb_idx]) |
| 10181 | i40e_veb_release(pf->veb[veb_idx]); |
| 10182 | } |
| 10183 | |
| 10184 | /** |
| 10185 | * i40e_veb_clear - remove veb struct |
| 10186 | * @veb: the veb to remove |
| 10187 | **/ |
| 10188 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 10189 | { |
| 10190 | if (!veb) |
| 10191 | return; |
| 10192 | |
| 10193 | if (veb->pf) { |
| 10194 | struct i40e_pf *pf = veb->pf; |
| 10195 | |
| 10196 | mutex_lock(&pf->switch_mutex); |
| 10197 | if (pf->veb[veb->idx] == veb) |
| 10198 | pf->veb[veb->idx] = NULL; |
| 10199 | mutex_unlock(&pf->switch_mutex); |
| 10200 | } |
| 10201 | |
| 10202 | kfree(veb); |
| 10203 | } |
| 10204 | |
| 10205 | /** |
| 10206 | * i40e_veb_release - Delete a VEB and free its resources |
| 10207 | * @veb: the VEB being removed |
| 10208 | **/ |
| 10209 | void i40e_veb_release(struct i40e_veb *veb) |
| 10210 | { |
| 10211 | struct i40e_vsi *vsi = NULL; |
| 10212 | struct i40e_pf *pf; |
| 10213 | int i, n = 0; |
| 10214 | |
| 10215 | pf = veb->pf; |
| 10216 | |
| 10217 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10218 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10219 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 10220 | n++; |
| 10221 | vsi = pf->vsi[i]; |
| 10222 | } |
| 10223 | } |
| 10224 | if (n != 1) { |
| 10225 | dev_info(&pf->pdev->dev, |
| 10226 | "can't remove VEB %d with %d VSIs left\n", |
| 10227 | veb->seid, n); |
| 10228 | return; |
| 10229 | } |
| 10230 | |
| 10231 | /* move the remaining VSI to uplink veb */ |
| 10232 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10233 | if (veb->uplink_seid) { |
| 10234 | vsi->uplink_seid = veb->uplink_seid; |
| 10235 | if (veb->uplink_seid == pf->mac_seid) |
| 10236 | vsi->veb_idx = I40E_NO_VEB; |
| 10237 | else |
| 10238 | vsi->veb_idx = veb->veb_idx; |
| 10239 | } else { |
| 10240 | /* floating VEB */ |
| 10241 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10242 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10243 | } |
| 10244 | |
| 10245 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10246 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10247 | } |
| 10248 | |
| 10249 | /** |
| 10250 | * i40e_add_veb - create the VEB in the switch |
| 10251 | * @veb: the VEB to be instantiated |
| 10252 | * @vsi: the controlling VSI |
| 10253 | **/ |
| 10254 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10255 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10256 | struct i40e_pf *pf = veb->pf; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10257 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10258 | int ret; |
| 10259 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10260 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10261 | veb->enabled_tc, false, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10262 | &veb->seid, enable_stats, NULL); |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10263 | |
| 10264 | /* get a VEB from the hardware */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10265 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10266 | dev_info(&pf->pdev->dev, |
| 10267 | "couldn't add VEB, err %s aq_err %s\n", |
| 10268 | i40e_stat_str(&pf->hw, ret), |
| 10269 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10270 | return -EPERM; |
| 10271 | } |
| 10272 | |
| 10273 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10274 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10275 | &veb->stats_idx, NULL, NULL, NULL); |
| 10276 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10277 | dev_info(&pf->pdev->dev, |
| 10278 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10279 | i40e_stat_str(&pf->hw, ret), |
| 10280 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10281 | return -EPERM; |
| 10282 | } |
| 10283 | ret = i40e_veb_get_bw_info(veb); |
| 10284 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10285 | dev_info(&pf->pdev->dev, |
| 10286 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10287 | i40e_stat_str(&pf->hw, ret), |
| 10288 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10289 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10290 | return -ENOENT; |
| 10291 | } |
| 10292 | |
| 10293 | vsi->uplink_seid = veb->seid; |
| 10294 | vsi->veb_idx = veb->idx; |
| 10295 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10296 | |
| 10297 | return 0; |
| 10298 | } |
| 10299 | |
| 10300 | /** |
| 10301 | * i40e_veb_setup - Set up a VEB |
| 10302 | * @pf: board private structure |
| 10303 | * @flags: VEB setup flags |
| 10304 | * @uplink_seid: the switch element to link to |
| 10305 | * @vsi_seid: the initial VSI seid |
| 10306 | * @enabled_tc: Enabled TC bit-map |
| 10307 | * |
| 10308 | * This allocates the sw VEB structure and links it into the switch |
| 10309 | * It is possible and legal for this to be a duplicate of an already |
| 10310 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10311 | * to be zero, in order to create a floating VEB. |
| 10312 | * |
| 10313 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10314 | * success, otherwise returns NULL on failure. |
| 10315 | **/ |
| 10316 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10317 | u16 uplink_seid, u16 vsi_seid, |
| 10318 | u8 enabled_tc) |
| 10319 | { |
| 10320 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10321 | int vsi_idx, veb_idx; |
| 10322 | int ret; |
| 10323 | |
| 10324 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10325 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10326 | (uplink_seid + vsi_seid != 0)) { |
| 10327 | dev_info(&pf->pdev->dev, |
| 10328 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10329 | uplink_seid, vsi_seid); |
| 10330 | return NULL; |
| 10331 | } |
| 10332 | |
| 10333 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10334 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10335 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10336 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10337 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10338 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10339 | vsi_seid); |
| 10340 | return NULL; |
| 10341 | } |
| 10342 | |
| 10343 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10344 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10345 | if (pf->veb[veb_idx] && |
| 10346 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10347 | uplink_veb = pf->veb[veb_idx]; |
| 10348 | break; |
| 10349 | } |
| 10350 | } |
| 10351 | if (!uplink_veb) { |
| 10352 | dev_info(&pf->pdev->dev, |
| 10353 | "uplink seid %d not found\n", uplink_seid); |
| 10354 | return NULL; |
| 10355 | } |
| 10356 | } |
| 10357 | |
| 10358 | /* get veb sw struct */ |
| 10359 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10360 | if (veb_idx < 0) |
| 10361 | goto err_alloc; |
| 10362 | veb = pf->veb[veb_idx]; |
| 10363 | veb->flags = flags; |
| 10364 | veb->uplink_seid = uplink_seid; |
| 10365 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10366 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10367 | |
| 10368 | /* create the VEB in the switch */ |
| 10369 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10370 | if (ret) |
| 10371 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10372 | if (vsi_idx == pf->lan_vsi) |
| 10373 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10374 | |
| 10375 | return veb; |
| 10376 | |
| 10377 | err_veb: |
| 10378 | i40e_veb_clear(veb); |
| 10379 | err_alloc: |
| 10380 | return NULL; |
| 10381 | } |
| 10382 | |
| 10383 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10384 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10385 | * @pf: board private structure |
| 10386 | * @ele: element we are building info from |
| 10387 | * @num_reported: total number of elements |
| 10388 | * @printconfig: should we print the contents |
| 10389 | * |
| 10390 | * helper function to assist in extracting a few useful SEID values. |
| 10391 | **/ |
| 10392 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10393 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10394 | u16 num_reported, bool printconfig) |
| 10395 | { |
| 10396 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10397 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10398 | u8 element_type = ele->element_type; |
| 10399 | u16 seid = le16_to_cpu(ele->seid); |
| 10400 | |
| 10401 | if (printconfig) |
| 10402 | dev_info(&pf->pdev->dev, |
| 10403 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10404 | element_type, seid, uplink_seid, downlink_seid); |
| 10405 | |
| 10406 | switch (element_type) { |
| 10407 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10408 | pf->mac_seid = seid; |
| 10409 | break; |
| 10410 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10411 | /* Main VEB? */ |
| 10412 | if (uplink_seid != pf->mac_seid) |
| 10413 | break; |
| 10414 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10415 | int v; |
| 10416 | |
| 10417 | /* find existing or else empty VEB */ |
| 10418 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10419 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10420 | pf->lan_veb = v; |
| 10421 | break; |
| 10422 | } |
| 10423 | } |
| 10424 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10425 | v = i40e_veb_mem_alloc(pf); |
| 10426 | if (v < 0) |
| 10427 | break; |
| 10428 | pf->lan_veb = v; |
| 10429 | } |
| 10430 | } |
| 10431 | |
| 10432 | pf->veb[pf->lan_veb]->seid = seid; |
| 10433 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10434 | pf->veb[pf->lan_veb]->pf = pf; |
| 10435 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10436 | break; |
| 10437 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10438 | if (num_reported != 1) |
| 10439 | break; |
| 10440 | /* This is immediately after a reset so we can assume this is |
| 10441 | * the PF's VSI |
| 10442 | */ |
| 10443 | pf->mac_seid = uplink_seid; |
| 10444 | pf->pf_seid = downlink_seid; |
| 10445 | pf->main_vsi_seid = seid; |
| 10446 | if (printconfig) |
| 10447 | dev_info(&pf->pdev->dev, |
| 10448 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10449 | pf->pf_seid, pf->main_vsi_seid); |
| 10450 | break; |
| 10451 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10452 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10453 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10454 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10455 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10456 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10457 | /* ignore these for now */ |
| 10458 | break; |
| 10459 | default: |
| 10460 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10461 | element_type, seid); |
| 10462 | break; |
| 10463 | } |
| 10464 | } |
| 10465 | |
| 10466 | /** |
| 10467 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10468 | * @pf: board private structure |
| 10469 | * @printconfig: should we print the contents |
| 10470 | * |
| 10471 | * Get the current switch configuration from the device and |
| 10472 | * extract a few useful SEID values. |
| 10473 | **/ |
| 10474 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10475 | { |
| 10476 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10477 | u16 next_seid = 0; |
| 10478 | int ret = 0; |
| 10479 | u8 *aq_buf; |
| 10480 | int i; |
| 10481 | |
| 10482 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10483 | if (!aq_buf) |
| 10484 | return -ENOMEM; |
| 10485 | |
| 10486 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10487 | do { |
| 10488 | u16 num_reported, num_total; |
| 10489 | |
| 10490 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10491 | I40E_AQ_LARGE_BUF, |
| 10492 | &next_seid, NULL); |
| 10493 | if (ret) { |
| 10494 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10495 | "get switch config failed err %s aq_err %s\n", |
| 10496 | i40e_stat_str(&pf->hw, ret), |
| 10497 | i40e_aq_str(&pf->hw, |
| 10498 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10499 | kfree(aq_buf); |
| 10500 | return -ENOENT; |
| 10501 | } |
| 10502 | |
| 10503 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10504 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10505 | |
| 10506 | if (printconfig) |
| 10507 | dev_info(&pf->pdev->dev, |
| 10508 | "header: %d reported %d total\n", |
| 10509 | num_reported, num_total); |
| 10510 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10511 | for (i = 0; i < num_reported; i++) { |
| 10512 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10513 | &sw_config->element[i]; |
| 10514 | |
| 10515 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10516 | printconfig); |
| 10517 | } |
| 10518 | } while (next_seid != 0); |
| 10519 | |
| 10520 | kfree(aq_buf); |
| 10521 | return ret; |
| 10522 | } |
| 10523 | |
| 10524 | /** |
| 10525 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10526 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10527 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10528 | * |
| 10529 | * Returns 0 on success, negative value on failure |
| 10530 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10531 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10532 | { |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10533 | u16 flags = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10534 | int ret; |
| 10535 | |
| 10536 | /* find out what's out there already */ |
| 10537 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10538 | if (ret) { |
| 10539 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10540 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10541 | i40e_stat_str(&pf->hw, ret), |
| 10542 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10543 | return ret; |
| 10544 | } |
| 10545 | i40e_pf_reset_stats(pf); |
| 10546 | |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10547 | /* set the switch config bit for the whole device to |
| 10548 | * support limited promisc or true promisc |
| 10549 | * when user requests promisc. The default is limited |
| 10550 | * promisc. |
| 10551 | */ |
| 10552 | |
| 10553 | if ((pf->hw.pf_id == 0) && |
| 10554 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) |
| 10555 | flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10556 | |
| 10557 | if (pf->hw.pf_id == 0) { |
| 10558 | u16 valid_flags; |
| 10559 | |
| 10560 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10561 | ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, |
| 10562 | NULL); |
| 10563 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { |
| 10564 | dev_info(&pf->pdev->dev, |
| 10565 | "couldn't set switch config bits, err %s aq_err %s\n", |
| 10566 | i40e_stat_str(&pf->hw, ret), |
| 10567 | i40e_aq_str(&pf->hw, |
| 10568 | pf->hw.aq.asq_last_status)); |
| 10569 | /* not a fatal problem, just keep going */ |
| 10570 | } |
| 10571 | } |
| 10572 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10573 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10574 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10575 | struct i40e_vsi *vsi = NULL; |
| 10576 | u16 uplink_seid; |
| 10577 | |
| 10578 | /* Set up the PF VSI associated with the PF's main VSI |
| 10579 | * that is already in the HW switch |
| 10580 | */ |
| 10581 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10582 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10583 | else |
| 10584 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10585 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10586 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10587 | else if (reinit) |
| 10588 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10589 | if (!vsi) { |
| 10590 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10591 | i40e_fdir_teardown(pf); |
| 10592 | return -EAGAIN; |
| 10593 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10594 | } else { |
| 10595 | /* force a reset of TC and queue layout configurations */ |
| 10596 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10597 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10598 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10599 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10600 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10601 | } |
| 10602 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 10603 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10604 | i40e_fdir_sb_setup(pf); |
| 10605 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10606 | /* Setup static PF queue filter control settings */ |
| 10607 | ret = i40e_setup_pf_filter_control(pf); |
| 10608 | if (ret) { |
| 10609 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 10610 | ret); |
| 10611 | /* Failure here should not stop continuing other steps */ |
| 10612 | } |
| 10613 | |
| 10614 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 10615 | * the hash |
| 10616 | */ |
| 10617 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 10618 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10619 | |
| 10620 | /* fill in link information and enable LSE reporting */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10621 | i40e_link_event(pf); |
| 10622 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10623 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10624 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 10625 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10626 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10627 | i40e_ptp_init(pf); |
| 10628 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10629 | return ret; |
| 10630 | } |
| 10631 | |
| 10632 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10633 | * i40e_determine_queue_usage - Work out queue distribution |
| 10634 | * @pf: board private structure |
| 10635 | **/ |
| 10636 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 10637 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10638 | int queues_left; |
| 10639 | |
| 10640 | pf->num_lan_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10641 | |
| 10642 | /* Find the max queues to be put into basic use. We'll always be |
| 10643 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 10644 | * big RSS set. |
| 10645 | */ |
| 10646 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 10647 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10648 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10649 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10650 | /* one qp for PF, no queues for anything else */ |
| 10651 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10652 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10653 | |
| 10654 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10655 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10656 | I40E_FLAG_IWARP_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10657 | I40E_FLAG_FD_SB_ENABLED | |
| 10658 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10659 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 10660 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10661 | I40E_FLAG_SRIOV_ENABLED | |
| 10662 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10663 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 10664 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 10665 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10666 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10667 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10668 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10669 | queues_left -= pf->num_lan_qps; |
| 10670 | |
| 10671 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10672 | I40E_FLAG_IWARP_ENABLED | |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10673 | I40E_FLAG_FD_SB_ENABLED | |
| 10674 | I40E_FLAG_FD_ATR_ENABLED | |
| 10675 | I40E_FLAG_DCB_ENABLED | |
| 10676 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10677 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10678 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10679 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10680 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 10681 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | |
| 10682 | I40E_FLAG_DCB_ENABLED); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10683 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 10684 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 10685 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 10686 | num_online_cpus()); |
| 10687 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 10688 | pf->hw.func_caps.num_tx_qp); |
| 10689 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10690 | queues_left -= pf->num_lan_qps; |
| 10691 | } |
| 10692 | |
| 10693 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10694 | if (queues_left > 1) { |
| 10695 | queues_left -= 1; /* save 1 queue for FD */ |
| 10696 | } else { |
| 10697 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 10698 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 10699 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10700 | } |
| 10701 | |
| 10702 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10703 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10704 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 10705 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10706 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 10707 | } |
| 10708 | |
| 10709 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 10710 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 10711 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 10712 | (queues_left / pf->num_vmdq_qps)); |
| 10713 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 10714 | } |
| 10715 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10716 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10717 | dev_dbg(&pf->pdev->dev, |
| 10718 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 10719 | pf->hw.func_caps.num_tx_qp, |
| 10720 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10721 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 10722 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 10723 | queues_left); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10724 | } |
| 10725 | |
| 10726 | /** |
| 10727 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 10728 | * @pf: PF to be setup |
| 10729 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10730 | * 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] | 10731 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 10732 | * based filter sizes required for them. It also enables Flow director, |
| 10733 | * ethertype and macvlan type filter settings for the pf. |
| 10734 | * |
| 10735 | * Returns 0 on success, negative on failure |
| 10736 | **/ |
| 10737 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 10738 | { |
| 10739 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 10740 | |
| 10741 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 10742 | |
| 10743 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10744 | 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] | 10745 | settings->enable_fdir = true; |
| 10746 | |
| 10747 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 10748 | settings->enable_ethtype = true; |
| 10749 | settings->enable_macvlan = true; |
| 10750 | |
| 10751 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 10752 | return -ENOENT; |
| 10753 | |
| 10754 | return 0; |
| 10755 | } |
| 10756 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10757 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10758 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10759 | static void i40e_print_features(struct i40e_pf *pf) |
| 10760 | { |
| 10761 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10762 | char *buf; |
| 10763 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10764 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10765 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 10766 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10767 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10768 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10769 | 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] | 10770 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10771 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10772 | #endif |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10773 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10774 | pf->hw.func_caps.num_vsis, |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10775 | pf->vsi[pf->lan_vsi]->num_queue_pairs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10776 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10777 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10778 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10779 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10780 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10781 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 10782 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10783 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10784 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10785 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10786 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10787 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10788 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10789 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10790 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10791 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10792 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10793 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10794 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10795 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 10796 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10797 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10798 | } |
| 10799 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10800 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10801 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
| 10802 | * |
| 10803 | * @pdev: PCI device information struct |
| 10804 | * @pf: board private structure |
| 10805 | * |
| 10806 | * Look up the MAC address in Open Firmware on systems that support it, |
| 10807 | * and use IDPROM on SPARC if no OF address is found. On return, the |
| 10808 | * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value |
| 10809 | * has been selected. |
| 10810 | **/ |
| 10811 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 10812 | { |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10813 | pf->flags &= ~I40E_FLAG_PF_MAC; |
Sowmini Varadhan | ba94272 | 2016-01-12 19:32:31 -0800 | [diff] [blame] | 10814 | if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10815 | pf->flags |= I40E_FLAG_PF_MAC; |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10816 | } |
| 10817 | |
| 10818 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10819 | * i40e_probe - Device initialization routine |
| 10820 | * @pdev: PCI device information struct |
| 10821 | * @ent: entry in i40e_pci_tbl |
| 10822 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10823 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 10824 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10825 | * and a hardware reset occur. |
| 10826 | * |
| 10827 | * Returns 0 on success, negative on failure |
| 10828 | **/ |
| 10829 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 10830 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 10831 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10832 | struct i40e_pf *pf; |
| 10833 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10834 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10835 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10836 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 10837 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10838 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10839 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10840 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10841 | |
| 10842 | err = pci_enable_device_mem(pdev); |
| 10843 | if (err) |
| 10844 | return err; |
| 10845 | |
| 10846 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10847 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10848 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 10849 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10850 | if (err) { |
| 10851 | dev_err(&pdev->dev, |
| 10852 | "DMA configuration failed: 0x%x\n", err); |
| 10853 | goto err_dma; |
| 10854 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10855 | } |
| 10856 | |
| 10857 | /* set up pci connections */ |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10858 | err = pci_request_mem_regions(pdev, i40e_driver_name); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10859 | if (err) { |
| 10860 | dev_info(&pdev->dev, |
| 10861 | "pci_request_selected_regions failed %d\n", err); |
| 10862 | goto err_pci_reg; |
| 10863 | } |
| 10864 | |
| 10865 | pci_enable_pcie_error_reporting(pdev); |
| 10866 | pci_set_master(pdev); |
| 10867 | |
| 10868 | /* Now that we have a PCI connection, we need to do the |
| 10869 | * low level device setup. This is primarily setting up |
| 10870 | * the Admin Queue structures and then querying for the |
| 10871 | * device's current profile information. |
| 10872 | */ |
| 10873 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 10874 | if (!pf) { |
| 10875 | err = -ENOMEM; |
| 10876 | goto err_pf_alloc; |
| 10877 | } |
| 10878 | pf->next_vsi = 0; |
| 10879 | pf->pdev = pdev; |
| 10880 | set_bit(__I40E_DOWN, &pf->state); |
| 10881 | |
| 10882 | hw = &pf->hw; |
| 10883 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10884 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10885 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 10886 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10887 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10888 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10889 | if (!hw->hw_addr) { |
| 10890 | err = -EIO; |
| 10891 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 10892 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10893 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10894 | goto err_ioremap; |
| 10895 | } |
| 10896 | hw->vendor_id = pdev->vendor; |
| 10897 | hw->device_id = pdev->device; |
| 10898 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 10899 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 10900 | hw->subsystem_device_id = pdev->subsystem_device; |
| 10901 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 10902 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Sudheer Mogilappagari | b3f028f | 2017-02-09 23:58:22 -0800 | [diff] [blame] | 10903 | hw->bus.bus_id = pdev->bus->number; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10904 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10905 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame] | 10906 | INIT_LIST_HEAD(&pf->l3_flex_pit_list); |
| 10907 | INIT_LIST_HEAD(&pf->l4_flex_pit_list); |
| 10908 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 10909 | /* set up the locks for the AQ, do this only once in probe |
| 10910 | * and destroy them only once in remove |
| 10911 | */ |
| 10912 | mutex_init(&hw->aq.asq_mutex); |
| 10913 | mutex_init(&hw->aq.arq_mutex); |
| 10914 | |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 10915 | pf->msg_enable = netif_msg_init(debug, |
| 10916 | NETIF_MSG_DRV | |
| 10917 | NETIF_MSG_PROBE | |
| 10918 | NETIF_MSG_LINK); |
| 10919 | if (debug < -1) |
| 10920 | pf->hw.debug_mask = debug; |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 10921 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10922 | /* do a special CORER for clearing PXE mode once at init */ |
| 10923 | if (hw->revision_id == 0 && |
| 10924 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 10925 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 10926 | i40e_flush(hw); |
| 10927 | msleep(200); |
| 10928 | pf->corer_count++; |
| 10929 | |
| 10930 | i40e_clear_pxe_mode(hw); |
| 10931 | } |
| 10932 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10933 | /* 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] | 10934 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10935 | err = i40e_pf_reset(hw); |
| 10936 | if (err) { |
| 10937 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 10938 | goto err_pf_reset; |
| 10939 | } |
| 10940 | pf->pfr_count++; |
| 10941 | |
| 10942 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 10943 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 10944 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10945 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10946 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10947 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 10948 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10949 | "%s-%s:misc", |
| 10950 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10951 | |
| 10952 | err = i40e_init_shared_code(hw); |
| 10953 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 10954 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 10955 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10956 | goto err_pf_reset; |
| 10957 | } |
| 10958 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10959 | /* set up a default setting for link flow control */ |
| 10960 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 10961 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10962 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 10963 | if (err) { |
| 10964 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 10965 | dev_info(&pdev->dev, |
| 10966 | "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"); |
| 10967 | else |
| 10968 | dev_info(&pdev->dev, |
| 10969 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 10970 | |
| 10971 | goto err_pf_reset; |
| 10972 | } |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10973 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10974 | /* provide nvm, fw, api versions */ |
| 10975 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 10976 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 10977 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 10978 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10979 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10980 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 10981 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10982 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10983 | "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"); |
| 10984 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 10985 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10986 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10987 | "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] | 10988 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 10989 | i40e_verify_eeprom(pf); |
| 10990 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 10991 | /* Rev 0 hardware was never productized */ |
| 10992 | if (hw->revision_id < 1) |
| 10993 | 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"); |
| 10994 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 10995 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10996 | err = i40e_get_capabilities(pf); |
| 10997 | if (err) |
| 10998 | goto err_adminq_setup; |
| 10999 | |
| 11000 | err = i40e_sw_init(pf); |
| 11001 | if (err) { |
| 11002 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 11003 | goto err_sw_init; |
| 11004 | } |
| 11005 | |
| 11006 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
Alexander Duyck | c76cb6e | 2017-02-21 15:55:48 -0800 | [diff] [blame^] | 11007 | hw->func_caps.num_rx_qp, 0, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11008 | if (err) { |
| 11009 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 11010 | goto err_init_lan_hmc; |
| 11011 | } |
| 11012 | |
| 11013 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 11014 | if (err) { |
| 11015 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 11016 | err = -ENOENT; |
| 11017 | goto err_configure_lan_hmc; |
| 11018 | } |
| 11019 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 11020 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 11021 | * Ignore error return codes because if it was already disabled via |
| 11022 | * hardware settings this will fail |
| 11023 | */ |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 11024 | if (pf->flags & I40E_FLAG_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 11025 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 11026 | i40e_aq_stop_lldp(hw, true, NULL); |
| 11027 | } |
| 11028 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11029 | i40e_get_mac_addr(hw, hw->mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 11030 | /* allow a platform config to override the HW addr */ |
| 11031 | i40e_get_platform_mac_addr(pdev, pf); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 11032 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11033 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 11034 | err = -EIO; |
| 11035 | goto err_mac_addr; |
| 11036 | } |
| 11037 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 11038 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 11039 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 11040 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 11041 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11042 | |
| 11043 | pci_set_drvdata(pdev, pf); |
| 11044 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11045 | #ifdef CONFIG_I40E_DCB |
| 11046 | err = i40e_init_pf_dcb(pf); |
| 11047 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 11048 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
David Ertman | c17ef43 | 2016-09-30 01:36:21 -0700 | [diff] [blame] | 11049 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED); |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 11050 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11051 | } |
| 11052 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11053 | |
| 11054 | /* set up periodic task facility */ |
| 11055 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 11056 | pf->service_timer_period = HZ; |
| 11057 | |
| 11058 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 11059 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 11060 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11061 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11062 | /* NVM bit on means WoL disabled for the port */ |
| 11063 | 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] | 11064 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11065 | pf->wol_en = false; |
| 11066 | else |
| 11067 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11068 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 11069 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11070 | /* set up the main switch operations */ |
| 11071 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 11072 | err = i40e_init_interrupt_scheme(pf); |
| 11073 | if (err) |
| 11074 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11075 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11076 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 11077 | * to us; HW supports far more and we share the remaining pool with |
| 11078 | * the other PFs. We allocate space for more than the guarantee with |
| 11079 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11080 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11081 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 11082 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 11083 | else |
| 11084 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 11085 | |
| 11086 | /* 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] | 11087 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 11088 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11089 | if (!pf->vsi) { |
| 11090 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11091 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11092 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11093 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 11094 | #ifdef CONFIG_PCI_IOV |
| 11095 | /* prep for VF support */ |
| 11096 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 11097 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11098 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 11099 | if (pci_num_vf(pdev)) |
| 11100 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 11101 | } |
| 11102 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11103 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11104 | if (err) { |
| 11105 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 11106 | goto err_vsis; |
| 11107 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11108 | |
| 11109 | /* Make sure flow control is set according to current settings */ |
| 11110 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 11111 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 11112 | dev_dbg(&pf->pdev->dev, |
| 11113 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 11114 | i40e_stat_str(hw, err), |
| 11115 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11116 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 11117 | dev_dbg(&pf->pdev->dev, |
| 11118 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 11119 | i40e_stat_str(hw, err), |
| 11120 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11121 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 11122 | dev_dbg(&pf->pdev->dev, |
| 11123 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 11124 | i40e_stat_str(hw, err), |
| 11125 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11126 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11127 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11128 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11129 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 11130 | i40e_vsi_open(pf->vsi[i]); |
| 11131 | break; |
| 11132 | } |
| 11133 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11134 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11135 | /* The driver only wants link up/down and module qualification |
| 11136 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11137 | */ |
| 11138 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11139 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 11140 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11141 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11142 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11143 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 11144 | i40e_stat_str(&pf->hw, err), |
| 11145 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11146 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11147 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 11148 | * of TSO, so that we avoid the MDD being fired and causing |
| 11149 | * a reset in the case of small MSS+TSO. |
| 11150 | */ |
| 11151 | val = rd32(hw, I40E_REG_MSS); |
| 11152 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 11153 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 11154 | val |= I40E_64BYTE_MSS; |
| 11155 | wr32(hw, I40E_REG_MSS, val); |
| 11156 | } |
| 11157 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 11158 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 11159 | msleep(75); |
| 11160 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 11161 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11162 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 11163 | i40e_stat_str(&pf->hw, err), |
| 11164 | i40e_aq_str(&pf->hw, |
| 11165 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 11166 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11167 | /* The main driver is (mostly) up and happy. We need to set this state |
| 11168 | * before setting up the misc vector or we get a race and the vector |
| 11169 | * ends up disabled forever. |
| 11170 | */ |
| 11171 | clear_bit(__I40E_DOWN, &pf->state); |
| 11172 | |
| 11173 | /* In case of MSIX we are going to setup the misc vector right here |
| 11174 | * to handle admin queue events etc. In case of legacy and MSI |
| 11175 | * the misc functionality and queue processing is combined in |
| 11176 | * the same vector and that gets setup at open. |
| 11177 | */ |
| 11178 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 11179 | err = i40e_setup_misc_vector(pf); |
| 11180 | if (err) { |
| 11181 | dev_info(&pdev->dev, |
| 11182 | "setup of misc vector failed: %d\n", err); |
| 11183 | goto err_vsis; |
| 11184 | } |
| 11185 | } |
| 11186 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11187 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11188 | /* prep for VF support */ |
| 11189 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11190 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11191 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11192 | /* disable link interrupts for VFs */ |
| 11193 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11194 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11195 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11196 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11197 | |
| 11198 | if (pci_num_vf(pdev)) { |
| 11199 | dev_info(&pdev->dev, |
| 11200 | "Active VFs found, allocating resources.\n"); |
| 11201 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11202 | if (err) |
| 11203 | dev_info(&pdev->dev, |
| 11204 | "Error %d allocating resources for existing VFs\n", |
| 11205 | err); |
| 11206 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11207 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11208 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11209 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11210 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11211 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11212 | pf->num_iwarp_msix, |
| 11213 | I40E_IWARP_IRQ_PILE_ID); |
| 11214 | if (pf->iwarp_base_vector < 0) { |
| 11215 | dev_info(&pdev->dev, |
| 11216 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 11217 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 11218 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 11219 | } |
| 11220 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11221 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11222 | i40e_dbg_pf_init(pf); |
| 11223 | |
| 11224 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11225 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11226 | |
| 11227 | /* since everything's happy, start the service_task timer */ |
| 11228 | mod_timer(&pf->service_timer, |
| 11229 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11230 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11231 | /* add this PF to client device list and launch a client service task */ |
| 11232 | err = i40e_lan_add_device(pf); |
| 11233 | if (err) |
| 11234 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 11235 | err); |
| 11236 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11237 | #define PCI_SPEED_SIZE 8 |
| 11238 | #define PCI_WIDTH_SIZE 8 |
| 11239 | /* Devices on the IOSF bus do not have this information |
| 11240 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11241 | * checking them. |
| 11242 | */ |
| 11243 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { |
| 11244 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11245 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11246 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11247 | /* Get the negotiated link width and speed from PCI config |
| 11248 | * space |
| 11249 | */ |
| 11250 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11251 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11252 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11253 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11254 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11255 | switch (hw->bus.speed) { |
| 11256 | case i40e_bus_speed_8000: |
| 11257 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11258 | case i40e_bus_speed_5000: |
| 11259 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11260 | case i40e_bus_speed_2500: |
| 11261 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11262 | default: |
| 11263 | break; |
| 11264 | } |
| 11265 | switch (hw->bus.width) { |
| 11266 | case i40e_bus_width_pcie_x8: |
| 11267 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11268 | case i40e_bus_width_pcie_x4: |
| 11269 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11270 | case i40e_bus_width_pcie_x2: |
| 11271 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11272 | case i40e_bus_width_pcie_x1: |
| 11273 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11274 | default: |
| 11275 | break; |
| 11276 | } |
| 11277 | |
| 11278 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11279 | speed, width); |
| 11280 | |
| 11281 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11282 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11283 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11284 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11285 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11286 | } |
| 11287 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11288 | /* get the requested speeds from the fw */ |
| 11289 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11290 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11291 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11292 | i40e_stat_str(&pf->hw, err), |
| 11293 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11294 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11295 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11296 | /* get the supported phy types from the fw */ |
| 11297 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11298 | if (err) |
| 11299 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11300 | i40e_stat_str(&pf->hw, err), |
| 11301 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11302 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11303 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11304 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11305 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11306 | * PF/VF VSIs. |
| 11307 | * The FW can still send Flow control frames if enabled. |
| 11308 | */ |
| 11309 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11310 | pf->main_vsi_seid); |
| 11311 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 11312 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
Henry Tieman | 4f9b430 | 2016-11-08 13:05:18 -0800 | [diff] [blame] | 11313 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
| 11314 | pf->flags |= I40E_FLAG_PHY_CONTROLS_LEDS; |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 11315 | if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722) |
| 11316 | pf->flags |= I40E_FLAG_HAVE_CRT_RETIMER; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11317 | /* print a string summarizing features */ |
| 11318 | i40e_print_features(pf); |
| 11319 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11320 | return 0; |
| 11321 | |
| 11322 | /* Unwind what we've done if something failed in the setup */ |
| 11323 | err_vsis: |
| 11324 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11325 | i40e_clear_interrupt_scheme(pf); |
| 11326 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11327 | err_switch_setup: |
| 11328 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11329 | del_timer_sync(&pf->service_timer); |
| 11330 | err_mac_addr: |
| 11331 | err_configure_lan_hmc: |
| 11332 | (void)i40e_shutdown_lan_hmc(hw); |
| 11333 | err_init_lan_hmc: |
| 11334 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11335 | err_sw_init: |
| 11336 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11337 | err_pf_reset: |
| 11338 | iounmap(hw->hw_addr); |
| 11339 | err_ioremap: |
| 11340 | kfree(pf); |
| 11341 | err_pf_alloc: |
| 11342 | pci_disable_pcie_error_reporting(pdev); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11343 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11344 | err_pci_reg: |
| 11345 | err_dma: |
| 11346 | pci_disable_device(pdev); |
| 11347 | return err; |
| 11348 | } |
| 11349 | |
| 11350 | /** |
| 11351 | * i40e_remove - Device removal routine |
| 11352 | * @pdev: PCI device information struct |
| 11353 | * |
| 11354 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11355 | * that is should release a PCI device. This could be caused by a |
| 11356 | * Hot-Plug event, or because the driver is going to be removed from |
| 11357 | * memory. |
| 11358 | **/ |
| 11359 | static void i40e_remove(struct pci_dev *pdev) |
| 11360 | { |
| 11361 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11362 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11363 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11364 | int i; |
| 11365 | |
| 11366 | i40e_dbg_pf_exit(pf); |
| 11367 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11368 | i40e_ptp_stop(pf); |
| 11369 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11370 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 11371 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 11372 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11373 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11374 | /* no more scheduling of any task */ |
Pandi Kumar Maharajan | a4618ec | 2016-02-18 09:19:25 -0800 | [diff] [blame] | 11375 | set_bit(__I40E_SUSPENDED, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11376 | set_bit(__I40E_DOWN, &pf->state); |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 11377 | if (pf->service_timer.data) |
| 11378 | del_timer_sync(&pf->service_timer); |
| 11379 | if (pf->service_task.func) |
| 11380 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11381 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11382 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11383 | i40e_free_vfs(pf); |
| 11384 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11385 | } |
| 11386 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11387 | i40e_fdir_teardown(pf); |
| 11388 | |
| 11389 | /* If there is a switch structure or any orphans, remove them. |
| 11390 | * This will leave only the PF's VSI remaining. |
| 11391 | */ |
| 11392 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11393 | if (!pf->veb[i]) |
| 11394 | continue; |
| 11395 | |
| 11396 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11397 | pf->veb[i]->uplink_seid == 0) |
| 11398 | i40e_switch_branch_release(pf->veb[i]); |
| 11399 | } |
| 11400 | |
| 11401 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11402 | * adminq and hmc. |
| 11403 | */ |
| 11404 | if (pf->vsi[pf->lan_vsi]) |
| 11405 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11406 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11407 | /* remove attached clients */ |
| 11408 | ret_code = i40e_lan_del_device(pf); |
| 11409 | if (ret_code) { |
| 11410 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 11411 | ret_code); |
| 11412 | } |
| 11413 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11414 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11415 | if (hw->hmc.hmc_obj) { |
| 11416 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11417 | if (ret_code) |
| 11418 | dev_warn(&pdev->dev, |
| 11419 | "Failed to destroy the HMC resources: %d\n", |
| 11420 | ret_code); |
| 11421 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11422 | |
| 11423 | /* shutdown the adminq */ |
Henry Tieman | ac9c5c6 | 2016-09-06 18:05:11 -0700 | [diff] [blame] | 11424 | i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11425 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11426 | /* destroy the locks only once, here */ |
| 11427 | mutex_destroy(&hw->aq.arq_mutex); |
| 11428 | mutex_destroy(&hw->aq.asq_mutex); |
| 11429 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11430 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11431 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11432 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11433 | if (pf->vsi[i]) { |
| 11434 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11435 | i40e_vsi_clear(pf->vsi[i]); |
| 11436 | pf->vsi[i] = NULL; |
| 11437 | } |
| 11438 | } |
| 11439 | |
| 11440 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11441 | kfree(pf->veb[i]); |
| 11442 | pf->veb[i] = NULL; |
| 11443 | } |
| 11444 | |
| 11445 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11446 | kfree(pf->vsi); |
| 11447 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11448 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11449 | kfree(pf); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11450 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11451 | |
| 11452 | pci_disable_pcie_error_reporting(pdev); |
| 11453 | pci_disable_device(pdev); |
| 11454 | } |
| 11455 | |
| 11456 | /** |
| 11457 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11458 | * @pdev: PCI device information struct |
| 11459 | * |
| 11460 | * Called to warn that something happened and the error handling steps |
| 11461 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11462 | * remediation. |
| 11463 | **/ |
| 11464 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11465 | enum pci_channel_state error) |
| 11466 | { |
| 11467 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11468 | |
| 11469 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11470 | |
Guilherme G Piccoli | edfc23ee | 2016-10-03 00:31:12 -0700 | [diff] [blame] | 11471 | if (!pf) { |
| 11472 | dev_info(&pdev->dev, |
| 11473 | "Cannot recover - error happened during device probe\n"); |
| 11474 | return PCI_ERS_RESULT_DISCONNECT; |
| 11475 | } |
| 11476 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11477 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11478 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11479 | rtnl_lock(); |
| 11480 | i40e_prep_for_reset(pf); |
| 11481 | rtnl_unlock(); |
| 11482 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11483 | |
| 11484 | /* Request a slot reset */ |
| 11485 | return PCI_ERS_RESULT_NEED_RESET; |
| 11486 | } |
| 11487 | |
| 11488 | /** |
| 11489 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11490 | * @pdev: PCI device information struct |
| 11491 | * |
| 11492 | * Called to find if the driver can work with the device now that |
| 11493 | * the pci slot has been reset. If a basic connection seems good |
| 11494 | * (registers are readable and have sane content) then return a |
| 11495 | * happy little PCI_ERS_RESULT_xxx. |
| 11496 | **/ |
| 11497 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11498 | { |
| 11499 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11500 | pci_ers_result_t result; |
| 11501 | int err; |
| 11502 | u32 reg; |
| 11503 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11504 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11505 | if (pci_enable_device_mem(pdev)) { |
| 11506 | dev_info(&pdev->dev, |
| 11507 | "Cannot re-enable PCI device after reset.\n"); |
| 11508 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11509 | } else { |
| 11510 | pci_set_master(pdev); |
| 11511 | pci_restore_state(pdev); |
| 11512 | pci_save_state(pdev); |
| 11513 | pci_wake_from_d3(pdev, false); |
| 11514 | |
| 11515 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11516 | if (reg == 0) |
| 11517 | result = PCI_ERS_RESULT_RECOVERED; |
| 11518 | else |
| 11519 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11520 | } |
| 11521 | |
| 11522 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11523 | if (err) { |
| 11524 | dev_info(&pdev->dev, |
| 11525 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11526 | err); |
| 11527 | /* non-fatal, continue */ |
| 11528 | } |
| 11529 | |
| 11530 | return result; |
| 11531 | } |
| 11532 | |
| 11533 | /** |
| 11534 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11535 | * @pdev: PCI device information struct |
| 11536 | * |
| 11537 | * Called to allow the driver to bring things back up after PCI error |
| 11538 | * and/or reset recovery has finished. |
| 11539 | **/ |
| 11540 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11541 | { |
| 11542 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11543 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11544 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11545 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 11546 | return; |
| 11547 | |
| 11548 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11549 | i40e_handle_reset_warning(pf); |
Vasily Averin | 4c4935a | 2015-07-08 15:04:26 +0300 | [diff] [blame] | 11550 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11551 | } |
| 11552 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11553 | /** |
Joshua Hay | 1d68005 | 2016-12-12 15:44:08 -0800 | [diff] [blame] | 11554 | * i40e_enable_mc_magic_wake - enable multicast magic packet wake up |
| 11555 | * using the mac_address_write admin q function |
| 11556 | * @pf: pointer to i40e_pf struct |
| 11557 | **/ |
| 11558 | static void i40e_enable_mc_magic_wake(struct i40e_pf *pf) |
| 11559 | { |
| 11560 | struct i40e_hw *hw = &pf->hw; |
| 11561 | i40e_status ret; |
| 11562 | u8 mac_addr[6]; |
| 11563 | u16 flags = 0; |
| 11564 | |
| 11565 | /* Get current MAC address in case it's an LAA */ |
| 11566 | if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) { |
| 11567 | ether_addr_copy(mac_addr, |
| 11568 | pf->vsi[pf->lan_vsi]->netdev->dev_addr); |
| 11569 | } else { |
| 11570 | dev_err(&pf->pdev->dev, |
| 11571 | "Failed to retrieve MAC address; using default\n"); |
| 11572 | ether_addr_copy(mac_addr, hw->mac.addr); |
| 11573 | } |
| 11574 | |
| 11575 | /* The FW expects the mac address write cmd to first be called with |
| 11576 | * one of these flags before calling it again with the multicast |
| 11577 | * enable flags. |
| 11578 | */ |
| 11579 | flags = I40E_AQC_WRITE_TYPE_LAA_WOL; |
| 11580 | |
| 11581 | if (hw->func_caps.flex10_enable && hw->partition_id != 1) |
| 11582 | flags = I40E_AQC_WRITE_TYPE_LAA_ONLY; |
| 11583 | |
| 11584 | ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL); |
| 11585 | if (ret) { |
| 11586 | dev_err(&pf->pdev->dev, |
| 11587 | "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up"); |
| 11588 | return; |
| 11589 | } |
| 11590 | |
| 11591 | flags = I40E_AQC_MC_MAG_EN |
| 11592 | | I40E_AQC_WOL_PRESERVE_ON_PFR |
| 11593 | | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG; |
| 11594 | ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL); |
| 11595 | if (ret) |
| 11596 | dev_err(&pf->pdev->dev, |
| 11597 | "Failed to enable Multicast Magic Packet wake up\n"); |
| 11598 | } |
| 11599 | |
| 11600 | /** |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11601 | * i40e_shutdown - PCI callback for shutting down |
| 11602 | * @pdev: PCI device information struct |
| 11603 | **/ |
| 11604 | static void i40e_shutdown(struct pci_dev *pdev) |
| 11605 | { |
| 11606 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11607 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11608 | |
| 11609 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11610 | set_bit(__I40E_DOWN, &pf->state); |
| 11611 | rtnl_lock(); |
| 11612 | i40e_prep_for_reset(pf); |
| 11613 | rtnl_unlock(); |
| 11614 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11615 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11616 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11617 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11618 | del_timer_sync(&pf->service_timer); |
| 11619 | cancel_work_sync(&pf->service_task); |
| 11620 | i40e_fdir_teardown(pf); |
| 11621 | |
Joshua Hay | 1d68005 | 2016-12-12 15:44:08 -0800 | [diff] [blame] | 11622 | if (pf->wol_en && (pf->flags & I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE)) |
| 11623 | i40e_enable_mc_magic_wake(pf); |
| 11624 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11625 | rtnl_lock(); |
| 11626 | i40e_prep_for_reset(pf); |
| 11627 | rtnl_unlock(); |
| 11628 | |
| 11629 | wr32(hw, I40E_PFPM_APM, |
| 11630 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11631 | wr32(hw, I40E_PFPM_WUFC, |
| 11632 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11633 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 11634 | i40e_clear_interrupt_scheme(pf); |
| 11635 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11636 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11637 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11638 | pci_set_power_state(pdev, PCI_D3hot); |
| 11639 | } |
| 11640 | } |
| 11641 | |
| 11642 | #ifdef CONFIG_PM |
| 11643 | /** |
| 11644 | * i40e_suspend - PCI callback for moving to D3 |
| 11645 | * @pdev: PCI device information struct |
| 11646 | **/ |
| 11647 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11648 | { |
| 11649 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11650 | struct i40e_hw *hw = &pf->hw; |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11651 | int retval = 0; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11652 | |
| 11653 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11654 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 11655 | |
Joshua Hay | 1d68005 | 2016-12-12 15:44:08 -0800 | [diff] [blame] | 11656 | if (pf->wol_en && (pf->flags & I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE)) |
| 11657 | i40e_enable_mc_magic_wake(pf); |
| 11658 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11659 | rtnl_lock(); |
| 11660 | i40e_prep_for_reset(pf); |
| 11661 | rtnl_unlock(); |
| 11662 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11663 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11664 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11665 | |
Greg Rose | b33d3b7 | 2016-05-16 10:26:37 -0700 | [diff] [blame] | 11666 | i40e_stop_misc_vector(pf); |
| 11667 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11668 | retval = pci_save_state(pdev); |
| 11669 | if (retval) |
| 11670 | return retval; |
| 11671 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11672 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11673 | pci_set_power_state(pdev, PCI_D3hot); |
| 11674 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11675 | return retval; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11676 | } |
| 11677 | |
| 11678 | /** |
| 11679 | * i40e_resume - PCI callback for waking up from D3 |
| 11680 | * @pdev: PCI device information struct |
| 11681 | **/ |
| 11682 | static int i40e_resume(struct pci_dev *pdev) |
| 11683 | { |
| 11684 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11685 | u32 err; |
| 11686 | |
| 11687 | pci_set_power_state(pdev, PCI_D0); |
| 11688 | pci_restore_state(pdev); |
| 11689 | /* pci_restore_state() clears dev->state_saves, so |
| 11690 | * call pci_save_state() again to restore it. |
| 11691 | */ |
| 11692 | pci_save_state(pdev); |
| 11693 | |
| 11694 | err = pci_enable_device_mem(pdev); |
| 11695 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11696 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11697 | return err; |
| 11698 | } |
| 11699 | pci_set_master(pdev); |
| 11700 | |
| 11701 | /* no wakeup events while running */ |
| 11702 | pci_wake_from_d3(pdev, false); |
| 11703 | |
| 11704 | /* handling the reset will rebuild the device state */ |
| 11705 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11706 | clear_bit(__I40E_DOWN, &pf->state); |
| 11707 | rtnl_lock(); |
| 11708 | i40e_reset_and_rebuild(pf, false); |
| 11709 | rtnl_unlock(); |
| 11710 | } |
| 11711 | |
| 11712 | return 0; |
| 11713 | } |
| 11714 | |
| 11715 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11716 | static const struct pci_error_handlers i40e_err_handler = { |
| 11717 | .error_detected = i40e_pci_error_detected, |
| 11718 | .slot_reset = i40e_pci_error_slot_reset, |
| 11719 | .resume = i40e_pci_error_resume, |
| 11720 | }; |
| 11721 | |
| 11722 | static struct pci_driver i40e_driver = { |
| 11723 | .name = i40e_driver_name, |
| 11724 | .id_table = i40e_pci_tbl, |
| 11725 | .probe = i40e_probe, |
| 11726 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11727 | #ifdef CONFIG_PM |
| 11728 | .suspend = i40e_suspend, |
| 11729 | .resume = i40e_resume, |
| 11730 | #endif |
| 11731 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11732 | .err_handler = &i40e_err_handler, |
| 11733 | .sriov_configure = i40e_pci_sriov_configure, |
| 11734 | }; |
| 11735 | |
| 11736 | /** |
| 11737 | * i40e_init_module - Driver registration routine |
| 11738 | * |
| 11739 | * i40e_init_module is the first routine called when the driver is |
| 11740 | * loaded. All it does is register with the PCI subsystem. |
| 11741 | **/ |
| 11742 | static int __init i40e_init_module(void) |
| 11743 | { |
| 11744 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 11745 | i40e_driver_string, i40e_driver_version_str); |
| 11746 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 11747 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11748 | /* we will see if single thread per module is enough for now, |
| 11749 | * it can't be any worse than using the system workqueue which |
| 11750 | * was already single threaded |
| 11751 | */ |
Jacob Keller | 6992a6c | 2016-08-04 11:37:01 -0700 | [diff] [blame] | 11752 | i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1, |
| 11753 | i40e_driver_name); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11754 | if (!i40e_wq) { |
| 11755 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 11756 | return -ENOMEM; |
| 11757 | } |
| 11758 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11759 | i40e_dbg_init(); |
| 11760 | return pci_register_driver(&i40e_driver); |
| 11761 | } |
| 11762 | module_init(i40e_init_module); |
| 11763 | |
| 11764 | /** |
| 11765 | * i40e_exit_module - Driver exit cleanup routine |
| 11766 | * |
| 11767 | * i40e_exit_module is called just before the driver is removed |
| 11768 | * from memory. |
| 11769 | **/ |
| 11770 | static void __exit i40e_exit_module(void) |
| 11771 | { |
| 11772 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11773 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11774 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11775 | } |
| 11776 | module_exit(i40e_exit_module); |