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 | |
Catherine Sullivan | e8e724d | 2014-07-10 07:58:26 +0000 | [diff] [blame] | 42 | #define DRV_VERSION_MAJOR 1 |
Bimmy Pujari | 0706195 | 2016-05-16 10:26:45 -0700 | [diff] [blame] | 43 | #define DRV_VERSION_MINOR 6 |
Bimmy Pujari | cfffef7 | 2016-11-28 16:06:11 -0800 | [diff] [blame] | 44 | #define DRV_VERSION_BUILD 27 |
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}, |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 80 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
Anjali Singhai Jain | 35dae51 | 2015-12-22 14:25:03 -0800 | [diff] [blame] | 81 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0}, |
| 82 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame] | 83 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0}, |
| 84 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0}, |
| 85 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0}, |
Catherine Sullivan | d6bf58c | 2016-03-18 12:18:08 -0700 | [diff] [blame] | 86 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0}, |
Shannon Nelson | 48a3b51 | 2015-07-23 16:54:39 -0400 | [diff] [blame] | 87 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
| 88 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0}, |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 89 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_B), 0}, |
| 90 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_SFP28), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 91 | /* required last entry */ |
| 92 | {0, } |
| 93 | }; |
| 94 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 95 | |
| 96 | #define I40E_MAX_VF_COUNT 128 |
| 97 | static int debug = -1; |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 98 | module_param(debug, uint, 0); |
| 99 | 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] | 100 | |
| 101 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 102 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 103 | MODULE_LICENSE("GPL"); |
| 104 | MODULE_VERSION(DRV_VERSION); |
| 105 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 106 | static struct workqueue_struct *i40e_wq; |
| 107 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 108 | /** |
| 109 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 110 | * @hw: pointer to the HW structure |
| 111 | * @mem: ptr to mem struct to fill out |
| 112 | * @size: size of memory requested |
| 113 | * @alignment: what to align the allocation to |
| 114 | **/ |
| 115 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 116 | u64 size, u32 alignment) |
| 117 | { |
| 118 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 119 | |
| 120 | mem->size = ALIGN(size, alignment); |
| 121 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 122 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 123 | if (!mem->va) |
| 124 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 125 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 126 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /** |
| 130 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 131 | * @hw: pointer to the HW structure |
| 132 | * @mem: ptr to mem struct to free |
| 133 | **/ |
| 134 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 135 | { |
| 136 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 137 | |
| 138 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 139 | mem->va = NULL; |
| 140 | mem->pa = 0; |
| 141 | mem->size = 0; |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 148 | * @hw: pointer to the HW structure |
| 149 | * @mem: ptr to mem struct to fill out |
| 150 | * @size: size of memory requested |
| 151 | **/ |
| 152 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 153 | u32 size) |
| 154 | { |
| 155 | mem->size = size; |
| 156 | mem->va = kzalloc(size, GFP_KERNEL); |
| 157 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 158 | if (!mem->va) |
| 159 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 160 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 161 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /** |
| 165 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 166 | * @hw: pointer to the HW structure |
| 167 | * @mem: ptr to mem struct to free |
| 168 | **/ |
| 169 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 170 | { |
| 171 | /* it's ok to kfree a NULL pointer */ |
| 172 | kfree(mem->va); |
| 173 | mem->va = NULL; |
| 174 | mem->size = 0; |
| 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * i40e_get_lump - find a lump of free generic resource |
| 181 | * @pf: board private structure |
| 182 | * @pile: the pile of resource to search |
| 183 | * @needed: the number of items needed |
| 184 | * @id: an owner id to stick on the items assigned |
| 185 | * |
| 186 | * Returns the base item index of the lump, or negative for error |
| 187 | * |
| 188 | * The search_hint trick and lack of advanced fit-finding only work |
| 189 | * because we're highly likely to have all the same size lump requests. |
| 190 | * Linear search time and any fragmentation should be minimal. |
| 191 | **/ |
| 192 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 193 | u16 needed, u16 id) |
| 194 | { |
| 195 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 196 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 197 | |
| 198 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 199 | dev_info(&pf->pdev->dev, |
| 200 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 201 | pile, needed, id); |
| 202 | return -EINVAL; |
| 203 | } |
| 204 | |
| 205 | /* start the linear search with an imperfect hint */ |
| 206 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 207 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 208 | /* skip already allocated entries */ |
| 209 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 210 | i++; |
| 211 | continue; |
| 212 | } |
| 213 | |
| 214 | /* do we have enough in this lump? */ |
| 215 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 216 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 217 | break; |
| 218 | } |
| 219 | |
| 220 | if (j == needed) { |
| 221 | /* there was enough, so assign it to the requestor */ |
| 222 | for (j = 0; j < needed; j++) |
| 223 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 224 | ret = i; |
| 225 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 226 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 227 | } |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 228 | |
| 229 | /* not enough, so skip over it and continue looking */ |
| 230 | i += j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | return ret; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * i40e_put_lump - return a lump of generic resource |
| 238 | * @pile: the pile of resource to search |
| 239 | * @index: the base item index |
| 240 | * @id: the owner id of the items assigned |
| 241 | * |
| 242 | * Returns the count of items in the lump |
| 243 | **/ |
| 244 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 245 | { |
| 246 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 247 | int count = 0; |
| 248 | int i; |
| 249 | |
| 250 | if (!pile || index >= pile->num_entries) |
| 251 | return -EINVAL; |
| 252 | |
| 253 | for (i = index; |
| 254 | i < pile->num_entries && pile->list[i] == valid_id; |
| 255 | i++) { |
| 256 | pile->list[i] = 0; |
| 257 | count++; |
| 258 | } |
| 259 | |
| 260 | if (count && index < pile->search_hint) |
| 261 | pile->search_hint = index; |
| 262 | |
| 263 | return count; |
| 264 | } |
| 265 | |
| 266 | /** |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 267 | * i40e_find_vsi_from_id - searches for the vsi with the given id |
| 268 | * @pf - the pf structure to search for the vsi |
| 269 | * @id - id of the vsi it is searching for |
| 270 | **/ |
| 271 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) |
| 272 | { |
| 273 | int i; |
| 274 | |
| 275 | for (i = 0; i < pf->num_alloc_vsi; i++) |
| 276 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) |
| 277 | return pf->vsi[i]; |
| 278 | |
| 279 | return NULL; |
| 280 | } |
| 281 | |
| 282 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 283 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 284 | * @pf: board private structure |
| 285 | * |
| 286 | * If not already scheduled, this puts the task into the work queue |
| 287 | **/ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 288 | void i40e_service_event_schedule(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 289 | { |
| 290 | if (!test_bit(__I40E_DOWN, &pf->state) && |
Mitch Williams | 9108903 | 2016-11-21 13:03:51 -0800 | [diff] [blame] | 291 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 292 | queue_work(i40e_wq, &pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /** |
| 296 | * i40e_tx_timeout - Respond to a Tx Hang |
| 297 | * @netdev: network interface device structure |
| 298 | * |
| 299 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 300 | * device is munged, not just the one netdev port, so go for the full |
| 301 | * reset. |
| 302 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 303 | #ifdef I40E_FCOE |
| 304 | void i40e_tx_timeout(struct net_device *netdev) |
| 305 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 306 | static void i40e_tx_timeout(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 307 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 308 | { |
| 309 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 310 | struct i40e_vsi *vsi = np->vsi; |
| 311 | struct i40e_pf *pf = vsi->back; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 312 | struct i40e_ring *tx_ring = NULL; |
| 313 | unsigned int i, hung_queue = 0; |
| 314 | u32 head, val; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 315 | |
| 316 | pf->tx_timeout_count++; |
| 317 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 318 | /* find the stopped queue the same way the stack does */ |
| 319 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 320 | struct netdev_queue *q; |
| 321 | unsigned long trans_start; |
| 322 | |
| 323 | q = netdev_get_tx_queue(netdev, i); |
Florian Westphal | 9b36627 | 2016-05-03 16:33:14 +0200 | [diff] [blame] | 324 | trans_start = q->trans_start; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 325 | if (netif_xmit_stopped(q) && |
| 326 | time_after(jiffies, |
| 327 | (trans_start + netdev->watchdog_timeo))) { |
| 328 | hung_queue = i; |
| 329 | break; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | if (i == netdev->num_tx_queues) { |
| 334 | netdev_info(netdev, "tx_timeout: no netdev hung queue found\n"); |
| 335 | } else { |
| 336 | /* now that we have an index, find the tx_ring struct */ |
| 337 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 338 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 339 | if (hung_queue == |
| 340 | vsi->tx_rings[i]->queue_index) { |
| 341 | tx_ring = vsi->tx_rings[i]; |
| 342 | break; |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 348 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 349 | pf->tx_timeout_recovery_level = 1; /* reset after some time */ |
| 350 | else if (time_before(jiffies, |
| 351 | (pf->tx_timeout_last_recovery + netdev->watchdog_timeo))) |
| 352 | return; /* don't do any new action before the next timeout */ |
| 353 | |
| 354 | if (tx_ring) { |
| 355 | head = i40e_get_head(tx_ring); |
| 356 | /* Read interrupt register */ |
| 357 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 358 | val = rd32(&pf->hw, |
| 359 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 360 | tx_ring->vsi->base_vector - 1)); |
| 361 | else |
| 362 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 363 | |
| 364 | 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", |
| 365 | vsi->seid, hung_queue, tx_ring->next_to_clean, |
| 366 | head, tx_ring->next_to_use, |
| 367 | readl(tx_ring->tail), val); |
| 368 | } |
| 369 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 370 | pf->tx_timeout_last_recovery = jiffies; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 371 | netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n", |
| 372 | pf->tx_timeout_recovery_level, hung_queue); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 373 | |
| 374 | switch (pf->tx_timeout_recovery_level) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 375 | case 1: |
| 376 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 377 | break; |
| 378 | case 2: |
| 379 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 380 | break; |
| 381 | case 3: |
| 382 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 383 | break; |
| 384 | default: |
| 385 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 386 | break; |
| 387 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 388 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 389 | i40e_service_event_schedule(pf); |
| 390 | pf->tx_timeout_recovery_level++; |
| 391 | } |
| 392 | |
| 393 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 394 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 395 | * @vsi: the VSI we care about |
| 396 | * |
| 397 | * Returns the address of the device statistics structure. |
| 398 | * The statistics are actually updated from the service task. |
| 399 | **/ |
| 400 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 401 | { |
| 402 | return &vsi->net_stats; |
| 403 | } |
| 404 | |
| 405 | /** |
| 406 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 407 | * @netdev: network interface device structure |
| 408 | * |
| 409 | * Returns the address of the device statistics structure. |
| 410 | * The statistics are actually updated from the service task. |
| 411 | **/ |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 412 | #ifndef I40E_FCOE |
| 413 | static |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 414 | #endif |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 415 | void i40e_get_netdev_stats_struct(struct net_device *netdev, |
| 416 | struct rtnl_link_stats64 *stats) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 417 | { |
| 418 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 419 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 420 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 421 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 422 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 423 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 424 | if (test_bit(__I40E_DOWN, &vsi->state)) |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 425 | return; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 426 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 427 | if (!vsi->tx_rings) |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 428 | return; |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 429 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 430 | rcu_read_lock(); |
| 431 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 432 | u64 bytes, packets; |
| 433 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 434 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 435 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 436 | if (!tx_ring) |
| 437 | continue; |
| 438 | |
| 439 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 440 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 441 | packets = tx_ring->stats.packets; |
| 442 | bytes = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 443 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 444 | |
| 445 | stats->tx_packets += packets; |
| 446 | stats->tx_bytes += bytes; |
| 447 | rx_ring = &tx_ring[1]; |
| 448 | |
| 449 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 450 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 451 | packets = rx_ring->stats.packets; |
| 452 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 453 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 454 | |
| 455 | stats->rx_packets += packets; |
| 456 | stats->rx_bytes += bytes; |
| 457 | } |
| 458 | rcu_read_unlock(); |
| 459 | |
Akeem G Abodunrin | a5282f4 | 2014-05-10 04:49:03 +0000 | [diff] [blame] | 460 | /* following stats updated by i40e_watchdog_subtask() */ |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 461 | stats->multicast = vsi_stats->multicast; |
| 462 | stats->tx_errors = vsi_stats->tx_errors; |
| 463 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 464 | stats->rx_errors = vsi_stats->rx_errors; |
Jesse Brandeburg | d8201e2 | 2015-07-23 16:54:35 -0400 | [diff] [blame] | 465 | stats->rx_dropped = vsi_stats->rx_dropped; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 466 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 467 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /** |
| 471 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 472 | * @vsi: the VSI to have its stats reset |
| 473 | **/ |
| 474 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 475 | { |
| 476 | struct rtnl_link_stats64 *ns; |
| 477 | int i; |
| 478 | |
| 479 | if (!vsi) |
| 480 | return; |
| 481 | |
| 482 | ns = i40e_get_vsi_stats_struct(vsi); |
| 483 | memset(ns, 0, sizeof(*ns)); |
| 484 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 485 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 486 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 487 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 488 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 489 | memset(&vsi->rx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 490 | sizeof(vsi->rx_rings[i]->stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 491 | memset(&vsi->rx_rings[i]->rx_stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 492 | sizeof(vsi->rx_rings[i]->rx_stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 493 | memset(&vsi->tx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 494 | sizeof(vsi->tx_rings[i]->stats)); |
| 495 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 496 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 497 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 498 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 499 | vsi->stat_offsets_loaded = false; |
| 500 | } |
| 501 | |
| 502 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 503 | * 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] | 504 | * @pf: the PF to be reset |
| 505 | **/ |
| 506 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 507 | { |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 508 | int i; |
| 509 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 510 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 511 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 512 | pf->stat_offsets_loaded = false; |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 513 | |
| 514 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 515 | if (pf->veb[i]) { |
| 516 | memset(&pf->veb[i]->stats, 0, |
| 517 | sizeof(pf->veb[i]->stats)); |
| 518 | memset(&pf->veb[i]->stats_offsets, 0, |
| 519 | sizeof(pf->veb[i]->stats_offsets)); |
| 520 | pf->veb[i]->stat_offsets_loaded = false; |
| 521 | } |
| 522 | } |
Catherine Sullivan | 42bce04 | 2016-07-27 12:02:32 -0700 | [diff] [blame] | 523 | pf->hw_csum_rx_error = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | /** |
| 527 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 528 | * @hw: ptr to the hardware info |
| 529 | * @hireg: the high 32 bit reg to read |
| 530 | * @loreg: the low 32 bit reg to read |
| 531 | * @offset_loaded: has the initial offset been loaded yet |
| 532 | * @offset: ptr to current offset value |
| 533 | * @stat: ptr to the stat |
| 534 | * |
| 535 | * Since the device stats are not reset at PFReset, they likely will not |
| 536 | * be zeroed when the driver starts. We'll save the first values read |
| 537 | * and use them as offsets to be subtracted from the raw values in order |
| 538 | * to report stats that count from zero. In the process, we also manage |
| 539 | * the potential roll-over. |
| 540 | **/ |
| 541 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 542 | bool offset_loaded, u64 *offset, u64 *stat) |
| 543 | { |
| 544 | u64 new_data; |
| 545 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 546 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 547 | new_data = rd32(hw, loreg); |
| 548 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 549 | } else { |
| 550 | new_data = rd64(hw, loreg); |
| 551 | } |
| 552 | if (!offset_loaded) |
| 553 | *offset = new_data; |
| 554 | if (likely(new_data >= *offset)) |
| 555 | *stat = new_data - *offset; |
| 556 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 557 | *stat = (new_data + BIT_ULL(48)) - *offset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 558 | *stat &= 0xFFFFFFFFFFFFULL; |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 563 | * @hw: ptr to the hardware info |
| 564 | * @reg: the hw reg to read |
| 565 | * @offset_loaded: has the initial offset been loaded yet |
| 566 | * @offset: ptr to current offset value |
| 567 | * @stat: ptr to the stat |
| 568 | **/ |
| 569 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 570 | bool offset_loaded, u64 *offset, u64 *stat) |
| 571 | { |
| 572 | u32 new_data; |
| 573 | |
| 574 | new_data = rd32(hw, reg); |
| 575 | if (!offset_loaded) |
| 576 | *offset = new_data; |
| 577 | if (likely(new_data >= *offset)) |
| 578 | *stat = (u32)(new_data - *offset); |
| 579 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 580 | *stat = (u32)((new_data + BIT_ULL(32)) - *offset); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | /** |
| 584 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 585 | * @vsi: the VSI to be updated |
| 586 | **/ |
| 587 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 588 | { |
| 589 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 590 | struct i40e_pf *pf = vsi->back; |
| 591 | struct i40e_hw *hw = &pf->hw; |
| 592 | struct i40e_eth_stats *oes; |
| 593 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 594 | |
| 595 | es = &vsi->eth_stats; |
| 596 | oes = &vsi->eth_stats_offsets; |
| 597 | |
| 598 | /* Gather up the stats that the hw collects */ |
| 599 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 600 | vsi->stat_offsets_loaded, |
| 601 | &oes->tx_errors, &es->tx_errors); |
| 602 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 603 | vsi->stat_offsets_loaded, |
| 604 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 605 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 606 | vsi->stat_offsets_loaded, |
| 607 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 608 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 609 | vsi->stat_offsets_loaded, |
| 610 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 611 | |
| 612 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 613 | I40E_GLV_GORCL(stat_idx), |
| 614 | vsi->stat_offsets_loaded, |
| 615 | &oes->rx_bytes, &es->rx_bytes); |
| 616 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 617 | I40E_GLV_UPRCL(stat_idx), |
| 618 | vsi->stat_offsets_loaded, |
| 619 | &oes->rx_unicast, &es->rx_unicast); |
| 620 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 621 | I40E_GLV_MPRCL(stat_idx), |
| 622 | vsi->stat_offsets_loaded, |
| 623 | &oes->rx_multicast, &es->rx_multicast); |
| 624 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 625 | I40E_GLV_BPRCL(stat_idx), |
| 626 | vsi->stat_offsets_loaded, |
| 627 | &oes->rx_broadcast, &es->rx_broadcast); |
| 628 | |
| 629 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 630 | I40E_GLV_GOTCL(stat_idx), |
| 631 | vsi->stat_offsets_loaded, |
| 632 | &oes->tx_bytes, &es->tx_bytes); |
| 633 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 634 | I40E_GLV_UPTCL(stat_idx), |
| 635 | vsi->stat_offsets_loaded, |
| 636 | &oes->tx_unicast, &es->tx_unicast); |
| 637 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 638 | I40E_GLV_MPTCL(stat_idx), |
| 639 | vsi->stat_offsets_loaded, |
| 640 | &oes->tx_multicast, &es->tx_multicast); |
| 641 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 642 | I40E_GLV_BPTCL(stat_idx), |
| 643 | vsi->stat_offsets_loaded, |
| 644 | &oes->tx_broadcast, &es->tx_broadcast); |
| 645 | vsi->stat_offsets_loaded = true; |
| 646 | } |
| 647 | |
| 648 | /** |
| 649 | * i40e_update_veb_stats - Update Switch component statistics |
| 650 | * @veb: the VEB being updated |
| 651 | **/ |
| 652 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 653 | { |
| 654 | struct i40e_pf *pf = veb->pf; |
| 655 | struct i40e_hw *hw = &pf->hw; |
| 656 | struct i40e_eth_stats *oes; |
| 657 | struct i40e_eth_stats *es; /* device's eth stats */ |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 658 | struct i40e_veb_tc_stats *veb_oes; |
| 659 | struct i40e_veb_tc_stats *veb_es; |
| 660 | int i, idx = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 661 | |
| 662 | idx = veb->stats_idx; |
| 663 | es = &veb->stats; |
| 664 | oes = &veb->stats_offsets; |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 665 | veb_es = &veb->tc_stats; |
| 666 | veb_oes = &veb->tc_stats_offsets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 667 | |
| 668 | /* Gather up the stats that the hw collects */ |
| 669 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 670 | veb->stat_offsets_loaded, |
| 671 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 672 | if (hw->revision_id > 0) |
| 673 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 674 | veb->stat_offsets_loaded, |
| 675 | &oes->rx_unknown_protocol, |
| 676 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 677 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 678 | veb->stat_offsets_loaded, |
| 679 | &oes->rx_bytes, &es->rx_bytes); |
| 680 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 681 | veb->stat_offsets_loaded, |
| 682 | &oes->rx_unicast, &es->rx_unicast); |
| 683 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 684 | veb->stat_offsets_loaded, |
| 685 | &oes->rx_multicast, &es->rx_multicast); |
| 686 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 687 | veb->stat_offsets_loaded, |
| 688 | &oes->rx_broadcast, &es->rx_broadcast); |
| 689 | |
| 690 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 691 | veb->stat_offsets_loaded, |
| 692 | &oes->tx_bytes, &es->tx_bytes); |
| 693 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 694 | veb->stat_offsets_loaded, |
| 695 | &oes->tx_unicast, &es->tx_unicast); |
| 696 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 697 | veb->stat_offsets_loaded, |
| 698 | &oes->tx_multicast, &es->tx_multicast); |
| 699 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 700 | veb->stat_offsets_loaded, |
| 701 | &oes->tx_broadcast, &es->tx_broadcast); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 702 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 703 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), |
| 704 | I40E_GLVEBTC_RPCL(i, idx), |
| 705 | veb->stat_offsets_loaded, |
| 706 | &veb_oes->tc_rx_packets[i], |
| 707 | &veb_es->tc_rx_packets[i]); |
| 708 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), |
| 709 | I40E_GLVEBTC_RBCL(i, idx), |
| 710 | veb->stat_offsets_loaded, |
| 711 | &veb_oes->tc_rx_bytes[i], |
| 712 | &veb_es->tc_rx_bytes[i]); |
| 713 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), |
| 714 | I40E_GLVEBTC_TPCL(i, idx), |
| 715 | veb->stat_offsets_loaded, |
| 716 | &veb_oes->tc_tx_packets[i], |
| 717 | &veb_es->tc_tx_packets[i]); |
| 718 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), |
| 719 | I40E_GLVEBTC_TBCL(i, idx), |
| 720 | veb->stat_offsets_loaded, |
| 721 | &veb_oes->tc_tx_bytes[i], |
| 722 | &veb_es->tc_tx_bytes[i]); |
| 723 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 724 | veb->stat_offsets_loaded = true; |
| 725 | } |
| 726 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 727 | #ifdef I40E_FCOE |
| 728 | /** |
| 729 | * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters. |
| 730 | * @vsi: the VSI that is capable of doing FCoE |
| 731 | **/ |
| 732 | static void i40e_update_fcoe_stats(struct i40e_vsi *vsi) |
| 733 | { |
| 734 | struct i40e_pf *pf = vsi->back; |
| 735 | struct i40e_hw *hw = &pf->hw; |
| 736 | struct i40e_fcoe_stats *ofs; |
| 737 | struct i40e_fcoe_stats *fs; /* device's eth stats */ |
| 738 | int idx; |
| 739 | |
| 740 | if (vsi->type != I40E_VSI_FCOE) |
| 741 | return; |
| 742 | |
Kiran Patil | 4147e2c | 2016-01-15 14:33:14 -0800 | [diff] [blame] | 743 | idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 744 | fs = &vsi->fcoe_stats; |
| 745 | ofs = &vsi->fcoe_stats_offsets; |
| 746 | |
| 747 | i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx), |
| 748 | vsi->fcoe_stat_offsets_loaded, |
| 749 | &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets); |
| 750 | i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx), |
| 751 | vsi->fcoe_stat_offsets_loaded, |
| 752 | &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords); |
| 753 | i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx), |
| 754 | vsi->fcoe_stat_offsets_loaded, |
| 755 | &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped); |
| 756 | i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx), |
| 757 | vsi->fcoe_stat_offsets_loaded, |
| 758 | &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets); |
| 759 | i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx), |
| 760 | vsi->fcoe_stat_offsets_loaded, |
| 761 | &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords); |
| 762 | i40e_stat_update32(hw, I40E_GL_FCOECRC(idx), |
| 763 | vsi->fcoe_stat_offsets_loaded, |
| 764 | &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc); |
| 765 | i40e_stat_update32(hw, I40E_GL_FCOELAST(idx), |
| 766 | vsi->fcoe_stat_offsets_loaded, |
| 767 | &ofs->fcoe_last_error, &fs->fcoe_last_error); |
| 768 | i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx), |
| 769 | vsi->fcoe_stat_offsets_loaded, |
| 770 | &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count); |
| 771 | |
| 772 | vsi->fcoe_stat_offsets_loaded = true; |
| 773 | } |
| 774 | |
| 775 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 776 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 777 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 778 | * @vsi: the VSI to be updated |
| 779 | * |
| 780 | * There are a few instances where we store the same stat in a |
| 781 | * couple of different structs. This is partly because we have |
| 782 | * the netdev stats that need to be filled out, which is slightly |
| 783 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 784 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 785 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 786 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 787 | { |
| 788 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 789 | struct rtnl_link_stats64 *ons; |
| 790 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 791 | struct i40e_eth_stats *oes; |
| 792 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 793 | u32 tx_restart, tx_busy; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 794 | u64 tx_lost_interrupt; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 795 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 796 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 797 | u64 bytes, packets; |
| 798 | unsigned int start; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 799 | u64 tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 800 | u64 tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 801 | u64 rx_p, rx_b; |
| 802 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 803 | u16 q; |
| 804 | |
| 805 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 806 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 807 | return; |
| 808 | |
| 809 | ns = i40e_get_vsi_stats_struct(vsi); |
| 810 | ons = &vsi->net_stats_offsets; |
| 811 | es = &vsi->eth_stats; |
| 812 | oes = &vsi->eth_stats_offsets; |
| 813 | |
| 814 | /* Gather up the netdev and vsi stats that the driver collects |
| 815 | * on the fly during packet processing |
| 816 | */ |
| 817 | rx_b = rx_p = 0; |
| 818 | tx_b = tx_p = 0; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 819 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 820 | tx_lost_interrupt = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 821 | rx_page = 0; |
| 822 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 823 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 824 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 825 | /* locate Tx ring */ |
| 826 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 827 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 828 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 829 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 830 | packets = p->stats.packets; |
| 831 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 832 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 833 | tx_b += bytes; |
| 834 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 835 | tx_restart += p->tx_stats.restart_queue; |
| 836 | tx_busy += p->tx_stats.tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 837 | tx_linearize += p->tx_stats.tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 838 | tx_force_wb += p->tx_stats.tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 839 | tx_lost_interrupt += p->tx_stats.tx_lost_interrupt; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 840 | |
| 841 | /* Rx queue is part of the same block as Tx queue */ |
| 842 | p = &p[1]; |
| 843 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 844 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 845 | packets = p->stats.packets; |
| 846 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 847 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 848 | rx_b += bytes; |
| 849 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 850 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 851 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 852 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 853 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 854 | vsi->tx_restart = tx_restart; |
| 855 | vsi->tx_busy = tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 856 | vsi->tx_linearize = tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 857 | vsi->tx_force_wb = tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 858 | vsi->tx_lost_interrupt = tx_lost_interrupt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 859 | vsi->rx_page_failed = rx_page; |
| 860 | vsi->rx_buf_failed = rx_buf; |
| 861 | |
| 862 | ns->rx_packets = rx_p; |
| 863 | ns->rx_bytes = rx_b; |
| 864 | ns->tx_packets = tx_p; |
| 865 | ns->tx_bytes = tx_b; |
| 866 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 867 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 868 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 869 | ons->tx_errors = oes->tx_errors; |
| 870 | ns->tx_errors = es->tx_errors; |
| 871 | ons->multicast = oes->rx_multicast; |
| 872 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 873 | ons->rx_dropped = oes->rx_discards; |
| 874 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 875 | ons->tx_dropped = oes->tx_discards; |
| 876 | ns->tx_dropped = es->tx_discards; |
| 877 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 878 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 879 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 880 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 881 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 882 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 883 | } |
| 884 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 885 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 886 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 887 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 888 | * @pf: the PF to be updated |
| 889 | **/ |
| 890 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 891 | { |
| 892 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 893 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 894 | struct i40e_hw *hw = &pf->hw; |
| 895 | u32 val; |
| 896 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 897 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 898 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 899 | I40E_GLPRT_GORCL(hw->port), |
| 900 | pf->stat_offsets_loaded, |
| 901 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 902 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 903 | I40E_GLPRT_GOTCL(hw->port), |
| 904 | pf->stat_offsets_loaded, |
| 905 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 906 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 907 | pf->stat_offsets_loaded, |
| 908 | &osd->eth.rx_discards, |
| 909 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 910 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 911 | I40E_GLPRT_UPRCL(hw->port), |
| 912 | pf->stat_offsets_loaded, |
| 913 | &osd->eth.rx_unicast, |
| 914 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 915 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 916 | I40E_GLPRT_MPRCL(hw->port), |
| 917 | pf->stat_offsets_loaded, |
| 918 | &osd->eth.rx_multicast, |
| 919 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 920 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 921 | I40E_GLPRT_BPRCL(hw->port), |
| 922 | pf->stat_offsets_loaded, |
| 923 | &osd->eth.rx_broadcast, |
| 924 | &nsd->eth.rx_broadcast); |
| 925 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 926 | I40E_GLPRT_UPTCL(hw->port), |
| 927 | pf->stat_offsets_loaded, |
| 928 | &osd->eth.tx_unicast, |
| 929 | &nsd->eth.tx_unicast); |
| 930 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 931 | I40E_GLPRT_MPTCL(hw->port), |
| 932 | pf->stat_offsets_loaded, |
| 933 | &osd->eth.tx_multicast, |
| 934 | &nsd->eth.tx_multicast); |
| 935 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 936 | I40E_GLPRT_BPTCL(hw->port), |
| 937 | pf->stat_offsets_loaded, |
| 938 | &osd->eth.tx_broadcast, |
| 939 | &nsd->eth.tx_broadcast); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 940 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 941 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 942 | pf->stat_offsets_loaded, |
| 943 | &osd->tx_dropped_link_down, |
| 944 | &nsd->tx_dropped_link_down); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 945 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 946 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 947 | pf->stat_offsets_loaded, |
| 948 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 949 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 950 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 951 | pf->stat_offsets_loaded, |
| 952 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 953 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 954 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 955 | pf->stat_offsets_loaded, |
| 956 | &osd->mac_local_faults, |
| 957 | &nsd->mac_local_faults); |
| 958 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 959 | pf->stat_offsets_loaded, |
| 960 | &osd->mac_remote_faults, |
| 961 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 962 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 963 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 964 | pf->stat_offsets_loaded, |
| 965 | &osd->rx_length_errors, |
| 966 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 967 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 968 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 969 | pf->stat_offsets_loaded, |
| 970 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 971 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 972 | pf->stat_offsets_loaded, |
| 973 | &osd->link_xon_tx, &nsd->link_xon_tx); |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 974 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 975 | pf->stat_offsets_loaded, |
| 976 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 977 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 978 | pf->stat_offsets_loaded, |
| 979 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 980 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 981 | for (i = 0; i < 8; i++) { |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 982 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 983 | pf->stat_offsets_loaded, |
| 984 | &osd->priority_xoff_rx[i], |
| 985 | &nsd->priority_xoff_rx[i]); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 986 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 987 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 988 | &osd->priority_xon_rx[i], |
| 989 | &nsd->priority_xon_rx[i]); |
| 990 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 991 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 992 | &osd->priority_xon_tx[i], |
| 993 | &nsd->priority_xon_tx[i]); |
| 994 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 995 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 996 | &osd->priority_xoff_tx[i], |
| 997 | &nsd->priority_xoff_tx[i]); |
| 998 | i40e_stat_update32(hw, |
| 999 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1000 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1001 | &osd->priority_xon_2_xoff[i], |
| 1002 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1005 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 1006 | I40E_GLPRT_PRC64L(hw->port), |
| 1007 | pf->stat_offsets_loaded, |
| 1008 | &osd->rx_size_64, &nsd->rx_size_64); |
| 1009 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 1010 | I40E_GLPRT_PRC127L(hw->port), |
| 1011 | pf->stat_offsets_loaded, |
| 1012 | &osd->rx_size_127, &nsd->rx_size_127); |
| 1013 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 1014 | I40E_GLPRT_PRC255L(hw->port), |
| 1015 | pf->stat_offsets_loaded, |
| 1016 | &osd->rx_size_255, &nsd->rx_size_255); |
| 1017 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 1018 | I40E_GLPRT_PRC511L(hw->port), |
| 1019 | pf->stat_offsets_loaded, |
| 1020 | &osd->rx_size_511, &nsd->rx_size_511); |
| 1021 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 1022 | I40E_GLPRT_PRC1023L(hw->port), |
| 1023 | pf->stat_offsets_loaded, |
| 1024 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 1025 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 1026 | I40E_GLPRT_PRC1522L(hw->port), |
| 1027 | pf->stat_offsets_loaded, |
| 1028 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 1029 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 1030 | I40E_GLPRT_PRC9522L(hw->port), |
| 1031 | pf->stat_offsets_loaded, |
| 1032 | &osd->rx_size_big, &nsd->rx_size_big); |
| 1033 | |
| 1034 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 1035 | I40E_GLPRT_PTC64L(hw->port), |
| 1036 | pf->stat_offsets_loaded, |
| 1037 | &osd->tx_size_64, &nsd->tx_size_64); |
| 1038 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 1039 | I40E_GLPRT_PTC127L(hw->port), |
| 1040 | pf->stat_offsets_loaded, |
| 1041 | &osd->tx_size_127, &nsd->tx_size_127); |
| 1042 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 1043 | I40E_GLPRT_PTC255L(hw->port), |
| 1044 | pf->stat_offsets_loaded, |
| 1045 | &osd->tx_size_255, &nsd->tx_size_255); |
| 1046 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 1047 | I40E_GLPRT_PTC511L(hw->port), |
| 1048 | pf->stat_offsets_loaded, |
| 1049 | &osd->tx_size_511, &nsd->tx_size_511); |
| 1050 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 1051 | I40E_GLPRT_PTC1023L(hw->port), |
| 1052 | pf->stat_offsets_loaded, |
| 1053 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 1054 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 1055 | I40E_GLPRT_PTC1522L(hw->port), |
| 1056 | pf->stat_offsets_loaded, |
| 1057 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1058 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1059 | I40E_GLPRT_PTC9522L(hw->port), |
| 1060 | pf->stat_offsets_loaded, |
| 1061 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1062 | |
| 1063 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1064 | pf->stat_offsets_loaded, |
| 1065 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1066 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1067 | pf->stat_offsets_loaded, |
| 1068 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1069 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1070 | pf->stat_offsets_loaded, |
| 1071 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1072 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1073 | pf->stat_offsets_loaded, |
| 1074 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1075 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1076 | /* FDIR stats */ |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1077 | i40e_stat_update32(hw, |
| 1078 | 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] | 1079 | pf->stat_offsets_loaded, |
| 1080 | &osd->fd_atr_match, &nsd->fd_atr_match); |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1081 | i40e_stat_update32(hw, |
| 1082 | 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] | 1083 | pf->stat_offsets_loaded, |
| 1084 | &osd->fd_sb_match, &nsd->fd_sb_match); |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 1085 | i40e_stat_update32(hw, |
| 1086 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), |
| 1087 | pf->stat_offsets_loaded, |
| 1088 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1089 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1090 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1091 | nsd->tx_lpi_status = |
| 1092 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1093 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1094 | nsd->rx_lpi_status = |
| 1095 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1096 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1097 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1098 | pf->stat_offsets_loaded, |
| 1099 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1100 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1101 | pf->stat_offsets_loaded, |
| 1102 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1103 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1104 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
| 1105 | !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) |
| 1106 | nsd->fd_sb_status = true; |
| 1107 | else |
| 1108 | nsd->fd_sb_status = false; |
| 1109 | |
| 1110 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
| 1111 | !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 1112 | nsd->fd_atr_status = true; |
| 1113 | else |
| 1114 | nsd->fd_atr_status = false; |
| 1115 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1116 | pf->stat_offsets_loaded = true; |
| 1117 | } |
| 1118 | |
| 1119 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1120 | * i40e_update_stats - Update the various statistics counters. |
| 1121 | * @vsi: the VSI to be updated |
| 1122 | * |
| 1123 | * Update the various stats for this VSI and its related entities. |
| 1124 | **/ |
| 1125 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1126 | { |
| 1127 | struct i40e_pf *pf = vsi->back; |
| 1128 | |
| 1129 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1130 | i40e_update_pf_stats(pf); |
| 1131 | |
| 1132 | i40e_update_vsi_stats(vsi); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1133 | #ifdef I40E_FCOE |
| 1134 | i40e_update_fcoe_stats(vsi); |
| 1135 | #endif |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1139 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1140 | * @vsi: the VSI to be searched |
| 1141 | * @macaddr: the MAC address |
| 1142 | * @vlan: the vlan |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1143 | * |
| 1144 | * Returns ptr to the filter object or NULL |
| 1145 | **/ |
| 1146 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1147 | const u8 *macaddr, s16 vlan) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1148 | { |
| 1149 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1150 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1151 | |
| 1152 | if (!vsi || !macaddr) |
| 1153 | return NULL; |
| 1154 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1155 | key = i40e_addr_to_hkey(macaddr); |
| 1156 | hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1157 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1158 | (vlan == f->vlan)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1159 | return f; |
| 1160 | } |
| 1161 | return NULL; |
| 1162 | } |
| 1163 | |
| 1164 | /** |
| 1165 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1166 | * @vsi: the VSI to be searched |
| 1167 | * @macaddr: the MAC address we are searching for |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1168 | * |
| 1169 | * Returns the first filter with the provided MAC address or NULL if |
| 1170 | * MAC address was not found |
| 1171 | **/ |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1172 | 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] | 1173 | { |
| 1174 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1175 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1176 | |
| 1177 | if (!vsi || !macaddr) |
| 1178 | return NULL; |
| 1179 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1180 | key = i40e_addr_to_hkey(macaddr); |
| 1181 | hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1182 | if ((ether_addr_equal(macaddr, f->macaddr))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1183 | return f; |
| 1184 | } |
| 1185 | return NULL; |
| 1186 | } |
| 1187 | |
| 1188 | /** |
| 1189 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1190 | * @vsi: the VSI to be searched |
| 1191 | * |
| 1192 | * Returns true if VSI is in vlan mode or false otherwise |
| 1193 | **/ |
| 1194 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1195 | { |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1196 | /* If we have a PVID, always operate in VLAN mode */ |
| 1197 | if (vsi->info.pvid) |
| 1198 | return true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1199 | |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1200 | /* We need to operate in VLAN mode whenever we have any filters with |
| 1201 | * a VLAN other than I40E_VLAN_ALL. We could check the table each |
| 1202 | * time, incurring search cost repeatedly. However, we can notice two |
| 1203 | * things: |
| 1204 | * |
| 1205 | * 1) the only place where we can gain a VLAN filter is in |
| 1206 | * i40e_add_filter. |
| 1207 | * |
| 1208 | * 2) the only place where filters are actually removed is in |
Jacob Keller | 0b7c8b5 | 2016-10-25 16:08:52 -0700 | [diff] [blame] | 1209 | * i40e_sync_filters_subtask. |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1210 | * |
| 1211 | * Thus, we can simply use a boolean value, has_vlan_filters which we |
| 1212 | * will set to true when we add a VLAN filter in i40e_add_filter. Then |
| 1213 | * we have to perform the full search after deleting filters in |
Jacob Keller | 0b7c8b5 | 2016-10-25 16:08:52 -0700 | [diff] [blame] | 1214 | * i40e_sync_filters_subtask, but we already have to search |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1215 | * filters here and can perform the check at the same time. This |
| 1216 | * results in avoiding embedding a loop for VLAN mode inside another |
| 1217 | * loop over all the filters, and should maintain correctness as noted |
| 1218 | * above. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1219 | */ |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1220 | return vsi->has_vlan_filter; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | /** |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1224 | * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary |
| 1225 | * @vsi: the VSI to configure |
| 1226 | * @tmp_add_list: list of filters ready to be added |
| 1227 | * @tmp_del_list: list of filters ready to be deleted |
| 1228 | * @vlan_filters: the number of active VLAN filters |
| 1229 | * |
| 1230 | * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they |
| 1231 | * behave as expected. If we have any active VLAN filters remaining or about |
| 1232 | * to be added then we need to update non-VLAN filters to be marked as VLAN=0 |
| 1233 | * so that they only match against untagged traffic. If we no longer have any |
| 1234 | * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1 |
| 1235 | * so that they match against both tagged and untagged traffic. In this way, |
| 1236 | * we ensure that we correctly receive the desired traffic. This ensures that |
| 1237 | * when we have an active VLAN we will receive only untagged traffic and |
| 1238 | * traffic matching active VLANs. If we have no active VLANs then we will |
| 1239 | * operate in non-VLAN mode and receive all traffic, tagged or untagged. |
| 1240 | * |
| 1241 | * Finally, in a similar fashion, this function also corrects filters when |
| 1242 | * there is an active PVID assigned to this VSI. |
| 1243 | * |
| 1244 | * In case of memory allocation failure return -ENOMEM. Otherwise, return 0. |
| 1245 | * |
| 1246 | * This function is only expected to be called from within |
| 1247 | * i40e_sync_vsi_filters. |
| 1248 | * |
| 1249 | * NOTE: This function expects to be called while under the |
| 1250 | * mac_filter_hash_lock |
| 1251 | */ |
| 1252 | static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi, |
| 1253 | struct hlist_head *tmp_add_list, |
| 1254 | struct hlist_head *tmp_del_list, |
| 1255 | int vlan_filters) |
| 1256 | { |
| 1257 | struct i40e_mac_filter *f, *add_head; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1258 | struct i40e_new_mac_filter *new; |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1259 | struct hlist_node *h; |
| 1260 | int bkt, new_vlan; |
| 1261 | |
| 1262 | /* To determine if a particular filter needs to be replaced we |
| 1263 | * have the three following conditions: |
| 1264 | * |
| 1265 | * a) if we have a PVID assigned, then all filters which are |
| 1266 | * not marked as VLAN=PVID must be replaced with filters that |
| 1267 | * are. |
| 1268 | * b) otherwise, if we have any active VLANS, all filters |
| 1269 | * which are marked as VLAN=-1 must be replaced with |
| 1270 | * filters marked as VLAN=0 |
| 1271 | * c) finally, if we do not have any active VLANS, all filters |
| 1272 | * which are marked as VLAN=0 must be replaced with filters |
| 1273 | * marked as VLAN=-1 |
| 1274 | */ |
| 1275 | |
| 1276 | /* Update the filters about to be added in place */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1277 | hlist_for_each_entry(new, tmp_add_list, hlist) { |
| 1278 | if (vsi->info.pvid && new->f->vlan != vsi->info.pvid) |
| 1279 | new->f->vlan = vsi->info.pvid; |
| 1280 | else if (vlan_filters && new->f->vlan == I40E_VLAN_ANY) |
| 1281 | new->f->vlan = 0; |
| 1282 | else if (!vlan_filters && new->f->vlan == 0) |
| 1283 | new->f->vlan = I40E_VLAN_ANY; |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | /* Update the remaining active filters */ |
| 1287 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
| 1288 | /* Combine the checks for whether a filter needs to be changed |
| 1289 | * and then determine the new VLAN inside the if block, in |
| 1290 | * order to avoid duplicating code for adding the new filter |
| 1291 | * then deleting the old filter. |
| 1292 | */ |
| 1293 | if ((vsi->info.pvid && f->vlan != vsi->info.pvid) || |
| 1294 | (vlan_filters && f->vlan == I40E_VLAN_ANY) || |
| 1295 | (!vlan_filters && f->vlan == 0)) { |
| 1296 | /* Determine the new vlan we will be adding */ |
| 1297 | if (vsi->info.pvid) |
| 1298 | new_vlan = vsi->info.pvid; |
| 1299 | else if (vlan_filters) |
| 1300 | new_vlan = 0; |
| 1301 | else |
| 1302 | new_vlan = I40E_VLAN_ANY; |
| 1303 | |
| 1304 | /* Create the new filter */ |
| 1305 | add_head = i40e_add_filter(vsi, f->macaddr, new_vlan); |
| 1306 | if (!add_head) |
| 1307 | return -ENOMEM; |
| 1308 | |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1309 | /* Create a temporary i40e_new_mac_filter */ |
| 1310 | new = kzalloc(sizeof(*new), GFP_ATOMIC); |
| 1311 | if (!new) |
| 1312 | return -ENOMEM; |
| 1313 | |
| 1314 | new->f = add_head; |
| 1315 | new->state = add_head->state; |
| 1316 | |
| 1317 | /* Add the new filter to the tmp list */ |
| 1318 | hlist_add_head(&new->hlist, tmp_add_list); |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 1319 | |
| 1320 | /* Put the original filter into the delete list */ |
| 1321 | f->state = I40E_FILTER_REMOVE; |
| 1322 | hash_del(&f->hlist); |
| 1323 | hlist_add_head(&f->hlist, tmp_del_list); |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | vsi->has_vlan_filter = !!vlan_filters; |
| 1328 | |
| 1329 | return 0; |
| 1330 | } |
| 1331 | |
| 1332 | /** |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 1333 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM |
| 1334 | * @vsi: the PF Main VSI - inappropriate for any other VSI |
| 1335 | * @macaddr: the MAC address |
| 1336 | * |
| 1337 | * Remove whatever filter the firmware set up so the driver can manage |
| 1338 | * its own filtering intelligently. |
| 1339 | **/ |
| 1340 | static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr) |
| 1341 | { |
| 1342 | struct i40e_aqc_remove_macvlan_element_data element; |
| 1343 | struct i40e_pf *pf = vsi->back; |
| 1344 | |
| 1345 | /* Only appropriate for the PF main VSI */ |
| 1346 | if (vsi->type != I40E_VSI_MAIN) |
| 1347 | return; |
| 1348 | |
| 1349 | memset(&element, 0, sizeof(element)); |
| 1350 | ether_addr_copy(element.mac_addr, macaddr); |
| 1351 | element.vlan_tag = 0; |
| 1352 | /* Ignore error returns, some firmware does it this way... */ |
| 1353 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1354 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1355 | |
| 1356 | memset(&element, 0, sizeof(element)); |
| 1357 | ether_addr_copy(element.mac_addr, macaddr); |
| 1358 | element.vlan_tag = 0; |
| 1359 | /* ...and some firmware does it this way. */ |
| 1360 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | |
| 1361 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
| 1362 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1363 | } |
| 1364 | |
| 1365 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1366 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1367 | * @vsi: the VSI to be searched |
| 1368 | * @macaddr: the MAC address |
| 1369 | * @vlan: the vlan |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1370 | * |
| 1371 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1372 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1373 | * 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] | 1374 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1375 | **/ |
| 1376 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1377 | const u8 *macaddr, s16 vlan) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1378 | { |
| 1379 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1380 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1381 | |
| 1382 | if (!vsi || !macaddr) |
| 1383 | return NULL; |
| 1384 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1385 | f = i40e_find_filter(vsi, macaddr, vlan); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1386 | if (!f) { |
| 1387 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1388 | if (!f) |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1389 | return NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1390 | |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1391 | /* Update the boolean indicating if we need to function in |
| 1392 | * VLAN mode. |
| 1393 | */ |
| 1394 | if (vlan >= 0) |
| 1395 | vsi->has_vlan_filter = true; |
| 1396 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1397 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1398 | f->vlan = vlan; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1399 | /* If we're in overflow promisc mode, set the state directly |
| 1400 | * to failed, so we don't bother to try sending the filter |
| 1401 | * to the hardware. |
| 1402 | */ |
| 1403 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state)) |
| 1404 | f->state = I40E_FILTER_FAILED; |
| 1405 | else |
| 1406 | f->state = I40E_FILTER_NEW; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1407 | INIT_HLIST_NODE(&f->hlist); |
| 1408 | |
| 1409 | key = i40e_addr_to_hkey(macaddr); |
| 1410 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1411 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1412 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1413 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1414 | } |
| 1415 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1416 | /* If we're asked to add a filter that has been marked for removal, it |
| 1417 | * is safe to simply restore it to active state. __i40e_del_filter |
| 1418 | * will have simply deleted any filters which were previously marked |
| 1419 | * NEW or FAILED, so if it is currently marked REMOVE it must have |
| 1420 | * previously been ACTIVE. Since we haven't yet run the sync filters |
| 1421 | * task, just restore this filter to the ACTIVE state so that the |
| 1422 | * sync task leaves it in place |
| 1423 | */ |
| 1424 | if (f->state == I40E_FILTER_REMOVE) |
| 1425 | f->state = I40E_FILTER_ACTIVE; |
| 1426 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1427 | return f; |
| 1428 | } |
| 1429 | |
| 1430 | /** |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1431 | * __i40e_del_filter - Remove a specific filter from the VSI |
| 1432 | * @vsi: VSI to remove from |
| 1433 | * @f: the filter to remove from the list |
| 1434 | * |
| 1435 | * This function should be called instead of i40e_del_filter only if you know |
| 1436 | * the exact filter you will remove already, such as via i40e_find_filter or |
| 1437 | * i40e_find_mac. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1438 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1439 | * 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] | 1440 | * being held. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1441 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1442 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1443 | * instead of list_for_each_entry(). |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1444 | **/ |
Jacob Keller | 148141b | 2016-11-11 12:39:36 -0800 | [diff] [blame] | 1445 | 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] | 1446 | { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1447 | if (!f) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1448 | return; |
| 1449 | |
Alan Brady | a410c82 | 2016-12-12 15:44:07 -0800 | [diff] [blame] | 1450 | /* If the filter was never added to firmware then we can just delete it |
| 1451 | * directly and we don't want to set the status to remove or else an |
| 1452 | * admin queue command will unnecessarily fire. |
| 1453 | */ |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1454 | if ((f->state == I40E_FILTER_FAILED) || |
| 1455 | (f->state == I40E_FILTER_NEW)) { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1456 | hash_del(&f->hlist); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1457 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1458 | } else { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1459 | f->state = I40E_FILTER_REMOVE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1460 | } |
Alan Brady | a410c82 | 2016-12-12 15:44:07 -0800 | [diff] [blame] | 1461 | |
| 1462 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1463 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | /** |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1467 | * i40e_del_filter - Remove a MAC/VLAN filter from the VSI |
| 1468 | * @vsi: the VSI to be searched |
| 1469 | * @macaddr: the MAC address |
| 1470 | * @vlan: the VLAN |
| 1471 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1472 | * 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] | 1473 | * being held. |
| 1474 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1475 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1476 | * instead of list_for_each_entry(). |
| 1477 | **/ |
| 1478 | void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan) |
| 1479 | { |
| 1480 | struct i40e_mac_filter *f; |
| 1481 | |
| 1482 | if (!vsi || !macaddr) |
| 1483 | return; |
| 1484 | |
| 1485 | f = i40e_find_filter(vsi, macaddr, vlan); |
| 1486 | __i40e_del_filter(vsi, f); |
| 1487 | } |
| 1488 | |
| 1489 | /** |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1490 | * i40e_add_mac_filter - Add a MAC filter for all active VLANs |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1491 | * @vsi: the VSI to be searched |
| 1492 | * @macaddr: the mac address to be filtered |
| 1493 | * |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1494 | * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise, |
| 1495 | * 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] | 1496 | * unique vlan that already exists. If a PVID has been assigned, instead only |
| 1497 | * add the macaddr to that VLAN. |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1498 | * |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1499 | * Returns last filter added on success, else NULL |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1500 | **/ |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1501 | struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi, |
| 1502 | const u8 *macaddr) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1503 | { |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1504 | struct i40e_mac_filter *f, *add = NULL; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1505 | struct hlist_node *h; |
| 1506 | int bkt; |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1507 | |
| 1508 | if (vsi->info.pvid) |
| 1509 | return i40e_add_filter(vsi, macaddr, |
| 1510 | le16_to_cpu(vsi->info.pvid)); |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1511 | |
Jacob Keller | 7aaf9536 | 2016-11-11 12:39:33 -0800 | [diff] [blame] | 1512 | if (!i40e_is_vsi_in_vlan(vsi)) |
| 1513 | return i40e_add_filter(vsi, macaddr, I40E_VLAN_ANY); |
| 1514 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1515 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 1516 | if (f->state == I40E_FILTER_REMOVE) |
| 1517 | continue; |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1518 | add = i40e_add_filter(vsi, macaddr, f->vlan); |
| 1519 | if (!add) |
| 1520 | return NULL; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1523 | return add; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | /** |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1527 | * i40e_del_mac_filter - Remove a MAC filter from all VLANs |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1528 | * @vsi: the VSI to be searched |
| 1529 | * @macaddr: the mac address to be removed |
| 1530 | * |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1531 | * Removes a given MAC address from a VSI regardless of what VLAN it has been |
| 1532 | * associated with. |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1533 | * |
| 1534 | * Returns 0 for success, or error |
| 1535 | **/ |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1536 | int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1537 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1538 | struct i40e_mac_filter *f; |
| 1539 | struct hlist_node *h; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1540 | bool found = false; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1541 | int bkt; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1542 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1543 | WARN(!spin_is_locked(&vsi->mac_filter_hash_lock), |
| 1544 | "Missing mac_filter_hash_lock\n"); |
| 1545 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1546 | if (ether_addr_equal(macaddr, f->macaddr)) { |
| 1547 | __i40e_del_filter(vsi, f); |
| 1548 | found = true; |
| 1549 | } |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1550 | } |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1551 | |
| 1552 | if (found) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1553 | return 0; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1554 | else |
| 1555 | return -ENOENT; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1559 | * i40e_set_mac - NDO callback to set mac address |
| 1560 | * @netdev: network interface device structure |
| 1561 | * @p: pointer to an address structure |
| 1562 | * |
| 1563 | * Returns 0 on success, negative on failure |
| 1564 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1565 | #ifdef I40E_FCOE |
| 1566 | int i40e_set_mac(struct net_device *netdev, void *p) |
| 1567 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1568 | static int i40e_set_mac(struct net_device *netdev, void *p) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1569 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1570 | { |
| 1571 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1572 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1573 | struct i40e_pf *pf = vsi->back; |
| 1574 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1575 | struct sockaddr *addr = p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1576 | |
| 1577 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1578 | return -EADDRNOTAVAIL; |
| 1579 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1580 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1581 | netdev_info(netdev, "already using mac address %pM\n", |
| 1582 | addr->sa_data); |
| 1583 | return 0; |
| 1584 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1585 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1586 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1587 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1588 | return -EADDRNOTAVAIL; |
| 1589 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1590 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1591 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1592 | hw->mac.addr); |
| 1593 | else |
| 1594 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1595 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1596 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1597 | i40e_del_mac_filter(vsi, netdev->dev_addr); |
| 1598 | i40e_add_mac_filter(vsi, addr->sa_data); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1599 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1600 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1601 | if (vsi->type == I40E_VSI_MAIN) { |
| 1602 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1603 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1604 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1605 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1606 | addr->sa_data, NULL); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1607 | if (ret) |
| 1608 | netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n", |
| 1609 | i40e_stat_str(hw, ret), |
| 1610 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1613 | /* schedule our worker thread which will take care of |
| 1614 | * applying the new filter changes |
| 1615 | */ |
| 1616 | i40e_service_event_schedule(vsi->back); |
| 1617 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | /** |
| 1621 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1622 | * @vsi: the VSI being setup |
| 1623 | * @ctxt: VSI context structure |
| 1624 | * @enabled_tc: Enabled TCs bitmap |
| 1625 | * @is_add: True if called before Add VSI |
| 1626 | * |
| 1627 | * Setup VSI queue mapping for enabled traffic classes. |
| 1628 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1629 | #ifdef I40E_FCOE |
| 1630 | void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1631 | struct i40e_vsi_context *ctxt, |
| 1632 | u8 enabled_tc, |
| 1633 | bool is_add) |
| 1634 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1635 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1636 | struct i40e_vsi_context *ctxt, |
| 1637 | u8 enabled_tc, |
| 1638 | bool is_add) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1639 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1640 | { |
| 1641 | struct i40e_pf *pf = vsi->back; |
| 1642 | u16 sections = 0; |
| 1643 | u8 netdev_tc = 0; |
| 1644 | u16 numtc = 0; |
| 1645 | u16 qcount; |
| 1646 | u8 offset; |
| 1647 | u16 qmap; |
| 1648 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1649 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1650 | |
| 1651 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1652 | offset = 0; |
| 1653 | |
| 1654 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1655 | /* Find numtc from enabled TC bitmap */ |
| 1656 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1657 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1658 | numtc++; |
| 1659 | } |
| 1660 | if (!numtc) { |
| 1661 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1662 | numtc = 1; |
| 1663 | } |
| 1664 | } else { |
| 1665 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1666 | numtc = 1; |
| 1667 | } |
| 1668 | |
| 1669 | vsi->tc_config.numtc = numtc; |
| 1670 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1671 | /* Number of queues per enabled TC */ |
Catherine Sullivan | 7d64402 | 2016-05-16 10:26:41 -0700 | [diff] [blame] | 1672 | qcount = vsi->alloc_queue_pairs; |
| 1673 | |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1674 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1675 | 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] | 1676 | |
| 1677 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1678 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1679 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1680 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1681 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1682 | int pow, num_qps; |
| 1683 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1684 | switch (vsi->type) { |
| 1685 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1686 | qcount = min_t(int, pf->alloc_rss_size, |
| 1687 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1688 | break; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1689 | #ifdef I40E_FCOE |
| 1690 | case I40E_VSI_FCOE: |
| 1691 | qcount = num_tc_qps; |
| 1692 | break; |
| 1693 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1694 | case I40E_VSI_FDIR: |
| 1695 | case I40E_VSI_SRIOV: |
| 1696 | case I40E_VSI_VMDQ2: |
| 1697 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1698 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1699 | WARN_ON(i != 0); |
| 1700 | break; |
| 1701 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1702 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1703 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1704 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1705 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1706 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1707 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1708 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1709 | pow++; |
| 1710 | num_qps >>= 1; |
| 1711 | } |
| 1712 | |
| 1713 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1714 | qmap = |
| 1715 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1716 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1717 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1718 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1719 | } else { |
| 1720 | /* TC is not enabled so set the offset to |
| 1721 | * default queue and allocate one queue |
| 1722 | * for the given TC. |
| 1723 | */ |
| 1724 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1725 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1726 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1727 | |
| 1728 | qmap = 0; |
| 1729 | } |
| 1730 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1731 | } |
| 1732 | |
| 1733 | /* Set actual Tx/Rx queue pairs */ |
| 1734 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1735 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1736 | if (vsi->req_queue_pairs > 0) |
| 1737 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1738 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1739 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1740 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1741 | |
| 1742 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1743 | if (is_add) { |
| 1744 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1745 | |
| 1746 | ctxt->info.up_enable_bits = enabled_tc; |
| 1747 | } |
| 1748 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1749 | ctxt->info.mapping_flags |= |
| 1750 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1751 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1752 | ctxt->info.queue_mapping[i] = |
| 1753 | cpu_to_le16(vsi->base_queue + i); |
| 1754 | } else { |
| 1755 | ctxt->info.mapping_flags |= |
| 1756 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1757 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1758 | } |
| 1759 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1760 | } |
| 1761 | |
| 1762 | /** |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1763 | * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address |
| 1764 | * @netdev: the netdevice |
| 1765 | * @addr: address to add |
| 1766 | * |
| 1767 | * Called by __dev_(mc|uc)_sync when an address needs to be added. We call |
| 1768 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1769 | */ |
| 1770 | static int i40e_addr_sync(struct net_device *netdev, const u8 *addr) |
| 1771 | { |
| 1772 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1773 | struct i40e_vsi *vsi = np->vsi; |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1774 | |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1775 | if (i40e_add_mac_filter(vsi, addr)) |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1776 | return 0; |
| 1777 | else |
| 1778 | return -ENOMEM; |
| 1779 | } |
| 1780 | |
| 1781 | /** |
| 1782 | * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address |
| 1783 | * @netdev: the netdevice |
| 1784 | * @addr: address to add |
| 1785 | * |
| 1786 | * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call |
| 1787 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1788 | */ |
| 1789 | static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr) |
| 1790 | { |
| 1791 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1792 | struct i40e_vsi *vsi = np->vsi; |
| 1793 | |
Jacob Keller | feffdbe | 2016-11-11 12:39:35 -0800 | [diff] [blame] | 1794 | i40e_del_mac_filter(vsi, addr); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1795 | |
| 1796 | return 0; |
| 1797 | } |
| 1798 | |
| 1799 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1800 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1801 | * @netdev: network interface device structure |
| 1802 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1803 | #ifdef I40E_FCOE |
| 1804 | void i40e_set_rx_mode(struct net_device *netdev) |
| 1805 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1806 | static void i40e_set_rx_mode(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1807 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1808 | { |
| 1809 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1810 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1811 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1812 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1813 | |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1814 | __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
| 1815 | __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1816 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1817 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1818 | |
| 1819 | /* check for other flag changes */ |
| 1820 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1821 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1822 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1823 | } |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1824 | |
| 1825 | /* schedule our worker thread which will take care of |
| 1826 | * applying the new filter changes |
| 1827 | */ |
| 1828 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | /** |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1832 | * 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] | 1833 | * @vsi: Pointer to VSI struct |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1834 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1835 | * those entries needs to be undone. |
| 1836 | * |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1837 | * MAC filter entries from this list were slated for deletion. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1838 | **/ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1839 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1840 | struct hlist_head *from) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1841 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1842 | struct i40e_mac_filter *f; |
| 1843 | struct hlist_node *h; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1844 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1845 | hlist_for_each_entry_safe(f, h, from, hlist) { |
| 1846 | u64 key = i40e_addr_to_hkey(f->macaddr); |
| 1847 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1848 | /* Move the element back into MAC filter list*/ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1849 | hlist_del(&f->hlist); |
| 1850 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1851 | } |
| 1852 | } |
| 1853 | |
| 1854 | /** |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1855 | * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries |
| 1856 | * @vsi: Pointer to vsi struct |
| 1857 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1858 | * those entries needs to be undone. |
| 1859 | * |
| 1860 | * MAC filter entries from this list were slated for addition. |
| 1861 | **/ |
| 1862 | static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi, |
| 1863 | struct hlist_head *from) |
| 1864 | { |
| 1865 | struct i40e_new_mac_filter *new; |
| 1866 | struct hlist_node *h; |
| 1867 | |
| 1868 | hlist_for_each_entry_safe(new, h, from, hlist) { |
| 1869 | /* We can simply free the wrapper structure */ |
| 1870 | hlist_del(&new->hlist); |
| 1871 | kfree(new); |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | /** |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1876 | * i40e_next_entry - Get the next non-broadcast filter from a list |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1877 | * @next: pointer to filter in list |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1878 | * |
| 1879 | * Returns the next non-broadcast filter in the list. Required so that we |
| 1880 | * ignore broadcast filters within the list, since these are not handled via |
| 1881 | * the normal firmware update path. |
| 1882 | */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1883 | static |
| 1884 | 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] | 1885 | { |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1886 | while (next) { |
| 1887 | next = hlist_entry(next->hlist.next, |
| 1888 | typeof(struct i40e_new_mac_filter), |
| 1889 | hlist); |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1890 | |
| 1891 | /* keep going if we found a broadcast filter */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1892 | if (next && is_broadcast_ether_addr(next->f->macaddr)) |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1893 | continue; |
| 1894 | |
| 1895 | break; |
| 1896 | } |
| 1897 | |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1898 | return next; |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | /** |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1902 | * i40e_update_filter_state - Update filter state based on return data |
| 1903 | * from firmware |
| 1904 | * @count: Number of filters added |
| 1905 | * @add_list: return data from fw |
| 1906 | * @head: pointer to first filter in current batch |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1907 | * |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1908 | * MAC filter entries from list were slated to be added to device. Returns |
| 1909 | * number of successful filters. Note that 0 does NOT mean success! |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1910 | **/ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1911 | static int |
| 1912 | i40e_update_filter_state(int count, |
| 1913 | struct i40e_aqc_add_macvlan_element_data *add_list, |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1914 | struct i40e_new_mac_filter *add_head) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1915 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1916 | int retval = 0; |
| 1917 | int i; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1918 | |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1919 | for (i = 0; i < count; i++) { |
| 1920 | /* Always check status of each filter. We don't need to check |
| 1921 | * the firmware return status because we pre-set the filter |
| 1922 | * status to I40E_AQC_MM_ERR_NO_RES when sending the filter |
| 1923 | * request to the adminq. Thus, if it no longer matches then |
| 1924 | * we know the filter is active. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1925 | */ |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1926 | if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1927 | add_head->state = I40E_FILTER_FAILED; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1928 | } else { |
| 1929 | add_head->state = I40E_FILTER_ACTIVE; |
| 1930 | retval++; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1931 | } |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1932 | |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 1933 | add_head = i40e_next_filter(add_head); |
| 1934 | if (!add_head) |
| 1935 | break; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1936 | } |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1937 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1938 | return retval; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | /** |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1942 | * i40e_aqc_del_filters - Request firmware to delete a set of filters |
| 1943 | * @vsi: ptr to the VSI |
| 1944 | * @vsi_name: name to display in messages |
| 1945 | * @list: the list of filters to send to firmware |
| 1946 | * @num_del: the number of filters to delete |
| 1947 | * @retval: Set to -EIO on failure to delete |
| 1948 | * |
| 1949 | * Send a request to firmware via AdminQ to delete a set of filters. Uses |
| 1950 | * *retval instead of a return value so that success does not force ret_val to |
| 1951 | * be set to 0. This ensures that a sequence of calls to this function |
| 1952 | * preserve the previous value of *retval on successful delete. |
| 1953 | */ |
| 1954 | static |
| 1955 | void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 1956 | struct i40e_aqc_remove_macvlan_element_data *list, |
| 1957 | int num_del, int *retval) |
| 1958 | { |
| 1959 | struct i40e_hw *hw = &vsi->back->hw; |
| 1960 | i40e_status aq_ret; |
| 1961 | int aq_err; |
| 1962 | |
| 1963 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL); |
| 1964 | aq_err = hw->aq.asq_last_status; |
| 1965 | |
| 1966 | /* Explicitly ignore and do not report when firmware returns ENOENT */ |
| 1967 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { |
| 1968 | *retval = -EIO; |
| 1969 | dev_info(&vsi->back->pdev->dev, |
| 1970 | "ignoring delete macvlan error on %s, err %s, aq_err %s\n", |
| 1971 | vsi_name, i40e_stat_str(hw, aq_ret), |
| 1972 | i40e_aq_str(hw, aq_err)); |
| 1973 | } |
| 1974 | } |
| 1975 | |
| 1976 | /** |
| 1977 | * i40e_aqc_add_filters - Request firmware to add a set of filters |
| 1978 | * @vsi: ptr to the VSI |
| 1979 | * @vsi_name: name to display in messages |
| 1980 | * @list: the list of filters to send to firmware |
| 1981 | * @add_head: Position in the add hlist |
| 1982 | * @num_add: the number of filters to add |
| 1983 | * @promisc_change: set to true on exit if promiscuous mode was forced on |
| 1984 | * |
| 1985 | * Send a request to firmware via AdminQ to add a chunk of filters. Will set |
| 1986 | * promisc_changed to true if the firmware has run out of space for more |
| 1987 | * filters. |
| 1988 | */ |
| 1989 | static |
| 1990 | void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 1991 | struct i40e_aqc_add_macvlan_element_data *list, |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 1992 | struct i40e_new_mac_filter *add_head, |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1993 | int num_add, bool *promisc_changed) |
| 1994 | { |
| 1995 | struct i40e_hw *hw = &vsi->back->hw; |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1996 | int aq_err, fcnt; |
| 1997 | |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 1998 | i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1999 | aq_err = hw->aq.asq_last_status; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 2000 | fcnt = i40e_update_filter_state(num_add, list, add_head); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2001 | |
| 2002 | if (fcnt != num_add) { |
| 2003 | *promisc_changed = true; |
| 2004 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2005 | dev_warn(&vsi->back->pdev->dev, |
| 2006 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", |
| 2007 | i40e_aq_str(hw, aq_err), |
| 2008 | vsi_name); |
| 2009 | } |
| 2010 | } |
| 2011 | |
| 2012 | /** |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2013 | * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags |
| 2014 | * @vsi: pointer to the VSI |
| 2015 | * @f: filter data |
| 2016 | * |
| 2017 | * This function sets or clears the promiscuous broadcast flags for VLAN |
| 2018 | * filters in order to properly receive broadcast frames. Assumes that only |
| 2019 | * broadcast filters are passed. |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2020 | * |
| 2021 | * Returns status indicating success or failure; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2022 | **/ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2023 | static i40e_status |
| 2024 | i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name, |
| 2025 | struct i40e_mac_filter *f) |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2026 | { |
| 2027 | bool enable = f->state == I40E_FILTER_NEW; |
| 2028 | struct i40e_hw *hw = &vsi->back->hw; |
| 2029 | i40e_status aq_ret; |
| 2030 | |
| 2031 | if (f->vlan == I40E_VLAN_ANY) { |
| 2032 | aq_ret = i40e_aq_set_vsi_broadcast(hw, |
| 2033 | vsi->seid, |
| 2034 | enable, |
| 2035 | NULL); |
| 2036 | } else { |
| 2037 | aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw, |
| 2038 | vsi->seid, |
| 2039 | enable, |
| 2040 | f->vlan, |
| 2041 | NULL); |
| 2042 | } |
| 2043 | |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2044 | if (aq_ret) |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2045 | dev_warn(&vsi->back->pdev->dev, |
| 2046 | "Error %s setting broadcast promiscuous mode on %s\n", |
| 2047 | i40e_aq_str(hw, hw->aq.asq_last_status), |
| 2048 | vsi_name); |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2049 | |
| 2050 | return aq_ret; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2054 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 2055 | * @vsi: ptr to the VSI |
| 2056 | * |
| 2057 | * Push any outstanding VSI filter changes through the AdminQ. |
| 2058 | * |
| 2059 | * Returns 0 or error value |
| 2060 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2061 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2062 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2063 | struct hlist_head tmp_add_list, tmp_del_list; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2064 | struct i40e_mac_filter *f; |
| 2065 | struct i40e_new_mac_filter *new, *add_head = NULL; |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2066 | struct i40e_hw *hw = &vsi->back->hw; |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2067 | unsigned int failed_filters = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2068 | unsigned int vlan_filters = 0; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2069 | bool promisc_changed = false; |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2070 | char vsi_name[16] = "PF"; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2071 | int filter_list_len = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2072 | i40e_status aq_ret = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2073 | u32 changed_flags = 0; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2074 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2075 | struct i40e_pf *pf; |
| 2076 | int num_add = 0; |
| 2077 | int num_del = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2078 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2079 | u16 cmd_flags; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2080 | int list_size; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2081 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2082 | |
| 2083 | /* empty array typed pointers, kcalloc later */ |
| 2084 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 2085 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 2086 | |
| 2087 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 2088 | usleep_range(1000, 2000); |
| 2089 | pf = vsi->back; |
| 2090 | |
| 2091 | if (vsi->netdev) { |
| 2092 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 2093 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 2094 | } |
| 2095 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2096 | INIT_HLIST_HEAD(&tmp_add_list); |
| 2097 | INIT_HLIST_HEAD(&tmp_del_list); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2098 | |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2099 | if (vsi->type == I40E_VSI_SRIOV) |
| 2100 | snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id); |
| 2101 | else if (vsi->type != I40E_VSI_MAIN) |
| 2102 | snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid); |
| 2103 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2104 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 2105 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 2106 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2107 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2108 | /* Create a list of filters to delete. */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2109 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2110 | if (f->state == I40E_FILTER_REMOVE) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2111 | /* Move the element into temporary del_list */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2112 | hash_del(&f->hlist); |
| 2113 | hlist_add_head(&f->hlist, &tmp_del_list); |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2114 | |
| 2115 | /* Avoid counting removed filters */ |
| 2116 | continue; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2117 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2118 | if (f->state == I40E_FILTER_NEW) { |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2119 | /* Create a temporary i40e_new_mac_filter */ |
| 2120 | new = kzalloc(sizeof(*new), GFP_ATOMIC); |
| 2121 | if (!new) |
| 2122 | goto err_no_memory_locked; |
| 2123 | |
| 2124 | /* Store pointer to the real filter */ |
| 2125 | new->f = f; |
| 2126 | new->state = f->state; |
| 2127 | |
| 2128 | /* Add it to the hash list */ |
| 2129 | hlist_add_head(&new->hlist, &tmp_add_list); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2130 | } |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2131 | |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2132 | /* Count the number of active (current and new) VLAN |
| 2133 | * filters we have now. Does not count filters which |
| 2134 | * are marked for deletion. |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2135 | */ |
| 2136 | if (f->vlan > 0) |
| 2137 | vlan_filters++; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2140 | retval = i40e_correct_mac_vlan_filters(vsi, |
| 2141 | &tmp_add_list, |
| 2142 | &tmp_del_list, |
| 2143 | vlan_filters); |
| 2144 | if (retval) |
| 2145 | goto err_no_memory_locked; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2146 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2147 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | /* Now process 'del_list' outside the lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2151 | if (!hlist_empty(&tmp_del_list)) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2152 | filter_list_len = hw->aq.asq_buf_size / |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2153 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2154 | list_size = filter_list_len * |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2155 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2156 | del_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2157 | if (!del_list) |
| 2158 | goto err_no_memory; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2159 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2160 | hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2161 | cmd_flags = 0; |
| 2162 | |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2163 | /* handle broadcast filters by updating the broadcast |
Jacob Keller | d88d40b | 2016-12-02 12:32:59 -0800 | [diff] [blame] | 2164 | * promiscuous flag and release filter list. |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2165 | */ |
| 2166 | if (is_broadcast_ether_addr(f->macaddr)) { |
| 2167 | i40e_aqc_broadcast_filter(vsi, vsi_name, f); |
| 2168 | |
| 2169 | hlist_del(&f->hlist); |
| 2170 | kfree(f); |
| 2171 | continue; |
| 2172 | } |
| 2173 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2174 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2175 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2176 | if (f->vlan == I40E_VLAN_ANY) { |
| 2177 | del_list[num_del].vlan_tag = 0; |
Alan Brady | a6cb914 | 2016-09-06 18:05:07 -0700 | [diff] [blame] | 2178 | cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2179 | } else { |
| 2180 | del_list[num_del].vlan_tag = |
| 2181 | cpu_to_le16((u16)(f->vlan)); |
| 2182 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2183 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2184 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 2185 | del_list[num_del].flags = cmd_flags; |
| 2186 | num_del++; |
| 2187 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2188 | /* flush a full buffer */ |
| 2189 | if (num_del == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2190 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2191 | num_del, &retval); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2192 | memset(del_list, 0, list_size); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2193 | num_del = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2194 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2195 | /* Release memory for MAC filter entries which were |
| 2196 | * synced up with HW. |
| 2197 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2198 | hlist_del(&f->hlist); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2199 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2200 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2201 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2202 | if (num_del) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2203 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2204 | num_del, &retval); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | kfree(del_list); |
| 2208 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2209 | } |
| 2210 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2211 | if (!hlist_empty(&tmp_add_list)) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2212 | /* Do all the adds now. */ |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2213 | filter_list_len = hw->aq.asq_buf_size / |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2214 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2215 | list_size = filter_list_len * |
| 2216 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
| 2217 | add_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2218 | if (!add_list) |
| 2219 | goto err_no_memory; |
| 2220 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2221 | num_add = 0; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2222 | hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2223 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2224 | &vsi->state)) { |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2225 | new->state = I40E_FILTER_FAILED; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2226 | continue; |
| 2227 | } |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2228 | |
| 2229 | /* handle broadcast filters by updating the broadcast |
| 2230 | * promiscuous flag instead of adding a MAC filter. |
| 2231 | */ |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2232 | if (is_broadcast_ether_addr(new->f->macaddr)) { |
| 2233 | if (i40e_aqc_broadcast_filter(vsi, vsi_name, |
| 2234 | new->f)) |
| 2235 | new->state = I40E_FILTER_FAILED; |
| 2236 | else |
| 2237 | new->state = I40E_FILTER_ACTIVE; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 2238 | continue; |
| 2239 | } |
| 2240 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2241 | /* add to add array */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2242 | if (num_add == 0) |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2243 | add_head = new; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2244 | cmd_flags = 0; |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2245 | ether_addr_copy(add_list[num_add].mac_addr, |
| 2246 | new->f->macaddr); |
| 2247 | if (new->f->vlan == I40E_VLAN_ANY) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2248 | add_list[num_add].vlan_tag = 0; |
| 2249 | cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; |
| 2250 | } else { |
| 2251 | add_list[num_add].vlan_tag = |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2252 | cpu_to_le16((u16)(new->f->vlan)); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2253 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2254 | add_list[num_add].queue_number = 0; |
Jacob Keller | ac9e239 | 2016-11-11 12:39:27 -0800 | [diff] [blame] | 2255 | /* set invalid match method for later detection */ |
Keller, Jacob E | 0266ac4 | 2016-12-09 13:39:21 -0800 | [diff] [blame] | 2256 | add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2257 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2258 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2259 | num_add++; |
| 2260 | |
| 2261 | /* flush a full buffer */ |
| 2262 | if (num_add == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2263 | i40e_aqc_add_filters(vsi, vsi_name, add_list, |
| 2264 | add_head, num_add, |
| 2265 | &promisc_changed); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2266 | memset(add_list, 0, list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2267 | num_add = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2268 | } |
| 2269 | } |
| 2270 | if (num_add) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2271 | i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head, |
| 2272 | num_add, &promisc_changed); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2273 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2274 | /* Now move all of the filters from the temp add list back to |
| 2275 | * the VSI's list. |
| 2276 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2277 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2278 | hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) { |
| 2279 | /* Only update the state if we're still NEW */ |
| 2280 | if (new->f->state == I40E_FILTER_NEW) |
| 2281 | new->f->state = new->state; |
| 2282 | hlist_del(&new->hlist); |
| 2283 | kfree(new); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2284 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2285 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2286 | kfree(add_list); |
| 2287 | add_list = NULL; |
| 2288 | } |
| 2289 | |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2290 | /* Determine the number of active and failed filters. */ |
| 2291 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2292 | vsi->active_filters = 0; |
| 2293 | hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) { |
| 2294 | if (f->state == I40E_FILTER_ACTIVE) |
| 2295 | vsi->active_filters++; |
| 2296 | else if (f->state == I40E_FILTER_FAILED) |
| 2297 | failed_filters++; |
| 2298 | } |
| 2299 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 2300 | |
| 2301 | /* If promiscuous mode has changed, we need to calculate a new |
| 2302 | * threshold for when we are safe to exit |
| 2303 | */ |
| 2304 | if (promisc_changed) |
| 2305 | vsi->promisc_threshold = (vsi->active_filters * 3) / 4; |
| 2306 | |
| 2307 | /* Check if we are able to exit overflow promiscuous mode. We can |
| 2308 | * safely exit if we didn't just enter, we no longer have any failed |
| 2309 | * filters, and we have reduced filters below the threshold value. |
| 2310 | */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2311 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) && |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2312 | !promisc_changed && !failed_filters && |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2313 | (vsi->active_filters < vsi->promisc_threshold)) { |
Jacob Keller | 3832621 | 2016-11-11 12:39:26 -0800 | [diff] [blame] | 2314 | dev_info(&pf->pdev->dev, |
| 2315 | "filter logjam cleared on %s, leaving overflow promiscuous mode\n", |
| 2316 | vsi_name); |
| 2317 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2318 | promisc_changed = true; |
| 2319 | vsi->promisc_threshold = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2322 | /* if the VF is not trusted do not do promisc */ |
| 2323 | if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) { |
| 2324 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2325 | goto out; |
| 2326 | } |
| 2327 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2328 | /* check for changes in promiscuous modes */ |
| 2329 | if (changed_flags & IFF_ALLMULTI) { |
| 2330 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2331 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2332 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2333 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2334 | vsi->seid, |
| 2335 | cur_multipromisc, |
| 2336 | NULL); |
| 2337 | if (aq_ret) { |
| 2338 | retval = i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2339 | hw->aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2340 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2341 | "set multi promisc failed on %s, err %s aq_err %s\n", |
| 2342 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2343 | i40e_stat_str(hw, aq_ret), |
| 2344 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2345 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2346 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2347 | if ((changed_flags & IFF_PROMISC) || |
| 2348 | (promisc_changed && |
| 2349 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2350 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2351 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2352 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 2353 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2354 | &vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2355 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2356 | (pf->lan_veb != I40E_NO_VEB) && |
| 2357 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2358 | /* set defport ON for Main VSI instead of true promisc |
| 2359 | * this way we will get all unicast/multicast and VLAN |
| 2360 | * promisc behavior but will not get VF or VMDq traffic |
| 2361 | * replicated on the Main VSI. |
| 2362 | */ |
| 2363 | if (pf->cur_promisc != cur_promisc) { |
| 2364 | pf->cur_promisc = cur_promisc; |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2365 | if (cur_promisc) |
| 2366 | aq_ret = |
| 2367 | i40e_aq_set_default_vsi(hw, |
| 2368 | vsi->seid, |
| 2369 | NULL); |
| 2370 | else |
| 2371 | aq_ret = |
| 2372 | i40e_aq_clear_default_vsi(hw, |
| 2373 | vsi->seid, |
| 2374 | NULL); |
| 2375 | if (aq_ret) { |
| 2376 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2377 | hw->aq.asq_last_status); |
| 2378 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2379 | "Set default VSI failed on %s, err %s, aq_err %s\n", |
| 2380 | vsi_name, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2381 | i40e_stat_str(hw, aq_ret), |
| 2382 | i40e_aq_str(hw, |
| 2383 | hw->aq.asq_last_status)); |
| 2384 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2385 | } |
| 2386 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2387 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2388 | hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2389 | vsi->seid, |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 2390 | cur_promisc, NULL, |
| 2391 | true); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2392 | if (aq_ret) { |
| 2393 | retval = |
| 2394 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2395 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2396 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2397 | "set unicast promisc failed on %s, err %s, aq_err %s\n", |
| 2398 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2399 | i40e_stat_str(hw, aq_ret), |
| 2400 | i40e_aq_str(hw, |
| 2401 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2402 | } |
| 2403 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2404 | hw, |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2405 | vsi->seid, |
| 2406 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2407 | if (aq_ret) { |
| 2408 | retval = |
| 2409 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2410 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2411 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2412 | "set multicast promisc failed on %s, err %s, aq_err %s\n", |
| 2413 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2414 | i40e_stat_str(hw, aq_ret), |
| 2415 | i40e_aq_str(hw, |
| 2416 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2417 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2418 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2419 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2420 | vsi->seid, |
| 2421 | cur_promisc, NULL); |
| 2422 | if (aq_ret) { |
| 2423 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2424 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2425 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2426 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2427 | i40e_stat_str(hw, aq_ret), |
| 2428 | i40e_aq_str(hw, |
| 2429 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2430 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2431 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2432 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2433 | /* if something went wrong then set the changed flag so we try again */ |
| 2434 | if (retval) |
| 2435 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2436 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2437 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2438 | return retval; |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2439 | |
| 2440 | err_no_memory: |
| 2441 | /* Restore elements on the temporary add and delete lists */ |
| 2442 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2443 | err_no_memory_locked: |
Jacob Keller | 671889e | 2016-12-02 12:33:00 -0800 | [diff] [blame] | 2444 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 2445 | i40e_undo_add_filter_entries(vsi, &tmp_add_list); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2446 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 2447 | |
| 2448 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2449 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
| 2450 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | /** |
| 2454 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2455 | * @pf: board private structure |
| 2456 | **/ |
| 2457 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2458 | { |
| 2459 | int v; |
| 2460 | |
| 2461 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2462 | return; |
| 2463 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2464 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2465 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2466 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2467 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2468 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2469 | |
| 2470 | if (ret) { |
| 2471 | /* come back and try again later */ |
| 2472 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2473 | break; |
| 2474 | } |
| 2475 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | /** |
| 2480 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2481 | * @netdev: network interface device structure |
| 2482 | * @new_mtu: new value for maximum frame size |
| 2483 | * |
| 2484 | * Returns 0 on success, negative on failure |
| 2485 | **/ |
| 2486 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2487 | { |
| 2488 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2489 | struct i40e_vsi *vsi = np->vsi; |
| 2490 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2491 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2492 | netdev->mtu, new_mtu); |
| 2493 | netdev->mtu = new_mtu; |
| 2494 | if (netif_running(netdev)) |
| 2495 | i40e_vsi_reinit_locked(vsi); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 2496 | i40e_notify_client_of_l2_param_changes(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2497 | return 0; |
| 2498 | } |
| 2499 | |
| 2500 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2501 | * i40e_ioctl - Access the hwtstamp interface |
| 2502 | * @netdev: network interface device structure |
| 2503 | * @ifr: interface request data |
| 2504 | * @cmd: ioctl command |
| 2505 | **/ |
| 2506 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2507 | { |
| 2508 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2509 | struct i40e_pf *pf = np->vsi->back; |
| 2510 | |
| 2511 | switch (cmd) { |
| 2512 | case SIOCGHWTSTAMP: |
| 2513 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2514 | case SIOCSHWTSTAMP: |
| 2515 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2516 | default: |
| 2517 | return -EOPNOTSUPP; |
| 2518 | } |
| 2519 | } |
| 2520 | |
| 2521 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2522 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2523 | * @vsi: the vsi being adjusted |
| 2524 | **/ |
| 2525 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2526 | { |
| 2527 | struct i40e_vsi_context ctxt; |
| 2528 | i40e_status ret; |
| 2529 | |
| 2530 | if ((vsi->info.valid_sections & |
| 2531 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2532 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2533 | return; /* already enabled */ |
| 2534 | |
| 2535 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2536 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2537 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2538 | |
| 2539 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2540 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2541 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2542 | if (ret) { |
| 2543 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2544 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2545 | i40e_stat_str(&vsi->back->hw, ret), |
| 2546 | i40e_aq_str(&vsi->back->hw, |
| 2547 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | /** |
| 2552 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2553 | * @vsi: the vsi being adjusted |
| 2554 | **/ |
| 2555 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2556 | { |
| 2557 | struct i40e_vsi_context ctxt; |
| 2558 | i40e_status ret; |
| 2559 | |
| 2560 | if ((vsi->info.valid_sections & |
| 2561 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2562 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2563 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2564 | return; /* already disabled */ |
| 2565 | |
| 2566 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2567 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2568 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2569 | |
| 2570 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2571 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2572 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2573 | if (ret) { |
| 2574 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2575 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2576 | i40e_stat_str(&vsi->back->hw, ret), |
| 2577 | i40e_aq_str(&vsi->back->hw, |
| 2578 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2579 | } |
| 2580 | } |
| 2581 | |
| 2582 | /** |
| 2583 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2584 | * @netdev: network interface to be adjusted |
| 2585 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2586 | **/ |
| 2587 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2588 | { |
| 2589 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2590 | struct i40e_vsi *vsi = np->vsi; |
| 2591 | |
| 2592 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2593 | i40e_vlan_stripping_enable(vsi); |
| 2594 | else |
| 2595 | i40e_vlan_stripping_disable(vsi); |
| 2596 | } |
| 2597 | |
| 2598 | /** |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2599 | * 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] | 2600 | * @vsi: the vsi being configured |
| 2601 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2602 | * |
| 2603 | * This is a helper function for adding a new MAC/VLAN filter with the |
| 2604 | * specified VLAN for each existing MAC address already in the hash table. |
| 2605 | * This function does *not* perform any accounting to update filters based on |
| 2606 | * VLAN mode. |
| 2607 | * |
| 2608 | * NOTE: this function expects to be called while under the |
| 2609 | * mac_filter_hash_lock |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2610 | **/ |
Jacob Keller | 9af52f6 | 2016-11-11 12:39:30 -0800 | [diff] [blame] | 2611 | int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2612 | { |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2613 | struct i40e_mac_filter *f, *add_f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2614 | struct hlist_node *h; |
| 2615 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2616 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2617 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 2618 | if (f->state == I40E_FILTER_REMOVE) |
| 2619 | continue; |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2620 | add_f = i40e_add_filter(vsi, f->macaddr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2621 | if (!add_f) { |
| 2622 | dev_info(&vsi->back->pdev->dev, |
| 2623 | "Could not add vlan filter %d for %pM\n", |
| 2624 | vid, f->macaddr); |
| 2625 | return -ENOMEM; |
| 2626 | } |
| 2627 | } |
| 2628 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2629 | return 0; |
| 2630 | } |
| 2631 | |
| 2632 | /** |
| 2633 | * i40e_vsi_add_vlan - Add VSI membership for given VLAN |
| 2634 | * @vsi: the VSI being configured |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2635 | * @vid: VLAN id to be added |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2636 | **/ |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2637 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2638 | { |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2639 | int err; |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2640 | |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2641 | if (!vid || vsi->info.pvid) |
| 2642 | return -EINVAL; |
| 2643 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2644 | /* Locked once because all functions invoked below iterates list*/ |
| 2645 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2646 | err = i40e_add_vlan_all_mac(vsi, vid); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2647 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 489a326 | 2016-11-11 12:39:31 -0800 | [diff] [blame] | 2648 | if (err) |
| 2649 | return err; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2650 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2651 | /* schedule our worker thread which will take care of |
| 2652 | * applying the new filter changes |
| 2653 | */ |
| 2654 | i40e_service_event_schedule(vsi->back); |
| 2655 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | /** |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2659 | * 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] | 2660 | * @vsi: the vsi being configured |
| 2661 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2662 | * |
| 2663 | * This function should be used to remove all VLAN filters which match the |
| 2664 | * given VID. It does not schedule the service event and does not take the |
| 2665 | * mac_filter_hash_lock so it may be combined with other operations under |
| 2666 | * a single invocation of the mac_filter_hash_lock. |
| 2667 | * |
| 2668 | * NOTE: this function expects to be called while under the |
| 2669 | * mac_filter_hash_lock |
| 2670 | */ |
Jacob Keller | 9af52f6 | 2016-11-11 12:39:30 -0800 | [diff] [blame] | 2671 | void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2672 | { |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2673 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2674 | struct hlist_node *h; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2675 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2676 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2677 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 2678 | if (f->vlan == vid) |
| 2679 | __i40e_del_filter(vsi, f); |
| 2680 | } |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2681 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2682 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2683 | /** |
| 2684 | * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN |
| 2685 | * @vsi: the VSI being configured |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2686 | * @vid: VLAN id to be removed |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2687 | **/ |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2688 | void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid) |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2689 | { |
Jacob Keller | f94484b | 2016-12-07 14:05:34 -0800 | [diff] [blame] | 2690 | if (!vid || vsi->info.pvid) |
| 2691 | return; |
| 2692 | |
Jacob Keller | 490a4ad | 2016-11-11 12:39:29 -0800 | [diff] [blame] | 2693 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2694 | i40e_rm_vlan_all_mac(vsi, vid); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2695 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2696 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2697 | /* schedule our worker thread which will take care of |
| 2698 | * applying the new filter changes |
| 2699 | */ |
| 2700 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | /** |
| 2704 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2705 | * @netdev: network interface to be adjusted |
| 2706 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2707 | * |
| 2708 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2709 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2710 | #ifdef I40E_FCOE |
| 2711 | int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2712 | __always_unused __be16 proto, u16 vid) |
| 2713 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2714 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2715 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2716 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2717 | { |
| 2718 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2719 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2720 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2721 | |
Jacob Keller | 6a112785 | 2016-10-25 16:08:49 -0700 | [diff] [blame] | 2722 | if (vid >= VLAN_N_VID) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2723 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2724 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2725 | /* If the network stack called us with vid = 0 then |
| 2726 | * it is asking to receive priority tagged packets with |
| 2727 | * vlan id 0. Our HW receives them by default when configured |
| 2728 | * to receive untagged packets so there is no need to add an |
| 2729 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2730 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2731 | if (vid) |
| 2732 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2733 | |
Jacob Keller | 6a112785 | 2016-10-25 16:08:49 -0700 | [diff] [blame] | 2734 | if (!ret) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2735 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2736 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2737 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | /** |
| 2741 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2742 | * @netdev: network interface to be adjusted |
| 2743 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2744 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2745 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2746 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2747 | #ifdef I40E_FCOE |
| 2748 | int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2749 | __always_unused __be16 proto, u16 vid) |
| 2750 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2751 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2752 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2753 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2754 | { |
| 2755 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2756 | struct i40e_vsi *vsi = np->vsi; |
| 2757 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2758 | /* return code is ignored as there is nothing a user |
| 2759 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2760 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2761 | */ |
| 2762 | i40e_vsi_kill_vlan(vsi, vid); |
| 2763 | |
| 2764 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2765 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2766 | return 0; |
| 2767 | } |
| 2768 | |
| 2769 | /** |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 2770 | * i40e_macaddr_init - explicitly write the mac address filters |
| 2771 | * |
| 2772 | * @vsi: pointer to the vsi |
| 2773 | * @macaddr: the MAC address |
| 2774 | * |
| 2775 | * This is needed when the macaddr has been obtained by other |
| 2776 | * means than the default, e.g., from Open Firmware or IDPROM. |
| 2777 | * Returns 0 on success, negative on failure |
| 2778 | **/ |
| 2779 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) |
| 2780 | { |
| 2781 | int ret; |
| 2782 | struct i40e_aqc_add_macvlan_element_data element; |
| 2783 | |
| 2784 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 2785 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 2786 | macaddr, NULL); |
| 2787 | if (ret) { |
| 2788 | dev_info(&vsi->back->pdev->dev, |
| 2789 | "Addr change for VSI failed: %d\n", ret); |
| 2790 | return -EADDRNOTAVAIL; |
| 2791 | } |
| 2792 | |
| 2793 | memset(&element, 0, sizeof(element)); |
| 2794 | ether_addr_copy(element.mac_addr, macaddr); |
| 2795 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 2796 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); |
| 2797 | if (ret) { |
| 2798 | dev_info(&vsi->back->pdev->dev, |
| 2799 | "add filter failed err %s aq_err %s\n", |
| 2800 | i40e_stat_str(&vsi->back->hw, ret), |
| 2801 | i40e_aq_str(&vsi->back->hw, |
| 2802 | vsi->back->hw.aq.asq_last_status)); |
| 2803 | } |
| 2804 | return ret; |
| 2805 | } |
| 2806 | |
| 2807 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2808 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2809 | * @vsi: the vsi being brought back up |
| 2810 | **/ |
| 2811 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2812 | { |
| 2813 | u16 vid; |
| 2814 | |
| 2815 | if (!vsi->netdev) |
| 2816 | return; |
| 2817 | |
| 2818 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2819 | |
| 2820 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2821 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2822 | vid); |
| 2823 | } |
| 2824 | |
| 2825 | /** |
| 2826 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2827 | * @vsi: the vsi being adjusted |
| 2828 | * @vid: the vlan id to set as a PVID |
| 2829 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2830 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2831 | { |
| 2832 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2833 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2834 | |
| 2835 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2836 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2837 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2838 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2839 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2840 | |
| 2841 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2842 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2843 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2844 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2845 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2846 | "add pvid failed, err %s aq_err %s\n", |
| 2847 | i40e_stat_str(&vsi->back->hw, ret), |
| 2848 | i40e_aq_str(&vsi->back->hw, |
| 2849 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2850 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2851 | } |
| 2852 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2853 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | /** |
| 2857 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2858 | * @vsi: the vsi being adjusted |
| 2859 | * |
| 2860 | * Just use the vlan_rx_register() service to put it back to normal |
| 2861 | **/ |
| 2862 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2863 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2864 | i40e_vlan_stripping_disable(vsi); |
| 2865 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2866 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | /** |
| 2870 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2871 | * @vsi: ptr to the VSI |
| 2872 | * |
| 2873 | * If this function returns with an error, then it's possible one or |
| 2874 | * more of the rings is populated (while the rest are not). It is the |
| 2875 | * callers duty to clean those orphaned rings. |
| 2876 | * |
| 2877 | * Return 0 on success, negative on failure |
| 2878 | **/ |
| 2879 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2880 | { |
| 2881 | int i, err = 0; |
| 2882 | |
| 2883 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2884 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2885 | |
| 2886 | return err; |
| 2887 | } |
| 2888 | |
| 2889 | /** |
| 2890 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2891 | * @vsi: ptr to the VSI |
| 2892 | * |
| 2893 | * Free VSI's transmit software resources |
| 2894 | **/ |
| 2895 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2896 | { |
| 2897 | int i; |
| 2898 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2899 | if (!vsi->tx_rings) |
| 2900 | return; |
| 2901 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2902 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2903 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2904 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | /** |
| 2908 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2909 | * @vsi: ptr to the VSI |
| 2910 | * |
| 2911 | * If this function returns with an error, then it's possible one or |
| 2912 | * more of the rings is populated (while the rest are not). It is the |
| 2913 | * callers duty to clean those orphaned rings. |
| 2914 | * |
| 2915 | * Return 0 on success, negative on failure |
| 2916 | **/ |
| 2917 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2918 | { |
| 2919 | int i, err = 0; |
| 2920 | |
| 2921 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2922 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2923 | #ifdef I40E_FCOE |
| 2924 | i40e_fcoe_setup_ddp_resources(vsi); |
| 2925 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2926 | return err; |
| 2927 | } |
| 2928 | |
| 2929 | /** |
| 2930 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2931 | * @vsi: ptr to the VSI |
| 2932 | * |
| 2933 | * Free all receive software resources |
| 2934 | **/ |
| 2935 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2936 | { |
| 2937 | int i; |
| 2938 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2939 | if (!vsi->rx_rings) |
| 2940 | return; |
| 2941 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2942 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2943 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2944 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2945 | #ifdef I40E_FCOE |
| 2946 | i40e_fcoe_free_ddp_resources(vsi); |
| 2947 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2951 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2952 | * @ring: The Tx ring to configure |
| 2953 | * |
| 2954 | * This enables/disables XPS for a given Tx descriptor ring |
| 2955 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2956 | **/ |
| 2957 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2958 | { |
| 2959 | struct i40e_vsi *vsi = ring->vsi; |
| 2960 | cpumask_var_t mask; |
| 2961 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2962 | if (!ring->q_vector || !ring->netdev) |
| 2963 | return; |
| 2964 | |
| 2965 | /* Single TC mode enable XPS */ |
| 2966 | if (vsi->tc_config.numtc <= 1) { |
| 2967 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2968 | netif_set_xps_queue(ring->netdev, |
| 2969 | &ring->q_vector->affinity_mask, |
| 2970 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2971 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2972 | /* Disable XPS to allow selection based on TC */ |
| 2973 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2974 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2975 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2976 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2977 | |
| 2978 | /* schedule our worker thread which will take care of |
| 2979 | * applying the new filter changes |
| 2980 | */ |
| 2981 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2985 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2986 | * @ring: The Tx ring to configure |
| 2987 | * |
| 2988 | * Configure the Tx descriptor ring in the HMC context. |
| 2989 | **/ |
| 2990 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2991 | { |
| 2992 | struct i40e_vsi *vsi = ring->vsi; |
| 2993 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2994 | struct i40e_hw *hw = &vsi->back->hw; |
| 2995 | struct i40e_hmc_obj_txq tx_ctx; |
| 2996 | i40e_status err = 0; |
| 2997 | u32 qtx_ctl = 0; |
| 2998 | |
| 2999 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 3000 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3001 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 3002 | ring->atr_count = 0; |
| 3003 | } else { |
| 3004 | ring->atr_sample_rate = 0; |
| 3005 | } |
| 3006 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 3007 | /* configure XPS */ |
| 3008 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3009 | |
| 3010 | /* clear the context structure first */ |
| 3011 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 3012 | |
| 3013 | tx_ctx.new_context = 1; |
| 3014 | tx_ctx.base = (ring->dma / 128); |
| 3015 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 3016 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 3017 | I40E_FLAG_FD_ATR_ENABLED)); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3018 | #ifdef I40E_FCOE |
| 3019 | tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 3020 | #endif |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3021 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 3022 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 3023 | if (vsi->type != I40E_VSI_FDIR) |
| 3024 | tx_ctx.head_wb_ena = 1; |
| 3025 | tx_ctx.head_wb_addr = ring->dma + |
| 3026 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3027 | |
| 3028 | /* As part of VSI creation/update, FW allocates certain |
| 3029 | * Tx arbitration queue sets for each TC enabled for |
| 3030 | * the VSI. The FW returns the handles to these queue |
| 3031 | * sets as part of the response buffer to Add VSI, |
| 3032 | * Update VSI, etc. AQ commands. It is expected that |
| 3033 | * these queue set handles be associated with the Tx |
| 3034 | * queues by the driver as part of the TX queue context |
| 3035 | * initialization. This has to be done regardless of |
| 3036 | * DCB as by default everything is mapped to TC0. |
| 3037 | */ |
| 3038 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 3039 | tx_ctx.rdylist_act = 0; |
| 3040 | |
| 3041 | /* clear the context in the HMC */ |
| 3042 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 3043 | if (err) { |
| 3044 | dev_info(&vsi->back->pdev->dev, |
| 3045 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 3046 | ring->queue_index, pf_q, err); |
| 3047 | return -ENOMEM; |
| 3048 | } |
| 3049 | |
| 3050 | /* set the context in the HMC */ |
| 3051 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 3052 | if (err) { |
| 3053 | dev_info(&vsi->back->pdev->dev, |
| 3054 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 3055 | ring->queue_index, pf_q, err); |
| 3056 | return -ENOMEM; |
| 3057 | } |
| 3058 | |
| 3059 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 3060 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 3061 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 3062 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 3063 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 3064 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 3065 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 3066 | } |
| 3067 | |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 3068 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 3069 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3070 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 3071 | i40e_flush(hw); |
| 3072 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3073 | /* cache tail off for easier writes later */ |
| 3074 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 3075 | |
| 3076 | return 0; |
| 3077 | } |
| 3078 | |
| 3079 | /** |
| 3080 | * i40e_configure_rx_ring - Configure a receive ring context |
| 3081 | * @ring: The Rx ring to configure |
| 3082 | * |
| 3083 | * Configure the Rx descriptor ring in the HMC context. |
| 3084 | **/ |
| 3085 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 3086 | { |
| 3087 | struct i40e_vsi *vsi = ring->vsi; |
| 3088 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 3089 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 3090 | struct i40e_hw *hw = &vsi->back->hw; |
| 3091 | struct i40e_hmc_obj_rxq rx_ctx; |
| 3092 | i40e_status err = 0; |
| 3093 | |
| 3094 | ring->state = 0; |
| 3095 | |
| 3096 | /* clear the context structure first */ |
| 3097 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 3098 | |
| 3099 | ring->rx_buf_len = vsi->rx_buf_len; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3100 | |
| 3101 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3102 | |
| 3103 | rx_ctx.base = (ring->dma / 128); |
| 3104 | rx_ctx.qlen = ring->count; |
| 3105 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 3106 | /* use 32 byte descriptors */ |
| 3107 | rx_ctx.dsize = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3108 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 3109 | /* descriptor type is always zero |
| 3110 | * rx_ctx.dtype = 0; |
| 3111 | */ |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 3112 | rx_ctx.hsplit_0 = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3113 | |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 3114 | 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] | 3115 | if (hw->revision_id == 0) |
| 3116 | rx_ctx.lrxqthresh = 0; |
| 3117 | else |
| 3118 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3119 | rx_ctx.crcstrip = 1; |
| 3120 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 3121 | /* this controls whether VLAN is stripped from inner headers */ |
| 3122 | rx_ctx.showiv = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3123 | #ifdef I40E_FCOE |
| 3124 | rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 3125 | #endif |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 3126 | /* set the prefena field to 1 because the manual says to */ |
| 3127 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3128 | |
| 3129 | /* clear the context in the HMC */ |
| 3130 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 3131 | if (err) { |
| 3132 | dev_info(&vsi->back->pdev->dev, |
| 3133 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 3134 | ring->queue_index, pf_q, err); |
| 3135 | return -ENOMEM; |
| 3136 | } |
| 3137 | |
| 3138 | /* set the context in the HMC */ |
| 3139 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 3140 | if (err) { |
| 3141 | dev_info(&vsi->back->pdev->dev, |
| 3142 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 3143 | ring->queue_index, pf_q, err); |
| 3144 | return -ENOMEM; |
| 3145 | } |
| 3146 | |
| 3147 | /* cache tail for quicker writes, and clear the reg before use */ |
| 3148 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 3149 | writel(0, ring->tail); |
| 3150 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 3151 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3152 | |
| 3153 | return 0; |
| 3154 | } |
| 3155 | |
| 3156 | /** |
| 3157 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 3158 | * @vsi: VSI structure describing this set of rings and resources |
| 3159 | * |
| 3160 | * Configure the Tx VSI for operation. |
| 3161 | **/ |
| 3162 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 3163 | { |
| 3164 | int err = 0; |
| 3165 | u16 i; |
| 3166 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3167 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 3168 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3169 | |
| 3170 | return err; |
| 3171 | } |
| 3172 | |
| 3173 | /** |
| 3174 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 3175 | * @vsi: the VSI being configured |
| 3176 | * |
| 3177 | * Configure the Rx VSI for operation. |
| 3178 | **/ |
| 3179 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 3180 | { |
| 3181 | int err = 0; |
| 3182 | u16 i; |
| 3183 | |
| 3184 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 3185 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 3186 | + ETH_FCS_LEN + VLAN_HLEN; |
| 3187 | else |
| 3188 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 3189 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 3190 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3191 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3192 | #ifdef I40E_FCOE |
| 3193 | /* setup rx buffer for FCoE */ |
| 3194 | if ((vsi->type == I40E_VSI_FCOE) && |
| 3195 | (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) { |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3196 | vsi->rx_buf_len = I40E_RXBUFFER_3072; |
| 3197 | vsi->max_frame = I40E_RXBUFFER_3072; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3201 | /* round up for the chip's needs */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3202 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3203 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3204 | |
| 3205 | /* set up individual rings */ |
| 3206 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3207 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3208 | |
| 3209 | return err; |
| 3210 | } |
| 3211 | |
| 3212 | /** |
| 3213 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3214 | * @vsi: ptr to the VSI |
| 3215 | **/ |
| 3216 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3217 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3218 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3219 | u16 qoffset, qcount; |
| 3220 | int i, n; |
| 3221 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3222 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3223 | /* Reset the TC information */ |
| 3224 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3225 | rx_ring = vsi->rx_rings[i]; |
| 3226 | tx_ring = vsi->tx_rings[i]; |
| 3227 | rx_ring->dcb_tc = 0; |
| 3228 | tx_ring->dcb_tc = 0; |
| 3229 | } |
| 3230 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3231 | |
| 3232 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3233 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3234 | continue; |
| 3235 | |
| 3236 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3237 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3238 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3239 | rx_ring = vsi->rx_rings[i]; |
| 3240 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3241 | rx_ring->dcb_tc = n; |
| 3242 | tx_ring->dcb_tc = n; |
| 3243 | } |
| 3244 | } |
| 3245 | } |
| 3246 | |
| 3247 | /** |
| 3248 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3249 | * @vsi: ptr to the VSI |
| 3250 | **/ |
| 3251 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3252 | { |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 3253 | struct i40e_pf *pf = vsi->back; |
| 3254 | int err; |
| 3255 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3256 | if (vsi->netdev) |
| 3257 | i40e_set_rx_mode(vsi->netdev); |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 3258 | |
| 3259 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 3260 | err = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 3261 | if (err) { |
| 3262 | dev_warn(&pf->pdev->dev, |
| 3263 | "could not set up macaddr; err %d\n", err); |
| 3264 | } |
| 3265 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3266 | } |
| 3267 | |
| 3268 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3269 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3270 | * @vsi: Pointer to the targeted VSI |
| 3271 | * |
| 3272 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3273 | * filters were saved. |
| 3274 | **/ |
| 3275 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3276 | { |
| 3277 | struct i40e_fdir_filter *filter; |
| 3278 | struct i40e_pf *pf = vsi->back; |
| 3279 | struct hlist_node *node; |
| 3280 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3281 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3282 | return; |
| 3283 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3284 | hlist_for_each_entry_safe(filter, node, |
| 3285 | &pf->fdir_filter_list, fdir_node) { |
| 3286 | i40e_add_del_fdir(vsi, filter, true); |
| 3287 | } |
| 3288 | } |
| 3289 | |
| 3290 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3291 | * i40e_vsi_configure - Set up the VSI for action |
| 3292 | * @vsi: the VSI being configured |
| 3293 | **/ |
| 3294 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3295 | { |
| 3296 | int err; |
| 3297 | |
| 3298 | i40e_set_vsi_rx_mode(vsi); |
| 3299 | i40e_restore_vlan(vsi); |
| 3300 | i40e_vsi_config_dcb_rings(vsi); |
| 3301 | err = i40e_vsi_configure_tx(vsi); |
| 3302 | if (!err) |
| 3303 | err = i40e_vsi_configure_rx(vsi); |
| 3304 | |
| 3305 | return err; |
| 3306 | } |
| 3307 | |
| 3308 | /** |
| 3309 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3310 | * @vsi: the VSI being configured |
| 3311 | **/ |
| 3312 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3313 | { |
| 3314 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3315 | struct i40e_hw *hw = &pf->hw; |
| 3316 | u16 vector; |
| 3317 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3318 | u32 qp; |
| 3319 | |
| 3320 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3321 | * and PFINT_LNKLSTn registers, e.g.: |
| 3322 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3323 | */ |
| 3324 | qp = vsi->base_queue; |
| 3325 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3326 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3327 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3328 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3329 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3330 | 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] | 3331 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3332 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3333 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3334 | 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] | 3335 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3336 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3337 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3338 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
Alan Brady | 1c0e6a3 | 2016-11-28 16:06:02 -0800 | [diff] [blame] | 3339 | i40e_intrl_usec_to_reg(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3340 | |
| 3341 | /* Linked list for the queuepairs assigned to this vector */ |
| 3342 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3343 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3344 | u32 val; |
| 3345 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3346 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3347 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3348 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3349 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 3350 | (I40E_QUEUE_TYPE_TX |
| 3351 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 3352 | |
| 3353 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3354 | |
| 3355 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3356 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3357 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3358 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 3359 | (I40E_QUEUE_TYPE_RX |
| 3360 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3361 | |
| 3362 | /* Terminate the linked list */ |
| 3363 | if (q == (q_vector->num_ringpairs - 1)) |
| 3364 | val |= (I40E_QUEUE_END_OF_LIST |
| 3365 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3366 | |
| 3367 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3368 | qp++; |
| 3369 | } |
| 3370 | } |
| 3371 | |
| 3372 | i40e_flush(hw); |
| 3373 | } |
| 3374 | |
| 3375 | /** |
| 3376 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3377 | * @hw: ptr to the hardware info |
| 3378 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3379 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3380 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3381 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3382 | u32 val; |
| 3383 | |
| 3384 | /* clear things first */ |
| 3385 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3386 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3387 | |
| 3388 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3389 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3390 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3391 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3392 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3393 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3394 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3395 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3396 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3397 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3398 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3399 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3400 | if (pf->flags & I40E_FLAG_PTP) |
| 3401 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3402 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3403 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3404 | |
| 3405 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3406 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3407 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3408 | |
| 3409 | /* OTHER_ITR_IDX = 0 */ |
| 3410 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3411 | } |
| 3412 | |
| 3413 | /** |
| 3414 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3415 | * @vsi: the VSI being configured |
| 3416 | **/ |
| 3417 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3418 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3419 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3420 | struct i40e_pf *pf = vsi->back; |
| 3421 | struct i40e_hw *hw = &pf->hw; |
| 3422 | u32 val; |
| 3423 | |
| 3424 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3425 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3426 | 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] | 3427 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3428 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3429 | 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] | 3430 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3431 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3432 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3433 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3434 | |
| 3435 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3436 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3437 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3438 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3439 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3440 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3441 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3442 | |
| 3443 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3444 | |
| 3445 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3446 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3447 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3448 | |
| 3449 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3450 | i40e_flush(hw); |
| 3451 | } |
| 3452 | |
| 3453 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3454 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3455 | * @pf: board private structure |
| 3456 | **/ |
| 3457 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3458 | { |
| 3459 | struct i40e_hw *hw = &pf->hw; |
| 3460 | |
| 3461 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3462 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3463 | i40e_flush(hw); |
| 3464 | } |
| 3465 | |
| 3466 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3467 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3468 | * @pf: board private structure |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3469 | * @clearpba: true when all pending interrupt events should be cleared |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3470 | **/ |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3471 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3472 | { |
| 3473 | struct i40e_hw *hw = &pf->hw; |
| 3474 | u32 val; |
| 3475 | |
| 3476 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3477 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3478 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3479 | |
| 3480 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3481 | i40e_flush(hw); |
| 3482 | } |
| 3483 | |
| 3484 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3485 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3486 | * @irq: interrupt number |
| 3487 | * @data: pointer to a q_vector |
| 3488 | **/ |
| 3489 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3490 | { |
| 3491 | struct i40e_q_vector *q_vector = data; |
| 3492 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3493 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3494 | return IRQ_HANDLED; |
| 3495 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3496 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3497 | |
| 3498 | return IRQ_HANDLED; |
| 3499 | } |
| 3500 | |
| 3501 | /** |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3502 | * i40e_irq_affinity_notify - Callback for affinity changes |
| 3503 | * @notify: context as to what irq was changed |
| 3504 | * @mask: the new affinity mask |
| 3505 | * |
| 3506 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3507 | * so that we may register to receive changes to the irq affinity masks. |
| 3508 | **/ |
| 3509 | static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify, |
| 3510 | const cpumask_t *mask) |
| 3511 | { |
| 3512 | struct i40e_q_vector *q_vector = |
| 3513 | container_of(notify, struct i40e_q_vector, affinity_notify); |
| 3514 | |
| 3515 | q_vector->affinity_mask = *mask; |
| 3516 | } |
| 3517 | |
| 3518 | /** |
| 3519 | * i40e_irq_affinity_release - Callback for affinity notifier release |
| 3520 | * @ref: internal core kernel usage |
| 3521 | * |
| 3522 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3523 | * to inform the current notification subscriber that they will no longer |
| 3524 | * receive notifications. |
| 3525 | **/ |
| 3526 | static void i40e_irq_affinity_release(struct kref *ref) {} |
| 3527 | |
| 3528 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3529 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3530 | * @vsi: the VSI being configured |
| 3531 | * @basename: name for the vector |
| 3532 | * |
| 3533 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3534 | **/ |
| 3535 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3536 | { |
| 3537 | int q_vectors = vsi->num_q_vectors; |
| 3538 | struct i40e_pf *pf = vsi->back; |
| 3539 | int base = vsi->base_vector; |
| 3540 | int rx_int_idx = 0; |
| 3541 | int tx_int_idx = 0; |
| 3542 | int vector, err; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3543 | int irq_num; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3544 | |
| 3545 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3546 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3547 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3548 | irq_num = pf->msix_entries[base + vector].vector; |
| 3549 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3550 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3551 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3552 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3553 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3554 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3555 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3556 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3557 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3558 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3559 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3560 | } else { |
| 3561 | /* skip this unused q_vector */ |
| 3562 | continue; |
| 3563 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3564 | err = request_irq(irq_num, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3565 | vsi->irq_handler, |
| 3566 | 0, |
| 3567 | q_vector->name, |
| 3568 | q_vector); |
| 3569 | if (err) { |
| 3570 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3571 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3572 | goto free_queue_irqs; |
| 3573 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3574 | |
| 3575 | /* register for affinity change notifications */ |
| 3576 | q_vector->affinity_notify.notify = i40e_irq_affinity_notify; |
| 3577 | q_vector->affinity_notify.release = i40e_irq_affinity_release; |
| 3578 | irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3579 | /* assign the mask for this irq */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3580 | irq_set_affinity_hint(irq_num, &q_vector->affinity_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3581 | } |
| 3582 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3583 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3584 | return 0; |
| 3585 | |
| 3586 | free_queue_irqs: |
| 3587 | while (vector) { |
| 3588 | vector--; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3589 | irq_num = pf->msix_entries[base + vector].vector; |
| 3590 | irq_set_affinity_notifier(irq_num, NULL); |
| 3591 | irq_set_affinity_hint(irq_num, NULL); |
| 3592 | free_irq(irq_num, &vsi->q_vectors[vector]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3593 | } |
| 3594 | return err; |
| 3595 | } |
| 3596 | |
| 3597 | /** |
| 3598 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3599 | * @vsi: the VSI being un-configured |
| 3600 | **/ |
| 3601 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3602 | { |
| 3603 | struct i40e_pf *pf = vsi->back; |
| 3604 | struct i40e_hw *hw = &pf->hw; |
| 3605 | int base = vsi->base_vector; |
| 3606 | int i; |
| 3607 | |
| 3608 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3609 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3610 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3614 | for (i = vsi->base_vector; |
| 3615 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3616 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3617 | |
| 3618 | i40e_flush(hw); |
| 3619 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3620 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3621 | } else { |
| 3622 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3623 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3624 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3625 | i40e_flush(hw); |
| 3626 | synchronize_irq(pf->pdev->irq); |
| 3627 | } |
| 3628 | } |
| 3629 | |
| 3630 | /** |
| 3631 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3632 | * @vsi: the VSI being configured |
| 3633 | **/ |
| 3634 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3635 | { |
| 3636 | struct i40e_pf *pf = vsi->back; |
| 3637 | int i; |
| 3638 | |
| 3639 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3640 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3641 | i40e_irq_dynamic_enable(vsi, i); |
| 3642 | } else { |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3643 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3644 | } |
| 3645 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3646 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3647 | return 0; |
| 3648 | } |
| 3649 | |
| 3650 | /** |
| 3651 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3652 | * @pf: board private structure |
| 3653 | **/ |
| 3654 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3655 | { |
| 3656 | /* Disable ICR 0 */ |
| 3657 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3658 | i40e_flush(&pf->hw); |
| 3659 | } |
| 3660 | |
| 3661 | /** |
| 3662 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3663 | * @irq: interrupt number |
| 3664 | * @data: pointer to a q_vector |
| 3665 | * |
| 3666 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3667 | * with both queue and non-queue interrupts. This is also used in |
| 3668 | * MSIX mode to handle the non-queue interrupts. |
| 3669 | **/ |
| 3670 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3671 | { |
| 3672 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3673 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3674 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3675 | u32 icr0, icr0_remaining; |
| 3676 | u32 val, ena_mask; |
| 3677 | |
| 3678 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3679 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3680 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3681 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3682 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3683 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3684 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3685 | /* if interrupt but no bits showing, must be SWINT */ |
| 3686 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3687 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3688 | pf->sw_int_count++; |
| 3689 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3690 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 3691 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
| 3692 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3693 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
Carolyn Wyborny | 23bb6dc | 2016-11-08 13:05:12 -0800 | [diff] [blame] | 3694 | dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3695 | } |
| 3696 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3697 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3698 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3699 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3700 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3701 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3702 | /* We do not have a way to disarm Queue causes while leaving |
| 3703 | * interrupt enabled for all other causes, ideally |
| 3704 | * interrupt should be disabled while we are in NAPI but |
| 3705 | * this is not a performance path and napi_schedule() |
| 3706 | * can deal with rescheduling. |
| 3707 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3708 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3709 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3710 | } |
| 3711 | |
| 3712 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3713 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3714 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3715 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3719 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3720 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3721 | } |
| 3722 | |
| 3723 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3724 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3725 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3726 | } |
| 3727 | |
| 3728 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3729 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3730 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3731 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3732 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3733 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3734 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3735 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3736 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3737 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3738 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3739 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3740 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3741 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3742 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3743 | } |
| 3744 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3745 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3746 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3747 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3748 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3749 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3750 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3751 | } |
| 3752 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3753 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3754 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3755 | |
| 3756 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3757 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3758 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3759 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3760 | } |
| 3761 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3762 | /* If a critical error is pending we have no choice but to reset the |
| 3763 | * device. |
| 3764 | * Report and mask out any remaining unexpected interrupts. |
| 3765 | */ |
| 3766 | icr0_remaining = icr0 & ena_mask; |
| 3767 | if (icr0_remaining) { |
| 3768 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3769 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3770 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3771 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3772 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3773 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3774 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3775 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3776 | } |
| 3777 | ena_mask &= ~icr0_remaining; |
| 3778 | } |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3779 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3780 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3781 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3782 | /* re-enable interrupt causes */ |
| 3783 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3784 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3785 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3786 | i40e_irq_dynamic_enable_icr0(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3787 | } |
| 3788 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3789 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3790 | } |
| 3791 | |
| 3792 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3793 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3794 | * @tx_ring: tx ring to clean |
| 3795 | * @budget: how many cleans we're allowed |
| 3796 | * |
| 3797 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3798 | **/ |
| 3799 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3800 | { |
| 3801 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3802 | u16 i = tx_ring->next_to_clean; |
| 3803 | struct i40e_tx_buffer *tx_buf; |
| 3804 | struct i40e_tx_desc *tx_desc; |
| 3805 | |
| 3806 | tx_buf = &tx_ring->tx_bi[i]; |
| 3807 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3808 | i -= tx_ring->count; |
| 3809 | |
| 3810 | do { |
| 3811 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3812 | |
| 3813 | /* if next_to_watch is not set then there is no work pending */ |
| 3814 | if (!eop_desc) |
| 3815 | break; |
| 3816 | |
| 3817 | /* prevent any other reads prior to eop_desc */ |
| 3818 | read_barrier_depends(); |
| 3819 | |
| 3820 | /* if the descriptor isn't done, no work yet to do */ |
| 3821 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3822 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3823 | break; |
| 3824 | |
| 3825 | /* clear next_to_watch to prevent false hangs */ |
| 3826 | tx_buf->next_to_watch = NULL; |
| 3827 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3828 | tx_desc->buffer_addr = 0; |
| 3829 | tx_desc->cmd_type_offset_bsz = 0; |
| 3830 | /* move past filter desc */ |
| 3831 | tx_buf++; |
| 3832 | tx_desc++; |
| 3833 | i++; |
| 3834 | if (unlikely(!i)) { |
| 3835 | i -= tx_ring->count; |
| 3836 | tx_buf = tx_ring->tx_bi; |
| 3837 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3838 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3839 | /* unmap skb header data */ |
| 3840 | dma_unmap_single(tx_ring->dev, |
| 3841 | dma_unmap_addr(tx_buf, dma), |
| 3842 | dma_unmap_len(tx_buf, len), |
| 3843 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3844 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3845 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3846 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3847 | tx_buf->raw_buf = NULL; |
| 3848 | tx_buf->tx_flags = 0; |
| 3849 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3850 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3851 | tx_desc->buffer_addr = 0; |
| 3852 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3853 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3854 | /* 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] | 3855 | tx_buf++; |
| 3856 | tx_desc++; |
| 3857 | i++; |
| 3858 | if (unlikely(!i)) { |
| 3859 | i -= tx_ring->count; |
| 3860 | tx_buf = tx_ring->tx_bi; |
| 3861 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3862 | } |
| 3863 | |
| 3864 | /* update budget accounting */ |
| 3865 | budget--; |
| 3866 | } while (likely(budget)); |
| 3867 | |
| 3868 | i += tx_ring->count; |
| 3869 | tx_ring->next_to_clean = i; |
| 3870 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3871 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3872 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3873 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3874 | return budget > 0; |
| 3875 | } |
| 3876 | |
| 3877 | /** |
| 3878 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3879 | * @irq: interrupt number |
| 3880 | * @data: pointer to a q_vector |
| 3881 | **/ |
| 3882 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3883 | { |
| 3884 | struct i40e_q_vector *q_vector = data; |
| 3885 | struct i40e_vsi *vsi; |
| 3886 | |
| 3887 | if (!q_vector->tx.ring) |
| 3888 | return IRQ_HANDLED; |
| 3889 | |
| 3890 | vsi = q_vector->tx.ring->vsi; |
| 3891 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3892 | |
| 3893 | return IRQ_HANDLED; |
| 3894 | } |
| 3895 | |
| 3896 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3897 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3898 | * @vsi: the VSI being configured |
| 3899 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3900 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3901 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3902 | 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] | 3903 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3904 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3905 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3906 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3907 | |
| 3908 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3909 | tx_ring->next = q_vector->tx.ring; |
| 3910 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3911 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3912 | |
| 3913 | rx_ring->q_vector = q_vector; |
| 3914 | rx_ring->next = q_vector->rx.ring; |
| 3915 | q_vector->rx.ring = rx_ring; |
| 3916 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | /** |
| 3920 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3921 | * @vsi: the VSI being configured |
| 3922 | * |
| 3923 | * This function maps descriptor rings to the queue-specific vectors |
| 3924 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3925 | * one vector per queue pair, but on a constrained vector budget, we |
| 3926 | * group the queue pairs as "efficiently" as possible. |
| 3927 | **/ |
| 3928 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3929 | { |
| 3930 | int qp_remaining = vsi->num_queue_pairs; |
| 3931 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3932 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3933 | int v_start = 0; |
| 3934 | int qp_idx = 0; |
| 3935 | |
| 3936 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3937 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3938 | * It is also important to go through all the vectors available to be |
| 3939 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3940 | * are cleared. This is especially important when decreasing the |
| 3941 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3942 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3943 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3944 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3945 | |
| 3946 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3947 | |
| 3948 | q_vector->num_ringpairs = num_ringpairs; |
| 3949 | |
| 3950 | q_vector->rx.count = 0; |
| 3951 | q_vector->tx.count = 0; |
| 3952 | q_vector->rx.ring = NULL; |
| 3953 | q_vector->tx.ring = NULL; |
| 3954 | |
| 3955 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3956 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3957 | qp_idx++; |
| 3958 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3959 | } |
| 3960 | } |
| 3961 | } |
| 3962 | |
| 3963 | /** |
| 3964 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3965 | * @vsi: the VSI being configured |
| 3966 | * @basename: name for the vector |
| 3967 | **/ |
| 3968 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3969 | { |
| 3970 | struct i40e_pf *pf = vsi->back; |
| 3971 | int err; |
| 3972 | |
| 3973 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3974 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3975 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3976 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3977 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3978 | else |
| 3979 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3980 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3981 | |
| 3982 | if (err) |
| 3983 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3984 | |
| 3985 | return err; |
| 3986 | } |
| 3987 | |
| 3988 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3989 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3990 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3991 | * @netdev: network interface device structure |
| 3992 | * |
| 3993 | * This is used by netconsole to send skbs without having to re-enable |
| 3994 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3995 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3996 | #ifdef I40E_FCOE |
| 3997 | void i40e_netpoll(struct net_device *netdev) |
| 3998 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3999 | static void i40e_netpoll(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4000 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4001 | { |
| 4002 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 4003 | struct i40e_vsi *vsi = np->vsi; |
| 4004 | struct i40e_pf *pf = vsi->back; |
| 4005 | int i; |
| 4006 | |
| 4007 | /* if interface is down do nothing */ |
| 4008 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4009 | return; |
| 4010 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4011 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4012 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4013 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4014 | } else { |
| 4015 | i40e_intr(pf->pdev->irq, netdev); |
| 4016 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4017 | } |
| 4018 | #endif |
| 4019 | |
| 4020 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4021 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 4022 | * @pf: the PF being configured |
| 4023 | * @pf_q: the PF queue |
| 4024 | * @enable: enable or disable state of the queue |
| 4025 | * |
| 4026 | * This routine will wait for the given Tx queue of the PF to reach the |
| 4027 | * enabled or disabled state. |
| 4028 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 4029 | * multiple retries; else will return 0 in case of success. |
| 4030 | **/ |
| 4031 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 4032 | { |
| 4033 | int i; |
| 4034 | u32 tx_reg; |
| 4035 | |
| 4036 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 4037 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 4038 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 4039 | break; |
| 4040 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 4041 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4042 | } |
| 4043 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 4044 | return -ETIMEDOUT; |
| 4045 | |
| 4046 | return 0; |
| 4047 | } |
| 4048 | |
| 4049 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4050 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 4051 | * @vsi: the VSI being configured |
| 4052 | * @enable: start or stop the rings |
| 4053 | **/ |
| 4054 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 4055 | { |
| 4056 | struct i40e_pf *pf = vsi->back; |
| 4057 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4058 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4059 | u32 tx_reg; |
| 4060 | |
| 4061 | pf_q = vsi->base_queue; |
| 4062 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 4063 | |
| 4064 | /* warn the TX unit of coming changes */ |
| 4065 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 4066 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 4067 | usleep_range(10, 20); |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 4068 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4069 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4070 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4071 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 4072 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 4073 | break; |
| 4074 | usleep_range(1000, 2000); |
| 4075 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 4076 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 4077 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 4078 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4079 | |
| 4080 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 4081 | if (enable) { |
| 4082 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4083 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 4084 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4085 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 4086 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4087 | |
| 4088 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4089 | /* No waiting for the Tx queue to disable */ |
| 4090 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 4091 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4092 | |
| 4093 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4094 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 4095 | if (ret) { |
| 4096 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4097 | "VSI seid %d Tx ring %d %sable timeout\n", |
| 4098 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4099 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4100 | } |
| 4101 | } |
| 4102 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 4103 | if (hw->revision_id == 0) |
| 4104 | mdelay(50); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4105 | return ret; |
| 4106 | } |
| 4107 | |
| 4108 | /** |
| 4109 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 4110 | * @pf: the PF being configured |
| 4111 | * @pf_q: the PF queue |
| 4112 | * @enable: enable or disable state of the queue |
| 4113 | * |
| 4114 | * This routine will wait for the given Rx queue of the PF to reach the |
| 4115 | * enabled or disabled state. |
| 4116 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 4117 | * multiple retries; else will return 0 in case of success. |
| 4118 | **/ |
| 4119 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 4120 | { |
| 4121 | int i; |
| 4122 | u32 rx_reg; |
| 4123 | |
| 4124 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 4125 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 4126 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 4127 | break; |
| 4128 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 4129 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4130 | } |
| 4131 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 4132 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 4133 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4134 | return 0; |
| 4135 | } |
| 4136 | |
| 4137 | /** |
| 4138 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 4139 | * @vsi: the VSI being configured |
| 4140 | * @enable: start or stop the rings |
| 4141 | **/ |
| 4142 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 4143 | { |
| 4144 | struct i40e_pf *pf = vsi->back; |
| 4145 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4146 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4147 | u32 rx_reg; |
| 4148 | |
| 4149 | pf_q = vsi->base_queue; |
| 4150 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4151 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4152 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4153 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 4154 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 4155 | break; |
| 4156 | usleep_range(1000, 2000); |
| 4157 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4158 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 4159 | /* Skip if the queue is already in the requested state */ |
| 4160 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 4161 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4162 | |
| 4163 | /* turn on/off the queue */ |
| 4164 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4165 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4166 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4167 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4168 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4169 | /* No waiting for the Tx queue to disable */ |
| 4170 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 4171 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4172 | |
| 4173 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4174 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 4175 | if (ret) { |
| 4176 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4177 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 4178 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4179 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4180 | } |
| 4181 | } |
| 4182 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4183 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | /** |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4187 | * i40e_vsi_start_rings - Start a VSI's rings |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4188 | * @vsi: the VSI being configured |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4189 | **/ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4190 | int i40e_vsi_start_rings(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4191 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 4192 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4193 | |
| 4194 | /* do rx first for enable and last for disable */ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4195 | ret = i40e_vsi_control_rx(vsi, true); |
| 4196 | if (ret) |
| 4197 | return ret; |
| 4198 | ret = i40e_vsi_control_tx(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4199 | |
| 4200 | return ret; |
| 4201 | } |
| 4202 | |
| 4203 | /** |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4204 | * i40e_vsi_stop_rings - Stop a VSI's rings |
| 4205 | * @vsi: the VSI being configured |
| 4206 | **/ |
| 4207 | void i40e_vsi_stop_rings(struct i40e_vsi *vsi) |
| 4208 | { |
| 4209 | /* do rx first for enable and last for disable |
| 4210 | * Ignore return value, we need to shutdown whatever we can |
| 4211 | */ |
| 4212 | i40e_vsi_control_tx(vsi, false); |
| 4213 | i40e_vsi_control_rx(vsi, false); |
| 4214 | } |
| 4215 | |
| 4216 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4217 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 4218 | * @vsi: the VSI being configured |
| 4219 | **/ |
| 4220 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 4221 | { |
| 4222 | struct i40e_pf *pf = vsi->back; |
| 4223 | struct i40e_hw *hw = &pf->hw; |
| 4224 | int base = vsi->base_vector; |
| 4225 | u32 val, qp; |
| 4226 | int i; |
| 4227 | |
| 4228 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4229 | if (!vsi->q_vectors) |
| 4230 | return; |
| 4231 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 4232 | if (!vsi->irqs_ready) |
| 4233 | return; |
| 4234 | |
| 4235 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4236 | for (i = 0; i < vsi->num_q_vectors; i++) { |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4237 | int irq_num; |
| 4238 | u16 vector; |
| 4239 | |
| 4240 | vector = i + base; |
| 4241 | irq_num = pf->msix_entries[vector].vector; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4242 | |
| 4243 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 4244 | if (!vsi->q_vectors[i] || |
| 4245 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4246 | continue; |
| 4247 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4248 | /* clear the affinity notifier in the IRQ descriptor */ |
| 4249 | irq_set_affinity_notifier(irq_num, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4250 | /* clear the affinity_mask in the IRQ descriptor */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4251 | irq_set_affinity_hint(irq_num, NULL); |
| 4252 | synchronize_irq(irq_num); |
| 4253 | free_irq(irq_num, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4254 | |
| 4255 | /* Tear down the interrupt queue link list |
| 4256 | * |
| 4257 | * We know that they come in pairs and always |
| 4258 | * the Rx first, then the Tx. To clear the |
| 4259 | * link list, stick the EOL value into the |
| 4260 | * next_q field of the registers. |
| 4261 | */ |
| 4262 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4263 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4264 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4265 | val |= I40E_QUEUE_END_OF_LIST |
| 4266 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4267 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4268 | |
| 4269 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4270 | u32 next; |
| 4271 | |
| 4272 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4273 | |
| 4274 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4275 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4276 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4277 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4278 | |
| 4279 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4280 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4281 | |
| 4282 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4283 | |
| 4284 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4285 | |
| 4286 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4287 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4288 | |
| 4289 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4290 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4291 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4292 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4293 | |
| 4294 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4295 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4296 | |
| 4297 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4298 | qp = next; |
| 4299 | } |
| 4300 | } |
| 4301 | } else { |
| 4302 | free_irq(pf->pdev->irq, pf); |
| 4303 | |
| 4304 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4305 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4306 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4307 | val |= I40E_QUEUE_END_OF_LIST |
| 4308 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4309 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4310 | |
| 4311 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4312 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4313 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4314 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4315 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4316 | |
| 4317 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4318 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4319 | |
| 4320 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4321 | |
| 4322 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4323 | |
| 4324 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4325 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4326 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4327 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4328 | |
| 4329 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4330 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4331 | |
| 4332 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4333 | } |
| 4334 | } |
| 4335 | |
| 4336 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4337 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4338 | * @vsi: the VSI being configured |
| 4339 | * @v_idx: Index of vector to be freed |
| 4340 | * |
| 4341 | * This function frees the memory allocated to the q_vector. In addition if |
| 4342 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4343 | * to freeing the q_vector. |
| 4344 | **/ |
| 4345 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4346 | { |
| 4347 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4348 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4349 | |
| 4350 | if (!q_vector) |
| 4351 | return; |
| 4352 | |
| 4353 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4354 | i40e_for_each_ring(ring, q_vector->tx) |
| 4355 | ring->q_vector = NULL; |
| 4356 | |
| 4357 | i40e_for_each_ring(ring, q_vector->rx) |
| 4358 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4359 | |
| 4360 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4361 | if (vsi->netdev) |
| 4362 | netif_napi_del(&q_vector->napi); |
| 4363 | |
| 4364 | vsi->q_vectors[v_idx] = NULL; |
| 4365 | |
| 4366 | kfree_rcu(q_vector, rcu); |
| 4367 | } |
| 4368 | |
| 4369 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4370 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4371 | * @vsi: the VSI being un-configured |
| 4372 | * |
| 4373 | * This frees the memory allocated to the q_vectors and |
| 4374 | * deletes references to the NAPI struct. |
| 4375 | **/ |
| 4376 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4377 | { |
| 4378 | int v_idx; |
| 4379 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4380 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4381 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4382 | } |
| 4383 | |
| 4384 | /** |
| 4385 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4386 | * @pf: board private structure |
| 4387 | **/ |
| 4388 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4389 | { |
| 4390 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4391 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4392 | pci_disable_msix(pf->pdev); |
| 4393 | kfree(pf->msix_entries); |
| 4394 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4395 | kfree(pf->irq_pile); |
| 4396 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4397 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4398 | pci_disable_msi(pf->pdev); |
| 4399 | } |
| 4400 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4401 | } |
| 4402 | |
| 4403 | /** |
| 4404 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4405 | * @pf: board private structure |
| 4406 | * |
| 4407 | * We go through and clear interrupt specific resources and reset the structure |
| 4408 | * to pre-load conditions |
| 4409 | **/ |
| 4410 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4411 | { |
| 4412 | int i; |
| 4413 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4414 | i40e_stop_misc_vector(pf); |
Shannon Nelson | 6927839 | 2016-03-10 14:59:43 -0800 | [diff] [blame] | 4415 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4416 | synchronize_irq(pf->msix_entries[0].vector); |
| 4417 | free_irq(pf->msix_entries[0].vector, pf); |
| 4418 | } |
| 4419 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4420 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4421 | I40E_IWARP_IRQ_PILE_ID); |
| 4422 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4423 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4424 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4425 | if (pf->vsi[i]) |
| 4426 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4427 | i40e_reset_interrupt_capability(pf); |
| 4428 | } |
| 4429 | |
| 4430 | /** |
| 4431 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4432 | * @vsi: the VSI being configured |
| 4433 | **/ |
| 4434 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4435 | { |
| 4436 | int q_idx; |
| 4437 | |
| 4438 | if (!vsi->netdev) |
| 4439 | return; |
| 4440 | |
| 4441 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4442 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4443 | } |
| 4444 | |
| 4445 | /** |
| 4446 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4447 | * @vsi: the VSI being configured |
| 4448 | **/ |
| 4449 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4450 | { |
| 4451 | int q_idx; |
| 4452 | |
| 4453 | if (!vsi->netdev) |
| 4454 | return; |
| 4455 | |
| 4456 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4457 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4458 | } |
| 4459 | |
| 4460 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4461 | * i40e_vsi_close - Shut down a VSI |
| 4462 | * @vsi: the vsi to be quelled |
| 4463 | **/ |
| 4464 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4465 | { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4466 | bool reset = false; |
| 4467 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4468 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4469 | i40e_down(vsi); |
| 4470 | i40e_vsi_free_irq(vsi); |
| 4471 | i40e_vsi_free_tx_resources(vsi); |
| 4472 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4473 | vsi->current_netdev_flags = 0; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4474 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4475 | reset = true; |
| 4476 | i40e_notify_client_of_netdev_close(vsi, reset); |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4480 | * i40e_quiesce_vsi - Pause a given VSI |
| 4481 | * @vsi: the VSI being paused |
| 4482 | **/ |
| 4483 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4484 | { |
| 4485 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4486 | return; |
| 4487 | |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4488 | /* No need to disable FCoE VSI when Tx suspended */ |
| 4489 | if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) && |
| 4490 | vsi->type == I40E_VSI_FCOE) { |
| 4491 | dev_dbg(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4492 | "VSI seid %d skipping FCoE VSI disable\n", vsi->seid); |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4493 | return; |
| 4494 | } |
| 4495 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4496 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4497 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4498 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4499 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4500 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4501 | } |
| 4502 | |
| 4503 | /** |
| 4504 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4505 | * @vsi: the VSI being resumed |
| 4506 | **/ |
| 4507 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4508 | { |
| 4509 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 4510 | return; |
| 4511 | |
| 4512 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4513 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4514 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4515 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4516 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | /** |
| 4520 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4521 | * @pf: the PF |
| 4522 | **/ |
| 4523 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4524 | { |
| 4525 | int v; |
| 4526 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4527 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4528 | if (pf->vsi[v]) |
| 4529 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4530 | } |
| 4531 | } |
| 4532 | |
| 4533 | /** |
| 4534 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4535 | * @pf: the PF |
| 4536 | **/ |
| 4537 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4538 | { |
| 4539 | int v; |
| 4540 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4541 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4542 | if (pf->vsi[v]) |
| 4543 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4544 | } |
| 4545 | } |
| 4546 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4547 | #ifdef CONFIG_I40E_DCB |
| 4548 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4549 | * 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] | 4550 | * @vsi: the VSI being configured |
| 4551 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4552 | * This function waits for the given VSI's queues to be disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4553 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4554 | static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4555 | { |
| 4556 | struct i40e_pf *pf = vsi->back; |
| 4557 | int i, pf_q, ret; |
| 4558 | |
| 4559 | pf_q = vsi->base_queue; |
| 4560 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4561 | /* Check and wait for the disable status of the queue */ |
| 4562 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4563 | if (ret) { |
| 4564 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4565 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4566 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4567 | return ret; |
| 4568 | } |
| 4569 | } |
| 4570 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4571 | pf_q = vsi->base_queue; |
| 4572 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4573 | /* Check and wait for the disable status of the queue */ |
| 4574 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4575 | if (ret) { |
| 4576 | dev_info(&pf->pdev->dev, |
| 4577 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4578 | vsi->seid, pf_q); |
| 4579 | return ret; |
| 4580 | } |
| 4581 | } |
| 4582 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4583 | return 0; |
| 4584 | } |
| 4585 | |
| 4586 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4587 | * 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] | 4588 | * @pf: the PF |
| 4589 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4590 | * 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] | 4591 | * VSIs that are managed by this PF. |
| 4592 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4593 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4594 | { |
| 4595 | int v, ret = 0; |
| 4596 | |
| 4597 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4598 | /* No need to wait for FCoE VSI queues */ |
| 4599 | if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4600 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4601 | if (ret) |
| 4602 | break; |
| 4603 | } |
| 4604 | } |
| 4605 | |
| 4606 | return ret; |
| 4607 | } |
| 4608 | |
| 4609 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4610 | |
| 4611 | /** |
| 4612 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4613 | * @q_idx: TX queue number |
| 4614 | * @vsi: Pointer to VSI struct |
| 4615 | * |
| 4616 | * This function checks specified queue for given VSI. Detects hung condition. |
| 4617 | * Sets hung bit since it is two step process. Before next run of service task |
| 4618 | * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not, |
| 4619 | * hung condition remain unchanged and during subsequent run, this function |
| 4620 | * issues SW interrupt to recover from hung condition. |
| 4621 | **/ |
| 4622 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4623 | { |
| 4624 | struct i40e_ring *tx_ring = NULL; |
| 4625 | struct i40e_pf *pf; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4626 | u32 head, val, tx_pending_hw; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4627 | int i; |
| 4628 | |
| 4629 | pf = vsi->back; |
| 4630 | |
| 4631 | /* now that we have an index, find the tx_ring struct */ |
| 4632 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4633 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4634 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4635 | tx_ring = vsi->tx_rings[i]; |
| 4636 | break; |
| 4637 | } |
| 4638 | } |
| 4639 | } |
| 4640 | |
| 4641 | if (!tx_ring) |
| 4642 | return; |
| 4643 | |
| 4644 | /* Read interrupt register */ |
| 4645 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4646 | val = rd32(&pf->hw, |
| 4647 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4648 | tx_ring->vsi->base_vector - 1)); |
| 4649 | else |
| 4650 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4651 | |
| 4652 | head = i40e_get_head(tx_ring); |
| 4653 | |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4654 | tx_pending_hw = i40e_get_tx_pending(tx_ring, false); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4655 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4656 | /* HW is done executing descriptors, updated HEAD write back, |
| 4657 | * but SW hasn't processed those descriptors. If interrupt is |
| 4658 | * not generated from this point ON, it could result into |
| 4659 | * dev_watchdog detecting timeout on those netdev_queue, |
| 4660 | * hence proactively trigger SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4661 | */ |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4662 | if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4663 | /* NAPI Poll didn't run and clear since it was set */ |
| 4664 | if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4665 | &tx_ring->q_vector->hung_detected)) { |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4666 | 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", |
| 4667 | vsi->seid, q_idx, tx_pending_hw, |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4668 | tx_ring->next_to_clean, head, |
| 4669 | tx_ring->next_to_use, |
| 4670 | readl(tx_ring->tail)); |
| 4671 | netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n", |
| 4672 | vsi->seid, q_idx, val); |
| 4673 | i40e_force_wb(vsi, tx_ring->q_vector); |
| 4674 | } else { |
| 4675 | /* First Chance - detected possible hung */ |
| 4676 | set_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4677 | &tx_ring->q_vector->hung_detected); |
| 4678 | } |
| 4679 | } |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4680 | |
| 4681 | /* This is the case where we have interrupts missing, |
| 4682 | * so the tx_pending in HW will most likely be 0, but we |
| 4683 | * will have tx_pending in SW since the WB happened but the |
| 4684 | * interrupt got lost. |
| 4685 | */ |
| 4686 | if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) && |
| 4687 | (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
| 4688 | if (napi_reschedule(&tx_ring->q_vector->napi)) |
| 4689 | tx_ring->tx_stats.tx_lost_interrupt++; |
| 4690 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4691 | } |
| 4692 | |
| 4693 | /** |
| 4694 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4695 | * @pf: pointer to PF struct |
| 4696 | * |
| 4697 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4698 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4699 | * SW interrupt. |
| 4700 | **/ |
| 4701 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4702 | { |
| 4703 | struct net_device *netdev; |
| 4704 | struct i40e_vsi *vsi; |
| 4705 | int i; |
| 4706 | |
| 4707 | /* Only for LAN VSI */ |
| 4708 | vsi = pf->vsi[pf->lan_vsi]; |
| 4709 | |
| 4710 | if (!vsi) |
| 4711 | return; |
| 4712 | |
| 4713 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
| 4714 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 4715 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4716 | return; |
| 4717 | |
| 4718 | /* Make sure type is MAIN VSI */ |
| 4719 | if (vsi->type != I40E_VSI_MAIN) |
| 4720 | return; |
| 4721 | |
| 4722 | netdev = vsi->netdev; |
| 4723 | if (!netdev) |
| 4724 | return; |
| 4725 | |
| 4726 | /* Bail out if netif_carrier is not OK */ |
| 4727 | if (!netif_carrier_ok(netdev)) |
| 4728 | return; |
| 4729 | |
| 4730 | /* Go thru' TX queues for netdev */ |
| 4731 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4732 | struct netdev_queue *q; |
| 4733 | |
| 4734 | q = netdev_get_tx_queue(netdev, i); |
| 4735 | if (q) |
| 4736 | i40e_detect_recover_hung_queue(i, vsi); |
| 4737 | } |
| 4738 | } |
| 4739 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4740 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4741 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4742 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4743 | * |
| 4744 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4745 | * and LAN TC. |
| 4746 | **/ |
| 4747 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4748 | { |
| 4749 | struct i40e_dcb_app_priority_table app; |
| 4750 | struct i40e_hw *hw = &pf->hw; |
| 4751 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4752 | u8 tc, i; |
| 4753 | /* Get the iSCSI APP TLV */ |
| 4754 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4755 | |
| 4756 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4757 | app = dcbcfg->app[i]; |
| 4758 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4759 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4760 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4761 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4762 | break; |
| 4763 | } |
| 4764 | } |
| 4765 | |
| 4766 | return enabled_tc; |
| 4767 | } |
| 4768 | |
| 4769 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4770 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4771 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4772 | * |
| 4773 | * Return the number of TCs from given DCBx configuration |
| 4774 | **/ |
| 4775 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4776 | { |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4777 | int i, tc_unused = 0; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4778 | u8 num_tc = 0; |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4779 | u8 ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4780 | |
| 4781 | /* Scan the ETS Config Priority Table to find |
| 4782 | * traffic class enabled for a given priority |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4783 | * and create a bitmask of enabled TCs |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4784 | */ |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4785 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) |
| 4786 | num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]); |
| 4787 | |
| 4788 | /* Now scan the bitmask to check for |
| 4789 | * contiguous TCs starting with TC0 |
| 4790 | */ |
| 4791 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4792 | if (num_tc & BIT(i)) { |
| 4793 | if (!tc_unused) { |
| 4794 | ret++; |
| 4795 | } else { |
| 4796 | pr_err("Non-contiguous TC - Disabling DCB\n"); |
| 4797 | return 1; |
| 4798 | } |
| 4799 | } else { |
| 4800 | tc_unused = 1; |
| 4801 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4802 | } |
| 4803 | |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4804 | /* There is always at least TC0 */ |
| 4805 | if (!ret) |
| 4806 | ret = 1; |
| 4807 | |
| 4808 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4809 | } |
| 4810 | |
| 4811 | /** |
| 4812 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4813 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4814 | * |
| 4815 | * Query the current DCB configuration and return the number of |
| 4816 | * traffic classes enabled from the given DCBX config |
| 4817 | **/ |
| 4818 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4819 | { |
| 4820 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4821 | u8 enabled_tc = 1; |
| 4822 | u8 i; |
| 4823 | |
| 4824 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4825 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4826 | |
| 4827 | return enabled_tc; |
| 4828 | } |
| 4829 | |
| 4830 | /** |
| 4831 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4832 | * @pf: PF being queried |
| 4833 | * |
| 4834 | * Return number of traffic classes enabled for the given PF |
| 4835 | **/ |
| 4836 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4837 | { |
| 4838 | struct i40e_hw *hw = &pf->hw; |
Dave Ertman | 52a08ca | 2016-07-27 12:02:34 -0700 | [diff] [blame] | 4839 | u8 i, enabled_tc = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4840 | u8 num_tc = 0; |
| 4841 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4842 | |
| 4843 | /* If DCB is not enabled then always in single TC */ |
| 4844 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4845 | return 1; |
| 4846 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4847 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4848 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4849 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4850 | |
| 4851 | /* MFP mode return count of enabled TCs for this PF */ |
| 4852 | if (pf->hw.func_caps.iscsi) |
| 4853 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4854 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4855 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4856 | |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4857 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4858 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4859 | num_tc++; |
| 4860 | } |
| 4861 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4862 | } |
| 4863 | |
| 4864 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4865 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4866 | * @pf: PF being queried |
| 4867 | * |
| 4868 | * Return a bitmap for enabled traffic classes for this PF. |
| 4869 | **/ |
| 4870 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4871 | { |
| 4872 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4873 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4874 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4875 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4876 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4877 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4878 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4879 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4880 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4881 | if (pf->hw.func_caps.iscsi) |
| 4882 | return i40e_get_iscsi_tc_map(pf); |
| 4883 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4884 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4885 | } |
| 4886 | |
| 4887 | /** |
| 4888 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4889 | * @vsi: the VSI being queried |
| 4890 | * |
| 4891 | * Returns 0 on success, negative value on failure |
| 4892 | **/ |
| 4893 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4894 | { |
| 4895 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4896 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4897 | struct i40e_pf *pf = vsi->back; |
| 4898 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4899 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4900 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4901 | int i; |
| 4902 | |
| 4903 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4904 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4905 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4906 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4907 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4908 | i40e_stat_str(&pf->hw, ret), |
| 4909 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4910 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4914 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4915 | NULL); |
| 4916 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4917 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4918 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4919 | i40e_stat_str(&pf->hw, ret), |
| 4920 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4921 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4925 | dev_info(&pf->pdev->dev, |
| 4926 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4927 | bw_config.tc_valid_bits, |
| 4928 | bw_ets_config.tc_valid_bits); |
| 4929 | /* Still continuing */ |
| 4930 | } |
| 4931 | |
| 4932 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4933 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4934 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4935 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4936 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4937 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4938 | vsi->bw_ets_limit_credits[i] = |
| 4939 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4940 | /* 3 bits out of 4 for each TC */ |
| 4941 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4942 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4943 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4944 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4945 | } |
| 4946 | |
| 4947 | /** |
| 4948 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4949 | * @vsi: the VSI being configured |
| 4950 | * @enabled_tc: TC bitmap |
| 4951 | * @bw_credits: BW shared credits per TC |
| 4952 | * |
| 4953 | * Returns 0 on success, negative value on failure |
| 4954 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4955 | 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] | 4956 | u8 *bw_share) |
| 4957 | { |
| 4958 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4959 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4960 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4961 | |
| 4962 | bw_data.tc_valid_bits = enabled_tc; |
| 4963 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4964 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4965 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4966 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4967 | NULL); |
| 4968 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4969 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4970 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4971 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4972 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4973 | } |
| 4974 | |
| 4975 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4976 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4977 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4978 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | /** |
| 4982 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4983 | * @vsi: the VSI being configured |
| 4984 | * @enabled_tc: TC map to be enabled |
| 4985 | * |
| 4986 | **/ |
| 4987 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4988 | { |
| 4989 | struct net_device *netdev = vsi->netdev; |
| 4990 | struct i40e_pf *pf = vsi->back; |
| 4991 | struct i40e_hw *hw = &pf->hw; |
| 4992 | u8 netdev_tc = 0; |
| 4993 | int i; |
| 4994 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4995 | |
| 4996 | if (!netdev) |
| 4997 | return; |
| 4998 | |
| 4999 | if (!enabled_tc) { |
| 5000 | netdev_reset_tc(netdev); |
| 5001 | return; |
| 5002 | } |
| 5003 | |
| 5004 | /* Set up actual enabled TCs on the VSI */ |
| 5005 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 5006 | return; |
| 5007 | |
| 5008 | /* set per TC queues for the VSI */ |
| 5009 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 5010 | /* Only set TC queues for enabled tcs |
| 5011 | * |
| 5012 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 5013 | * enabled_tc bitmap would be 0x00001001; the driver |
| 5014 | * will set the numtc for netdev as 2 that will be |
| 5015 | * referenced by the netdev layer as TC 0 and 1. |
| 5016 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5017 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5018 | netdev_set_tc_queue(netdev, |
| 5019 | vsi->tc_config.tc_info[i].netdev_tc, |
| 5020 | vsi->tc_config.tc_info[i].qcount, |
| 5021 | vsi->tc_config.tc_info[i].qoffset); |
| 5022 | } |
| 5023 | |
| 5024 | /* Assign UP2TC map for the VSI */ |
| 5025 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 5026 | /* Get the actual TC# for the UP */ |
| 5027 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 5028 | /* Get the mapped netdev TC# for the UP */ |
| 5029 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 5030 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 5031 | } |
| 5032 | } |
| 5033 | |
| 5034 | /** |
| 5035 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 5036 | * @vsi: the VSI being configured |
| 5037 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 5038 | **/ |
| 5039 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 5040 | struct i40e_vsi_context *ctxt) |
| 5041 | { |
| 5042 | /* copy just the sections touched not the entire info |
| 5043 | * since not all sections are valid as returned by |
| 5044 | * update vsi params |
| 5045 | */ |
| 5046 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 5047 | memcpy(&vsi->info.queue_mapping, |
| 5048 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 5049 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 5050 | sizeof(vsi->info.tc_mapping)); |
| 5051 | } |
| 5052 | |
| 5053 | /** |
| 5054 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 5055 | * @vsi: VSI to be configured |
| 5056 | * @enabled_tc: TC bitmap |
| 5057 | * |
| 5058 | * This configures a particular VSI for TCs that are mapped to the |
| 5059 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 5060 | * VSIs to configure TC for a particular VSI. |
| 5061 | * |
| 5062 | * NOTE: |
| 5063 | * It is expected that the VSI queues have been quisced before calling |
| 5064 | * this function. |
| 5065 | **/ |
| 5066 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 5067 | { |
| 5068 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 5069 | struct i40e_vsi_context ctxt; |
| 5070 | int ret = 0; |
| 5071 | int i; |
| 5072 | |
| 5073 | /* Check if enabled_tc is same as existing or new TCs */ |
| 5074 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 5075 | return ret; |
| 5076 | |
| 5077 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 5078 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5079 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5080 | bw_share[i] = 1; |
| 5081 | } |
| 5082 | |
| 5083 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 5084 | if (ret) { |
| 5085 | dev_info(&vsi->back->pdev->dev, |
| 5086 | "Failed configuring TC map %d for VSI %d\n", |
| 5087 | enabled_tc, vsi->seid); |
| 5088 | goto out; |
| 5089 | } |
| 5090 | |
| 5091 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 5092 | ctxt.seid = vsi->seid; |
| 5093 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 5094 | ctxt.vf_num = 0; |
| 5095 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5096 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5097 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 5098 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5099 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 5100 | ctxt.info.valid_sections |= |
| 5101 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 5102 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 5103 | } |
| 5104 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5105 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 5106 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 5107 | if (ret) { |
| 5108 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5109 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 5110 | i40e_stat_str(&vsi->back->hw, ret), |
| 5111 | i40e_aq_str(&vsi->back->hw, |
| 5112 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5113 | goto out; |
| 5114 | } |
| 5115 | /* update the local VSI info with updated queue map */ |
| 5116 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 5117 | vsi->info.valid_sections = 0; |
| 5118 | |
| 5119 | /* Update current VSI BW information */ |
| 5120 | ret = i40e_vsi_get_bw_info(vsi); |
| 5121 | if (ret) { |
| 5122 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5123 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 5124 | i40e_stat_str(&vsi->back->hw, ret), |
| 5125 | i40e_aq_str(&vsi->back->hw, |
| 5126 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5127 | goto out; |
| 5128 | } |
| 5129 | |
| 5130 | /* Update the netdev TC setup */ |
| 5131 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 5132 | out: |
| 5133 | return ret; |
| 5134 | } |
| 5135 | |
| 5136 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5137 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 5138 | * @veb: given VEB |
| 5139 | * @enabled_tc: TC bitmap |
| 5140 | * |
| 5141 | * Configures given TC bitmap for VEB (switching) element |
| 5142 | **/ |
| 5143 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 5144 | { |
| 5145 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 5146 | struct i40e_pf *pf = veb->pf; |
| 5147 | int ret = 0; |
| 5148 | int i; |
| 5149 | |
| 5150 | /* No TCs or already enabled TCs just return */ |
| 5151 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 5152 | return ret; |
| 5153 | |
| 5154 | bw_data.tc_valid_bits = enabled_tc; |
| 5155 | /* bw_data.absolute_credits is not set (relative) */ |
| 5156 | |
| 5157 | /* Enable ETS TCs with equal BW Share for now */ |
| 5158 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5159 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5160 | bw_data.tc_bw_share_credits[i] = 1; |
| 5161 | } |
| 5162 | |
| 5163 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 5164 | &bw_data, NULL); |
| 5165 | if (ret) { |
| 5166 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5167 | "VEB bw config failed, err %s aq_err %s\n", |
| 5168 | i40e_stat_str(&pf->hw, ret), |
| 5169 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5170 | goto out; |
| 5171 | } |
| 5172 | |
| 5173 | /* Update the BW information */ |
| 5174 | ret = i40e_veb_get_bw_info(veb); |
| 5175 | if (ret) { |
| 5176 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5177 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 5178 | i40e_stat_str(&pf->hw, ret), |
| 5179 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5180 | } |
| 5181 | |
| 5182 | out: |
| 5183 | return ret; |
| 5184 | } |
| 5185 | |
| 5186 | #ifdef CONFIG_I40E_DCB |
| 5187 | /** |
| 5188 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 5189 | * @pf: PF struct |
| 5190 | * |
| 5191 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 5192 | * the caller would've quiesce all the VSIs before calling |
| 5193 | * this function |
| 5194 | **/ |
| 5195 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 5196 | { |
| 5197 | u8 tc_map = 0; |
| 5198 | int ret; |
| 5199 | u8 v; |
| 5200 | |
| 5201 | /* Enable the TCs available on PF to all VEBs */ |
| 5202 | tc_map = i40e_pf_get_tc_map(pf); |
| 5203 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 5204 | if (!pf->veb[v]) |
| 5205 | continue; |
| 5206 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 5207 | if (ret) { |
| 5208 | dev_info(&pf->pdev->dev, |
| 5209 | "Failed configuring TC for VEB seid=%d\n", |
| 5210 | pf->veb[v]->seid); |
| 5211 | /* Will try to configure as many components */ |
| 5212 | } |
| 5213 | } |
| 5214 | |
| 5215 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5216 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5217 | if (!pf->vsi[v]) |
| 5218 | continue; |
| 5219 | |
| 5220 | /* - Enable all TCs for the LAN VSI |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5221 | #ifdef I40E_FCOE |
| 5222 | * - For FCoE VSI only enable the TC configured |
| 5223 | * as per the APP TLV |
| 5224 | #endif |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5225 | * - For all others keep them at TC0 for now |
| 5226 | */ |
| 5227 | if (v == pf->lan_vsi) |
| 5228 | tc_map = i40e_pf_get_tc_map(pf); |
| 5229 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5230 | tc_map = I40E_DEFAULT_TRAFFIC_CLASS; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5231 | #ifdef I40E_FCOE |
| 5232 | if (pf->vsi[v]->type == I40E_VSI_FCOE) |
| 5233 | tc_map = i40e_get_fcoe_tc_map(pf); |
| 5234 | #endif /* #ifdef I40E_FCOE */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5235 | |
| 5236 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 5237 | if (ret) { |
| 5238 | dev_info(&pf->pdev->dev, |
| 5239 | "Failed configuring TC for VSI seid=%d\n", |
| 5240 | pf->vsi[v]->seid); |
| 5241 | /* Will try to configure as many components */ |
| 5242 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 5243 | /* Re-configure VSI vectors based on updated TC map */ |
| 5244 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5245 | if (pf->vsi[v]->netdev) |
| 5246 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 5247 | } |
| 5248 | } |
| 5249 | } |
| 5250 | |
| 5251 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5252 | * i40e_resume_port_tx - Resume port Tx |
| 5253 | * @pf: PF struct |
| 5254 | * |
| 5255 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 5256 | * resume. |
| 5257 | **/ |
| 5258 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 5259 | { |
| 5260 | struct i40e_hw *hw = &pf->hw; |
| 5261 | int ret; |
| 5262 | |
| 5263 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 5264 | if (ret) { |
| 5265 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5266 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 5267 | i40e_stat_str(&pf->hw, ret), |
| 5268 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5269 | /* Schedule PF reset to recover */ |
| 5270 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5271 | i40e_service_event_schedule(pf); |
| 5272 | } |
| 5273 | |
| 5274 | return ret; |
| 5275 | } |
| 5276 | |
| 5277 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5278 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 5279 | * @pf: PF being configured |
| 5280 | * |
| 5281 | * Query the current DCB configuration and cache it |
| 5282 | * in the hardware structure |
| 5283 | **/ |
| 5284 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 5285 | { |
| 5286 | struct i40e_hw *hw = &pf->hw; |
| 5287 | int err = 0; |
| 5288 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5289 | /* 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] | 5290 | if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5291 | goto out; |
| 5292 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5293 | /* Get the initial DCB configuration */ |
| 5294 | err = i40e_init_dcb(hw); |
| 5295 | if (!err) { |
| 5296 | /* Device/Function is not DCBX capable */ |
| 5297 | if ((!hw->func_caps.dcb) || |
| 5298 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5299 | dev_info(&pf->pdev->dev, |
| 5300 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 5301 | |
| 5302 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 5303 | goto out; |
| 5304 | |
| 5305 | } else { |
| 5306 | /* When status is not DISABLED then DCBX in FW */ |
| 5307 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5308 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5309 | |
| 5310 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5311 | /* Enable DCB tagging only when more than one TC |
| 5312 | * or explicitly disable if only one TC |
| 5313 | */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5314 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5315 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5316 | else |
| 5317 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5318 | dev_dbg(&pf->pdev->dev, |
| 5319 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5320 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5321 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5322 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5323 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5324 | i40e_stat_str(&pf->hw, err), |
| 5325 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5326 | } |
| 5327 | |
| 5328 | out: |
| 5329 | return err; |
| 5330 | } |
| 5331 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5332 | #define SPEED_SIZE 14 |
| 5333 | #define FC_SIZE 8 |
| 5334 | /** |
| 5335 | * i40e_print_link_message - print link up or down |
| 5336 | * @vsi: the VSI for which link needs a message |
| 5337 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5338 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5339 | { |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 5340 | enum i40e_aq_link_speed new_speed; |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5341 | char *speed = "Unknown"; |
| 5342 | char *fc = "Unknown"; |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5343 | char *fec = ""; |
| 5344 | char *an = ""; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5345 | |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 5346 | new_speed = vsi->back->hw.phy.link_info.link_speed; |
| 5347 | |
| 5348 | if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed)) |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5349 | return; |
| 5350 | vsi->current_isup = isup; |
Filip Sadowski | 7ec9ba1 | 2016-11-08 13:05:13 -0800 | [diff] [blame] | 5351 | vsi->current_speed = new_speed; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5352 | if (!isup) { |
| 5353 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5354 | return; |
| 5355 | } |
| 5356 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5357 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5358 | * least 10GB |
| 5359 | */ |
| 5360 | if (vsi->back->hw.func_caps.npar_enable && |
| 5361 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5362 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5363 | netdev_warn(vsi->netdev, |
| 5364 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5365 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5366 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5367 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5368 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5369 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5370 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5371 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5372 | break; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 5373 | case I40E_LINK_SPEED_25GB: |
| 5374 | speed = "25 G"; |
| 5375 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5376 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5377 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5378 | break; |
| 5379 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5380 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5381 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5382 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5383 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5384 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5385 | default: |
| 5386 | break; |
| 5387 | } |
| 5388 | |
| 5389 | switch (vsi->back->hw.fc.current_mode) { |
| 5390 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5391 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5392 | break; |
| 5393 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5394 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5395 | break; |
| 5396 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5397 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5398 | break; |
| 5399 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5400 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5401 | break; |
| 5402 | } |
| 5403 | |
Henry Tieman | 3e03d7c | 2016-12-02 12:32:57 -0800 | [diff] [blame] | 5404 | if (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) { |
| 5405 | fec = ", FEC: None"; |
| 5406 | an = ", Autoneg: False"; |
| 5407 | |
| 5408 | if (vsi->back->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED) |
| 5409 | an = ", Autoneg: True"; |
| 5410 | |
| 5411 | if (vsi->back->hw.phy.link_info.fec_info & |
| 5412 | I40E_AQ_CONFIG_FEC_KR_ENA) |
| 5413 | fec = ", FEC: CL74 FC-FEC/BASE-R"; |
| 5414 | else if (vsi->back->hw.phy.link_info.fec_info & |
| 5415 | I40E_AQ_CONFIG_FEC_RS_ENA) |
| 5416 | fec = ", FEC: CL108 RS-FEC"; |
| 5417 | } |
| 5418 | |
| 5419 | netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s, Flow Control: %s\n", |
| 5420 | speed, fec, an, fc); |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5421 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5422 | |
| 5423 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5424 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5425 | * @vsi: the VSI being configured |
| 5426 | **/ |
| 5427 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5428 | { |
| 5429 | struct i40e_pf *pf = vsi->back; |
| 5430 | int err; |
| 5431 | |
| 5432 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5433 | i40e_vsi_configure_msix(vsi); |
| 5434 | else |
| 5435 | i40e_configure_msi_and_legacy(vsi); |
| 5436 | |
| 5437 | /* start rings */ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 5438 | err = i40e_vsi_start_rings(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5439 | if (err) |
| 5440 | return err; |
| 5441 | |
| 5442 | clear_bit(__I40E_DOWN, &vsi->state); |
| 5443 | i40e_napi_enable_all(vsi); |
| 5444 | i40e_vsi_enable_irq(vsi); |
| 5445 | |
| 5446 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5447 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5448 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5449 | netif_tx_start_all_queues(vsi->netdev); |
| 5450 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5451 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5452 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5453 | /* need to check for qualified module here*/ |
| 5454 | if ((pf->hw.phy.link_info.link_info & |
| 5455 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5456 | (!(pf->hw.phy.link_info.an_info & |
| 5457 | I40E_AQ_QUALIFIED_MODULE))) |
| 5458 | netdev_err(vsi->netdev, |
| 5459 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5460 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5461 | |
| 5462 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5463 | if (vsi->type == I40E_VSI_FDIR) { |
| 5464 | /* reset fd counters */ |
| 5465 | pf->fd_add_err = pf->fd_atr_cnt = 0; |
| 5466 | if (pf->fd_tcp_rule > 0) { |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 5467 | pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5468 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5469 | dev_info(&pf->pdev->dev, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n"); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5470 | pf->fd_tcp_rule = 0; |
| 5471 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5472 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5473 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5474 | |
| 5475 | /* On the next run of the service_task, notify any clients of the new |
| 5476 | * opened netdev |
| 5477 | */ |
| 5478 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5479 | i40e_service_event_schedule(pf); |
| 5480 | |
| 5481 | return 0; |
| 5482 | } |
| 5483 | |
| 5484 | /** |
| 5485 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5486 | * @vsi: the VSI being configured |
| 5487 | * |
| 5488 | * Rebuild the ring structs after some configuration |
| 5489 | * has changed, e.g. MTU size. |
| 5490 | **/ |
| 5491 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5492 | { |
| 5493 | struct i40e_pf *pf = vsi->back; |
| 5494 | |
| 5495 | WARN_ON(in_interrupt()); |
| 5496 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5497 | usleep_range(1000, 2000); |
| 5498 | i40e_down(vsi); |
| 5499 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5500 | i40e_up(vsi); |
| 5501 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 5502 | } |
| 5503 | |
| 5504 | /** |
| 5505 | * i40e_up - Bring the connection back up after being down |
| 5506 | * @vsi: the VSI being configured |
| 5507 | **/ |
| 5508 | int i40e_up(struct i40e_vsi *vsi) |
| 5509 | { |
| 5510 | int err; |
| 5511 | |
| 5512 | err = i40e_vsi_configure(vsi); |
| 5513 | if (!err) |
| 5514 | err = i40e_up_complete(vsi); |
| 5515 | |
| 5516 | return err; |
| 5517 | } |
| 5518 | |
| 5519 | /** |
| 5520 | * i40e_down - Shutdown the connection processing |
| 5521 | * @vsi: the VSI being stopped |
| 5522 | **/ |
| 5523 | void i40e_down(struct i40e_vsi *vsi) |
| 5524 | { |
| 5525 | int i; |
| 5526 | |
| 5527 | /* It is assumed that the caller of this function |
| 5528 | * sets the vsi->state __I40E_DOWN bit. |
| 5529 | */ |
| 5530 | if (vsi->netdev) { |
| 5531 | netif_carrier_off(vsi->netdev); |
| 5532 | netif_tx_disable(vsi->netdev); |
| 5533 | } |
| 5534 | i40e_vsi_disable_irq(vsi); |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 5535 | i40e_vsi_stop_rings(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5536 | i40e_napi_disable_all(vsi); |
| 5537 | |
| 5538 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5539 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 5540 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5541 | } |
Catherine Sullivan | f980d44 | 2016-05-16 10:26:34 -0700 | [diff] [blame] | 5542 | |
| 5543 | i40e_notify_client_of_netdev_close(vsi, false); |
| 5544 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5545 | } |
| 5546 | |
| 5547 | /** |
| 5548 | * i40e_setup_tc - configure multiple traffic classes |
| 5549 | * @netdev: net device to configure |
| 5550 | * @tc: number of traffic classes to enable |
| 5551 | **/ |
| 5552 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5553 | { |
| 5554 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5555 | struct i40e_vsi *vsi = np->vsi; |
| 5556 | struct i40e_pf *pf = vsi->back; |
| 5557 | u8 enabled_tc = 0; |
| 5558 | int ret = -EINVAL; |
| 5559 | int i; |
| 5560 | |
| 5561 | /* Check if DCB enabled to continue */ |
| 5562 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5563 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5564 | goto exit; |
| 5565 | } |
| 5566 | |
| 5567 | /* Check if MFP enabled */ |
| 5568 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5569 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5570 | goto exit; |
| 5571 | } |
| 5572 | |
| 5573 | /* Check whether tc count is within enabled limit */ |
| 5574 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5575 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5576 | goto exit; |
| 5577 | } |
| 5578 | |
| 5579 | /* Generate TC map for number of tc requested */ |
| 5580 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5581 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5582 | |
| 5583 | /* Requesting same TC configuration as already enabled */ |
| 5584 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5585 | return 0; |
| 5586 | |
| 5587 | /* Quiesce VSI queues */ |
| 5588 | i40e_quiesce_vsi(vsi); |
| 5589 | |
| 5590 | /* Configure VSI for enabled TCs */ |
| 5591 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5592 | if (ret) { |
| 5593 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5594 | vsi->seid); |
| 5595 | goto exit; |
| 5596 | } |
| 5597 | |
| 5598 | /* Unquiesce VSI */ |
| 5599 | i40e_unquiesce_vsi(vsi); |
| 5600 | |
| 5601 | exit: |
| 5602 | return ret; |
| 5603 | } |
| 5604 | |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5605 | #ifdef I40E_FCOE |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5606 | int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5607 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5608 | #else |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5609 | static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5610 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5611 | #endif |
| 5612 | { |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5613 | if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5614 | return -EINVAL; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5615 | return i40e_setup_tc(netdev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5616 | } |
| 5617 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5618 | /** |
| 5619 | * i40e_open - Called when a network interface is made active |
| 5620 | * @netdev: network interface device structure |
| 5621 | * |
| 5622 | * The open entry point is called when a network interface is made |
| 5623 | * active by the system (IFF_UP). At this point all resources needed |
| 5624 | * for transmit and receive operations are allocated, the interrupt |
| 5625 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5626 | * enabled, and the stack is notified that the interface is ready. |
| 5627 | * |
| 5628 | * Returns 0 on success, negative value on failure |
| 5629 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5630 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5631 | { |
| 5632 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5633 | struct i40e_vsi *vsi = np->vsi; |
| 5634 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5635 | int err; |
| 5636 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5637 | /* disallow open during test or if eeprom is broken */ |
| 5638 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 5639 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5640 | return -EBUSY; |
| 5641 | |
| 5642 | netif_carrier_off(netdev); |
| 5643 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5644 | err = i40e_vsi_open(vsi); |
| 5645 | if (err) |
| 5646 | return err; |
| 5647 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5648 | /* configure global TSO hardware offload settings */ |
| 5649 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5650 | TCP_FLAG_FIN) >> 16); |
| 5651 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5652 | TCP_FLAG_FIN | |
| 5653 | TCP_FLAG_CWR) >> 16); |
| 5654 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5655 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 5656 | udp_tunnel_get_rx_info(netdev); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5657 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5658 | return 0; |
| 5659 | } |
| 5660 | |
| 5661 | /** |
| 5662 | * i40e_vsi_open - |
| 5663 | * @vsi: the VSI to open |
| 5664 | * |
| 5665 | * Finish initialization of the VSI. |
| 5666 | * |
| 5667 | * Returns 0 on success, negative value on failure |
| 5668 | **/ |
| 5669 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5670 | { |
| 5671 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5672 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5673 | int err; |
| 5674 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5675 | /* allocate descriptors */ |
| 5676 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5677 | if (err) |
| 5678 | goto err_setup_tx; |
| 5679 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5680 | if (err) |
| 5681 | goto err_setup_rx; |
| 5682 | |
| 5683 | err = i40e_vsi_configure(vsi); |
| 5684 | if (err) |
| 5685 | goto err_setup_rx; |
| 5686 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5687 | if (vsi->netdev) { |
| 5688 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5689 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5690 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5691 | if (err) |
| 5692 | goto err_setup_rx; |
| 5693 | |
| 5694 | /* Notify the stack of the actual queue counts. */ |
| 5695 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5696 | vsi->num_queue_pairs); |
| 5697 | if (err) |
| 5698 | goto err_set_queues; |
| 5699 | |
| 5700 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5701 | vsi->num_queue_pairs); |
| 5702 | if (err) |
| 5703 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5704 | |
| 5705 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5706 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5707 | dev_driver_string(&pf->pdev->dev), |
| 5708 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5709 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5710 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5711 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5712 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5713 | goto err_setup_rx; |
| 5714 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5715 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5716 | err = i40e_up_complete(vsi); |
| 5717 | if (err) |
| 5718 | goto err_up_complete; |
| 5719 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5720 | return 0; |
| 5721 | |
| 5722 | err_up_complete: |
| 5723 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5724 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5725 | i40e_vsi_free_irq(vsi); |
| 5726 | err_setup_rx: |
| 5727 | i40e_vsi_free_rx_resources(vsi); |
| 5728 | err_setup_tx: |
| 5729 | i40e_vsi_free_tx_resources(vsi); |
| 5730 | if (vsi == pf->vsi[pf->lan_vsi]) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5731 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5732 | |
| 5733 | return err; |
| 5734 | } |
| 5735 | |
| 5736 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5737 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5738 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5739 | * |
| 5740 | * This function destroys the hlist where all the Flow Director |
| 5741 | * filters were saved. |
| 5742 | **/ |
| 5743 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5744 | { |
| 5745 | struct i40e_fdir_filter *filter; |
| 5746 | struct hlist_node *node2; |
| 5747 | |
| 5748 | hlist_for_each_entry_safe(filter, node2, |
| 5749 | &pf->fdir_filter_list, fdir_node) { |
| 5750 | hlist_del(&filter->fdir_node); |
| 5751 | kfree(filter); |
| 5752 | } |
| 5753 | pf->fdir_pf_active_filters = 0; |
| 5754 | } |
| 5755 | |
| 5756 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5757 | * i40e_close - Disables a network interface |
| 5758 | * @netdev: network interface device structure |
| 5759 | * |
| 5760 | * The close entry point is called when an interface is de-activated |
| 5761 | * by the OS. The hardware is still under the driver's control, but |
| 5762 | * this netdev interface is disabled. |
| 5763 | * |
| 5764 | * Returns 0, this is not allowed to fail |
| 5765 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5766 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5767 | { |
| 5768 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5769 | struct i40e_vsi *vsi = np->vsi; |
| 5770 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5771 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5772 | |
| 5773 | return 0; |
| 5774 | } |
| 5775 | |
| 5776 | /** |
| 5777 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5778 | * @pf: board private structure |
| 5779 | * @reset_flags: which reset is requested |
| 5780 | * |
| 5781 | * The essential difference in resets is that the PF Reset |
| 5782 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5783 | * firmware, and doesn't bother the other PFs on the chip. |
| 5784 | **/ |
| 5785 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5786 | { |
| 5787 | u32 val; |
| 5788 | |
| 5789 | WARN_ON(in_interrupt()); |
| 5790 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5791 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5792 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5793 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5794 | |
| 5795 | /* Request a Global Reset |
| 5796 | * |
| 5797 | * This will start the chip's countdown to the actual full |
| 5798 | * chip reset event, and a warning interrupt to be sent |
| 5799 | * to all PFs, including the requestor. Our handler |
| 5800 | * for the warning interrupt will deal with the shutdown |
| 5801 | * and recovery of the switch setup. |
| 5802 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5803 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5804 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5805 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5806 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5807 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5808 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5809 | |
| 5810 | /* Request a Core Reset |
| 5811 | * |
| 5812 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5813 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5814 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5815 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5816 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5817 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5818 | i40e_flush(&pf->hw); |
| 5819 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5820 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5821 | |
| 5822 | /* Request a PF Reset |
| 5823 | * |
| 5824 | * Resets only the PF-specific registers |
| 5825 | * |
| 5826 | * This goes directly to the tear-down and rebuild of |
| 5827 | * the switch, since we need to do all the recovery as |
| 5828 | * for the Core Reset. |
| 5829 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5830 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5831 | i40e_handle_reset_warning(pf); |
| 5832 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5833 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5834 | int v; |
| 5835 | |
| 5836 | /* Find the VSI(s) that requested a re-init */ |
| 5837 | dev_info(&pf->pdev->dev, |
| 5838 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5839 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5840 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5841 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5842 | if (vsi != NULL && |
| 5843 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5844 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5845 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5846 | } |
| 5847 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5848 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5849 | int v; |
| 5850 | |
| 5851 | /* Find the VSI(s) that needs to be brought down */ |
| 5852 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5853 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5854 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5855 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5856 | if (vsi != NULL && |
| 5857 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5858 | set_bit(__I40E_DOWN, &vsi->state); |
| 5859 | i40e_down(vsi); |
| 5860 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5861 | } |
| 5862 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5863 | } else { |
| 5864 | dev_info(&pf->pdev->dev, |
| 5865 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5866 | } |
| 5867 | } |
| 5868 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5869 | #ifdef CONFIG_I40E_DCB |
| 5870 | /** |
| 5871 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5872 | * @pf: board private structure |
| 5873 | * @old_cfg: current DCB config |
| 5874 | * @new_cfg: new DCB config |
| 5875 | **/ |
| 5876 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5877 | struct i40e_dcbx_config *old_cfg, |
| 5878 | struct i40e_dcbx_config *new_cfg) |
| 5879 | { |
| 5880 | bool need_reconfig = false; |
| 5881 | |
| 5882 | /* Check if ETS configuration has changed */ |
| 5883 | if (memcmp(&new_cfg->etscfg, |
| 5884 | &old_cfg->etscfg, |
| 5885 | sizeof(new_cfg->etscfg))) { |
| 5886 | /* If Priority Table has changed reconfig is needed */ |
| 5887 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5888 | &old_cfg->etscfg.prioritytable, |
| 5889 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5890 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5891 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5895 | &old_cfg->etscfg.tcbwtable, |
| 5896 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5897 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5898 | |
| 5899 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5900 | &old_cfg->etscfg.tsatable, |
| 5901 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5902 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | /* Check if PFC configuration has changed */ |
| 5906 | if (memcmp(&new_cfg->pfc, |
| 5907 | &old_cfg->pfc, |
| 5908 | sizeof(new_cfg->pfc))) { |
| 5909 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5910 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5911 | } |
| 5912 | |
| 5913 | /* Check if APP Table has changed */ |
| 5914 | if (memcmp(&new_cfg->app, |
| 5915 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5916 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5917 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5918 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5919 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5920 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5921 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5922 | return need_reconfig; |
| 5923 | } |
| 5924 | |
| 5925 | /** |
| 5926 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5927 | * @pf: board private structure |
| 5928 | * @e: event info posted on ARQ |
| 5929 | **/ |
| 5930 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5931 | struct i40e_arq_event_info *e) |
| 5932 | { |
| 5933 | struct i40e_aqc_lldp_get_mib *mib = |
| 5934 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5935 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5936 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5937 | bool need_reconfig = false; |
| 5938 | int ret = 0; |
| 5939 | u8 type; |
| 5940 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5941 | /* Not DCB capable or capability disabled */ |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5942 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5943 | return ret; |
| 5944 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5945 | /* Ignore if event is not for Nearest Bridge */ |
| 5946 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5947 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5948 | 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] | 5949 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5950 | return ret; |
| 5951 | |
| 5952 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5953 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5954 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5955 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5956 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5957 | /* Update the remote cached instance and return */ |
| 5958 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5959 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5960 | &hw->remote_dcbx_config); |
| 5961 | goto exit; |
| 5962 | } |
| 5963 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5964 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5965 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5966 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5967 | /* Reset the old DCBx configuration data */ |
| 5968 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5969 | /* Get updated DCBX data from firmware */ |
| 5970 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5971 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5972 | dev_info(&pf->pdev->dev, |
| 5973 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 5974 | i40e_stat_str(&pf->hw, ret), |
| 5975 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5976 | goto exit; |
| 5977 | } |
| 5978 | |
| 5979 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5980 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5981 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5982 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5983 | goto exit; |
| 5984 | } |
| 5985 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5986 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5987 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5988 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5989 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5990 | |
| 5991 | if (!need_reconfig) |
| 5992 | goto exit; |
| 5993 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5994 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5995 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5996 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5997 | else |
| 5998 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5999 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 6000 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6001 | /* Reconfiguration needed quiesce all VSIs */ |
| 6002 | i40e_pf_quiesce_all_vsi(pf); |
| 6003 | |
| 6004 | /* Changes in configuration update VEB/VSI */ |
| 6005 | i40e_dcb_reconfigure(pf); |
| 6006 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 6007 | ret = i40e_resume_port_tx(pf); |
| 6008 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 6009 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 6010 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 6011 | if (ret) |
| 6012 | goto exit; |
| 6013 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 6014 | /* Wait for the PF's queues to be disabled */ |
| 6015 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 6016 | if (ret) { |
| 6017 | /* Schedule PF reset to recover */ |
| 6018 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6019 | i40e_service_event_schedule(pf); |
| 6020 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 6021 | i40e_pf_unquiesce_all_vsi(pf); |
Neerav Parikh | 85a1aab | 2016-06-07 09:14:55 -0700 | [diff] [blame] | 6022 | /* Notify the client for the DCB changes */ |
| 6023 | i40e_notify_client_of_l2_param_changes(pf->vsi[pf->lan_vsi]); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 6024 | } |
| 6025 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6026 | exit: |
| 6027 | return ret; |
| 6028 | } |
| 6029 | #endif /* CONFIG_I40E_DCB */ |
| 6030 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6031 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6032 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 6033 | * @pf: board private structure |
| 6034 | * @reset_flags: which reset is requested |
| 6035 | * |
| 6036 | **/ |
| 6037 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 6038 | { |
| 6039 | rtnl_lock(); |
| 6040 | i40e_do_reset(pf, reset_flags); |
| 6041 | rtnl_unlock(); |
| 6042 | } |
| 6043 | |
| 6044 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6045 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 6046 | * @pf: board private structure |
| 6047 | * @e: event info posted on ARQ |
| 6048 | * |
| 6049 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 6050 | * and VF queues |
| 6051 | **/ |
| 6052 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 6053 | struct i40e_arq_event_info *e) |
| 6054 | { |
| 6055 | struct i40e_aqc_lan_overflow *data = |
| 6056 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 6057 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 6058 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 6059 | struct i40e_hw *hw = &pf->hw; |
| 6060 | struct i40e_vf *vf; |
| 6061 | u16 vf_id; |
| 6062 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6063 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 6064 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6065 | |
| 6066 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 6067 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 6068 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 6069 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 6070 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 6071 | vf_id -= hw->func_caps.vf_base_id; |
| 6072 | vf = &pf->vf[vf_id]; |
| 6073 | i40e_vc_notify_vf_reset(vf); |
| 6074 | /* Allow VF to process pending reset notification */ |
| 6075 | msleep(20); |
| 6076 | i40e_reset_vf(vf, false); |
| 6077 | } |
| 6078 | } |
| 6079 | |
| 6080 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6081 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 6082 | * @pf: board private structure |
| 6083 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6084 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6085 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6086 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6087 | |
| 6088 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 6089 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 6090 | return fcnt_prog; |
| 6091 | } |
| 6092 | |
| 6093 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6094 | * 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] | 6095 | * @pf: board private structure |
| 6096 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6097 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6098 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6099 | u32 val, fcnt_prog; |
| 6100 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6101 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 6102 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 6103 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 6104 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 6105 | return fcnt_prog; |
| 6106 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6107 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6108 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6109 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 6110 | * @pf: board private structure |
| 6111 | **/ |
| 6112 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 6113 | { |
| 6114 | u32 val, fcnt_prog; |
| 6115 | |
| 6116 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 6117 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 6118 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 6119 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 6120 | return fcnt_prog; |
| 6121 | } |
| 6122 | |
| 6123 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6124 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 6125 | * @pf: board private structure |
| 6126 | **/ |
| 6127 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 6128 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6129 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6130 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6131 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6132 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6133 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 6134 | return; |
| 6135 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6136 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 6137 | * to re-enable |
| 6138 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6139 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6140 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6141 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 6142 | (pf->fd_add_err == 0) || |
| 6143 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6144 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 6145 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 6146 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 6147 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6148 | 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] | 6149 | } |
| 6150 | } |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6151 | |
| 6152 | /* Wait for some more space to be available to turn on ATR. We also |
| 6153 | * must check that no existing ntuple rules for TCP are in effect |
| 6154 | */ |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6155 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 6156 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6157 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 6158 | (pf->fd_tcp_rule == 0)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6159 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 6160 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6161 | 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] | 6162 | } |
| 6163 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6164 | |
| 6165 | /* if hw had a problem adding a filter, delete it */ |
| 6166 | if (pf->fd_inv > 0) { |
| 6167 | hlist_for_each_entry_safe(filter, node, |
| 6168 | &pf->fdir_filter_list, fdir_node) { |
| 6169 | if (filter->fd_id == pf->fd_inv) { |
| 6170 | hlist_del(&filter->fdir_node); |
| 6171 | kfree(filter); |
| 6172 | pf->fdir_pf_active_filters--; |
| 6173 | } |
| 6174 | } |
| 6175 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6176 | } |
| 6177 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6178 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6179 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6180 | /** |
| 6181 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 6182 | * @pf: board private structure |
| 6183 | **/ |
| 6184 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 6185 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6186 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6187 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6188 | bool disable_atr = false; |
| 6189 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6190 | int reg; |
| 6191 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6192 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 6193 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 6194 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6195 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6196 | /* If the flush is happening too quick and we have mostly SB rules we |
| 6197 | * should not re-enable ATR for some time. |
| 6198 | */ |
| 6199 | min_flush_time = pf->fd_flush_timestamp + |
| 6200 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 6201 | 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] | 6202 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6203 | if (!(time_after(jiffies, min_flush_time)) && |
| 6204 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 6205 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6206 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 6207 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6208 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6209 | |
| 6210 | pf->fd_flush_timestamp = jiffies; |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 6211 | pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6212 | /* flush all filters */ |
| 6213 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 6214 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 6215 | i40e_flush(&pf->hw); |
| 6216 | pf->fd_flush_cnt++; |
| 6217 | pf->fd_add_err = 0; |
| 6218 | do { |
| 6219 | /* Check FD flush status every 5-6msec */ |
| 6220 | usleep_range(5000, 6000); |
| 6221 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 6222 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 6223 | break; |
| 6224 | } while (flush_wait_retry--); |
| 6225 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 6226 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 6227 | } else { |
| 6228 | /* replay sideband filters */ |
| 6229 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
| 6230 | if (!disable_atr) |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 6231 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6232 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
| 6233 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6234 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 6235 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6236 | } |
| 6237 | |
| 6238 | /** |
| 6239 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 6240 | * @pf: board private structure |
| 6241 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6242 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6243 | { |
| 6244 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 6245 | } |
| 6246 | |
| 6247 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 6248 | * being applied really fast; before we see the first |
| 6249 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 6250 | * reacting will make sure we don't cause flush too often. |
| 6251 | */ |
| 6252 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 6253 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6254 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6255 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 6256 | * @pf: board private structure |
| 6257 | **/ |
| 6258 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 6259 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6260 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6261 | /* if interface is down do nothing */ |
| 6262 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 6263 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6264 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6265 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6266 | i40e_fdir_flush_and_replay(pf); |
| 6267 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6268 | i40e_fdir_check_and_reenable(pf); |
| 6269 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6270 | } |
| 6271 | |
| 6272 | /** |
| 6273 | * i40e_vsi_link_event - notify VSI of a link event |
| 6274 | * @vsi: vsi to be notified |
| 6275 | * @link_up: link up or down |
| 6276 | **/ |
| 6277 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 6278 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 6279 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6280 | return; |
| 6281 | |
| 6282 | switch (vsi->type) { |
| 6283 | case I40E_VSI_MAIN: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6284 | #ifdef I40E_FCOE |
| 6285 | case I40E_VSI_FCOE: |
| 6286 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6287 | if (!vsi->netdev || !vsi->netdev_registered) |
| 6288 | break; |
| 6289 | |
| 6290 | if (link_up) { |
| 6291 | netif_carrier_on(vsi->netdev); |
| 6292 | netif_tx_wake_all_queues(vsi->netdev); |
| 6293 | } else { |
| 6294 | netif_carrier_off(vsi->netdev); |
| 6295 | netif_tx_stop_all_queues(vsi->netdev); |
| 6296 | } |
| 6297 | break; |
| 6298 | |
| 6299 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6300 | case I40E_VSI_VMDQ2: |
| 6301 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6302 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6303 | case I40E_VSI_MIRROR: |
| 6304 | default: |
| 6305 | /* there is no notification for other VSIs */ |
| 6306 | break; |
| 6307 | } |
| 6308 | } |
| 6309 | |
| 6310 | /** |
| 6311 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6312 | * @veb: veb to be notified |
| 6313 | * @link_up: link up or down |
| 6314 | **/ |
| 6315 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6316 | { |
| 6317 | struct i40e_pf *pf; |
| 6318 | int i; |
| 6319 | |
| 6320 | if (!veb || !veb->pf) |
| 6321 | return; |
| 6322 | pf = veb->pf; |
| 6323 | |
| 6324 | /* depth first... */ |
| 6325 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6326 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6327 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6328 | |
| 6329 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6330 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6331 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6332 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6333 | } |
| 6334 | |
| 6335 | /** |
| 6336 | * i40e_link_event - Update netif_carrier status |
| 6337 | * @pf: board private structure |
| 6338 | **/ |
| 6339 | static void i40e_link_event(struct i40e_pf *pf) |
| 6340 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6341 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6342 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6343 | i40e_status status; |
| 6344 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6345 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6346 | /* save off old link status information */ |
| 6347 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6348 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6349 | /* set this to force the get_link_status call to refresh state */ |
| 6350 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6351 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6352 | 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] | 6353 | |
| 6354 | status = i40e_get_link_status(&pf->hw, &new_link); |
| 6355 | if (status) { |
| 6356 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6357 | status); |
| 6358 | return; |
| 6359 | } |
| 6360 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6361 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6362 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6363 | |
| 6364 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6365 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6366 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 6367 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6368 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6369 | |
| 6370 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 6371 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6372 | |
| 6373 | /* Notify the base of the switch tree connected to |
| 6374 | * the link. Floating VEBs are not notified. |
| 6375 | */ |
| 6376 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6377 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6378 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6379 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6380 | |
| 6381 | if (pf->vf) |
| 6382 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6383 | |
| 6384 | if (pf->flags & I40E_FLAG_PTP) |
| 6385 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6386 | } |
| 6387 | |
| 6388 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6389 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6390 | * @pf: board private structure |
| 6391 | **/ |
| 6392 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6393 | { |
| 6394 | int i; |
| 6395 | |
| 6396 | /* if interface is down do nothing */ |
| 6397 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 6398 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6399 | return; |
| 6400 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6401 | /* make sure we don't do these things too often */ |
| 6402 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6403 | pf->service_timer_period))) |
| 6404 | return; |
| 6405 | pf->service_timer_previous = jiffies; |
| 6406 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6407 | if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) |
| 6408 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6409 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6410 | /* Update the stats for active netdevs so the network stack |
| 6411 | * can look at updated numbers whenever it cares to |
| 6412 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6413 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6414 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6415 | i40e_update_stats(pf->vsi[i]); |
| 6416 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6417 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6418 | /* Update the stats for the active switching components */ |
| 6419 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6420 | if (pf->veb[i]) |
| 6421 | i40e_update_veb_stats(pf->veb[i]); |
| 6422 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6423 | |
| 6424 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6425 | } |
| 6426 | |
| 6427 | /** |
| 6428 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6429 | * @pf: board private structure |
| 6430 | **/ |
| 6431 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6432 | { |
| 6433 | u32 reset_flags = 0; |
| 6434 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6435 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6436 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6437 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6438 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 6439 | } |
| 6440 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6441 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6442 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6443 | } |
| 6444 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6445 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6446 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 6447 | } |
| 6448 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6449 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6450 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 6451 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6452 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6453 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6454 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 6455 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6456 | |
| 6457 | /* If there's a recovery already waiting, it takes |
| 6458 | * precedence before starting a new reset sequence. |
| 6459 | */ |
| 6460 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 6461 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6462 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6463 | } |
| 6464 | |
| 6465 | /* If we're already down or resetting, just bail */ |
| 6466 | if (reset_flags && |
| 6467 | !test_bit(__I40E_DOWN, &pf->state) && |
| 6468 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6469 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6470 | |
| 6471 | unlock: |
| 6472 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6473 | } |
| 6474 | |
| 6475 | /** |
| 6476 | * i40e_handle_link_event - Handle link event |
| 6477 | * @pf: board private structure |
| 6478 | * @e: event info posted on ARQ |
| 6479 | **/ |
| 6480 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6481 | struct i40e_arq_event_info *e) |
| 6482 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6483 | struct i40e_aqc_get_link_status *status = |
| 6484 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6485 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6486 | /* Do a new status request to re-enable LSE reporting |
| 6487 | * and load new status information into the hw struct |
| 6488 | * This completely ignores any state information |
| 6489 | * in the ARQ event info, instead choosing to always |
| 6490 | * issue the AQ update link status command. |
| 6491 | */ |
| 6492 | i40e_link_event(pf); |
| 6493 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6494 | /* check for unqualified module, if link is down */ |
| 6495 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6496 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6497 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6498 | dev_err(&pf->pdev->dev, |
| 6499 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | /** |
| 6503 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6504 | * @pf: board private structure |
| 6505 | **/ |
| 6506 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6507 | { |
| 6508 | struct i40e_arq_event_info event; |
| 6509 | struct i40e_hw *hw = &pf->hw; |
| 6510 | u16 pending, i = 0; |
| 6511 | i40e_status ret; |
| 6512 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6513 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6514 | u32 val; |
| 6515 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6516 | /* Do not run clean AQ when PF reset fails */ |
| 6517 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 6518 | return; |
| 6519 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6520 | /* check for error indications */ |
| 6521 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6522 | oldval = val; |
| 6523 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6524 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6525 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6526 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6527 | } |
| 6528 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6529 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6530 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6531 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6532 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6533 | } |
| 6534 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6535 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6536 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6537 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6538 | } |
| 6539 | if (oldval != val) |
| 6540 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6541 | |
| 6542 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6543 | oldval = val; |
| 6544 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6545 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6546 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6547 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6548 | } |
| 6549 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6550 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6551 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6552 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6553 | } |
| 6554 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6555 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6556 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6557 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6558 | } |
| 6559 | if (oldval != val) |
| 6560 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6561 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6562 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6563 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6564 | if (!event.msg_buf) |
| 6565 | return; |
| 6566 | |
| 6567 | do { |
| 6568 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6569 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6570 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6571 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6572 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6573 | break; |
| 6574 | } |
| 6575 | |
| 6576 | opcode = le16_to_cpu(event.desc.opcode); |
| 6577 | switch (opcode) { |
| 6578 | |
| 6579 | case i40e_aqc_opc_get_link_status: |
| 6580 | i40e_handle_link_event(pf, &event); |
| 6581 | break; |
| 6582 | case i40e_aqc_opc_send_msg_to_pf: |
| 6583 | ret = i40e_vc_process_vf_msg(pf, |
| 6584 | le16_to_cpu(event.desc.retval), |
| 6585 | le32_to_cpu(event.desc.cookie_high), |
| 6586 | le32_to_cpu(event.desc.cookie_low), |
| 6587 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6588 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6589 | break; |
| 6590 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6591 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6592 | #ifdef CONFIG_I40E_DCB |
| 6593 | rtnl_lock(); |
| 6594 | ret = i40e_handle_lldp_event(pf, &event); |
| 6595 | rtnl_unlock(); |
| 6596 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6597 | break; |
| 6598 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6599 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6600 | i40e_handle_lan_overflow_event(pf, &event); |
| 6601 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6602 | case i40e_aqc_opc_send_msg_to_peer: |
| 6603 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6604 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6605 | case i40e_aqc_opc_nvm_erase: |
| 6606 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6607 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 6608 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 6609 | "ARQ NVM operation 0x%04x completed\n", |
| 6610 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6611 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6612 | default: |
| 6613 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 6614 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6615 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6616 | break; |
| 6617 | } |
| 6618 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 6619 | |
| 6620 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 6621 | /* re-enable Admin queue interrupt cause */ |
| 6622 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6623 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6624 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6625 | i40e_flush(hw); |
| 6626 | |
| 6627 | kfree(event.msg_buf); |
| 6628 | } |
| 6629 | |
| 6630 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6631 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6632 | * @pf: board private structure |
| 6633 | **/ |
| 6634 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6635 | { |
| 6636 | int err; |
| 6637 | |
| 6638 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6639 | if (err) { |
| 6640 | /* retry in case of garbage read */ |
| 6641 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6642 | if (err) { |
| 6643 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6644 | err); |
| 6645 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6646 | } |
| 6647 | } |
| 6648 | |
| 6649 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 6650 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 6651 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6652 | } |
| 6653 | } |
| 6654 | |
| 6655 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6656 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6657 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6658 | * |
| 6659 | * enable switch loop back or die - no point in a return value |
| 6660 | **/ |
| 6661 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6662 | { |
| 6663 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6664 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6665 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6666 | |
| 6667 | ctxt.seid = pf->main_vsi_seid; |
| 6668 | ctxt.pf_num = pf->hw.pf_id; |
| 6669 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6670 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6671 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6672 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6673 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6674 | i40e_stat_str(&pf->hw, ret), |
| 6675 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6676 | return; |
| 6677 | } |
| 6678 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6679 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6680 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6681 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6682 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6683 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6684 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6685 | "update vsi switch failed, err %s aq_err %s\n", |
| 6686 | i40e_stat_str(&pf->hw, ret), |
| 6687 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6688 | } |
| 6689 | } |
| 6690 | |
| 6691 | /** |
| 6692 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6693 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6694 | * |
| 6695 | * disable switch loop back or die - no point in a return value |
| 6696 | **/ |
| 6697 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6698 | { |
| 6699 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6700 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6701 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6702 | |
| 6703 | ctxt.seid = pf->main_vsi_seid; |
| 6704 | ctxt.pf_num = pf->hw.pf_id; |
| 6705 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6706 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6707 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6708 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6709 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6710 | i40e_stat_str(&pf->hw, ret), |
| 6711 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6712 | return; |
| 6713 | } |
| 6714 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6715 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6716 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6717 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6718 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6719 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6720 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6721 | "update vsi switch failed, err %s aq_err %s\n", |
| 6722 | i40e_stat_str(&pf->hw, ret), |
| 6723 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6724 | } |
| 6725 | } |
| 6726 | |
| 6727 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6728 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6729 | * @veb: pointer to the bridge instance |
| 6730 | * |
| 6731 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6732 | * specified HW bridge instance. It is expected this function is called |
| 6733 | * when a new HW bridge is instantiated. |
| 6734 | **/ |
| 6735 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6736 | { |
| 6737 | struct i40e_pf *pf = veb->pf; |
| 6738 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6739 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6740 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6741 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6742 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6743 | i40e_disable_pf_switch_lb(pf); |
| 6744 | else |
| 6745 | i40e_enable_pf_switch_lb(pf); |
| 6746 | } |
| 6747 | |
| 6748 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6749 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6750 | * @veb: pointer to the VEB instance |
| 6751 | * |
| 6752 | * This is a recursive function that first builds the attached VSIs then |
| 6753 | * recurses in to build the next layer of VEB. We track the connections |
| 6754 | * through our own index numbers because the seid's from the HW could |
| 6755 | * change across the reset. |
| 6756 | **/ |
| 6757 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6758 | { |
| 6759 | struct i40e_vsi *ctl_vsi = NULL; |
| 6760 | struct i40e_pf *pf = veb->pf; |
| 6761 | int v, veb_idx; |
| 6762 | int ret; |
| 6763 | |
| 6764 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6765 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6766 | if (pf->vsi[v] && |
| 6767 | pf->vsi[v]->veb_idx == veb->idx && |
| 6768 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6769 | ctl_vsi = pf->vsi[v]; |
| 6770 | break; |
| 6771 | } |
| 6772 | } |
| 6773 | if (!ctl_vsi) { |
| 6774 | dev_info(&pf->pdev->dev, |
| 6775 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6776 | ret = -ENOENT; |
| 6777 | goto end_reconstitute; |
| 6778 | } |
| 6779 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6780 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6781 | ret = i40e_add_vsi(ctl_vsi); |
| 6782 | if (ret) { |
| 6783 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6784 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6785 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6786 | goto end_reconstitute; |
| 6787 | } |
| 6788 | i40e_vsi_reset_stats(ctl_vsi); |
| 6789 | |
| 6790 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6791 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6792 | if (ret) |
| 6793 | goto end_reconstitute; |
| 6794 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6795 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6796 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6797 | else |
| 6798 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6799 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6800 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6801 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6802 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6803 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6804 | continue; |
| 6805 | |
| 6806 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6807 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6808 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6809 | vsi->uplink_seid = veb->seid; |
| 6810 | ret = i40e_add_vsi(vsi); |
| 6811 | if (ret) { |
| 6812 | dev_info(&pf->pdev->dev, |
| 6813 | "rebuild of vsi_idx %d failed: %d\n", |
| 6814 | v, ret); |
| 6815 | goto end_reconstitute; |
| 6816 | } |
| 6817 | i40e_vsi_reset_stats(vsi); |
| 6818 | } |
| 6819 | } |
| 6820 | |
| 6821 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6822 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6823 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6824 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6825 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6826 | if (ret) |
| 6827 | break; |
| 6828 | } |
| 6829 | } |
| 6830 | |
| 6831 | end_reconstitute: |
| 6832 | return ret; |
| 6833 | } |
| 6834 | |
| 6835 | /** |
| 6836 | * i40e_get_capabilities - get info about the HW |
| 6837 | * @pf: the PF struct |
| 6838 | **/ |
| 6839 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6840 | { |
| 6841 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6842 | u16 data_size; |
| 6843 | int buf_len; |
| 6844 | int err; |
| 6845 | |
| 6846 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6847 | do { |
| 6848 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6849 | if (!cap_buf) |
| 6850 | return -ENOMEM; |
| 6851 | |
| 6852 | /* this loads the data into the hw struct for us */ |
| 6853 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6854 | &data_size, |
| 6855 | i40e_aqc_opc_list_func_capabilities, |
| 6856 | NULL); |
| 6857 | /* data loaded, buffer no longer needed */ |
| 6858 | kfree(cap_buf); |
| 6859 | |
| 6860 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6861 | /* retry with a larger buffer */ |
| 6862 | buf_len = data_size; |
| 6863 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6864 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6865 | "capability discovery failed, err %s aq_err %s\n", |
| 6866 | i40e_stat_str(&pf->hw, err), |
| 6867 | i40e_aq_str(&pf->hw, |
| 6868 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6869 | return -ENODEV; |
| 6870 | } |
| 6871 | } while (err); |
| 6872 | |
| 6873 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6874 | dev_info(&pf->pdev->dev, |
| 6875 | "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", |
| 6876 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6877 | pf->hw.func_caps.num_msix_vectors, |
| 6878 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6879 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6880 | pf->hw.func_caps.fd_filters_best_effort, |
| 6881 | pf->hw.func_caps.num_tx_qp, |
| 6882 | pf->hw.func_caps.num_vsis); |
| 6883 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6884 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6885 | + pf->hw.func_caps.num_vfs) |
| 6886 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6887 | dev_info(&pf->pdev->dev, |
| 6888 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6889 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6890 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6891 | } |
| 6892 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6893 | return 0; |
| 6894 | } |
| 6895 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6896 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6897 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6898 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6899 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6900 | * @pf: board private structure |
| 6901 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6902 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6903 | { |
| 6904 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6905 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6906 | /* quick workaround for an NVM issue that leaves a critical register |
| 6907 | * uninitialized |
| 6908 | */ |
| 6909 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6910 | static const u32 hkey[] = { |
| 6911 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6912 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6913 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6914 | 0x95b3a76d}; |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6915 | int i; |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6916 | |
| 6917 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6918 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6919 | } |
| 6920 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6921 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6922 | return; |
| 6923 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6924 | /* find existing VSI and see if it needs configuring */ |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6925 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6926 | |
| 6927 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6928 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6929 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6930 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6931 | if (!vsi) { |
| 6932 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6933 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6934 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6935 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6936 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6937 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6938 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6939 | } |
| 6940 | |
| 6941 | /** |
| 6942 | * i40e_fdir_teardown - release the Flow Director resources |
| 6943 | * @pf: board private structure |
| 6944 | **/ |
| 6945 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6946 | { |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6947 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6948 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6949 | i40e_fdir_filter_exit(pf); |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6950 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
| 6951 | if (vsi) |
| 6952 | i40e_vsi_release(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6953 | } |
| 6954 | |
| 6955 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6956 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6957 | * @pf: board private structure |
| 6958 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6959 | * 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] | 6960 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6961 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6962 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6963 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6964 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6965 | u32 v; |
| 6966 | |
| 6967 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6968 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6969 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 6970 | if (i40e_check_asq_alive(&pf->hw)) |
| 6971 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6972 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6973 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6974 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6975 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6976 | i40e_pf_quiesce_all_vsi(pf); |
| 6977 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6978 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6979 | if (pf->vsi[v]) |
| 6980 | pf->vsi[v]->seid = 0; |
| 6981 | } |
| 6982 | |
| 6983 | i40e_shutdown_adminq(&pf->hw); |
| 6984 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6985 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6986 | if (hw->hmc.hmc_obj) { |
| 6987 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6988 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6989 | dev_warn(&pf->pdev->dev, |
| 6990 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6991 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6992 | } |
| 6993 | |
| 6994 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6995 | * i40e_send_version - update firmware with driver version |
| 6996 | * @pf: PF struct |
| 6997 | */ |
| 6998 | static void i40e_send_version(struct i40e_pf *pf) |
| 6999 | { |
| 7000 | struct i40e_driver_version dv; |
| 7001 | |
| 7002 | dv.major_version = DRV_VERSION_MAJOR; |
| 7003 | dv.minor_version = DRV_VERSION_MINOR; |
| 7004 | dv.build_version = DRV_VERSION_BUILD; |
| 7005 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 7006 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 7007 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 7008 | } |
| 7009 | |
| 7010 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 7011 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7012 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7013 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7014 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7015 | 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] | 7016 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7017 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7018 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7019 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 7020 | u32 val; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7021 | u32 v; |
| 7022 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7023 | /* Now we wait for GRST to settle out. |
| 7024 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 7025 | * because the reset will make them disappear. |
| 7026 | */ |
| 7027 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 7028 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7029 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7030 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 7031 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 7032 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7033 | pf->pfr_count++; |
| 7034 | |
| 7035 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7036 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7037 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7038 | |
| 7039 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 7040 | ret = i40e_init_adminq(&pf->hw); |
| 7041 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7042 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 7043 | i40e_stat_str(&pf->hw, ret), |
| 7044 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7045 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7046 | } |
| 7047 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 7048 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 7049 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 7050 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 7051 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 7052 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7053 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7054 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7055 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7056 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7057 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 7058 | hw->func_caps.num_rx_qp, |
| 7059 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 7060 | if (ret) { |
| 7061 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 7062 | goto end_core_reset; |
| 7063 | } |
| 7064 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 7065 | if (ret) { |
| 7066 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 7067 | goto end_core_reset; |
| 7068 | } |
| 7069 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7070 | #ifdef CONFIG_I40E_DCB |
| 7071 | ret = i40e_init_pf_dcb(pf); |
| 7072 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 7073 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 7074 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 7075 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7076 | } |
| 7077 | #endif /* CONFIG_I40E_DCB */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7078 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 7079 | i40e_init_pf_fcoe(pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7080 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7081 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7082 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7083 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7084 | if (ret) |
| 7085 | goto end_core_reset; |
| 7086 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 7087 | /* The driver only wants link up/down and module qualification |
| 7088 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 7089 | */ |
| 7090 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 7091 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 7092 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 7093 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 7094 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7095 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 7096 | i40e_stat_str(&pf->hw, ret), |
| 7097 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 7098 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7099 | /* make sure our flow control settings are restored */ |
| 7100 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 7101 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 7102 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 7103 | i40e_stat_str(&pf->hw, ret), |
| 7104 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7105 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7106 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 7107 | * They are still in our local switch element arrays, so only |
| 7108 | * need to rebuild the switch model in the HW. |
| 7109 | * |
| 7110 | * If there were VEBs but the reconstitution failed, we'll try |
| 7111 | * try to recover minimal use by getting the basic PF VSI working. |
| 7112 | */ |
| 7113 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 7114 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7115 | /* find the one VEB connected to the MAC, and find orphans */ |
| 7116 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 7117 | if (!pf->veb[v]) |
| 7118 | continue; |
| 7119 | |
| 7120 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 7121 | pf->veb[v]->uplink_seid == 0) { |
| 7122 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 7123 | |
| 7124 | if (!ret) |
| 7125 | continue; |
| 7126 | |
| 7127 | /* If Main VEB failed, we're in deep doodoo, |
| 7128 | * so give up rebuilding the switch and set up |
| 7129 | * for minimal rebuild of PF VSI. |
| 7130 | * If orphan failed, we'll report the error |
| 7131 | * but try to keep going. |
| 7132 | */ |
| 7133 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 7134 | dev_info(&pf->pdev->dev, |
| 7135 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 7136 | ret); |
| 7137 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 7138 | = pf->mac_seid; |
| 7139 | break; |
| 7140 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 7141 | dev_info(&pf->pdev->dev, |
| 7142 | "rebuild of orphan VEB failed: %d\n", |
| 7143 | ret); |
| 7144 | } |
| 7145 | } |
| 7146 | } |
| 7147 | } |
| 7148 | |
| 7149 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 7150 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7151 | /* no VEB, so rebuild only the Main VSI */ |
| 7152 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 7153 | if (ret) { |
| 7154 | dev_info(&pf->pdev->dev, |
| 7155 | "rebuild of Main VSI failed: %d\n", ret); |
| 7156 | goto end_core_reset; |
| 7157 | } |
| 7158 | } |
| 7159 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 7160 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 7161 | * of TSO, so that we avoid the MDD being fired and causing |
| 7162 | * a reset in the case of small MSS+TSO. |
| 7163 | */ |
| 7164 | #define I40E_REG_MSS 0x000E64DC |
| 7165 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 7166 | #define I40E_64BYTE_MSS 0x400000 |
| 7167 | val = rd32(hw, I40E_REG_MSS); |
| 7168 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 7169 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 7170 | val |= I40E_64BYTE_MSS; |
| 7171 | wr32(hw, I40E_REG_MSS, val); |
| 7172 | } |
| 7173 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 7174 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 7175 | msleep(75); |
| 7176 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 7177 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7178 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 7179 | i40e_stat_str(&pf->hw, ret), |
| 7180 | i40e_aq_str(&pf->hw, |
| 7181 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7182 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7183 | /* reinit the misc interrupt */ |
| 7184 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7185 | ret = i40e_setup_misc_vector(pf); |
| 7186 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 7187 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 7188 | * transmitted. By doing so we stop a malicious VF from sending out |
| 7189 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 7190 | * PF/VF VSIs. |
| 7191 | * The FW can still send Flow control frames if enabled. |
| 7192 | */ |
| 7193 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 7194 | pf->main_vsi_seid); |
| 7195 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7196 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 7197 | i40e_pf_unquiesce_all_vsi(pf); |
| 7198 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 7199 | if (pf->num_alloc_vfs) { |
| 7200 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 7201 | i40e_reset_vf(&pf->vf[v], true); |
| 7202 | } |
| 7203 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7204 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 7205 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7206 | |
| 7207 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7208 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 7209 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7210 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 7211 | } |
| 7212 | |
| 7213 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7214 | * 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] | 7215 | * @pf: board private structure |
| 7216 | * |
| 7217 | * Close up the VFs and other things in prep for a Core Reset, |
| 7218 | * then get ready to rebuild the world. |
| 7219 | **/ |
| 7220 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 7221 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 7222 | i40e_prep_for_reset(pf); |
| 7223 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7224 | } |
| 7225 | |
| 7226 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7227 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7228 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7229 | * |
| 7230 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 7231 | **/ |
| 7232 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 7233 | { |
| 7234 | struct i40e_hw *hw = &pf->hw; |
| 7235 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7236 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7237 | struct i40e_vf *vf; |
| 7238 | u32 reg; |
| 7239 | int i; |
| 7240 | |
| 7241 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 7242 | return; |
| 7243 | |
| 7244 | /* find what triggered the MDD event */ |
| 7245 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 7246 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7247 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 7248 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7249 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7250 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7251 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7252 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7253 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 7254 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 7255 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7256 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7257 | 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] | 7258 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7259 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 7260 | mdd_detected = true; |
| 7261 | } |
| 7262 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 7263 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7264 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 7265 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7266 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7267 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7268 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 7269 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 7270 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7271 | if (netif_msg_rx_err(pf)) |
| 7272 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 7273 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7274 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 7275 | mdd_detected = true; |
| 7276 | } |
| 7277 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7278 | if (mdd_detected) { |
| 7279 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 7280 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 7281 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7282 | 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] | 7283 | pf_mdd_detected = true; |
| 7284 | } |
| 7285 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 7286 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 7287 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7288 | 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] | 7289 | pf_mdd_detected = true; |
| 7290 | } |
| 7291 | /* Queue belongs to the PF, initiate a reset */ |
| 7292 | if (pf_mdd_detected) { |
| 7293 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 7294 | i40e_service_event_schedule(pf); |
| 7295 | } |
| 7296 | } |
| 7297 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7298 | /* see if one of the VFs needs its hand slapped */ |
| 7299 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7300 | vf = &(pf->vf[i]); |
| 7301 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7302 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7303 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7304 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7305 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7306 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7307 | } |
| 7308 | |
| 7309 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7310 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7311 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7312 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7313 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7314 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7315 | } |
| 7316 | |
| 7317 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7318 | dev_info(&pf->pdev->dev, |
| 7319 | "Too many MDD events on VF %d, disabled\n", i); |
| 7320 | dev_info(&pf->pdev->dev, |
| 7321 | "Use PF Control I/F to re-enable the VF\n"); |
| 7322 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 7323 | } |
| 7324 | } |
| 7325 | |
| 7326 | /* re-enable mdd interrupt cause */ |
| 7327 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 7328 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7329 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7330 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7331 | i40e_flush(hw); |
| 7332 | } |
| 7333 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7334 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7335 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7336 | * @pf: board private structure |
| 7337 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7338 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7339 | { |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7340 | struct i40e_hw *hw = &pf->hw; |
| 7341 | i40e_status ret; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7342 | __be16 port; |
| 7343 | int i; |
| 7344 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7345 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7346 | return; |
| 7347 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7348 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7349 | |
| 7350 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7351 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7352 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
| 7353 | port = pf->udp_ports[i].index; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7354 | if (port) |
Carolyn Wyborny | b3f5c7b | 2016-08-24 11:33:51 -0700 | [diff] [blame] | 7355 | ret = i40e_aq_add_udp_tunnel(hw, port, |
| 7356 | pf->udp_ports[i].type, |
| 7357 | NULL, NULL); |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7358 | else |
| 7359 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7360 | |
| 7361 | if (ret) { |
Carolyn Wyborny | 730a8f8 | 2016-02-17 16:12:16 -0800 | [diff] [blame] | 7362 | dev_dbg(&pf->pdev->dev, |
| 7363 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 7364 | pf->udp_ports[i].type ? "vxlan" : "geneve", |
| 7365 | port ? "add" : "delete", |
| 7366 | ntohs(port), i, |
| 7367 | i40e_stat_str(&pf->hw, ret), |
| 7368 | i40e_aq_str(&pf->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7369 | pf->hw.aq.asq_last_status)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7370 | pf->udp_ports[i].index = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7371 | } |
| 7372 | } |
| 7373 | } |
| 7374 | } |
| 7375 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7376 | /** |
| 7377 | * i40e_service_task - Run the driver's async subtasks |
| 7378 | * @work: pointer to work_struct containing our data |
| 7379 | **/ |
| 7380 | static void i40e_service_task(struct work_struct *work) |
| 7381 | { |
| 7382 | struct i40e_pf *pf = container_of(work, |
| 7383 | struct i40e_pf, |
| 7384 | service_task); |
| 7385 | unsigned long start_time = jiffies; |
| 7386 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7387 | /* don't bother with service tasks if a reset is in progress */ |
| 7388 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7389 | return; |
| 7390 | } |
| 7391 | |
Mitch Williams | 9108903 | 2016-11-21 13:03:51 -0800 | [diff] [blame] | 7392 | if (test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
| 7393 | return; |
| 7394 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7395 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 7396 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7397 | i40e_reset_subtask(pf); |
| 7398 | i40e_handle_mdd_event(pf); |
| 7399 | i40e_vc_process_vflr_event(pf); |
| 7400 | i40e_watchdog_subtask(pf); |
| 7401 | i40e_fdir_reinit_subtask(pf); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7402 | i40e_client_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7403 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7404 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7405 | i40e_clean_adminq_subtask(pf); |
| 7406 | |
Mitch Williams | 9108903 | 2016-11-21 13:03:51 -0800 | [diff] [blame] | 7407 | /* flush memory to make sure state is correct before next watchdog */ |
| 7408 | smp_mb__before_atomic(); |
| 7409 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7410 | |
| 7411 | /* If the tasks have taken longer than one timer cycle or there |
| 7412 | * is more work to be done, reschedule the service task now |
| 7413 | * rather than wait for the timer to tick again. |
| 7414 | */ |
| 7415 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 7416 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 7417 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 7418 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 7419 | i40e_service_event_schedule(pf); |
| 7420 | } |
| 7421 | |
| 7422 | /** |
| 7423 | * i40e_service_timer - timer callback |
| 7424 | * @data: pointer to PF struct |
| 7425 | **/ |
| 7426 | static void i40e_service_timer(unsigned long data) |
| 7427 | { |
| 7428 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7429 | |
| 7430 | mod_timer(&pf->service_timer, |
| 7431 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7432 | i40e_service_event_schedule(pf); |
| 7433 | } |
| 7434 | |
| 7435 | /** |
| 7436 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7437 | * @vsi: the VSI being configured |
| 7438 | **/ |
| 7439 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7440 | { |
| 7441 | struct i40e_pf *pf = vsi->back; |
| 7442 | |
| 7443 | switch (vsi->type) { |
| 7444 | case I40E_VSI_MAIN: |
| 7445 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7446 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7447 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7448 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7449 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7450 | else |
| 7451 | vsi->num_q_vectors = 1; |
| 7452 | |
| 7453 | break; |
| 7454 | |
| 7455 | case I40E_VSI_FDIR: |
| 7456 | vsi->alloc_queue_pairs = 1; |
| 7457 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7458 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7459 | vsi->num_q_vectors = pf->num_fdsb_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7460 | break; |
| 7461 | |
| 7462 | case I40E_VSI_VMDQ2: |
| 7463 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7464 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7465 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7466 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7467 | break; |
| 7468 | |
| 7469 | case I40E_VSI_SRIOV: |
| 7470 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7471 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7472 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7473 | break; |
| 7474 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7475 | #ifdef I40E_FCOE |
| 7476 | case I40E_VSI_FCOE: |
| 7477 | vsi->alloc_queue_pairs = pf->num_fcoe_qps; |
| 7478 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7479 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7480 | vsi->num_q_vectors = pf->num_fcoe_msix; |
| 7481 | break; |
| 7482 | |
| 7483 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7484 | default: |
| 7485 | WARN_ON(1); |
| 7486 | return -ENODATA; |
| 7487 | } |
| 7488 | |
| 7489 | return 0; |
| 7490 | } |
| 7491 | |
| 7492 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7493 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7494 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7495 | * @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] | 7496 | * |
| 7497 | * On error: returns error code (negative) |
| 7498 | * On success: returns 0 |
| 7499 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7500 | 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] | 7501 | { |
| 7502 | int size; |
| 7503 | int ret = 0; |
| 7504 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7505 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7506 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 7507 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7508 | if (!vsi->tx_rings) |
| 7509 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7510 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 7511 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7512 | if (alloc_qvectors) { |
| 7513 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7514 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7515 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7516 | if (!vsi->q_vectors) { |
| 7517 | ret = -ENOMEM; |
| 7518 | goto err_vectors; |
| 7519 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7520 | } |
| 7521 | return ret; |
| 7522 | |
| 7523 | err_vectors: |
| 7524 | kfree(vsi->tx_rings); |
| 7525 | return ret; |
| 7526 | } |
| 7527 | |
| 7528 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7529 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7530 | * @pf: board private structure |
| 7531 | * @type: type of VSI |
| 7532 | * |
| 7533 | * On error: returns error code (negative) |
| 7534 | * On success: returns vsi index in PF (positive) |
| 7535 | **/ |
| 7536 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7537 | { |
| 7538 | int ret = -ENODEV; |
| 7539 | struct i40e_vsi *vsi; |
| 7540 | int vsi_idx; |
| 7541 | int i; |
| 7542 | |
| 7543 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7544 | mutex_lock(&pf->switch_mutex); |
| 7545 | |
| 7546 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7547 | * been happening. We can afford to do a quick scan to look |
| 7548 | * for any free VSIs in the list. |
| 7549 | * |
| 7550 | * find next empty vsi slot, looping back around if necessary |
| 7551 | */ |
| 7552 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7553 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7554 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7555 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7556 | i = 0; |
| 7557 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7558 | i++; |
| 7559 | } |
| 7560 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7561 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7562 | vsi_idx = i; /* Found one! */ |
| 7563 | } else { |
| 7564 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7565 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7566 | } |
| 7567 | pf->next_vsi = ++i; |
| 7568 | |
| 7569 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7570 | if (!vsi) { |
| 7571 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7572 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7573 | } |
| 7574 | vsi->type = type; |
| 7575 | vsi->back = pf; |
| 7576 | set_bit(__I40E_DOWN, &vsi->state); |
| 7577 | vsi->flags = 0; |
| 7578 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7579 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7580 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7581 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7582 | vsi->netdev_registered = false; |
| 7583 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 7584 | hash_init(vsi->mac_filter_hash); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7585 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7586 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7587 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7588 | if (ret) |
| 7589 | goto err_rings; |
| 7590 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7591 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7592 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7593 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7594 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7595 | /* Setup default MSIX irq handler for VSI */ |
| 7596 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7597 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7598 | /* Initialize VSI lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 7599 | spin_lock_init(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7600 | pf->vsi[vsi_idx] = vsi; |
| 7601 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7602 | goto unlock_pf; |
| 7603 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7604 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7605 | pf->next_vsi = i - 1; |
| 7606 | kfree(vsi); |
| 7607 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7608 | mutex_unlock(&pf->switch_mutex); |
| 7609 | return ret; |
| 7610 | } |
| 7611 | |
| 7612 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7613 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7614 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7615 | * @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] | 7616 | * |
| 7617 | * On error: returns error code (negative) |
| 7618 | * On success: returns 0 |
| 7619 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7620 | 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] | 7621 | { |
| 7622 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7623 | if (free_qvectors) { |
| 7624 | kfree(vsi->q_vectors); |
| 7625 | vsi->q_vectors = NULL; |
| 7626 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7627 | kfree(vsi->tx_rings); |
| 7628 | vsi->tx_rings = NULL; |
| 7629 | vsi->rx_rings = NULL; |
| 7630 | } |
| 7631 | |
| 7632 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7633 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7634 | * and lookup table |
| 7635 | * @vsi: Pointer to VSI structure |
| 7636 | */ |
| 7637 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7638 | { |
| 7639 | if (!vsi) |
| 7640 | return; |
| 7641 | |
| 7642 | kfree(vsi->rss_hkey_user); |
| 7643 | vsi->rss_hkey_user = NULL; |
| 7644 | |
| 7645 | kfree(vsi->rss_lut_user); |
| 7646 | vsi->rss_lut_user = NULL; |
| 7647 | } |
| 7648 | |
| 7649 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7650 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7651 | * @vsi: the VSI being un-configured |
| 7652 | **/ |
| 7653 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7654 | { |
| 7655 | struct i40e_pf *pf; |
| 7656 | |
| 7657 | if (!vsi) |
| 7658 | return 0; |
| 7659 | |
| 7660 | if (!vsi->back) |
| 7661 | goto free_vsi; |
| 7662 | pf = vsi->back; |
| 7663 | |
| 7664 | mutex_lock(&pf->switch_mutex); |
| 7665 | if (!pf->vsi[vsi->idx]) { |
| 7666 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7667 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7668 | goto unlock_vsi; |
| 7669 | } |
| 7670 | |
| 7671 | if (pf->vsi[vsi->idx] != vsi) { |
| 7672 | dev_err(&pf->pdev->dev, |
| 7673 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7674 | pf->vsi[vsi->idx]->idx, |
| 7675 | pf->vsi[vsi->idx], |
| 7676 | pf->vsi[vsi->idx]->type, |
| 7677 | vsi->idx, vsi, vsi->type); |
| 7678 | goto unlock_vsi; |
| 7679 | } |
| 7680 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7681 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7682 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7683 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7684 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7685 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7686 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7687 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7688 | pf->vsi[vsi->idx] = NULL; |
| 7689 | if (vsi->idx < pf->next_vsi) |
| 7690 | pf->next_vsi = vsi->idx; |
| 7691 | |
| 7692 | unlock_vsi: |
| 7693 | mutex_unlock(&pf->switch_mutex); |
| 7694 | free_vsi: |
| 7695 | kfree(vsi); |
| 7696 | |
| 7697 | return 0; |
| 7698 | } |
| 7699 | |
| 7700 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7701 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7702 | * @vsi: the VSI being cleaned |
| 7703 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7704 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7705 | { |
| 7706 | int i; |
| 7707 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7708 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7709 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7710 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7711 | vsi->tx_rings[i] = NULL; |
| 7712 | vsi->rx_rings[i] = NULL; |
| 7713 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7714 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7715 | } |
| 7716 | |
| 7717 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7718 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7719 | * @vsi: the VSI being configured |
| 7720 | **/ |
| 7721 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7722 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7723 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7724 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7725 | int i; |
| 7726 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7727 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7728 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7729 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7730 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7731 | if (!tx_ring) |
| 7732 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7733 | |
| 7734 | tx_ring->queue_index = i; |
| 7735 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7736 | tx_ring->ring_active = false; |
| 7737 | tx_ring->vsi = vsi; |
| 7738 | tx_ring->netdev = vsi->netdev; |
| 7739 | tx_ring->dev = &pf->pdev->dev; |
| 7740 | tx_ring->count = vsi->num_desc; |
| 7741 | tx_ring->size = 0; |
| 7742 | tx_ring->dcb_tc = 0; |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 7743 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 7744 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7745 | tx_ring->tx_itr_setting = pf->tx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7746 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7747 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7748 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7749 | rx_ring->queue_index = i; |
| 7750 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7751 | rx_ring->ring_active = false; |
| 7752 | rx_ring->vsi = vsi; |
| 7753 | rx_ring->netdev = vsi->netdev; |
| 7754 | rx_ring->dev = &pf->pdev->dev; |
| 7755 | rx_ring->count = vsi->num_desc; |
| 7756 | rx_ring->size = 0; |
| 7757 | rx_ring->dcb_tc = 0; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7758 | rx_ring->rx_itr_setting = pf->rx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7759 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7760 | } |
| 7761 | |
| 7762 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7763 | |
| 7764 | err_out: |
| 7765 | i40e_vsi_clear_rings(vsi); |
| 7766 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7767 | } |
| 7768 | |
| 7769 | /** |
| 7770 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7771 | * @pf: board private structure |
| 7772 | * @vectors: the number of MSI-X vectors to request |
| 7773 | * |
| 7774 | * Returns the number of vectors reserved, or error |
| 7775 | **/ |
| 7776 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7777 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7778 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7779 | I40E_MIN_MSIX, vectors); |
| 7780 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7781 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7782 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7783 | vectors = 0; |
| 7784 | } |
| 7785 | |
| 7786 | return vectors; |
| 7787 | } |
| 7788 | |
| 7789 | /** |
| 7790 | * i40e_init_msix - Setup the MSIX capability |
| 7791 | * @pf: board private structure |
| 7792 | * |
| 7793 | * Work with the OS to set up the MSIX vectors needed. |
| 7794 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7795 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7796 | **/ |
| 7797 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7798 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7799 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7800 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7801 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7802 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7803 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7804 | |
| 7805 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7806 | return -ENODEV; |
| 7807 | |
| 7808 | /* The number of vectors we'll request will be comprised of: |
| 7809 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7810 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7811 | * - Queues being used for RSS. |
| 7812 | * We don't need as many as max_rss_size vectors. |
| 7813 | * use rss_size instead in the calculation since that |
| 7814 | * is governed by number of cpus in the system. |
| 7815 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7816 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7817 | * - The CPU count within the NUMA node if iWARP is enabled |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7818 | #ifdef I40E_FCOE |
| 7819 | * - The number of FCOE qps. |
| 7820 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7821 | * Once we count this up, try the request. |
| 7822 | * |
| 7823 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7824 | * and try again. If that still fails, we punt. |
| 7825 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7826 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7827 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7828 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7829 | /* reserve one vector for miscellaneous handler */ |
| 7830 | if (vectors_left) { |
| 7831 | v_budget++; |
| 7832 | vectors_left--; |
| 7833 | } |
| 7834 | |
| 7835 | /* reserve vectors for the main PF traffic queues */ |
| 7836 | pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left); |
| 7837 | vectors_left -= pf->num_lan_msix; |
| 7838 | v_budget += pf->num_lan_msix; |
| 7839 | |
| 7840 | /* reserve one vector for sideband flow director */ |
| 7841 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7842 | if (vectors_left) { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7843 | pf->num_fdsb_msix = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7844 | v_budget++; |
| 7845 | vectors_left--; |
| 7846 | } else { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7847 | pf->num_fdsb_msix = 0; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7848 | } |
| 7849 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7850 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7851 | #ifdef I40E_FCOE |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7852 | /* can we reserve enough for FCoE? */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7853 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7854 | if (!vectors_left) |
| 7855 | pf->num_fcoe_msix = 0; |
| 7856 | else if (vectors_left >= pf->num_fcoe_qps) |
| 7857 | pf->num_fcoe_msix = pf->num_fcoe_qps; |
| 7858 | else |
| 7859 | pf->num_fcoe_msix = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7860 | v_budget += pf->num_fcoe_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7861 | vectors_left -= pf->num_fcoe_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7862 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7863 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7864 | #endif |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7865 | /* can we reserve enough for iWARP? */ |
| 7866 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7867 | iwarp_requested = pf->num_iwarp_msix; |
| 7868 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7869 | if (!vectors_left) |
| 7870 | pf->num_iwarp_msix = 0; |
| 7871 | else if (vectors_left < pf->num_iwarp_msix) |
| 7872 | pf->num_iwarp_msix = 1; |
| 7873 | v_budget += pf->num_iwarp_msix; |
| 7874 | vectors_left -= pf->num_iwarp_msix; |
| 7875 | } |
| 7876 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7877 | /* any vectors left over go for VMDq support */ |
| 7878 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7879 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7880 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7881 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 7882 | if (!vectors_left) { |
| 7883 | pf->num_vmdq_msix = 0; |
| 7884 | pf->num_vmdq_qps = 0; |
| 7885 | } else { |
| 7886 | /* if we're short on vectors for what's desired, we limit |
| 7887 | * the queues per vmdq. If this is still more than are |
| 7888 | * available, the user will need to change the number of |
| 7889 | * queues/vectors used by the PF later with the ethtool |
| 7890 | * channels command |
| 7891 | */ |
| 7892 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7893 | pf->num_vmdq_qps = 1; |
| 7894 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7895 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 7896 | v_budget += vmdq_vecs; |
| 7897 | vectors_left -= vmdq_vecs; |
| 7898 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7899 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7900 | |
| 7901 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7902 | GFP_KERNEL); |
| 7903 | if (!pf->msix_entries) |
| 7904 | return -ENOMEM; |
| 7905 | |
| 7906 | for (i = 0; i < v_budget; i++) |
| 7907 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7908 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7909 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7910 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7911 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7912 | kfree(pf->msix_entries); |
| 7913 | pf->msix_entries = NULL; |
Guilherme G Piccoli | 4c95aa5 | 2016-09-22 10:03:58 -0300 | [diff] [blame] | 7914 | pci_disable_msix(pf->pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7915 | return -ENODEV; |
| 7916 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7917 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7918 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7919 | pf->num_vmdq_vsis = 0; |
| 7920 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7921 | pf->num_lan_qps = 1; |
| 7922 | pf->num_lan_msix = 1; |
| 7923 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7924 | } else if (!vectors_left) { |
| 7925 | /* If we have limited resources, we will start with no vectors |
| 7926 | * for the special features and then allocate vectors to some |
| 7927 | * of these features based on the policy and at the end disable |
| 7928 | * the features that did not get any vectors. |
| 7929 | */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7930 | int vec; |
| 7931 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7932 | dev_info(&pf->pdev->dev, |
| 7933 | "MSI-X vector limit reached, attempting to redistribute vectors\n"); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7934 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7935 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7936 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7937 | /* Scale vector usage down */ |
| 7938 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7939 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7940 | pf->num_vmdq_qps = 1; |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7941 | #ifdef I40E_FCOE |
| 7942 | pf->num_fcoe_qps = 0; |
| 7943 | pf->num_fcoe_msix = 0; |
| 7944 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7945 | |
| 7946 | /* partition out the remaining vectors */ |
| 7947 | switch (vec) { |
| 7948 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7949 | pf->num_lan_msix = 1; |
| 7950 | break; |
| 7951 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7952 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7953 | pf->num_lan_msix = 1; |
| 7954 | pf->num_iwarp_msix = 1; |
| 7955 | } else { |
| 7956 | pf->num_lan_msix = 2; |
| 7957 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7958 | #ifdef I40E_FCOE |
| 7959 | /* give one vector to FCoE */ |
| 7960 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7961 | pf->num_lan_msix = 1; |
| 7962 | pf->num_fcoe_msix = 1; |
| 7963 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7964 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7965 | break; |
| 7966 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7967 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7968 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 7969 | iwarp_requested); |
| 7970 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 7971 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7972 | } else { |
| 7973 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 7974 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7975 | } |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 7976 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7977 | pf->num_fdsb_msix = 1; |
| 7978 | vec--; |
| 7979 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7980 | pf->num_lan_msix = min_t(int, |
| 7981 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 7982 | pf->num_lan_msix); |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7983 | pf->num_lan_qps = pf->num_lan_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7984 | #ifdef I40E_FCOE |
| 7985 | /* give one vector to FCoE */ |
| 7986 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7987 | pf->num_fcoe_msix = 1; |
| 7988 | vec--; |
| 7989 | } |
| 7990 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7991 | break; |
| 7992 | } |
| 7993 | } |
| 7994 | |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 7995 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 7996 | (pf->num_fdsb_msix == 0)) { |
| 7997 | dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n"); |
| 7998 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7999 | } |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 8000 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 8001 | (pf->num_vmdq_msix == 0)) { |
| 8002 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 8003 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 8004 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8005 | |
| 8006 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 8007 | (pf->num_iwarp_msix == 0)) { |
| 8008 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 8009 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 8010 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8011 | #ifdef I40E_FCOE |
| 8012 | |
| 8013 | if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { |
| 8014 | dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n"); |
| 8015 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 8016 | } |
| 8017 | #endif |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 8018 | i40e_debug(&pf->hw, I40E_DEBUG_INIT, |
| 8019 | "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n", |
| 8020 | pf->num_lan_msix, |
| 8021 | pf->num_vmdq_msix * pf->num_vmdq_vsis, |
| 8022 | pf->num_fdsb_msix, |
| 8023 | pf->num_iwarp_msix); |
| 8024 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8025 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8026 | } |
| 8027 | |
| 8028 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 8029 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8030 | * @vsi: the VSI being configured |
| 8031 | * @v_idx: index of the vector in the vsi struct |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8032 | * @cpu: cpu to be used on affinity_mask |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8033 | * |
| 8034 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 8035 | **/ |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8036 | 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] | 8037 | { |
| 8038 | struct i40e_q_vector *q_vector; |
| 8039 | |
| 8040 | /* allocate q_vector */ |
| 8041 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 8042 | if (!q_vector) |
| 8043 | return -ENOMEM; |
| 8044 | |
| 8045 | q_vector->vsi = vsi; |
| 8046 | q_vector->v_idx = v_idx; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8047 | cpumask_set_cpu(cpu, &q_vector->affinity_mask); |
| 8048 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8049 | if (vsi->netdev) |
| 8050 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 8051 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8052 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 8053 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 8054 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 8055 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8056 | /* tie q_vector and vsi together */ |
| 8057 | vsi->q_vectors[v_idx] = q_vector; |
| 8058 | |
| 8059 | return 0; |
| 8060 | } |
| 8061 | |
| 8062 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 8063 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8064 | * @vsi: the VSI being configured |
| 8065 | * |
| 8066 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 8067 | * return -ENOMEM. |
| 8068 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 8069 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8070 | { |
| 8071 | struct i40e_pf *pf = vsi->back; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8072 | int err, v_idx, num_q_vectors, current_cpu; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8073 | |
| 8074 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 8075 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 8076 | num_q_vectors = vsi->num_q_vectors; |
| 8077 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 8078 | num_q_vectors = 1; |
| 8079 | else |
| 8080 | return -EINVAL; |
| 8081 | |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8082 | current_cpu = cpumask_first(cpu_online_mask); |
| 8083 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8084 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8085 | err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8086 | if (err) |
| 8087 | goto err_out; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 8088 | current_cpu = cpumask_next(current_cpu, cpu_online_mask); |
| 8089 | if (unlikely(current_cpu >= nr_cpu_ids)) |
| 8090 | current_cpu = cpumask_first(cpu_online_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8091 | } |
| 8092 | |
| 8093 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8094 | |
| 8095 | err_out: |
| 8096 | while (v_idx--) |
| 8097 | i40e_free_q_vector(vsi, v_idx); |
| 8098 | |
| 8099 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8100 | } |
| 8101 | |
| 8102 | /** |
| 8103 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 8104 | * @pf: board private structure to initialize |
| 8105 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8106 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8107 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8108 | int vectors = 0; |
| 8109 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8110 | |
| 8111 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8112 | vectors = i40e_init_msix(pf); |
| 8113 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 8114 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8115 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8116 | #ifdef I40E_FCOE |
| 8117 | I40E_FLAG_FCOE_ENABLED | |
| 8118 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 8119 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 8120 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 8121 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 8122 | I40E_FLAG_SRIOV_ENABLED | |
| 8123 | I40E_FLAG_FD_SB_ENABLED | |
| 8124 | I40E_FLAG_FD_ATR_ENABLED | |
| 8125 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8126 | |
| 8127 | /* rework the queue expectations without MSIX */ |
| 8128 | i40e_determine_queue_usage(pf); |
| 8129 | } |
| 8130 | } |
| 8131 | |
| 8132 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 8133 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8134 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8135 | vectors = pci_enable_msi(pf->pdev); |
| 8136 | if (vectors < 0) { |
| 8137 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 8138 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8139 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 8140 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8141 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8142 | } |
| 8143 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 8144 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8145 | 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] | 8146 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8147 | /* set up vector assignment tracking */ |
| 8148 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 8149 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8150 | if (!pf->irq_pile) { |
| 8151 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 8152 | return -ENOMEM; |
| 8153 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8154 | pf->irq_pile->num_entries = vectors; |
| 8155 | pf->irq_pile->search_hint = 0; |
| 8156 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8157 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8158 | (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] | 8159 | |
| 8160 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8161 | } |
| 8162 | |
| 8163 | /** |
| 8164 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 8165 | * @pf: board private structure |
| 8166 | * |
| 8167 | * This sets up the handler for MSIX 0, which is used to manage the |
| 8168 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 8169 | * when in MSI or Legacy interrupt mode. |
| 8170 | **/ |
| 8171 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 8172 | { |
| 8173 | struct i40e_hw *hw = &pf->hw; |
| 8174 | int err = 0; |
| 8175 | |
| 8176 | /* Only request the irq if this is the first time through, and |
| 8177 | * not when we're rebuilding after a Reset |
| 8178 | */ |
| 8179 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 8180 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8181 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8182 | if (err) { |
| 8183 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8184 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8185 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8186 | return -EFAULT; |
| 8187 | } |
| 8188 | } |
| 8189 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 8190 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8191 | |
| 8192 | /* associate no queues to the misc vector */ |
| 8193 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 8194 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 8195 | |
| 8196 | i40e_flush(hw); |
| 8197 | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 8198 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8199 | |
| 8200 | return err; |
| 8201 | } |
| 8202 | |
| 8203 | /** |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8204 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 8205 | * @vsi: vsi structure |
| 8206 | * @seed: RSS hash seed |
| 8207 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8208 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8209 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8210 | { |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8211 | struct i40e_pf *pf = vsi->back; |
| 8212 | struct i40e_hw *hw = &pf->hw; |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8213 | int ret = 0; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8214 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8215 | if (seed) { |
| 8216 | struct i40e_aqc_get_set_rss_key_data *seed_dw = |
| 8217 | (struct i40e_aqc_get_set_rss_key_data *)seed; |
| 8218 | ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw); |
| 8219 | if (ret) { |
| 8220 | dev_info(&pf->pdev->dev, |
| 8221 | "Cannot set RSS key, err %s aq_err %s\n", |
| 8222 | i40e_stat_str(hw, ret), |
| 8223 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8224 | return ret; |
| 8225 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8226 | } |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8227 | if (lut) { |
| 8228 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8229 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8230 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8231 | if (ret) { |
| 8232 | dev_info(&pf->pdev->dev, |
| 8233 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 8234 | i40e_stat_str(hw, ret), |
| 8235 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8236 | return ret; |
| 8237 | } |
| 8238 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8239 | return ret; |
| 8240 | } |
| 8241 | |
| 8242 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8243 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 8244 | * @vsi: Pointer to vsi structure |
| 8245 | * @seed: Buffter to store the hash keys |
| 8246 | * @lut: Buffer to store the lookup table entries |
| 8247 | * @lut_size: Size of buffer to store the lookup table entries |
| 8248 | * |
| 8249 | * Return 0 on success, negative on failure |
| 8250 | */ |
| 8251 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8252 | u8 *lut, u16 lut_size) |
| 8253 | { |
| 8254 | struct i40e_pf *pf = vsi->back; |
| 8255 | struct i40e_hw *hw = &pf->hw; |
| 8256 | int ret = 0; |
| 8257 | |
| 8258 | if (seed) { |
| 8259 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 8260 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 8261 | if (ret) { |
| 8262 | dev_info(&pf->pdev->dev, |
| 8263 | "Cannot get RSS key, err %s aq_err %s\n", |
| 8264 | i40e_stat_str(&pf->hw, ret), |
| 8265 | i40e_aq_str(&pf->hw, |
| 8266 | pf->hw.aq.asq_last_status)); |
| 8267 | return ret; |
| 8268 | } |
| 8269 | } |
| 8270 | |
| 8271 | if (lut) { |
| 8272 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 8273 | |
| 8274 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8275 | if (ret) { |
| 8276 | dev_info(&pf->pdev->dev, |
| 8277 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 8278 | i40e_stat_str(&pf->hw, ret), |
| 8279 | i40e_aq_str(&pf->hw, |
| 8280 | pf->hw.aq.asq_last_status)); |
| 8281 | return ret; |
| 8282 | } |
| 8283 | } |
| 8284 | |
| 8285 | return ret; |
| 8286 | } |
| 8287 | |
| 8288 | /** |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8289 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 8290 | * @vsi: VSI structure |
| 8291 | **/ |
| 8292 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 8293 | { |
| 8294 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 8295 | struct i40e_pf *pf = vsi->back; |
| 8296 | u8 *lut; |
| 8297 | int ret; |
| 8298 | |
| 8299 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) |
| 8300 | return 0; |
| 8301 | |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8302 | if (!vsi->rss_size) |
| 8303 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8304 | vsi->num_queue_pairs); |
| 8305 | if (!vsi->rss_size) |
| 8306 | return -EINVAL; |
| 8307 | |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8308 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8309 | if (!lut) |
| 8310 | return -ENOMEM; |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8311 | /* Use the user configured hash keys and lookup table if there is one, |
| 8312 | * otherwise use default |
| 8313 | */ |
| 8314 | if (vsi->rss_lut_user) |
| 8315 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8316 | else |
| 8317 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
| 8318 | if (vsi->rss_hkey_user) |
| 8319 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8320 | else |
| 8321 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8322 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 8323 | kfree(lut); |
| 8324 | |
| 8325 | return ret; |
| 8326 | } |
| 8327 | |
| 8328 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8329 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8330 | * @vsi: Pointer to vsi structure |
| 8331 | * @seed: RSS hash seed |
| 8332 | * @lut: Lookup table |
| 8333 | * @lut_size: Lookup table size |
| 8334 | * |
| 8335 | * Returns 0 on success, negative on failure |
| 8336 | **/ |
| 8337 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8338 | const u8 *lut, u16 lut_size) |
| 8339 | { |
| 8340 | struct i40e_pf *pf = vsi->back; |
| 8341 | struct i40e_hw *hw = &pf->hw; |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8342 | u16 vf_id = vsi->vf_id; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8343 | u8 i; |
| 8344 | |
| 8345 | /* Fill out hash function seed */ |
| 8346 | if (seed) { |
| 8347 | u32 *seed_dw = (u32 *)seed; |
| 8348 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8349 | if (vsi->type == I40E_VSI_MAIN) { |
| 8350 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 8351 | i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), |
| 8352 | seed_dw[i]); |
| 8353 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8354 | for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++) |
| 8355 | i40e_write_rx_ctl(hw, |
| 8356 | I40E_VFQF_HKEY1(i, vf_id), |
| 8357 | seed_dw[i]); |
| 8358 | } else { |
| 8359 | dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n"); |
| 8360 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8361 | } |
| 8362 | |
| 8363 | if (lut) { |
| 8364 | u32 *lut_dw = (u32 *)lut; |
| 8365 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8366 | if (vsi->type == I40E_VSI_MAIN) { |
| 8367 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8368 | return -EINVAL; |
| 8369 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8370 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8371 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8372 | if (lut_size != I40E_VF_HLUT_ARRAY_SIZE) |
| 8373 | return -EINVAL; |
| 8374 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8375 | i40e_write_rx_ctl(hw, |
| 8376 | I40E_VFQF_HLUT1(i, vf_id), |
| 8377 | lut_dw[i]); |
| 8378 | } else { |
| 8379 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8380 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8381 | } |
| 8382 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8383 | |
| 8384 | return 0; |
| 8385 | } |
| 8386 | |
| 8387 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8388 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8389 | * @vsi: Pointer to VSI structure |
| 8390 | * @seed: Buffer to store the keys |
| 8391 | * @lut: Buffer to store the lookup table entries |
| 8392 | * @lut_size: Size of buffer to store the lookup table entries |
| 8393 | * |
| 8394 | * Returns 0 on success, negative on failure |
| 8395 | */ |
| 8396 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8397 | u8 *lut, u16 lut_size) |
| 8398 | { |
| 8399 | struct i40e_pf *pf = vsi->back; |
| 8400 | struct i40e_hw *hw = &pf->hw; |
| 8401 | u16 i; |
| 8402 | |
| 8403 | if (seed) { |
| 8404 | u32 *seed_dw = (u32 *)seed; |
| 8405 | |
| 8406 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8407 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8408 | } |
| 8409 | if (lut) { |
| 8410 | u32 *lut_dw = (u32 *)lut; |
| 8411 | |
| 8412 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8413 | return -EINVAL; |
| 8414 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8415 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8416 | } |
| 8417 | |
| 8418 | return 0; |
| 8419 | } |
| 8420 | |
| 8421 | /** |
| 8422 | * i40e_config_rss - Configure RSS keys and lut |
| 8423 | * @vsi: Pointer to VSI structure |
| 8424 | * @seed: RSS hash seed |
| 8425 | * @lut: Lookup table |
| 8426 | * @lut_size: Lookup table size |
| 8427 | * |
| 8428 | * Returns 0 on success, negative on failure |
| 8429 | */ |
| 8430 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8431 | { |
| 8432 | struct i40e_pf *pf = vsi->back; |
| 8433 | |
| 8434 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8435 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8436 | else |
| 8437 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8438 | } |
| 8439 | |
| 8440 | /** |
| 8441 | * i40e_get_rss - Get RSS keys and lut |
| 8442 | * @vsi: Pointer to VSI structure |
| 8443 | * @seed: Buffer to store the keys |
| 8444 | * @lut: Buffer to store the lookup table entries |
| 8445 | * lut_size: Size of buffer to store the lookup table entries |
| 8446 | * |
| 8447 | * Returns 0 on success, negative on failure |
| 8448 | */ |
| 8449 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8450 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8451 | struct i40e_pf *pf = vsi->back; |
| 8452 | |
| 8453 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8454 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8455 | else |
| 8456 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8457 | } |
| 8458 | |
| 8459 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8460 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8461 | * @pf: Pointer to board private structure |
| 8462 | * @lut: Lookup table |
| 8463 | * @rss_table_size: Lookup table size |
| 8464 | * @rss_size: Range of queue number for hashing |
| 8465 | */ |
Alan Brady | f158235 | 2016-08-24 11:33:46 -0700 | [diff] [blame] | 8466 | void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8467 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8468 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8469 | u16 i; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8470 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8471 | for (i = 0; i < rss_table_size; i++) |
| 8472 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8473 | } |
| 8474 | |
| 8475 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8476 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8477 | * @pf: board private structure |
| 8478 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8479 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8480 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8481 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8482 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8483 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8484 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8485 | u32 reg_val; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8486 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8487 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8488 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8489 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8490 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 8491 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8492 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8493 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8494 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8495 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8496 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8497 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8498 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8499 | reg_val = (pf->rss_table_size == 512) ? |
| 8500 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8501 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8502 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8503 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8504 | /* Determine the RSS size of the VSI */ |
| 8505 | if (!vsi->rss_size) |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8506 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8507 | vsi->num_queue_pairs); |
Mitch Williams | a4fa59c | 2016-09-12 14:18:43 -0700 | [diff] [blame] | 8508 | if (!vsi->rss_size) |
| 8509 | return -EINVAL; |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8510 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8511 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8512 | if (!lut) |
| 8513 | return -ENOMEM; |
| 8514 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8515 | /* Use user configured lut if there is one, otherwise use default */ |
| 8516 | if (vsi->rss_lut_user) |
| 8517 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8518 | else |
| 8519 | 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] | 8520 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8521 | /* Use user configured hash key if there is one, otherwise |
| 8522 | * use default. |
| 8523 | */ |
| 8524 | if (vsi->rss_hkey_user) |
| 8525 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8526 | else |
| 8527 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8528 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8529 | kfree(lut); |
| 8530 | |
| 8531 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8532 | } |
| 8533 | |
| 8534 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8535 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8536 | * @pf: board private structure |
| 8537 | * @queue_count: the requested queue count for rss. |
| 8538 | * |
| 8539 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8540 | * count which may be different from the requested queue count. |
| 8541 | **/ |
| 8542 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8543 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8544 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8545 | int new_rss_size; |
| 8546 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8547 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8548 | return 0; |
| 8549 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8550 | 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] | 8551 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8552 | if (queue_count != vsi->num_queue_pairs) { |
| 8553 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8554 | i40e_prep_for_reset(pf); |
| 8555 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8556 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8557 | |
| 8558 | i40e_reset_and_rebuild(pf, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8559 | |
| 8560 | /* Discard the user configured hash keys and lut, if less |
| 8561 | * queues are enabled. |
| 8562 | */ |
| 8563 | if (queue_count < vsi->rss_size) { |
| 8564 | i40e_clear_rss_config_user(vsi); |
| 8565 | dev_dbg(&pf->pdev->dev, |
| 8566 | "discard user configured hash keys and lut\n"); |
| 8567 | } |
| 8568 | |
| 8569 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8570 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8571 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8572 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8573 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8574 | } |
Lihong Yang | 1281505 | 2016-09-27 11:28:48 -0700 | [diff] [blame] | 8575 | dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n", |
| 8576 | vsi->req_queue_pairs, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8577 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8578 | } |
| 8579 | |
| 8580 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8581 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 8582 | * @pf: board private structure |
| 8583 | **/ |
| 8584 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 8585 | { |
| 8586 | i40e_status status; |
| 8587 | bool min_valid, max_valid; |
| 8588 | u32 max_bw, min_bw; |
| 8589 | |
| 8590 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8591 | &min_valid, &max_valid); |
| 8592 | |
| 8593 | if (!status) { |
| 8594 | if (min_valid) |
| 8595 | pf->npar_min_bw = min_bw; |
| 8596 | if (max_valid) |
| 8597 | pf->npar_max_bw = max_bw; |
| 8598 | } |
| 8599 | |
| 8600 | return status; |
| 8601 | } |
| 8602 | |
| 8603 | /** |
| 8604 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 8605 | * @pf: board private structure |
| 8606 | **/ |
| 8607 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 8608 | { |
| 8609 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8610 | i40e_status status; |
| 8611 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8612 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8613 | 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] | 8614 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8615 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 8616 | |
| 8617 | /* Set the new bandwidths */ |
| 8618 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8619 | |
| 8620 | return status; |
| 8621 | } |
| 8622 | |
| 8623 | /** |
| 8624 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 8625 | * @pf: board private structure |
| 8626 | **/ |
| 8627 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 8628 | { |
| 8629 | /* Commit temporary BW setting to permanent NVM image */ |
| 8630 | enum i40e_admin_queue_err last_aq_status; |
| 8631 | i40e_status ret; |
| 8632 | u16 nvm_word; |
| 8633 | |
| 8634 | if (pf->hw.partition_id != 1) { |
| 8635 | dev_info(&pf->pdev->dev, |
| 8636 | "Commit BW only works on partition 1! This is partition %d", |
| 8637 | pf->hw.partition_id); |
| 8638 | ret = I40E_NOT_SUPPORTED; |
| 8639 | goto bw_commit_out; |
| 8640 | } |
| 8641 | |
| 8642 | /* Acquire NVM for read access */ |
| 8643 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8644 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8645 | if (ret) { |
| 8646 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8647 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8648 | i40e_stat_str(&pf->hw, ret), |
| 8649 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8650 | goto bw_commit_out; |
| 8651 | } |
| 8652 | |
| 8653 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8654 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8655 | I40E_SR_NVM_CONTROL_WORD, |
| 8656 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8657 | false, NULL); |
| 8658 | /* Save off last admin queue command status before releasing |
| 8659 | * the NVM |
| 8660 | */ |
| 8661 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8662 | i40e_release_nvm(&pf->hw); |
| 8663 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8664 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8665 | i40e_stat_str(&pf->hw, ret), |
| 8666 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8667 | goto bw_commit_out; |
| 8668 | } |
| 8669 | |
| 8670 | /* Wait a bit for NVM release to complete */ |
| 8671 | msleep(50); |
| 8672 | |
| 8673 | /* Acquire NVM for write access */ |
| 8674 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8675 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8676 | if (ret) { |
| 8677 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8678 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8679 | i40e_stat_str(&pf->hw, ret), |
| 8680 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8681 | goto bw_commit_out; |
| 8682 | } |
| 8683 | /* Write it back out unchanged to initiate update NVM, |
| 8684 | * which will force a write of the shadow (alt) RAM to |
| 8685 | * the NVM - thus storing the bandwidth values permanently. |
| 8686 | */ |
| 8687 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8688 | I40E_SR_NVM_CONTROL_WORD, |
| 8689 | 0x10, sizeof(nvm_word), |
| 8690 | &nvm_word, true, NULL); |
| 8691 | /* Save off last admin queue command status before releasing |
| 8692 | * the NVM |
| 8693 | */ |
| 8694 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8695 | i40e_release_nvm(&pf->hw); |
| 8696 | if (ret) |
| 8697 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8698 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8699 | i40e_stat_str(&pf->hw, ret), |
| 8700 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8701 | bw_commit_out: |
| 8702 | |
| 8703 | return ret; |
| 8704 | } |
| 8705 | |
| 8706 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8707 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8708 | * @pf: board private structure to initialize |
| 8709 | * |
| 8710 | * i40e_sw_init initializes the Adapter private data structure. |
| 8711 | * Fields are initialized based on PCI device information and |
| 8712 | * OS network device settings (MTU size). |
| 8713 | **/ |
| 8714 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8715 | { |
| 8716 | int err = 0; |
| 8717 | int size; |
| 8718 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8719 | /* Set default capability flags */ |
| 8720 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8721 | I40E_FLAG_MSI_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8722 | I40E_FLAG_MSIX_ENABLED; |
| 8723 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8724 | /* Set default ITR */ |
| 8725 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8726 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8727 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8728 | /* Depending on PF configurations, it is possible that the RSS |
| 8729 | * maximum might end up larger than the available queues |
| 8730 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8731 | 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] | 8732 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8733 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8734 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8735 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8736 | if (pf->hw.func_caps.rss) { |
| 8737 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8738 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8739 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8740 | } |
| 8741 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8742 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8743 | 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] | 8744 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8745 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8746 | if (i40e_get_npar_bw_setting(pf)) |
| 8747 | dev_warn(&pf->pdev->dev, |
| 8748 | "Could not get NPAR bw settings\n"); |
| 8749 | else |
| 8750 | dev_info(&pf->pdev->dev, |
| 8751 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 8752 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8753 | } |
| 8754 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8755 | /* FW/NVM is not yet fixed in this regard */ |
| 8756 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8757 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8758 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8759 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8760 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8761 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8762 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8763 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8764 | else |
| 8765 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8766 | pf->fdir_pf_filter_count = |
| 8767 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8768 | pf->hw.fdir_shared_filter_count = |
| 8769 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8770 | } |
| 8771 | |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 8772 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8773 | (((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] | 8774 | (pf->hw.aq.fw_maj_ver < 4))) { |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8775 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8776 | /* No DCB support for FW < v4.33 */ |
| 8777 | pf->flags |= I40E_FLAG_NO_DCB_SUPPORT; |
| 8778 | } |
| 8779 | |
| 8780 | /* Disable FW LLDP if FW < v4.3 */ |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 8781 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8782 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 8783 | (pf->hw.aq.fw_maj_ver < 4))) |
| 8784 | pf->flags |= I40E_FLAG_STOP_FW_LLDP; |
| 8785 | |
| 8786 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
Bimmy Pujari | 6de432c | 2016-11-11 12:39:38 -0800 | [diff] [blame] | 8787 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8788 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 8789 | (pf->hw.aq.fw_maj_ver >= 5))) |
| 8790 | pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8791 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8792 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8793 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8794 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 8795 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8796 | } |
| 8797 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8798 | if (pf->hw.func_caps.iwarp) { |
| 8799 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 8800 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 8801 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 8802 | } |
| 8803 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8804 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 8805 | i40e_init_pf_fcoe(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8806 | |
| 8807 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8808 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 8809 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8810 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 8811 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 8812 | pf->num_req_vfs = min_t(int, |
| 8813 | pf->hw.func_caps.num_vfs, |
| 8814 | I40E_MAX_VF_COUNT); |
| 8815 | } |
| 8816 | #endif /* CONFIG_PCI_IOV */ |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8817 | if (pf->hw.mac.type == I40E_MAC_X722) { |
Joshua Hay | 1d68005 | 2016-12-12 15:44:08 -0800 | [diff] [blame^] | 8818 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE |
| 8819 | | I40E_FLAG_128_QP_RSS_CAPABLE |
| 8820 | | I40E_FLAG_HW_ATR_EVICT_CAPABLE |
| 8821 | | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE |
| 8822 | | I40E_FLAG_WB_ON_ITR_CAPABLE |
| 8823 | | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE |
| 8824 | | I40E_FLAG_NO_PCI_LINK_CHECK |
| 8825 | | I40E_FLAG_USE_SET_LLDP_MIB |
| 8826 | | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE |
| 8827 | | I40E_FLAG_PTP_L4_CAPABLE |
| 8828 | | I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE; |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8829 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 8830 | ((pf->hw.aq.api_maj_ver == 1) && |
| 8831 | (pf->hw.aq.api_min_ver > 4))) { |
| 8832 | /* Supported in FW API version higher than 1.4 */ |
| 8833 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 8834 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
| 8835 | } else { |
| 8836 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8837 | } |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8838 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8839 | pf->eeprom_version = 0xDEAD; |
| 8840 | pf->lan_veb = I40E_NO_VEB; |
| 8841 | pf->lan_vsi = I40E_NO_VSI; |
| 8842 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 8843 | /* By default FW has this off for performance reasons */ |
| 8844 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 8845 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8846 | /* set up queue assignment tracking */ |
| 8847 | size = sizeof(struct i40e_lump_tracking) |
| 8848 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 8849 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 8850 | if (!pf->qp_pile) { |
| 8851 | err = -ENOMEM; |
| 8852 | goto sw_init_done; |
| 8853 | } |
| 8854 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 8855 | pf->qp_pile->search_hint = 0; |
| 8856 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 8857 | pf->tx_timeout_recovery_level = 1; |
| 8858 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8859 | mutex_init(&pf->switch_mutex); |
| 8860 | |
Greg Rose | c668a12 | 2015-02-26 16:10:39 +0000 | [diff] [blame] | 8861 | /* If NPAR is enabled nudge the Tx scheduler */ |
| 8862 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) |
| 8863 | i40e_set_npar_bw_setting(pf); |
| 8864 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8865 | sw_init_done: |
| 8866 | return err; |
| 8867 | } |
| 8868 | |
| 8869 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8870 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 8871 | * @pf: board private structure to initialize |
| 8872 | * @features: the feature set that the stack is suggesting |
| 8873 | * |
| 8874 | * returns a bool to indicate if reset needs to happen |
| 8875 | **/ |
| 8876 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 8877 | { |
| 8878 | bool need_reset = false; |
| 8879 | |
| 8880 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 8881 | * the state changed, we need to reset. |
| 8882 | */ |
| 8883 | if (features & NETIF_F_NTUPLE) { |
| 8884 | /* Enable filters and mark for reset */ |
| 8885 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 8886 | need_reset = true; |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 8887 | /* enable FD_SB only if there is MSI-X vector */ |
| 8888 | if (pf->num_fdsb_msix > 0) |
| 8889 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8890 | } else { |
| 8891 | /* turn off filters, mark for reset and clear SW filter list */ |
| 8892 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8893 | need_reset = true; |
| 8894 | i40e_fdir_filter_exit(pf); |
| 8895 | } |
| 8896 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8897 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 8898 | /* reset fd counters */ |
| 8899 | pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0; |
| 8900 | pf->fdir_pf_active_filters = 0; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8901 | /* if ATR was auto disabled it can be re-enabled. */ |
| 8902 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 8903 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8904 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 8905 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 8906 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
| 8907 | } |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8908 | } |
| 8909 | return need_reset; |
| 8910 | } |
| 8911 | |
| 8912 | /** |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8913 | * i40e_clear_rss_lut - clear the rx hash lookup table |
| 8914 | * @vsi: the VSI being configured |
| 8915 | **/ |
| 8916 | static void i40e_clear_rss_lut(struct i40e_vsi *vsi) |
| 8917 | { |
| 8918 | struct i40e_pf *pf = vsi->back; |
| 8919 | struct i40e_hw *hw = &pf->hw; |
| 8920 | u16 vf_id = vsi->vf_id; |
| 8921 | u8 i; |
| 8922 | |
| 8923 | if (vsi->type == I40E_VSI_MAIN) { |
| 8924 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8925 | wr32(hw, I40E_PFQF_HLUT(i), 0); |
| 8926 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8927 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8928 | i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0); |
| 8929 | } else { |
| 8930 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8931 | } |
| 8932 | } |
| 8933 | |
| 8934 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8935 | * i40e_set_features - set the netdev feature flags |
| 8936 | * @netdev: ptr to the netdev being adjusted |
| 8937 | * @features: the feature set that the stack is suggesting |
| 8938 | **/ |
| 8939 | static int i40e_set_features(struct net_device *netdev, |
| 8940 | netdev_features_t features) |
| 8941 | { |
| 8942 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8943 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8944 | struct i40e_pf *pf = vsi->back; |
| 8945 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8946 | |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8947 | if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH)) |
| 8948 | i40e_pf_config_rss(pf); |
| 8949 | else if (!(features & NETIF_F_RXHASH) && |
| 8950 | netdev->features & NETIF_F_RXHASH) |
| 8951 | i40e_clear_rss_lut(vsi); |
| 8952 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8953 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8954 | i40e_vlan_stripping_enable(vsi); |
| 8955 | else |
| 8956 | i40e_vlan_stripping_disable(vsi); |
| 8957 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8958 | need_reset = i40e_set_ntuple(pf, features); |
| 8959 | |
| 8960 | if (need_reset) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8961 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8962 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8963 | return 0; |
| 8964 | } |
| 8965 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8966 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8967 | * 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] | 8968 | * @pf: board private structure |
| 8969 | * @port: The UDP port to look up |
| 8970 | * |
| 8971 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 8972 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8973 | static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, __be16 port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8974 | { |
| 8975 | u8 i; |
| 8976 | |
| 8977 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8978 | if (pf->udp_ports[i].index == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8979 | return i; |
| 8980 | } |
| 8981 | |
| 8982 | return i; |
| 8983 | } |
| 8984 | |
| 8985 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8986 | * 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] | 8987 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8988 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8989 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8990 | static void i40e_udp_tunnel_add(struct net_device *netdev, |
| 8991 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8992 | { |
| 8993 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8994 | struct i40e_vsi *vsi = np->vsi; |
| 8995 | struct i40e_pf *pf = vsi->back; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8996 | __be16 port = ti->port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8997 | u8 next_idx; |
| 8998 | u8 idx; |
| 8999 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9000 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9001 | |
| 9002 | /* Check if port already exists */ |
| 9003 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9004 | netdev_info(netdev, "port %d already offloaded\n", |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 9005 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9006 | return; |
| 9007 | } |
| 9008 | |
| 9009 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9010 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9011 | |
| 9012 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9013 | netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n", |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9014 | ntohs(port)); |
| 9015 | return; |
| 9016 | } |
| 9017 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9018 | switch (ti->type) { |
| 9019 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9020 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 9021 | break; |
| 9022 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9023 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 9024 | return; |
| 9025 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 9026 | break; |
| 9027 | default: |
| 9028 | return; |
| 9029 | } |
| 9030 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9031 | /* New port: add it and mark its index in the bitmap */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9032 | pf->udp_ports[next_idx].index = port; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9033 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 9034 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9035 | } |
| 9036 | |
| 9037 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9038 | * 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] | 9039 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9040 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9041 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9042 | static void i40e_udp_tunnel_del(struct net_device *netdev, |
| 9043 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9044 | { |
| 9045 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 9046 | struct i40e_vsi *vsi = np->vsi; |
| 9047 | struct i40e_pf *pf = vsi->back; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9048 | __be16 port = ti->port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9049 | u8 idx; |
| 9050 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9051 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9052 | |
| 9053 | /* Check if port already exists */ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9054 | if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS) |
| 9055 | goto not_found; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9056 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9057 | switch (ti->type) { |
| 9058 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9059 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN) |
| 9060 | goto not_found; |
| 9061 | break; |
| 9062 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9063 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE) |
| 9064 | goto not_found; |
| 9065 | break; |
| 9066 | default: |
| 9067 | goto not_found; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9068 | } |
| 9069 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9070 | /* if port exists, set it to 0 (mark for deletion) |
| 9071 | * and make it pending |
| 9072 | */ |
| 9073 | pf->udp_ports[idx].index = 0; |
| 9074 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9075 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 9076 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9077 | return; |
| 9078 | not_found: |
| 9079 | netdev_warn(netdev, "UDP port %d was not found, not deleting\n", |
| 9080 | ntohs(port)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9081 | } |
| 9082 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9083 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 9084 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9085 | { |
| 9086 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 9087 | struct i40e_pf *pf = np->vsi->back; |
| 9088 | struct i40e_hw *hw = &pf->hw; |
| 9089 | |
| 9090 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 9091 | return -EOPNOTSUPP; |
| 9092 | |
| 9093 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 9094 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 9095 | |
| 9096 | return 0; |
| 9097 | } |
| 9098 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 9099 | /** |
| 9100 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 9101 | * @ndm: the input from the stack |
| 9102 | * @tb: pointer to array of nladdr (unused) |
| 9103 | * @dev: the net device pointer |
| 9104 | * @addr: the MAC address entry being added |
| 9105 | * @flags: instructions from stack about fdb operation |
| 9106 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9107 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 9108 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 9109 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9110 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9111 | { |
| 9112 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9113 | struct i40e_pf *pf = np->vsi->back; |
| 9114 | int err = 0; |
| 9115 | |
| 9116 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 9117 | return -EOPNOTSUPP; |
| 9118 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 9119 | if (vid) { |
| 9120 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 9121 | return -EINVAL; |
| 9122 | } |
| 9123 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9124 | /* Hardware does not support aging addresses so if a |
| 9125 | * ndm_state is given only allow permanent addresses |
| 9126 | */ |
| 9127 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 9128 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 9129 | return -EINVAL; |
| 9130 | } |
| 9131 | |
| 9132 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 9133 | err = dev_uc_add_excl(dev, addr); |
| 9134 | else if (is_multicast_ether_addr(addr)) |
| 9135 | err = dev_mc_add_excl(dev, addr); |
| 9136 | else |
| 9137 | err = -EINVAL; |
| 9138 | |
| 9139 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 9140 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 9141 | err = 0; |
| 9142 | |
| 9143 | return err; |
| 9144 | } |
| 9145 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9146 | /** |
| 9147 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 9148 | * @dev: the netdev being configured |
| 9149 | * @nlh: RTNL message |
| 9150 | * |
| 9151 | * Inserts a new hardware bridge if not already created and |
| 9152 | * enables the bridging mode requested (VEB or VEPA). If the |
| 9153 | * hardware bridge has already been inserted and the request |
| 9154 | * is to change the mode then that requires a PF reset to |
| 9155 | * allow rebuild of the components with required hardware |
| 9156 | * bridge mode enabled. |
| 9157 | **/ |
| 9158 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 9159 | struct nlmsghdr *nlh, |
| 9160 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9161 | { |
| 9162 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9163 | struct i40e_vsi *vsi = np->vsi; |
| 9164 | struct i40e_pf *pf = vsi->back; |
| 9165 | struct i40e_veb *veb = NULL; |
| 9166 | struct nlattr *attr, *br_spec; |
| 9167 | int i, rem; |
| 9168 | |
| 9169 | /* Only for PF VSI for now */ |
| 9170 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9171 | return -EOPNOTSUPP; |
| 9172 | |
| 9173 | /* Find the HW bridge for PF VSI */ |
| 9174 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9175 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9176 | veb = pf->veb[i]; |
| 9177 | } |
| 9178 | |
| 9179 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 9180 | |
| 9181 | nla_for_each_nested(attr, br_spec, rem) { |
| 9182 | __u16 mode; |
| 9183 | |
| 9184 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 9185 | continue; |
| 9186 | |
| 9187 | mode = nla_get_u16(attr); |
| 9188 | if ((mode != BRIDGE_MODE_VEPA) && |
| 9189 | (mode != BRIDGE_MODE_VEB)) |
| 9190 | return -EINVAL; |
| 9191 | |
| 9192 | /* Insert a new HW bridge */ |
| 9193 | if (!veb) { |
| 9194 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9195 | vsi->tc_config.enabled_tc); |
| 9196 | if (veb) { |
| 9197 | veb->bridge_mode = mode; |
| 9198 | i40e_config_bridge_mode(veb); |
| 9199 | } else { |
| 9200 | /* No Bridge HW offload available */ |
| 9201 | return -ENOENT; |
| 9202 | } |
| 9203 | break; |
| 9204 | } else if (mode != veb->bridge_mode) { |
| 9205 | /* Existing HW bridge but different mode needs reset */ |
| 9206 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9207 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 9208 | if (mode == BRIDGE_MODE_VEB) |
| 9209 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 9210 | else |
| 9211 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9212 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9213 | break; |
| 9214 | } |
| 9215 | } |
| 9216 | |
| 9217 | return 0; |
| 9218 | } |
| 9219 | |
| 9220 | /** |
| 9221 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 9222 | * @skb: skb buff |
| 9223 | * @pid: process id |
| 9224 | * @seq: RTNL message seq # |
| 9225 | * @dev: the netdev being configured |
| 9226 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 9227 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9228 | * |
| 9229 | * Return the mode in which the hardware bridge is operating in |
| 9230 | * i.e VEB or VEPA. |
| 9231 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9232 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 9233 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 9234 | u32 __always_unused filter_mask, |
| 9235 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9236 | { |
| 9237 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9238 | struct i40e_vsi *vsi = np->vsi; |
| 9239 | struct i40e_pf *pf = vsi->back; |
| 9240 | struct i40e_veb *veb = NULL; |
| 9241 | int i; |
| 9242 | |
| 9243 | /* Only for PF VSI for now */ |
| 9244 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9245 | return -EOPNOTSUPP; |
| 9246 | |
| 9247 | /* Find the HW bridge for the PF VSI */ |
| 9248 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9249 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9250 | veb = pf->veb[i]; |
| 9251 | } |
| 9252 | |
| 9253 | if (!veb) |
| 9254 | return 0; |
| 9255 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9256 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Huaibin Wang | 599b076 | 2016-09-26 09:51:18 +0200 | [diff] [blame] | 9257 | 0, 0, nlflags, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9258 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9259 | |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9260 | /** |
| 9261 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 9262 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 9263 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9264 | * @features: Offload features that the stack believes apply |
| 9265 | **/ |
| 9266 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 9267 | struct net_device *dev, |
| 9268 | netdev_features_t features) |
| 9269 | { |
Alexander Duyck | f114dca | 2016-10-25 16:08:46 -0700 | [diff] [blame] | 9270 | size_t len; |
| 9271 | |
| 9272 | /* No point in doing any of this if neither checksum nor GSO are |
| 9273 | * being requested for this frame. We can rule out both by just |
| 9274 | * checking for CHECKSUM_PARTIAL |
| 9275 | */ |
| 9276 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 9277 | return features; |
| 9278 | |
| 9279 | /* We cannot support GSO if the MSS is going to be less than |
| 9280 | * 64 bytes. If it is then we need to drop support for GSO. |
| 9281 | */ |
| 9282 | if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64)) |
| 9283 | features &= ~NETIF_F_GSO_MASK; |
| 9284 | |
| 9285 | /* MACLEN can support at most 63 words */ |
| 9286 | len = skb_network_header(skb) - skb->data; |
| 9287 | if (len & ~(63 * 2)) |
| 9288 | goto out_err; |
| 9289 | |
| 9290 | /* IPLEN and EIPLEN can support at most 127 dwords */ |
| 9291 | len = skb_transport_header(skb) - skb_network_header(skb); |
| 9292 | if (len & ~(127 * 4)) |
| 9293 | goto out_err; |
| 9294 | |
| 9295 | if (skb->encapsulation) { |
| 9296 | /* L4TUNLEN can support 127 words */ |
| 9297 | len = skb_inner_network_header(skb) - skb_transport_header(skb); |
| 9298 | if (len & ~(127 * 2)) |
| 9299 | goto out_err; |
| 9300 | |
| 9301 | /* IPLEN can support at most 127 dwords */ |
| 9302 | len = skb_inner_transport_header(skb) - |
| 9303 | skb_inner_network_header(skb); |
| 9304 | if (len & ~(127 * 4)) |
| 9305 | goto out_err; |
| 9306 | } |
| 9307 | |
| 9308 | /* No need to validate L4LEN as TCP is the only protocol with a |
| 9309 | * a flexible value and we support all possible values supported |
| 9310 | * by TCP, which is at most 15 dwords |
| 9311 | */ |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9312 | |
| 9313 | return features; |
Alexander Duyck | f114dca | 2016-10-25 16:08:46 -0700 | [diff] [blame] | 9314 | out_err: |
| 9315 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9316 | } |
| 9317 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 9318 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9319 | .ndo_open = i40e_open, |
| 9320 | .ndo_stop = i40e_close, |
| 9321 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 9322 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 9323 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 9324 | .ndo_validate_addr = eth_validate_addr, |
| 9325 | .ndo_set_mac_address = i40e_set_mac, |
| 9326 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 9327 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9328 | .ndo_tx_timeout = i40e_tx_timeout, |
| 9329 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 9330 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 9331 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9332 | .ndo_poll_controller = i40e_netpoll, |
| 9333 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9334 | .ndo_setup_tc = __i40e_setup_tc, |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9335 | #ifdef I40E_FCOE |
| 9336 | .ndo_fcoe_enable = i40e_fcoe_enable, |
| 9337 | .ndo_fcoe_disable = i40e_fcoe_disable, |
| 9338 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9339 | .ndo_set_features = i40e_set_features, |
| 9340 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 9341 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9342 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9343 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 9344 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 9345 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Anjali Singhai Jain | c3bbbd2 | 2016-04-01 03:56:07 -0700 | [diff] [blame] | 9346 | .ndo_set_vf_trust = i40e_ndo_set_vf_trust, |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9347 | .ndo_udp_tunnel_add = i40e_udp_tunnel_add, |
| 9348 | .ndo_udp_tunnel_del = i40e_udp_tunnel_del, |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9349 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9350 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9351 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9352 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 9353 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9354 | }; |
| 9355 | |
| 9356 | /** |
| 9357 | * i40e_config_netdev - Setup the netdev flags |
| 9358 | * @vsi: the VSI being configured |
| 9359 | * |
| 9360 | * Returns 0 on success, negative value on failure |
| 9361 | **/ |
| 9362 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 9363 | { |
| 9364 | struct i40e_pf *pf = vsi->back; |
| 9365 | struct i40e_hw *hw = &pf->hw; |
| 9366 | struct i40e_netdev_priv *np; |
| 9367 | struct net_device *netdev; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 9368 | u8 broadcast[ETH_ALEN]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9369 | u8 mac_addr[ETH_ALEN]; |
| 9370 | int etherdev_size; |
| 9371 | |
| 9372 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9373 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9374 | if (!netdev) |
| 9375 | return -ENOMEM; |
| 9376 | |
| 9377 | vsi->netdev = netdev; |
| 9378 | np = netdev_priv(netdev); |
| 9379 | np->vsi = vsi; |
| 9380 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9381 | netdev->hw_enc_features |= NETIF_F_SG | |
| 9382 | NETIF_F_IP_CSUM | |
| 9383 | NETIF_F_IPV6_CSUM | |
| 9384 | NETIF_F_HIGHDMA | |
| 9385 | NETIF_F_SOFT_FEATURES | |
| 9386 | NETIF_F_TSO | |
| 9387 | NETIF_F_TSO_ECN | |
| 9388 | NETIF_F_TSO6 | |
| 9389 | NETIF_F_GSO_GRE | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9390 | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 9391 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 9392 | NETIF_F_GSO_IPXIP6 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9393 | NETIF_F_GSO_UDP_TUNNEL | |
| 9394 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9395 | NETIF_F_GSO_PARTIAL | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9396 | NETIF_F_SCTP_CRC | |
| 9397 | NETIF_F_RXHASH | |
| 9398 | NETIF_F_RXCSUM | |
Jesse Brandeburg | 5afdaaa | 2015-12-10 11:38:50 -0800 | [diff] [blame] | 9399 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9400 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9401 | if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)) |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9402 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
| 9403 | |
| 9404 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9405 | |
| 9406 | /* record features VLANs can make use of */ |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9407 | netdev->vlan_features |= netdev->hw_enc_features | |
| 9408 | NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9409 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9410 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9411 | netdev->hw_features |= NETIF_F_NTUPLE; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9412 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9413 | netdev->hw_features |= netdev->hw_enc_features | |
| 9414 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9415 | NETIF_F_HW_VLAN_CTAG_RX; |
| 9416 | |
| 9417 | netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9418 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9419 | |
| 9420 | if (vsi->type == I40E_VSI_MAIN) { |
| 9421 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9422 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 9423 | /* The following steps are necessary to prevent reception |
| 9424 | * of tagged packets - some older NVM configurations load a |
| 9425 | * default a MAC-VLAN filter that accepts any tagged packet |
| 9426 | * which must be replaced by a normal filter. |
| 9427 | */ |
| 9428 | i40e_rm_default_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9429 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 9430 | i40e_add_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9431 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9432 | } else { |
| 9433 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 9434 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 9435 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9436 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9437 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9438 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 9439 | i40e_add_mac_filter(vsi, mac_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9440 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9441 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9442 | |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 9443 | /* Add the broadcast filter so that we initially will receive |
| 9444 | * broadcast packets. Note that when a new VLAN is first added the |
| 9445 | * driver will convert all filters marked I40E_VLAN_ANY into VLAN |
| 9446 | * specific filters as part of transitioning into "vlan" operation. |
| 9447 | * When more VLANs are added, the driver will copy each existing MAC |
| 9448 | * filter and add it for the new VLAN. |
| 9449 | * |
| 9450 | * Broadcast filters are handled specially by |
| 9451 | * i40e_sync_filters_subtask, as the driver must to set the broadcast |
| 9452 | * promiscuous bit instead of adding this directly as a MAC/VLAN |
| 9453 | * filter. The subtask will update the correct broadcast promiscuous |
| 9454 | * bits as VLANs become active or inactive. |
| 9455 | */ |
| 9456 | eth_broadcast_addr(broadcast); |
| 9457 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 9569a9a | 2016-11-11 12:39:37 -0800 | [diff] [blame] | 9458 | i40e_add_mac_filter(vsi, broadcast); |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame] | 9459 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 9460 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9461 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9462 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9463 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9464 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9465 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9466 | /* Setup netdev TC information */ |
| 9467 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9468 | |
| 9469 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9470 | netdev->watchdog_timeo = 5 * HZ; |
| 9471 | i40e_set_ethtool_ops(netdev); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9472 | #ifdef I40E_FCOE |
| 9473 | i40e_fcoe_config_netdev(netdev, vsi); |
| 9474 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9475 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 9476 | /* MTU range: 68 - 9706 */ |
| 9477 | netdev->min_mtu = ETH_MIN_MTU; |
| 9478 | netdev->max_mtu = I40E_MAX_RXBUFFER - |
| 9479 | (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
| 9480 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9481 | return 0; |
| 9482 | } |
| 9483 | |
| 9484 | /** |
| 9485 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9486 | * @vsi: the VSI being removed |
| 9487 | * |
| 9488 | * Returns 0 on success, negative value on failure |
| 9489 | **/ |
| 9490 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9491 | { |
| 9492 | /* remove default VSI is not allowed */ |
| 9493 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9494 | return; |
| 9495 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9496 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9497 | } |
| 9498 | |
| 9499 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9500 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9501 | * @vsi: the VSI being queried |
| 9502 | * |
| 9503 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9504 | **/ |
| 9505 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9506 | { |
| 9507 | struct i40e_veb *veb; |
| 9508 | struct i40e_pf *pf = vsi->back; |
| 9509 | |
| 9510 | /* Uplink is not a bridge so default to VEB */ |
| 9511 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9512 | return 1; |
| 9513 | |
| 9514 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9515 | if (!veb) { |
| 9516 | dev_info(&pf->pdev->dev, |
| 9517 | "There is no veb associated with the bridge\n"); |
| 9518 | return -ENOENT; |
| 9519 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9520 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9521 | /* Uplink is a bridge in VEPA mode */ |
| 9522 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9523 | return 0; |
| 9524 | } else { |
| 9525 | /* Uplink is a bridge in VEB mode */ |
| 9526 | return 1; |
| 9527 | } |
| 9528 | |
| 9529 | /* VEPA is now default bridge, so return 0 */ |
| 9530 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9531 | } |
| 9532 | |
| 9533 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9534 | * i40e_add_vsi - Add a VSI to the switch |
| 9535 | * @vsi: the VSI being configured |
| 9536 | * |
| 9537 | * This initializes a VSI context depending on the VSI type to be added and |
| 9538 | * passes it down to the add_vsi aq command. |
| 9539 | **/ |
| 9540 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9541 | { |
| 9542 | int ret = -ENODEV; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9543 | struct i40e_pf *pf = vsi->back; |
| 9544 | struct i40e_hw *hw = &pf->hw; |
| 9545 | struct i40e_vsi_context ctxt; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9546 | struct i40e_mac_filter *f; |
| 9547 | struct hlist_node *h; |
| 9548 | int bkt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9549 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9550 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9551 | int f_count = 0; |
| 9552 | |
| 9553 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9554 | switch (vsi->type) { |
| 9555 | case I40E_VSI_MAIN: |
| 9556 | /* The PF's main VSI is already setup as part of the |
| 9557 | * device initialization, so we'll not bother with |
| 9558 | * the add_vsi call, but we will retrieve the current |
| 9559 | * VSI context. |
| 9560 | */ |
| 9561 | ctxt.seid = pf->main_vsi_seid; |
| 9562 | ctxt.pf_num = pf->hw.pf_id; |
| 9563 | ctxt.vf_num = 0; |
| 9564 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9565 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9566 | if (ret) { |
| 9567 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9568 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9569 | i40e_stat_str(&pf->hw, ret), |
| 9570 | i40e_aq_str(&pf->hw, |
| 9571 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9572 | return -ENOENT; |
| 9573 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9574 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9575 | vsi->info.valid_sections = 0; |
| 9576 | |
| 9577 | vsi->seid = ctxt.seid; |
| 9578 | vsi->id = ctxt.vsi_number; |
| 9579 | |
| 9580 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9581 | |
| 9582 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9583 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9584 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9585 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9586 | ctxt.seid = pf->main_vsi_seid; |
| 9587 | ctxt.pf_num = pf->hw.pf_id; |
| 9588 | ctxt.vf_num = 0; |
| 9589 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9590 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9591 | if (ret) { |
| 9592 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9593 | "update vsi failed, err %s aq_err %s\n", |
| 9594 | i40e_stat_str(&pf->hw, ret), |
| 9595 | i40e_aq_str(&pf->hw, |
| 9596 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9597 | ret = -ENOENT; |
| 9598 | goto err; |
| 9599 | } |
| 9600 | /* update the local VSI info queue map */ |
| 9601 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9602 | vsi->info.valid_sections = 0; |
| 9603 | } else { |
| 9604 | /* Default/Main VSI is only enabled for TC0 |
| 9605 | * reconfigure it to enable all TCs that are |
| 9606 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9607 | * For MFP case the iSCSI PF would use this |
| 9608 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9609 | */ |
| 9610 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9611 | if (ret) { |
| 9612 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9613 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9614 | enabled_tc, |
| 9615 | i40e_stat_str(&pf->hw, ret), |
| 9616 | i40e_aq_str(&pf->hw, |
| 9617 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9618 | ret = -ENOENT; |
| 9619 | } |
| 9620 | } |
| 9621 | break; |
| 9622 | |
| 9623 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9624 | ctxt.pf_num = hw->pf_id; |
| 9625 | ctxt.vf_num = 0; |
| 9626 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9627 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9628 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9629 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9630 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9631 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9632 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9633 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9634 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9635 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9636 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9637 | break; |
| 9638 | |
| 9639 | case I40E_VSI_VMDQ2: |
| 9640 | ctxt.pf_num = hw->pf_id; |
| 9641 | ctxt.vf_num = 0; |
| 9642 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9643 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9644 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9645 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9646 | /* This VSI is connected to VEB so the switch_id |
| 9647 | * should be set to zero by default. |
| 9648 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9649 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9650 | ctxt.info.valid_sections |= |
| 9651 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9652 | ctxt.info.switch_id = |
| 9653 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9654 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9655 | |
| 9656 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9657 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9658 | break; |
| 9659 | |
| 9660 | case I40E_VSI_SRIOV: |
| 9661 | ctxt.pf_num = hw->pf_id; |
| 9662 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9663 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9664 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9665 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9666 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9667 | /* This VSI is connected to VEB so the switch_id |
| 9668 | * should be set to zero by default. |
| 9669 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9670 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9671 | ctxt.info.valid_sections |= |
| 9672 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9673 | ctxt.info.switch_id = |
| 9674 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9675 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9676 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9677 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9678 | ctxt.info.valid_sections |= |
| 9679 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 9680 | ctxt.info.queueing_opt_flags |= |
Ashish Shah | 4b28cdb | 2016-05-03 15:13:17 -0700 | [diff] [blame] | 9681 | (I40E_AQ_VSI_QUE_OPT_TCP_ENA | |
| 9682 | I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9683 | } |
| 9684 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9685 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9686 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9687 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9688 | ctxt.info.valid_sections |= |
| 9689 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9690 | ctxt.info.sec_flags |= |
| 9691 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9692 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9693 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9694 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9695 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9696 | break; |
| 9697 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9698 | #ifdef I40E_FCOE |
| 9699 | case I40E_VSI_FCOE: |
| 9700 | ret = i40e_fcoe_vsi_init(vsi, &ctxt); |
| 9701 | if (ret) { |
| 9702 | dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n"); |
| 9703 | return ret; |
| 9704 | } |
| 9705 | break; |
| 9706 | |
| 9707 | #endif /* I40E_FCOE */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9708 | case I40E_VSI_IWARP: |
| 9709 | /* send down message to iWARP */ |
| 9710 | break; |
| 9711 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9712 | default: |
| 9713 | return -ENODEV; |
| 9714 | } |
| 9715 | |
| 9716 | if (vsi->type != I40E_VSI_MAIN) { |
| 9717 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9718 | if (ret) { |
| 9719 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9720 | "add vsi failed, err %s aq_err %s\n", |
| 9721 | i40e_stat_str(&pf->hw, ret), |
| 9722 | i40e_aq_str(&pf->hw, |
| 9723 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9724 | ret = -ENOENT; |
| 9725 | goto err; |
| 9726 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9727 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9728 | vsi->info.valid_sections = 0; |
| 9729 | vsi->seid = ctxt.seid; |
| 9730 | vsi->id = ctxt.vsi_number; |
| 9731 | } |
| 9732 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9733 | vsi->active_filters = 0; |
| 9734 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9735 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9736 | /* If macvlan filters already exist, force them to get loaded */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9737 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9738 | f->state = I40E_FILTER_NEW; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9739 | f_count++; |
| 9740 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9741 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9742 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9743 | if (f_count) { |
| 9744 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 9745 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 9746 | } |
| 9747 | |
| 9748 | /* Update VSI BW information */ |
| 9749 | ret = i40e_vsi_get_bw_info(vsi); |
| 9750 | if (ret) { |
| 9751 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9752 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 9753 | i40e_stat_str(&pf->hw, ret), |
| 9754 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9755 | /* VSI is already added so not tearing that up */ |
| 9756 | ret = 0; |
| 9757 | } |
| 9758 | |
| 9759 | err: |
| 9760 | return ret; |
| 9761 | } |
| 9762 | |
| 9763 | /** |
| 9764 | * i40e_vsi_release - Delete a VSI and free its resources |
| 9765 | * @vsi: the VSI being removed |
| 9766 | * |
| 9767 | * Returns 0 on success or < 0 on error |
| 9768 | **/ |
| 9769 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 9770 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9771 | struct i40e_mac_filter *f; |
| 9772 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9773 | struct i40e_veb *veb = NULL; |
| 9774 | struct i40e_pf *pf; |
| 9775 | u16 uplink_seid; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9776 | int i, n, bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9777 | |
| 9778 | pf = vsi->back; |
| 9779 | |
| 9780 | /* release of a VEB-owner or last VSI is not allowed */ |
| 9781 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 9782 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 9783 | vsi->seid, vsi->uplink_seid); |
| 9784 | return -ENODEV; |
| 9785 | } |
| 9786 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 9787 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 9788 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 9789 | return -ENODEV; |
| 9790 | } |
| 9791 | |
| 9792 | uplink_seid = vsi->uplink_seid; |
| 9793 | if (vsi->type != I40E_VSI_SRIOV) { |
| 9794 | if (vsi->netdev_registered) { |
| 9795 | vsi->netdev_registered = false; |
| 9796 | if (vsi->netdev) { |
| 9797 | /* results in a call to i40e_close() */ |
| 9798 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9799 | } |
| 9800 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 9801 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9802 | } |
| 9803 | i40e_vsi_disable_irq(vsi); |
| 9804 | } |
| 9805 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9806 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 9807 | |
| 9808 | /* clear the sync flag on all filters */ |
| 9809 | if (vsi->netdev) { |
| 9810 | __dev_uc_unsync(vsi->netdev, NULL); |
| 9811 | __dev_mc_unsync(vsi->netdev, NULL); |
| 9812 | } |
| 9813 | |
| 9814 | /* make sure any remaining filters are marked for deletion */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9815 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 9816 | __i40e_del_filter(vsi, f); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 9817 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9818 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9819 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 9820 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9821 | |
| 9822 | i40e_vsi_delete(vsi); |
| 9823 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 9824 | if (vsi->netdev) { |
| 9825 | free_netdev(vsi->netdev); |
| 9826 | vsi->netdev = NULL; |
| 9827 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9828 | i40e_vsi_clear_rings(vsi); |
| 9829 | i40e_vsi_clear(vsi); |
| 9830 | |
| 9831 | /* If this was the last thing on the VEB, except for the |
| 9832 | * controlling VSI, remove the VEB, which puts the controlling |
| 9833 | * VSI onto the next level down in the switch. |
| 9834 | * |
| 9835 | * Well, okay, there's one more exception here: don't remove |
| 9836 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 9837 | * from up the network stack. |
| 9838 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9839 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9840 | if (pf->vsi[i] && |
| 9841 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 9842 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9843 | n++; /* count the VSIs */ |
| 9844 | } |
| 9845 | } |
| 9846 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9847 | if (!pf->veb[i]) |
| 9848 | continue; |
| 9849 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 9850 | n++; /* count the VEBs */ |
| 9851 | if (pf->veb[i]->seid == uplink_seid) |
| 9852 | veb = pf->veb[i]; |
| 9853 | } |
| 9854 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 9855 | i40e_veb_release(veb); |
| 9856 | |
| 9857 | return 0; |
| 9858 | } |
| 9859 | |
| 9860 | /** |
| 9861 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 9862 | * @vsi: ptr to the VSI |
| 9863 | * |
| 9864 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 9865 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 9866 | * newly allocated VSI. |
| 9867 | * |
| 9868 | * Returns 0 on success or negative on failure |
| 9869 | **/ |
| 9870 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 9871 | { |
| 9872 | int ret = -ENOENT; |
| 9873 | struct i40e_pf *pf = vsi->back; |
| 9874 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9875 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9876 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 9877 | vsi->seid); |
| 9878 | return -EEXIST; |
| 9879 | } |
| 9880 | |
| 9881 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 9882 | 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] | 9883 | vsi->seid, vsi->base_vector); |
| 9884 | return -EEXIST; |
| 9885 | } |
| 9886 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9887 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9888 | if (ret) { |
| 9889 | dev_info(&pf->pdev->dev, |
| 9890 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 9891 | vsi->num_q_vectors, vsi->seid, ret); |
| 9892 | vsi->num_q_vectors = 0; |
| 9893 | goto vector_setup_out; |
| 9894 | } |
| 9895 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 9896 | /* In Legacy mode, we do not have to get any other vector since we |
| 9897 | * piggyback on the misc/ICR0 for queue interrupts. |
| 9898 | */ |
| 9899 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9900 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9901 | if (vsi->num_q_vectors) |
| 9902 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 9903 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9904 | if (vsi->base_vector < 0) { |
| 9905 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9906 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 9907 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9908 | i40e_vsi_free_q_vectors(vsi); |
| 9909 | ret = -ENOENT; |
| 9910 | goto vector_setup_out; |
| 9911 | } |
| 9912 | |
| 9913 | vector_setup_out: |
| 9914 | return ret; |
| 9915 | } |
| 9916 | |
| 9917 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9918 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 9919 | * @vsi: pointer to the vsi. |
| 9920 | * |
| 9921 | * This re-allocates a vsi's queue resources. |
| 9922 | * |
| 9923 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 9924 | * on success, otherwise returns NULL on failure. |
| 9925 | **/ |
| 9926 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 9927 | { |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9928 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9929 | u8 enabled_tc; |
| 9930 | int ret; |
| 9931 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9932 | if (!vsi) |
| 9933 | return NULL; |
| 9934 | |
| 9935 | pf = vsi->back; |
| 9936 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9937 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9938 | i40e_vsi_clear_rings(vsi); |
| 9939 | |
| 9940 | i40e_vsi_free_arrays(vsi, false); |
| 9941 | i40e_set_num_rings_in_vsi(vsi); |
| 9942 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 9943 | if (ret) |
| 9944 | goto err_vsi; |
| 9945 | |
| 9946 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 9947 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9948 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9949 | "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] | 9950 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9951 | goto err_vsi; |
| 9952 | } |
| 9953 | vsi->base_queue = ret; |
| 9954 | |
| 9955 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 9956 | * layout configurations. |
| 9957 | */ |
| 9958 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9959 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9960 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9961 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
Jacob Keller | 1596b5d | 2016-11-08 13:05:15 -0800 | [diff] [blame] | 9962 | if (vsi->type == I40E_VSI_MAIN) |
| 9963 | i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9964 | |
| 9965 | /* assign it some queues */ |
| 9966 | ret = i40e_alloc_rings(vsi); |
| 9967 | if (ret) |
| 9968 | goto err_rings; |
| 9969 | |
| 9970 | /* map all of the rings to the q_vectors */ |
| 9971 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9972 | return vsi; |
| 9973 | |
| 9974 | err_rings: |
| 9975 | i40e_vsi_free_q_vectors(vsi); |
| 9976 | if (vsi->netdev_registered) { |
| 9977 | vsi->netdev_registered = false; |
| 9978 | unregister_netdev(vsi->netdev); |
| 9979 | free_netdev(vsi->netdev); |
| 9980 | vsi->netdev = NULL; |
| 9981 | } |
| 9982 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9983 | err_vsi: |
| 9984 | i40e_vsi_clear(vsi); |
| 9985 | return NULL; |
| 9986 | } |
| 9987 | |
| 9988 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9989 | * i40e_vsi_setup - Set up a VSI by a given type |
| 9990 | * @pf: board private structure |
| 9991 | * @type: VSI type |
| 9992 | * @uplink_seid: the switch element to link to |
| 9993 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 9994 | * |
| 9995 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 9996 | * to the identified VEB. |
| 9997 | * |
| 9998 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 9999 | * success, otherwise returns NULL on failure. |
| 10000 | **/ |
| 10001 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 10002 | u16 uplink_seid, u32 param1) |
| 10003 | { |
| 10004 | struct i40e_vsi *vsi = NULL; |
| 10005 | struct i40e_veb *veb = NULL; |
| 10006 | int ret, i; |
| 10007 | int v_idx; |
| 10008 | |
| 10009 | /* The requested uplink_seid must be either |
| 10010 | * - the PF's port seid |
| 10011 | * no VEB is needed because this is the PF |
| 10012 | * or this is a Flow Director special case VSI |
| 10013 | * - seid of an existing VEB |
| 10014 | * - seid of a VSI that owns an existing VEB |
| 10015 | * - seid of a VSI that doesn't own a VEB |
| 10016 | * a new VEB is created and the VSI becomes the owner |
| 10017 | * - seid of the PF VSI, which is what creates the first VEB |
| 10018 | * this is a special case of the previous |
| 10019 | * |
| 10020 | * Find which uplink_seid we were given and create a new VEB if needed |
| 10021 | */ |
| 10022 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10023 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 10024 | veb = pf->veb[i]; |
| 10025 | break; |
| 10026 | } |
| 10027 | } |
| 10028 | |
| 10029 | if (!veb && uplink_seid != pf->mac_seid) { |
| 10030 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10031 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10032 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 10033 | vsi = pf->vsi[i]; |
| 10034 | break; |
| 10035 | } |
| 10036 | } |
| 10037 | if (!vsi) { |
| 10038 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 10039 | uplink_seid); |
| 10040 | return NULL; |
| 10041 | } |
| 10042 | |
| 10043 | if (vsi->uplink_seid == pf->mac_seid) |
| 10044 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 10045 | vsi->tc_config.enabled_tc); |
| 10046 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 10047 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 10048 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 10049 | if (veb) { |
| 10050 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 10051 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 10052 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 10053 | return NULL; |
| 10054 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 10055 | /* We come up by default in VEPA mode if SRIOV is not |
| 10056 | * already enabled, in which case we can't force VEPA |
| 10057 | * mode. |
| 10058 | */ |
| 10059 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 10060 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 10061 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 10062 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 10063 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 10064 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10065 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 10066 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 10067 | veb = pf->veb[i]; |
| 10068 | } |
| 10069 | if (!veb) { |
| 10070 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 10071 | return NULL; |
| 10072 | } |
| 10073 | |
| 10074 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10075 | uplink_seid = veb->seid; |
| 10076 | } |
| 10077 | |
| 10078 | /* get vsi sw struct */ |
| 10079 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 10080 | if (v_idx < 0) |
| 10081 | goto err_alloc; |
| 10082 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10083 | if (!vsi) |
| 10084 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10085 | vsi->type = type; |
| 10086 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 10087 | |
| 10088 | if (type == I40E_VSI_MAIN) |
| 10089 | pf->lan_vsi = v_idx; |
| 10090 | else if (type == I40E_VSI_SRIOV) |
| 10091 | vsi->vf_id = param1; |
| 10092 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10093 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 10094 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10095 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 10096 | dev_info(&pf->pdev->dev, |
| 10097 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 10098 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10099 | goto err_vsi; |
| 10100 | } |
| 10101 | vsi->base_queue = ret; |
| 10102 | |
| 10103 | /* get a VSI from the hardware */ |
| 10104 | vsi->uplink_seid = uplink_seid; |
| 10105 | ret = i40e_add_vsi(vsi); |
| 10106 | if (ret) |
| 10107 | goto err_vsi; |
| 10108 | |
| 10109 | switch (vsi->type) { |
| 10110 | /* setup the netdev if needed */ |
| 10111 | case I40E_VSI_MAIN: |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10112 | /* Apply relevant filters if a platform-specific mac |
| 10113 | * address was selected. |
| 10114 | */ |
| 10115 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 10116 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 10117 | if (ret) { |
| 10118 | dev_warn(&pf->pdev->dev, |
| 10119 | "could not set up macaddr; err %d\n", |
| 10120 | ret); |
| 10121 | } |
| 10122 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10123 | case I40E_VSI_VMDQ2: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10124 | case I40E_VSI_FCOE: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10125 | ret = i40e_config_netdev(vsi); |
| 10126 | if (ret) |
| 10127 | goto err_netdev; |
| 10128 | ret = register_netdev(vsi->netdev); |
| 10129 | if (ret) |
| 10130 | goto err_netdev; |
| 10131 | vsi->netdev_registered = true; |
| 10132 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10133 | #ifdef CONFIG_I40E_DCB |
| 10134 | /* Setup DCB netlink interface */ |
| 10135 | i40e_dcbnl_setup(vsi); |
| 10136 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10137 | /* fall through */ |
| 10138 | |
| 10139 | case I40E_VSI_FDIR: |
| 10140 | /* set up vectors and rings if needed */ |
| 10141 | ret = i40e_vsi_setup_vectors(vsi); |
| 10142 | if (ret) |
| 10143 | goto err_msix; |
| 10144 | |
| 10145 | ret = i40e_alloc_rings(vsi); |
| 10146 | if (ret) |
| 10147 | goto err_rings; |
| 10148 | |
| 10149 | /* map all of the rings to the q_vectors */ |
| 10150 | i40e_vsi_map_rings_to_vectors(vsi); |
| 10151 | |
| 10152 | i40e_vsi_reset_stats(vsi); |
| 10153 | break; |
| 10154 | |
| 10155 | default: |
| 10156 | /* no netdev or rings for the other VSI types */ |
| 10157 | break; |
| 10158 | } |
| 10159 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 10160 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
| 10161 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 10162 | ret = i40e_vsi_config_rss(vsi); |
| 10163 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10164 | return vsi; |
| 10165 | |
| 10166 | err_rings: |
| 10167 | i40e_vsi_free_q_vectors(vsi); |
| 10168 | err_msix: |
| 10169 | if (vsi->netdev_registered) { |
| 10170 | vsi->netdev_registered = false; |
| 10171 | unregister_netdev(vsi->netdev); |
| 10172 | free_netdev(vsi->netdev); |
| 10173 | vsi->netdev = NULL; |
| 10174 | } |
| 10175 | err_netdev: |
| 10176 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 10177 | err_vsi: |
| 10178 | i40e_vsi_clear(vsi); |
| 10179 | err_alloc: |
| 10180 | return NULL; |
| 10181 | } |
| 10182 | |
| 10183 | /** |
| 10184 | * i40e_veb_get_bw_info - Query VEB BW information |
| 10185 | * @veb: the veb to query |
| 10186 | * |
| 10187 | * Query the Tx scheduler BW configuration data for given VEB |
| 10188 | **/ |
| 10189 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 10190 | { |
| 10191 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 10192 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 10193 | struct i40e_pf *pf = veb->pf; |
| 10194 | struct i40e_hw *hw = &pf->hw; |
| 10195 | u32 tc_bw_max; |
| 10196 | int ret = 0; |
| 10197 | int i; |
| 10198 | |
| 10199 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 10200 | &bw_data, NULL); |
| 10201 | if (ret) { |
| 10202 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10203 | "query veb bw config failed, err %s aq_err %s\n", |
| 10204 | i40e_stat_str(&pf->hw, ret), |
| 10205 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10206 | goto out; |
| 10207 | } |
| 10208 | |
| 10209 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 10210 | &ets_data, NULL); |
| 10211 | if (ret) { |
| 10212 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10213 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 10214 | i40e_stat_str(&pf->hw, ret), |
| 10215 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10216 | goto out; |
| 10217 | } |
| 10218 | |
| 10219 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 10220 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 10221 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 10222 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10223 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 10224 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 10225 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 10226 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 10227 | veb->bw_tc_limit_credits[i] = |
| 10228 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 10229 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 10230 | } |
| 10231 | |
| 10232 | out: |
| 10233 | return ret; |
| 10234 | } |
| 10235 | |
| 10236 | /** |
| 10237 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 10238 | * @pf: board private structure |
| 10239 | * |
| 10240 | * On error: returns error code (negative) |
| 10241 | * On success: returns vsi index in PF (positive) |
| 10242 | **/ |
| 10243 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 10244 | { |
| 10245 | int ret = -ENOENT; |
| 10246 | struct i40e_veb *veb; |
| 10247 | int i; |
| 10248 | |
| 10249 | /* Need to protect the allocation of switch elements at the PF level */ |
| 10250 | mutex_lock(&pf->switch_mutex); |
| 10251 | |
| 10252 | /* VEB list may be fragmented if VEB creation/destruction has |
| 10253 | * been happening. We can afford to do a quick scan to look |
| 10254 | * for any free slots in the list. |
| 10255 | * |
| 10256 | * find next empty veb slot, looping back around if necessary |
| 10257 | */ |
| 10258 | i = 0; |
| 10259 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 10260 | i++; |
| 10261 | if (i >= I40E_MAX_VEB) { |
| 10262 | ret = -ENOMEM; |
| 10263 | goto err_alloc_veb; /* out of VEB slots! */ |
| 10264 | } |
| 10265 | |
| 10266 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 10267 | if (!veb) { |
| 10268 | ret = -ENOMEM; |
| 10269 | goto err_alloc_veb; |
| 10270 | } |
| 10271 | veb->pf = pf; |
| 10272 | veb->idx = i; |
| 10273 | veb->enabled_tc = 1; |
| 10274 | |
| 10275 | pf->veb[i] = veb; |
| 10276 | ret = i; |
| 10277 | err_alloc_veb: |
| 10278 | mutex_unlock(&pf->switch_mutex); |
| 10279 | return ret; |
| 10280 | } |
| 10281 | |
| 10282 | /** |
| 10283 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 10284 | * @branch: where to start deleting |
| 10285 | * |
| 10286 | * This uses recursion to find the tips of the branch to be |
| 10287 | * removed, deleting until we get back to and can delete this VEB. |
| 10288 | **/ |
| 10289 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 10290 | { |
| 10291 | struct i40e_pf *pf = branch->pf; |
| 10292 | u16 branch_seid = branch->seid; |
| 10293 | u16 veb_idx = branch->idx; |
| 10294 | int i; |
| 10295 | |
| 10296 | /* release any VEBs on this VEB - RECURSION */ |
| 10297 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10298 | if (!pf->veb[i]) |
| 10299 | continue; |
| 10300 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 10301 | i40e_switch_branch_release(pf->veb[i]); |
| 10302 | } |
| 10303 | |
| 10304 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 10305 | * |
| 10306 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 10307 | * the VEB itself, so don't use (*branch) after this loop. |
| 10308 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10309 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10310 | if (!pf->vsi[i]) |
| 10311 | continue; |
| 10312 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 10313 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 10314 | i40e_vsi_release(pf->vsi[i]); |
| 10315 | } |
| 10316 | } |
| 10317 | |
| 10318 | /* There's one corner case where the VEB might not have been |
| 10319 | * removed, so double check it here and remove it if needed. |
| 10320 | * This case happens if the veb was created from the debugfs |
| 10321 | * commands and no VSIs were added to it. |
| 10322 | */ |
| 10323 | if (pf->veb[veb_idx]) |
| 10324 | i40e_veb_release(pf->veb[veb_idx]); |
| 10325 | } |
| 10326 | |
| 10327 | /** |
| 10328 | * i40e_veb_clear - remove veb struct |
| 10329 | * @veb: the veb to remove |
| 10330 | **/ |
| 10331 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 10332 | { |
| 10333 | if (!veb) |
| 10334 | return; |
| 10335 | |
| 10336 | if (veb->pf) { |
| 10337 | struct i40e_pf *pf = veb->pf; |
| 10338 | |
| 10339 | mutex_lock(&pf->switch_mutex); |
| 10340 | if (pf->veb[veb->idx] == veb) |
| 10341 | pf->veb[veb->idx] = NULL; |
| 10342 | mutex_unlock(&pf->switch_mutex); |
| 10343 | } |
| 10344 | |
| 10345 | kfree(veb); |
| 10346 | } |
| 10347 | |
| 10348 | /** |
| 10349 | * i40e_veb_release - Delete a VEB and free its resources |
| 10350 | * @veb: the VEB being removed |
| 10351 | **/ |
| 10352 | void i40e_veb_release(struct i40e_veb *veb) |
| 10353 | { |
| 10354 | struct i40e_vsi *vsi = NULL; |
| 10355 | struct i40e_pf *pf; |
| 10356 | int i, n = 0; |
| 10357 | |
| 10358 | pf = veb->pf; |
| 10359 | |
| 10360 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10361 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10362 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 10363 | n++; |
| 10364 | vsi = pf->vsi[i]; |
| 10365 | } |
| 10366 | } |
| 10367 | if (n != 1) { |
| 10368 | dev_info(&pf->pdev->dev, |
| 10369 | "can't remove VEB %d with %d VSIs left\n", |
| 10370 | veb->seid, n); |
| 10371 | return; |
| 10372 | } |
| 10373 | |
| 10374 | /* move the remaining VSI to uplink veb */ |
| 10375 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10376 | if (veb->uplink_seid) { |
| 10377 | vsi->uplink_seid = veb->uplink_seid; |
| 10378 | if (veb->uplink_seid == pf->mac_seid) |
| 10379 | vsi->veb_idx = I40E_NO_VEB; |
| 10380 | else |
| 10381 | vsi->veb_idx = veb->veb_idx; |
| 10382 | } else { |
| 10383 | /* floating VEB */ |
| 10384 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10385 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10386 | } |
| 10387 | |
| 10388 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10389 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10390 | } |
| 10391 | |
| 10392 | /** |
| 10393 | * i40e_add_veb - create the VEB in the switch |
| 10394 | * @veb: the VEB to be instantiated |
| 10395 | * @vsi: the controlling VSI |
| 10396 | **/ |
| 10397 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10398 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10399 | struct i40e_pf *pf = veb->pf; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10400 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10401 | int ret; |
| 10402 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10403 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10404 | veb->enabled_tc, false, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10405 | &veb->seid, enable_stats, NULL); |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10406 | |
| 10407 | /* get a VEB from the hardware */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10408 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10409 | dev_info(&pf->pdev->dev, |
| 10410 | "couldn't add VEB, err %s aq_err %s\n", |
| 10411 | i40e_stat_str(&pf->hw, ret), |
| 10412 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10413 | return -EPERM; |
| 10414 | } |
| 10415 | |
| 10416 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10417 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10418 | &veb->stats_idx, NULL, NULL, NULL); |
| 10419 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10420 | dev_info(&pf->pdev->dev, |
| 10421 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10422 | i40e_stat_str(&pf->hw, ret), |
| 10423 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10424 | return -EPERM; |
| 10425 | } |
| 10426 | ret = i40e_veb_get_bw_info(veb); |
| 10427 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10428 | dev_info(&pf->pdev->dev, |
| 10429 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10430 | i40e_stat_str(&pf->hw, ret), |
| 10431 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10432 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10433 | return -ENOENT; |
| 10434 | } |
| 10435 | |
| 10436 | vsi->uplink_seid = veb->seid; |
| 10437 | vsi->veb_idx = veb->idx; |
| 10438 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10439 | |
| 10440 | return 0; |
| 10441 | } |
| 10442 | |
| 10443 | /** |
| 10444 | * i40e_veb_setup - Set up a VEB |
| 10445 | * @pf: board private structure |
| 10446 | * @flags: VEB setup flags |
| 10447 | * @uplink_seid: the switch element to link to |
| 10448 | * @vsi_seid: the initial VSI seid |
| 10449 | * @enabled_tc: Enabled TC bit-map |
| 10450 | * |
| 10451 | * This allocates the sw VEB structure and links it into the switch |
| 10452 | * It is possible and legal for this to be a duplicate of an already |
| 10453 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10454 | * to be zero, in order to create a floating VEB. |
| 10455 | * |
| 10456 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10457 | * success, otherwise returns NULL on failure. |
| 10458 | **/ |
| 10459 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10460 | u16 uplink_seid, u16 vsi_seid, |
| 10461 | u8 enabled_tc) |
| 10462 | { |
| 10463 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10464 | int vsi_idx, veb_idx; |
| 10465 | int ret; |
| 10466 | |
| 10467 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10468 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10469 | (uplink_seid + vsi_seid != 0)) { |
| 10470 | dev_info(&pf->pdev->dev, |
| 10471 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10472 | uplink_seid, vsi_seid); |
| 10473 | return NULL; |
| 10474 | } |
| 10475 | |
| 10476 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10477 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10478 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10479 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10480 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10481 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10482 | vsi_seid); |
| 10483 | return NULL; |
| 10484 | } |
| 10485 | |
| 10486 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10487 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10488 | if (pf->veb[veb_idx] && |
| 10489 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10490 | uplink_veb = pf->veb[veb_idx]; |
| 10491 | break; |
| 10492 | } |
| 10493 | } |
| 10494 | if (!uplink_veb) { |
| 10495 | dev_info(&pf->pdev->dev, |
| 10496 | "uplink seid %d not found\n", uplink_seid); |
| 10497 | return NULL; |
| 10498 | } |
| 10499 | } |
| 10500 | |
| 10501 | /* get veb sw struct */ |
| 10502 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10503 | if (veb_idx < 0) |
| 10504 | goto err_alloc; |
| 10505 | veb = pf->veb[veb_idx]; |
| 10506 | veb->flags = flags; |
| 10507 | veb->uplink_seid = uplink_seid; |
| 10508 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10509 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10510 | |
| 10511 | /* create the VEB in the switch */ |
| 10512 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10513 | if (ret) |
| 10514 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10515 | if (vsi_idx == pf->lan_vsi) |
| 10516 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10517 | |
| 10518 | return veb; |
| 10519 | |
| 10520 | err_veb: |
| 10521 | i40e_veb_clear(veb); |
| 10522 | err_alloc: |
| 10523 | return NULL; |
| 10524 | } |
| 10525 | |
| 10526 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10527 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10528 | * @pf: board private structure |
| 10529 | * @ele: element we are building info from |
| 10530 | * @num_reported: total number of elements |
| 10531 | * @printconfig: should we print the contents |
| 10532 | * |
| 10533 | * helper function to assist in extracting a few useful SEID values. |
| 10534 | **/ |
| 10535 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10536 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10537 | u16 num_reported, bool printconfig) |
| 10538 | { |
| 10539 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10540 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10541 | u8 element_type = ele->element_type; |
| 10542 | u16 seid = le16_to_cpu(ele->seid); |
| 10543 | |
| 10544 | if (printconfig) |
| 10545 | dev_info(&pf->pdev->dev, |
| 10546 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10547 | element_type, seid, uplink_seid, downlink_seid); |
| 10548 | |
| 10549 | switch (element_type) { |
| 10550 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10551 | pf->mac_seid = seid; |
| 10552 | break; |
| 10553 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10554 | /* Main VEB? */ |
| 10555 | if (uplink_seid != pf->mac_seid) |
| 10556 | break; |
| 10557 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10558 | int v; |
| 10559 | |
| 10560 | /* find existing or else empty VEB */ |
| 10561 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10562 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10563 | pf->lan_veb = v; |
| 10564 | break; |
| 10565 | } |
| 10566 | } |
| 10567 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10568 | v = i40e_veb_mem_alloc(pf); |
| 10569 | if (v < 0) |
| 10570 | break; |
| 10571 | pf->lan_veb = v; |
| 10572 | } |
| 10573 | } |
| 10574 | |
| 10575 | pf->veb[pf->lan_veb]->seid = seid; |
| 10576 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10577 | pf->veb[pf->lan_veb]->pf = pf; |
| 10578 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10579 | break; |
| 10580 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10581 | if (num_reported != 1) |
| 10582 | break; |
| 10583 | /* This is immediately after a reset so we can assume this is |
| 10584 | * the PF's VSI |
| 10585 | */ |
| 10586 | pf->mac_seid = uplink_seid; |
| 10587 | pf->pf_seid = downlink_seid; |
| 10588 | pf->main_vsi_seid = seid; |
| 10589 | if (printconfig) |
| 10590 | dev_info(&pf->pdev->dev, |
| 10591 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10592 | pf->pf_seid, pf->main_vsi_seid); |
| 10593 | break; |
| 10594 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10595 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10596 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10597 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10598 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10599 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10600 | /* ignore these for now */ |
| 10601 | break; |
| 10602 | default: |
| 10603 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10604 | element_type, seid); |
| 10605 | break; |
| 10606 | } |
| 10607 | } |
| 10608 | |
| 10609 | /** |
| 10610 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10611 | * @pf: board private structure |
| 10612 | * @printconfig: should we print the contents |
| 10613 | * |
| 10614 | * Get the current switch configuration from the device and |
| 10615 | * extract a few useful SEID values. |
| 10616 | **/ |
| 10617 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10618 | { |
| 10619 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10620 | u16 next_seid = 0; |
| 10621 | int ret = 0; |
| 10622 | u8 *aq_buf; |
| 10623 | int i; |
| 10624 | |
| 10625 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10626 | if (!aq_buf) |
| 10627 | return -ENOMEM; |
| 10628 | |
| 10629 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10630 | do { |
| 10631 | u16 num_reported, num_total; |
| 10632 | |
| 10633 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10634 | I40E_AQ_LARGE_BUF, |
| 10635 | &next_seid, NULL); |
| 10636 | if (ret) { |
| 10637 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10638 | "get switch config failed err %s aq_err %s\n", |
| 10639 | i40e_stat_str(&pf->hw, ret), |
| 10640 | i40e_aq_str(&pf->hw, |
| 10641 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10642 | kfree(aq_buf); |
| 10643 | return -ENOENT; |
| 10644 | } |
| 10645 | |
| 10646 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10647 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10648 | |
| 10649 | if (printconfig) |
| 10650 | dev_info(&pf->pdev->dev, |
| 10651 | "header: %d reported %d total\n", |
| 10652 | num_reported, num_total); |
| 10653 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10654 | for (i = 0; i < num_reported; i++) { |
| 10655 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10656 | &sw_config->element[i]; |
| 10657 | |
| 10658 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10659 | printconfig); |
| 10660 | } |
| 10661 | } while (next_seid != 0); |
| 10662 | |
| 10663 | kfree(aq_buf); |
| 10664 | return ret; |
| 10665 | } |
| 10666 | |
| 10667 | /** |
| 10668 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10669 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10670 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10671 | * |
| 10672 | * Returns 0 on success, negative value on failure |
| 10673 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10674 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10675 | { |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10676 | u16 flags = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10677 | int ret; |
| 10678 | |
| 10679 | /* find out what's out there already */ |
| 10680 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10681 | if (ret) { |
| 10682 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10683 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10684 | i40e_stat_str(&pf->hw, ret), |
| 10685 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10686 | return ret; |
| 10687 | } |
| 10688 | i40e_pf_reset_stats(pf); |
| 10689 | |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10690 | /* set the switch config bit for the whole device to |
| 10691 | * support limited promisc or true promisc |
| 10692 | * when user requests promisc. The default is limited |
| 10693 | * promisc. |
| 10694 | */ |
| 10695 | |
| 10696 | if ((pf->hw.pf_id == 0) && |
| 10697 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) |
| 10698 | flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10699 | |
| 10700 | if (pf->hw.pf_id == 0) { |
| 10701 | u16 valid_flags; |
| 10702 | |
| 10703 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10704 | ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, |
| 10705 | NULL); |
| 10706 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { |
| 10707 | dev_info(&pf->pdev->dev, |
| 10708 | "couldn't set switch config bits, err %s aq_err %s\n", |
| 10709 | i40e_stat_str(&pf->hw, ret), |
| 10710 | i40e_aq_str(&pf->hw, |
| 10711 | pf->hw.aq.asq_last_status)); |
| 10712 | /* not a fatal problem, just keep going */ |
| 10713 | } |
| 10714 | } |
| 10715 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10716 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10717 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10718 | struct i40e_vsi *vsi = NULL; |
| 10719 | u16 uplink_seid; |
| 10720 | |
| 10721 | /* Set up the PF VSI associated with the PF's main VSI |
| 10722 | * that is already in the HW switch |
| 10723 | */ |
| 10724 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10725 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10726 | else |
| 10727 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10728 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10729 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10730 | else if (reinit) |
| 10731 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10732 | if (!vsi) { |
| 10733 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10734 | i40e_fdir_teardown(pf); |
| 10735 | return -EAGAIN; |
| 10736 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10737 | } else { |
| 10738 | /* force a reset of TC and queue layout configurations */ |
| 10739 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10740 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10741 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10742 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10743 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10744 | } |
| 10745 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 10746 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10747 | i40e_fdir_sb_setup(pf); |
| 10748 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10749 | /* Setup static PF queue filter control settings */ |
| 10750 | ret = i40e_setup_pf_filter_control(pf); |
| 10751 | if (ret) { |
| 10752 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 10753 | ret); |
| 10754 | /* Failure here should not stop continuing other steps */ |
| 10755 | } |
| 10756 | |
| 10757 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 10758 | * the hash |
| 10759 | */ |
| 10760 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 10761 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10762 | |
| 10763 | /* fill in link information and enable LSE reporting */ |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 10764 | i40e_update_link_info(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10765 | i40e_link_event(pf); |
| 10766 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10767 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10768 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 10769 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10770 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10771 | i40e_ptp_init(pf); |
| 10772 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10773 | return ret; |
| 10774 | } |
| 10775 | |
| 10776 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10777 | * i40e_determine_queue_usage - Work out queue distribution |
| 10778 | * @pf: board private structure |
| 10779 | **/ |
| 10780 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 10781 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10782 | int queues_left; |
| 10783 | |
| 10784 | pf->num_lan_qps = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10785 | #ifdef I40E_FCOE |
| 10786 | pf->num_fcoe_qps = 0; |
| 10787 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10788 | |
| 10789 | /* Find the max queues to be put into basic use. We'll always be |
| 10790 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 10791 | * big RSS set. |
| 10792 | */ |
| 10793 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 10794 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10795 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10796 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10797 | /* one qp for PF, no queues for anything else */ |
| 10798 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10799 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10800 | |
| 10801 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10802 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10803 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10804 | #ifdef I40E_FCOE |
| 10805 | I40E_FLAG_FCOE_ENABLED | |
| 10806 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10807 | I40E_FLAG_FD_SB_ENABLED | |
| 10808 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10809 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 10810 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10811 | I40E_FLAG_SRIOV_ENABLED | |
| 10812 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10813 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 10814 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 10815 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10816 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10817 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10818 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10819 | queues_left -= pf->num_lan_qps; |
| 10820 | |
| 10821 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10822 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10823 | #ifdef I40E_FCOE |
| 10824 | I40E_FLAG_FCOE_ENABLED | |
| 10825 | #endif |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10826 | I40E_FLAG_FD_SB_ENABLED | |
| 10827 | I40E_FLAG_FD_ATR_ENABLED | |
| 10828 | I40E_FLAG_DCB_ENABLED | |
| 10829 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10830 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10831 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10832 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10833 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 10834 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | |
| 10835 | I40E_FLAG_DCB_ENABLED); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10836 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 10837 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 10838 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 10839 | num_online_cpus()); |
| 10840 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 10841 | pf->hw.func_caps.num_tx_qp); |
| 10842 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10843 | queues_left -= pf->num_lan_qps; |
| 10844 | } |
| 10845 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10846 | #ifdef I40E_FCOE |
| 10847 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 10848 | if (I40E_DEFAULT_FCOE <= queues_left) { |
| 10849 | pf->num_fcoe_qps = I40E_DEFAULT_FCOE; |
| 10850 | } else if (I40E_MINIMUM_FCOE <= queues_left) { |
| 10851 | pf->num_fcoe_qps = I40E_MINIMUM_FCOE; |
| 10852 | } else { |
| 10853 | pf->num_fcoe_qps = 0; |
| 10854 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 10855 | dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n"); |
| 10856 | } |
| 10857 | |
| 10858 | queues_left -= pf->num_fcoe_qps; |
| 10859 | } |
| 10860 | |
| 10861 | #endif |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10862 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10863 | if (queues_left > 1) { |
| 10864 | queues_left -= 1; /* save 1 queue for FD */ |
| 10865 | } else { |
| 10866 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 10867 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 10868 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10869 | } |
| 10870 | |
| 10871 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10872 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10873 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 10874 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10875 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 10876 | } |
| 10877 | |
| 10878 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 10879 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 10880 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 10881 | (queues_left / pf->num_vmdq_qps)); |
| 10882 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 10883 | } |
| 10884 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10885 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10886 | dev_dbg(&pf->pdev->dev, |
| 10887 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 10888 | pf->hw.func_caps.num_tx_qp, |
| 10889 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10890 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 10891 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 10892 | queues_left); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10893 | #ifdef I40E_FCOE |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10894 | dev_dbg(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10895 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10896 | } |
| 10897 | |
| 10898 | /** |
| 10899 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 10900 | * @pf: PF to be setup |
| 10901 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10902 | * 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] | 10903 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 10904 | * based filter sizes required for them. It also enables Flow director, |
| 10905 | * ethertype and macvlan type filter settings for the pf. |
| 10906 | * |
| 10907 | * Returns 0 on success, negative on failure |
| 10908 | **/ |
| 10909 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 10910 | { |
| 10911 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 10912 | |
| 10913 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 10914 | |
| 10915 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10916 | 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] | 10917 | settings->enable_fdir = true; |
| 10918 | |
| 10919 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 10920 | settings->enable_ethtype = true; |
| 10921 | settings->enable_macvlan = true; |
| 10922 | |
| 10923 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 10924 | return -ENOENT; |
| 10925 | |
| 10926 | return 0; |
| 10927 | } |
| 10928 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10929 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10930 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10931 | static void i40e_print_features(struct i40e_pf *pf) |
| 10932 | { |
| 10933 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10934 | char *buf; |
| 10935 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10936 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10937 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 10938 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10939 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10940 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10941 | 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] | 10942 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10943 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10944 | #endif |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10945 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10946 | pf->hw.func_caps.num_vsis, |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10947 | pf->vsi[pf->lan_vsi]->num_queue_pairs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10948 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10949 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10950 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10951 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10952 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10953 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 10954 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10955 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10956 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10957 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10958 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10959 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10960 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10961 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10962 | #ifdef I40E_FCOE |
| 10963 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10964 | i += snprintf(&buf[i], REMAIN(i), " FCOE"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10965 | #endif |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10966 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10967 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10968 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10969 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10970 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10971 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 10972 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10973 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10974 | } |
| 10975 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10976 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10977 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
| 10978 | * |
| 10979 | * @pdev: PCI device information struct |
| 10980 | * @pf: board private structure |
| 10981 | * |
| 10982 | * Look up the MAC address in Open Firmware on systems that support it, |
| 10983 | * and use IDPROM on SPARC if no OF address is found. On return, the |
| 10984 | * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value |
| 10985 | * has been selected. |
| 10986 | **/ |
| 10987 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 10988 | { |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10989 | pf->flags &= ~I40E_FLAG_PF_MAC; |
Sowmini Varadhan | ba94272 | 2016-01-12 19:32:31 -0800 | [diff] [blame] | 10990 | if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10991 | pf->flags |= I40E_FLAG_PF_MAC; |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10992 | } |
| 10993 | |
| 10994 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10995 | * i40e_probe - Device initialization routine |
| 10996 | * @pdev: PCI device information struct |
| 10997 | * @ent: entry in i40e_pci_tbl |
| 10998 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10999 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 11000 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11001 | * and a hardware reset occur. |
| 11002 | * |
| 11003 | * Returns 0 on success, negative on failure |
| 11004 | **/ |
| 11005 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 11006 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11007 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11008 | struct i40e_pf *pf; |
| 11009 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11010 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11011 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11012 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 11013 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11014 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11015 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11016 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11017 | |
| 11018 | err = pci_enable_device_mem(pdev); |
| 11019 | if (err) |
| 11020 | return err; |
| 11021 | |
| 11022 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 11023 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 11024 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 11025 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 11026 | if (err) { |
| 11027 | dev_err(&pdev->dev, |
| 11028 | "DMA configuration failed: 0x%x\n", err); |
| 11029 | goto err_dma; |
| 11030 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11031 | } |
| 11032 | |
| 11033 | /* set up pci connections */ |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11034 | err = pci_request_mem_regions(pdev, i40e_driver_name); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11035 | if (err) { |
| 11036 | dev_info(&pdev->dev, |
| 11037 | "pci_request_selected_regions failed %d\n", err); |
| 11038 | goto err_pci_reg; |
| 11039 | } |
| 11040 | |
| 11041 | pci_enable_pcie_error_reporting(pdev); |
| 11042 | pci_set_master(pdev); |
| 11043 | |
| 11044 | /* Now that we have a PCI connection, we need to do the |
| 11045 | * low level device setup. This is primarily setting up |
| 11046 | * the Admin Queue structures and then querying for the |
| 11047 | * device's current profile information. |
| 11048 | */ |
| 11049 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 11050 | if (!pf) { |
| 11051 | err = -ENOMEM; |
| 11052 | goto err_pf_alloc; |
| 11053 | } |
| 11054 | pf->next_vsi = 0; |
| 11055 | pf->pdev = pdev; |
| 11056 | set_bit(__I40E_DOWN, &pf->state); |
| 11057 | |
| 11058 | hw = &pf->hw; |
| 11059 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 11060 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 11061 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 11062 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 11063 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 11064 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11065 | if (!hw->hw_addr) { |
| 11066 | err = -EIO; |
| 11067 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 11068 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 11069 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11070 | goto err_ioremap; |
| 11071 | } |
| 11072 | hw->vendor_id = pdev->vendor; |
| 11073 | hw->device_id = pdev->device; |
| 11074 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 11075 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 11076 | hw->subsystem_device_id = pdev->subsystem_device; |
| 11077 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 11078 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Sudheer Mogilappagari | b3f028f | 2017-02-09 23:58:22 -0800 | [diff] [blame] | 11079 | hw->bus.bus_id = pdev->bus->number; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11080 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11081 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 11082 | /* set up the locks for the AQ, do this only once in probe |
| 11083 | * and destroy them only once in remove |
| 11084 | */ |
| 11085 | mutex_init(&hw->aq.asq_mutex); |
| 11086 | mutex_init(&hw->aq.arq_mutex); |
| 11087 | |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 11088 | pf->msg_enable = netif_msg_init(debug, |
| 11089 | NETIF_MSG_DRV | |
| 11090 | NETIF_MSG_PROBE | |
| 11091 | NETIF_MSG_LINK); |
| 11092 | if (debug < -1) |
| 11093 | pf->hw.debug_mask = debug; |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 11094 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 11095 | /* do a special CORER for clearing PXE mode once at init */ |
| 11096 | if (hw->revision_id == 0 && |
| 11097 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 11098 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 11099 | i40e_flush(hw); |
| 11100 | msleep(200); |
| 11101 | pf->corer_count++; |
| 11102 | |
| 11103 | i40e_clear_pxe_mode(hw); |
| 11104 | } |
| 11105 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11106 | /* 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] | 11107 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11108 | err = i40e_pf_reset(hw); |
| 11109 | if (err) { |
| 11110 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 11111 | goto err_pf_reset; |
| 11112 | } |
| 11113 | pf->pfr_count++; |
| 11114 | |
| 11115 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 11116 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 11117 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 11118 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 11119 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 11120 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 11121 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 11122 | "%s-%s:misc", |
| 11123 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11124 | |
| 11125 | err = i40e_init_shared_code(hw); |
| 11126 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 11127 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 11128 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11129 | goto err_pf_reset; |
| 11130 | } |
| 11131 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 11132 | /* set up a default setting for link flow control */ |
| 11133 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 11134 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11135 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 11136 | if (err) { |
| 11137 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 11138 | dev_info(&pdev->dev, |
| 11139 | "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"); |
| 11140 | else |
| 11141 | dev_info(&pdev->dev, |
| 11142 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 11143 | |
| 11144 | goto err_pf_reset; |
| 11145 | } |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 11146 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 11147 | /* provide nvm, fw, api versions */ |
| 11148 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 11149 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 11150 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 11151 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 11152 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 11153 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 11154 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 11155 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 11156 | "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"); |
| 11157 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 11158 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 11159 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 11160 | "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] | 11161 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11162 | i40e_verify_eeprom(pf); |
| 11163 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 11164 | /* Rev 0 hardware was never productized */ |
| 11165 | if (hw->revision_id < 1) |
| 11166 | 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"); |
| 11167 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 11168 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11169 | err = i40e_get_capabilities(pf); |
| 11170 | if (err) |
| 11171 | goto err_adminq_setup; |
| 11172 | |
| 11173 | err = i40e_sw_init(pf); |
| 11174 | if (err) { |
| 11175 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 11176 | goto err_sw_init; |
| 11177 | } |
| 11178 | |
| 11179 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 11180 | hw->func_caps.num_rx_qp, |
| 11181 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 11182 | if (err) { |
| 11183 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 11184 | goto err_init_lan_hmc; |
| 11185 | } |
| 11186 | |
| 11187 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 11188 | if (err) { |
| 11189 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 11190 | err = -ENOENT; |
| 11191 | goto err_configure_lan_hmc; |
| 11192 | } |
| 11193 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 11194 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 11195 | * Ignore error return codes because if it was already disabled via |
| 11196 | * hardware settings this will fail |
| 11197 | */ |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 11198 | if (pf->flags & I40E_FLAG_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 11199 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 11200 | i40e_aq_stop_lldp(hw, true, NULL); |
| 11201 | } |
| 11202 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11203 | i40e_get_mac_addr(hw, hw->mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 11204 | /* allow a platform config to override the HW addr */ |
| 11205 | i40e_get_platform_mac_addr(pdev, pf); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 11206 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11207 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 11208 | err = -EIO; |
| 11209 | goto err_mac_addr; |
| 11210 | } |
| 11211 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 11212 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 11213 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 11214 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 11215 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11216 | #ifdef I40E_FCOE |
| 11217 | err = i40e_get_san_mac_addr(hw, hw->mac.san_addr); |
| 11218 | if (err) |
| 11219 | dev_info(&pdev->dev, |
| 11220 | "(non-fatal) SAN MAC retrieval failed: %d\n", err); |
| 11221 | if (!is_valid_ether_addr(hw->mac.san_addr)) { |
| 11222 | dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n", |
| 11223 | hw->mac.san_addr); |
| 11224 | ether_addr_copy(hw->mac.san_addr, hw->mac.addr); |
| 11225 | } |
| 11226 | dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr); |
| 11227 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11228 | |
| 11229 | pci_set_drvdata(pdev, pf); |
| 11230 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11231 | #ifdef CONFIG_I40E_DCB |
| 11232 | err = i40e_init_pf_dcb(pf); |
| 11233 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 11234 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
David Ertman | c17ef43 | 2016-09-30 01:36:21 -0700 | [diff] [blame] | 11235 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED); |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 11236 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11237 | } |
| 11238 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11239 | |
| 11240 | /* set up periodic task facility */ |
| 11241 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 11242 | pf->service_timer_period = HZ; |
| 11243 | |
| 11244 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 11245 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 11246 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11247 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11248 | /* NVM bit on means WoL disabled for the port */ |
| 11249 | 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] | 11250 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11251 | pf->wol_en = false; |
| 11252 | else |
| 11253 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11254 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 11255 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11256 | /* set up the main switch operations */ |
| 11257 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 11258 | err = i40e_init_interrupt_scheme(pf); |
| 11259 | if (err) |
| 11260 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11261 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11262 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 11263 | * to us; HW supports far more and we share the remaining pool with |
| 11264 | * the other PFs. We allocate space for more than the guarantee with |
| 11265 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11266 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11267 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 11268 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 11269 | else |
| 11270 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 11271 | |
| 11272 | /* 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] | 11273 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 11274 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11275 | if (!pf->vsi) { |
| 11276 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11277 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11278 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11279 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 11280 | #ifdef CONFIG_PCI_IOV |
| 11281 | /* prep for VF support */ |
| 11282 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 11283 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11284 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 11285 | if (pci_num_vf(pdev)) |
| 11286 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 11287 | } |
| 11288 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11289 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11290 | if (err) { |
| 11291 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 11292 | goto err_vsis; |
| 11293 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11294 | |
| 11295 | /* Make sure flow control is set according to current settings */ |
| 11296 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 11297 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 11298 | dev_dbg(&pf->pdev->dev, |
| 11299 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 11300 | i40e_stat_str(hw, err), |
| 11301 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11302 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 11303 | dev_dbg(&pf->pdev->dev, |
| 11304 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 11305 | i40e_stat_str(hw, err), |
| 11306 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11307 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 11308 | dev_dbg(&pf->pdev->dev, |
| 11309 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 11310 | i40e_stat_str(hw, err), |
| 11311 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11312 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11313 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11314 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11315 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 11316 | i40e_vsi_open(pf->vsi[i]); |
| 11317 | break; |
| 11318 | } |
| 11319 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11320 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11321 | /* The driver only wants link up/down and module qualification |
| 11322 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11323 | */ |
| 11324 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11325 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 11326 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11327 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11328 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11329 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 11330 | i40e_stat_str(&pf->hw, err), |
| 11331 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11332 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11333 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 11334 | * of TSO, so that we avoid the MDD being fired and causing |
| 11335 | * a reset in the case of small MSS+TSO. |
| 11336 | */ |
| 11337 | val = rd32(hw, I40E_REG_MSS); |
| 11338 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 11339 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 11340 | val |= I40E_64BYTE_MSS; |
| 11341 | wr32(hw, I40E_REG_MSS, val); |
| 11342 | } |
| 11343 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 11344 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 11345 | msleep(75); |
| 11346 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 11347 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11348 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 11349 | i40e_stat_str(&pf->hw, err), |
| 11350 | i40e_aq_str(&pf->hw, |
| 11351 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 11352 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11353 | /* The main driver is (mostly) up and happy. We need to set this state |
| 11354 | * before setting up the misc vector or we get a race and the vector |
| 11355 | * ends up disabled forever. |
| 11356 | */ |
| 11357 | clear_bit(__I40E_DOWN, &pf->state); |
| 11358 | |
| 11359 | /* In case of MSIX we are going to setup the misc vector right here |
| 11360 | * to handle admin queue events etc. In case of legacy and MSI |
| 11361 | * the misc functionality and queue processing is combined in |
| 11362 | * the same vector and that gets setup at open. |
| 11363 | */ |
| 11364 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 11365 | err = i40e_setup_misc_vector(pf); |
| 11366 | if (err) { |
| 11367 | dev_info(&pdev->dev, |
| 11368 | "setup of misc vector failed: %d\n", err); |
| 11369 | goto err_vsis; |
| 11370 | } |
| 11371 | } |
| 11372 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11373 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11374 | /* prep for VF support */ |
| 11375 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11376 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11377 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11378 | /* disable link interrupts for VFs */ |
| 11379 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11380 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11381 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11382 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11383 | |
| 11384 | if (pci_num_vf(pdev)) { |
| 11385 | dev_info(&pdev->dev, |
| 11386 | "Active VFs found, allocating resources.\n"); |
| 11387 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11388 | if (err) |
| 11389 | dev_info(&pdev->dev, |
| 11390 | "Error %d allocating resources for existing VFs\n", |
| 11391 | err); |
| 11392 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11393 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11394 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11395 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11396 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11397 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11398 | pf->num_iwarp_msix, |
| 11399 | I40E_IWARP_IRQ_PILE_ID); |
| 11400 | if (pf->iwarp_base_vector < 0) { |
| 11401 | dev_info(&pdev->dev, |
| 11402 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 11403 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 11404 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 11405 | } |
| 11406 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11407 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11408 | i40e_dbg_pf_init(pf); |
| 11409 | |
| 11410 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11411 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11412 | |
| 11413 | /* since everything's happy, start the service_task timer */ |
| 11414 | mod_timer(&pf->service_timer, |
| 11415 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11416 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11417 | /* add this PF to client device list and launch a client service task */ |
| 11418 | err = i40e_lan_add_device(pf); |
| 11419 | if (err) |
| 11420 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 11421 | err); |
| 11422 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11423 | #ifdef I40E_FCOE |
| 11424 | /* create FCoE interface */ |
| 11425 | i40e_fcoe_vsi_setup(pf); |
| 11426 | |
| 11427 | #endif |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11428 | #define PCI_SPEED_SIZE 8 |
| 11429 | #define PCI_WIDTH_SIZE 8 |
| 11430 | /* Devices on the IOSF bus do not have this information |
| 11431 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11432 | * checking them. |
| 11433 | */ |
| 11434 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { |
| 11435 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11436 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11437 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11438 | /* Get the negotiated link width and speed from PCI config |
| 11439 | * space |
| 11440 | */ |
| 11441 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11442 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11443 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11444 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11445 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11446 | switch (hw->bus.speed) { |
| 11447 | case i40e_bus_speed_8000: |
| 11448 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11449 | case i40e_bus_speed_5000: |
| 11450 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11451 | case i40e_bus_speed_2500: |
| 11452 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11453 | default: |
| 11454 | break; |
| 11455 | } |
| 11456 | switch (hw->bus.width) { |
| 11457 | case i40e_bus_width_pcie_x8: |
| 11458 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11459 | case i40e_bus_width_pcie_x4: |
| 11460 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11461 | case i40e_bus_width_pcie_x2: |
| 11462 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11463 | case i40e_bus_width_pcie_x1: |
| 11464 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11465 | default: |
| 11466 | break; |
| 11467 | } |
| 11468 | |
| 11469 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11470 | speed, width); |
| 11471 | |
| 11472 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11473 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11474 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11475 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11476 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11477 | } |
| 11478 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11479 | /* get the requested speeds from the fw */ |
| 11480 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11481 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11482 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11483 | i40e_stat_str(&pf->hw, err), |
| 11484 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11485 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11486 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11487 | /* get the supported phy types from the fw */ |
| 11488 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11489 | if (err) |
| 11490 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11491 | i40e_stat_str(&pf->hw, err), |
| 11492 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11493 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11494 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11495 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11496 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11497 | * PF/VF VSIs. |
| 11498 | * The FW can still send Flow control frames if enabled. |
| 11499 | */ |
| 11500 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11501 | pf->main_vsi_seid); |
| 11502 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 11503 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
Henry Tieman | 4f9b430 | 2016-11-08 13:05:18 -0800 | [diff] [blame] | 11504 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
| 11505 | pf->flags |= I40E_FLAG_PHY_CONTROLS_LEDS; |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 11506 | if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722) |
| 11507 | pf->flags |= I40E_FLAG_HAVE_CRT_RETIMER; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11508 | /* print a string summarizing features */ |
| 11509 | i40e_print_features(pf); |
| 11510 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11511 | return 0; |
| 11512 | |
| 11513 | /* Unwind what we've done if something failed in the setup */ |
| 11514 | err_vsis: |
| 11515 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11516 | i40e_clear_interrupt_scheme(pf); |
| 11517 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11518 | err_switch_setup: |
| 11519 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11520 | del_timer_sync(&pf->service_timer); |
| 11521 | err_mac_addr: |
| 11522 | err_configure_lan_hmc: |
| 11523 | (void)i40e_shutdown_lan_hmc(hw); |
| 11524 | err_init_lan_hmc: |
| 11525 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11526 | err_sw_init: |
| 11527 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11528 | err_pf_reset: |
| 11529 | iounmap(hw->hw_addr); |
| 11530 | err_ioremap: |
| 11531 | kfree(pf); |
| 11532 | err_pf_alloc: |
| 11533 | pci_disable_pcie_error_reporting(pdev); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11534 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11535 | err_pci_reg: |
| 11536 | err_dma: |
| 11537 | pci_disable_device(pdev); |
| 11538 | return err; |
| 11539 | } |
| 11540 | |
| 11541 | /** |
| 11542 | * i40e_remove - Device removal routine |
| 11543 | * @pdev: PCI device information struct |
| 11544 | * |
| 11545 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11546 | * that is should release a PCI device. This could be caused by a |
| 11547 | * Hot-Plug event, or because the driver is going to be removed from |
| 11548 | * memory. |
| 11549 | **/ |
| 11550 | static void i40e_remove(struct pci_dev *pdev) |
| 11551 | { |
| 11552 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11553 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11554 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11555 | int i; |
| 11556 | |
| 11557 | i40e_dbg_pf_exit(pf); |
| 11558 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11559 | i40e_ptp_stop(pf); |
| 11560 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11561 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 11562 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 11563 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11564 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11565 | /* no more scheduling of any task */ |
Pandi Kumar Maharajan | a4618ec | 2016-02-18 09:19:25 -0800 | [diff] [blame] | 11566 | set_bit(__I40E_SUSPENDED, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11567 | set_bit(__I40E_DOWN, &pf->state); |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 11568 | if (pf->service_timer.data) |
| 11569 | del_timer_sync(&pf->service_timer); |
| 11570 | if (pf->service_task.func) |
| 11571 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11572 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11573 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11574 | i40e_free_vfs(pf); |
| 11575 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11576 | } |
| 11577 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11578 | i40e_fdir_teardown(pf); |
| 11579 | |
| 11580 | /* If there is a switch structure or any orphans, remove them. |
| 11581 | * This will leave only the PF's VSI remaining. |
| 11582 | */ |
| 11583 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11584 | if (!pf->veb[i]) |
| 11585 | continue; |
| 11586 | |
| 11587 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11588 | pf->veb[i]->uplink_seid == 0) |
| 11589 | i40e_switch_branch_release(pf->veb[i]); |
| 11590 | } |
| 11591 | |
| 11592 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11593 | * adminq and hmc. |
| 11594 | */ |
| 11595 | if (pf->vsi[pf->lan_vsi]) |
| 11596 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11597 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11598 | /* remove attached clients */ |
| 11599 | ret_code = i40e_lan_del_device(pf); |
| 11600 | if (ret_code) { |
| 11601 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 11602 | ret_code); |
| 11603 | } |
| 11604 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11605 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11606 | if (hw->hmc.hmc_obj) { |
| 11607 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11608 | if (ret_code) |
| 11609 | dev_warn(&pdev->dev, |
| 11610 | "Failed to destroy the HMC resources: %d\n", |
| 11611 | ret_code); |
| 11612 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11613 | |
| 11614 | /* shutdown the adminq */ |
Henry Tieman | ac9c5c6 | 2016-09-06 18:05:11 -0700 | [diff] [blame] | 11615 | i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11616 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11617 | /* destroy the locks only once, here */ |
| 11618 | mutex_destroy(&hw->aq.arq_mutex); |
| 11619 | mutex_destroy(&hw->aq.asq_mutex); |
| 11620 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11621 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11622 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11623 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11624 | if (pf->vsi[i]) { |
| 11625 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11626 | i40e_vsi_clear(pf->vsi[i]); |
| 11627 | pf->vsi[i] = NULL; |
| 11628 | } |
| 11629 | } |
| 11630 | |
| 11631 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11632 | kfree(pf->veb[i]); |
| 11633 | pf->veb[i] = NULL; |
| 11634 | } |
| 11635 | |
| 11636 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11637 | kfree(pf->vsi); |
| 11638 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11639 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11640 | kfree(pf); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11641 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11642 | |
| 11643 | pci_disable_pcie_error_reporting(pdev); |
| 11644 | pci_disable_device(pdev); |
| 11645 | } |
| 11646 | |
| 11647 | /** |
| 11648 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11649 | * @pdev: PCI device information struct |
| 11650 | * |
| 11651 | * Called to warn that something happened and the error handling steps |
| 11652 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11653 | * remediation. |
| 11654 | **/ |
| 11655 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11656 | enum pci_channel_state error) |
| 11657 | { |
| 11658 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11659 | |
| 11660 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11661 | |
Guilherme G Piccoli | edfc23ee | 2016-10-03 00:31:12 -0700 | [diff] [blame] | 11662 | if (!pf) { |
| 11663 | dev_info(&pdev->dev, |
| 11664 | "Cannot recover - error happened during device probe\n"); |
| 11665 | return PCI_ERS_RESULT_DISCONNECT; |
| 11666 | } |
| 11667 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11668 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11669 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11670 | rtnl_lock(); |
| 11671 | i40e_prep_for_reset(pf); |
| 11672 | rtnl_unlock(); |
| 11673 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11674 | |
| 11675 | /* Request a slot reset */ |
| 11676 | return PCI_ERS_RESULT_NEED_RESET; |
| 11677 | } |
| 11678 | |
| 11679 | /** |
| 11680 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11681 | * @pdev: PCI device information struct |
| 11682 | * |
| 11683 | * Called to find if the driver can work with the device now that |
| 11684 | * the pci slot has been reset. If a basic connection seems good |
| 11685 | * (registers are readable and have sane content) then return a |
| 11686 | * happy little PCI_ERS_RESULT_xxx. |
| 11687 | **/ |
| 11688 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11689 | { |
| 11690 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11691 | pci_ers_result_t result; |
| 11692 | int err; |
| 11693 | u32 reg; |
| 11694 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11695 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11696 | if (pci_enable_device_mem(pdev)) { |
| 11697 | dev_info(&pdev->dev, |
| 11698 | "Cannot re-enable PCI device after reset.\n"); |
| 11699 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11700 | } else { |
| 11701 | pci_set_master(pdev); |
| 11702 | pci_restore_state(pdev); |
| 11703 | pci_save_state(pdev); |
| 11704 | pci_wake_from_d3(pdev, false); |
| 11705 | |
| 11706 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11707 | if (reg == 0) |
| 11708 | result = PCI_ERS_RESULT_RECOVERED; |
| 11709 | else |
| 11710 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11711 | } |
| 11712 | |
| 11713 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11714 | if (err) { |
| 11715 | dev_info(&pdev->dev, |
| 11716 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11717 | err); |
| 11718 | /* non-fatal, continue */ |
| 11719 | } |
| 11720 | |
| 11721 | return result; |
| 11722 | } |
| 11723 | |
| 11724 | /** |
| 11725 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11726 | * @pdev: PCI device information struct |
| 11727 | * |
| 11728 | * Called to allow the driver to bring things back up after PCI error |
| 11729 | * and/or reset recovery has finished. |
| 11730 | **/ |
| 11731 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11732 | { |
| 11733 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11734 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11735 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11736 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 11737 | return; |
| 11738 | |
| 11739 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11740 | i40e_handle_reset_warning(pf); |
Vasily Averin | 4c4935a | 2015-07-08 15:04:26 +0300 | [diff] [blame] | 11741 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11742 | } |
| 11743 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11744 | /** |
Joshua Hay | 1d68005 | 2016-12-12 15:44:08 -0800 | [diff] [blame^] | 11745 | * i40e_enable_mc_magic_wake - enable multicast magic packet wake up |
| 11746 | * using the mac_address_write admin q function |
| 11747 | * @pf: pointer to i40e_pf struct |
| 11748 | **/ |
| 11749 | static void i40e_enable_mc_magic_wake(struct i40e_pf *pf) |
| 11750 | { |
| 11751 | struct i40e_hw *hw = &pf->hw; |
| 11752 | i40e_status ret; |
| 11753 | u8 mac_addr[6]; |
| 11754 | u16 flags = 0; |
| 11755 | |
| 11756 | /* Get current MAC address in case it's an LAA */ |
| 11757 | if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) { |
| 11758 | ether_addr_copy(mac_addr, |
| 11759 | pf->vsi[pf->lan_vsi]->netdev->dev_addr); |
| 11760 | } else { |
| 11761 | dev_err(&pf->pdev->dev, |
| 11762 | "Failed to retrieve MAC address; using default\n"); |
| 11763 | ether_addr_copy(mac_addr, hw->mac.addr); |
| 11764 | } |
| 11765 | |
| 11766 | /* The FW expects the mac address write cmd to first be called with |
| 11767 | * one of these flags before calling it again with the multicast |
| 11768 | * enable flags. |
| 11769 | */ |
| 11770 | flags = I40E_AQC_WRITE_TYPE_LAA_WOL; |
| 11771 | |
| 11772 | if (hw->func_caps.flex10_enable && hw->partition_id != 1) |
| 11773 | flags = I40E_AQC_WRITE_TYPE_LAA_ONLY; |
| 11774 | |
| 11775 | ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL); |
| 11776 | if (ret) { |
| 11777 | dev_err(&pf->pdev->dev, |
| 11778 | "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up"); |
| 11779 | return; |
| 11780 | } |
| 11781 | |
| 11782 | flags = I40E_AQC_MC_MAG_EN |
| 11783 | | I40E_AQC_WOL_PRESERVE_ON_PFR |
| 11784 | | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG; |
| 11785 | ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL); |
| 11786 | if (ret) |
| 11787 | dev_err(&pf->pdev->dev, |
| 11788 | "Failed to enable Multicast Magic Packet wake up\n"); |
| 11789 | } |
| 11790 | |
| 11791 | /** |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11792 | * i40e_shutdown - PCI callback for shutting down |
| 11793 | * @pdev: PCI device information struct |
| 11794 | **/ |
| 11795 | static void i40e_shutdown(struct pci_dev *pdev) |
| 11796 | { |
| 11797 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11798 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11799 | |
| 11800 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11801 | set_bit(__I40E_DOWN, &pf->state); |
| 11802 | rtnl_lock(); |
| 11803 | i40e_prep_for_reset(pf); |
| 11804 | rtnl_unlock(); |
| 11805 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11806 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11807 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11808 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11809 | del_timer_sync(&pf->service_timer); |
| 11810 | cancel_work_sync(&pf->service_task); |
| 11811 | i40e_fdir_teardown(pf); |
| 11812 | |
Joshua Hay | 1d68005 | 2016-12-12 15:44:08 -0800 | [diff] [blame^] | 11813 | if (pf->wol_en && (pf->flags & I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE)) |
| 11814 | i40e_enable_mc_magic_wake(pf); |
| 11815 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11816 | rtnl_lock(); |
| 11817 | i40e_prep_for_reset(pf); |
| 11818 | rtnl_unlock(); |
| 11819 | |
| 11820 | wr32(hw, I40E_PFPM_APM, |
| 11821 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11822 | wr32(hw, I40E_PFPM_WUFC, |
| 11823 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11824 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 11825 | i40e_clear_interrupt_scheme(pf); |
| 11826 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11827 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11828 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11829 | pci_set_power_state(pdev, PCI_D3hot); |
| 11830 | } |
| 11831 | } |
| 11832 | |
| 11833 | #ifdef CONFIG_PM |
| 11834 | /** |
| 11835 | * i40e_suspend - PCI callback for moving to D3 |
| 11836 | * @pdev: PCI device information struct |
| 11837 | **/ |
| 11838 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11839 | { |
| 11840 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11841 | struct i40e_hw *hw = &pf->hw; |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11842 | int retval = 0; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11843 | |
| 11844 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11845 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 11846 | |
Joshua Hay | 1d68005 | 2016-12-12 15:44:08 -0800 | [diff] [blame^] | 11847 | if (pf->wol_en && (pf->flags & I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE)) |
| 11848 | i40e_enable_mc_magic_wake(pf); |
| 11849 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11850 | rtnl_lock(); |
| 11851 | i40e_prep_for_reset(pf); |
| 11852 | rtnl_unlock(); |
| 11853 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11854 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11855 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11856 | |
Greg Rose | b33d3b7 | 2016-05-16 10:26:37 -0700 | [diff] [blame] | 11857 | i40e_stop_misc_vector(pf); |
| 11858 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11859 | retval = pci_save_state(pdev); |
| 11860 | if (retval) |
| 11861 | return retval; |
| 11862 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11863 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11864 | pci_set_power_state(pdev, PCI_D3hot); |
| 11865 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11866 | return retval; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11867 | } |
| 11868 | |
| 11869 | /** |
| 11870 | * i40e_resume - PCI callback for waking up from D3 |
| 11871 | * @pdev: PCI device information struct |
| 11872 | **/ |
| 11873 | static int i40e_resume(struct pci_dev *pdev) |
| 11874 | { |
| 11875 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11876 | u32 err; |
| 11877 | |
| 11878 | pci_set_power_state(pdev, PCI_D0); |
| 11879 | pci_restore_state(pdev); |
| 11880 | /* pci_restore_state() clears dev->state_saves, so |
| 11881 | * call pci_save_state() again to restore it. |
| 11882 | */ |
| 11883 | pci_save_state(pdev); |
| 11884 | |
| 11885 | err = pci_enable_device_mem(pdev); |
| 11886 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11887 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11888 | return err; |
| 11889 | } |
| 11890 | pci_set_master(pdev); |
| 11891 | |
| 11892 | /* no wakeup events while running */ |
| 11893 | pci_wake_from_d3(pdev, false); |
| 11894 | |
| 11895 | /* handling the reset will rebuild the device state */ |
| 11896 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11897 | clear_bit(__I40E_DOWN, &pf->state); |
| 11898 | rtnl_lock(); |
| 11899 | i40e_reset_and_rebuild(pf, false); |
| 11900 | rtnl_unlock(); |
| 11901 | } |
| 11902 | |
| 11903 | return 0; |
| 11904 | } |
| 11905 | |
| 11906 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11907 | static const struct pci_error_handlers i40e_err_handler = { |
| 11908 | .error_detected = i40e_pci_error_detected, |
| 11909 | .slot_reset = i40e_pci_error_slot_reset, |
| 11910 | .resume = i40e_pci_error_resume, |
| 11911 | }; |
| 11912 | |
| 11913 | static struct pci_driver i40e_driver = { |
| 11914 | .name = i40e_driver_name, |
| 11915 | .id_table = i40e_pci_tbl, |
| 11916 | .probe = i40e_probe, |
| 11917 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11918 | #ifdef CONFIG_PM |
| 11919 | .suspend = i40e_suspend, |
| 11920 | .resume = i40e_resume, |
| 11921 | #endif |
| 11922 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11923 | .err_handler = &i40e_err_handler, |
| 11924 | .sriov_configure = i40e_pci_sriov_configure, |
| 11925 | }; |
| 11926 | |
| 11927 | /** |
| 11928 | * i40e_init_module - Driver registration routine |
| 11929 | * |
| 11930 | * i40e_init_module is the first routine called when the driver is |
| 11931 | * loaded. All it does is register with the PCI subsystem. |
| 11932 | **/ |
| 11933 | static int __init i40e_init_module(void) |
| 11934 | { |
| 11935 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 11936 | i40e_driver_string, i40e_driver_version_str); |
| 11937 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 11938 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11939 | /* we will see if single thread per module is enough for now, |
| 11940 | * it can't be any worse than using the system workqueue which |
| 11941 | * was already single threaded |
| 11942 | */ |
Jacob Keller | 6992a6c | 2016-08-04 11:37:01 -0700 | [diff] [blame] | 11943 | i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1, |
| 11944 | i40e_driver_name); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11945 | if (!i40e_wq) { |
| 11946 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 11947 | return -ENOMEM; |
| 11948 | } |
| 11949 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11950 | i40e_dbg_init(); |
| 11951 | return pci_register_driver(&i40e_driver); |
| 11952 | } |
| 11953 | module_init(i40e_init_module); |
| 11954 | |
| 11955 | /** |
| 11956 | * i40e_exit_module - Driver exit cleanup routine |
| 11957 | * |
| 11958 | * i40e_exit_module is called just before the driver is removed |
| 11959 | * from memory. |
| 11960 | **/ |
| 11961 | static void __exit i40e_exit_module(void) |
| 11962 | { |
| 11963 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11964 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11965 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11966 | } |
| 11967 | module_exit(i40e_exit_module); |