Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2015 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 | |
| 31 | #ifdef CONFIG_SPARC |
| 32 | #include <asm/idprom.h> |
| 33 | #include <asm/prom.h> |
| 34 | #endif |
| 35 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 36 | /* Local includes */ |
| 37 | #include "i40e.h" |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 38 | #include "i40e_diag.h" |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 39 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 40 | #include <net/vxlan.h> |
| 41 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 42 | #if IS_ENABLED(CONFIG_GENEVE) |
| 43 | #include <net/geneve.h> |
| 44 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 45 | |
| 46 | const char i40e_driver_name[] = "i40e"; |
| 47 | static const char i40e_driver_string[] = |
| 48 | "Intel(R) Ethernet Connection XL710 Network Driver"; |
| 49 | |
| 50 | #define DRV_KERN "-k" |
| 51 | |
Catherine Sullivan | e8e724d | 2014-07-10 07:58:26 +0000 | [diff] [blame] | 52 | #define DRV_VERSION_MAJOR 1 |
Catherine Sullivan | 1c2df9e | 2015-10-21 19:56:24 -0400 | [diff] [blame] | 53 | #define DRV_VERSION_MINOR 4 |
Catherine Sullivan | 82f399c | 2015-12-23 12:05:56 -0800 | [diff] [blame] | 54 | #define DRV_VERSION_BUILD 11 |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 55 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 56 | __stringify(DRV_VERSION_MINOR) "." \ |
| 57 | __stringify(DRV_VERSION_BUILD) DRV_KERN |
| 58 | const char i40e_driver_version_str[] = DRV_VERSION; |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 59 | static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation."; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 60 | |
| 61 | /* a bit of forward declarations */ |
| 62 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); |
| 63 | static void i40e_handle_reset_warning(struct i40e_pf *pf); |
| 64 | static int i40e_add_vsi(struct i40e_vsi *vsi); |
| 65 | 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] | 66 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 67 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
| 68 | static void i40e_determine_queue_usage(struct i40e_pf *pf); |
| 69 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 70 | static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 71 | u16 rss_table_size, u16 rss_size); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 72 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 73 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 74 | |
| 75 | /* i40e_pci_tbl - PCI Device ID Table |
| 76 | * |
| 77 | * Last entry must be all 0s |
| 78 | * |
| 79 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 80 | * Class, Class Mask, private data (not used) } |
| 81 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 82 | static const struct pci_device_id i40e_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 83 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 84 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 85 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, |
| 86 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 87 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, |
| 88 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, |
| 89 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 90 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0}, |
Shannon Nelson | bc5166b9 | 2015-08-26 15:14:10 -0400 | [diff] [blame] | 91 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0}, |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 92 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
Anjali Singhai Jain | 35dae51 | 2015-12-22 14:25:03 -0800 | [diff] [blame] | 93 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0}, |
| 94 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame] | 95 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0}, |
| 96 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0}, |
| 97 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0}, |
Shannon Nelson | 48a3b51 | 2015-07-23 16:54:39 -0400 | [diff] [blame] | 98 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
| 99 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 100 | /* required last entry */ |
| 101 | {0, } |
| 102 | }; |
| 103 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 104 | |
| 105 | #define I40E_MAX_VF_COUNT 128 |
| 106 | static int debug = -1; |
| 107 | module_param(debug, int, 0); |
| 108 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 109 | |
| 110 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 111 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 112 | MODULE_LICENSE("GPL"); |
| 113 | MODULE_VERSION(DRV_VERSION); |
| 114 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 115 | static struct workqueue_struct *i40e_wq; |
| 116 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 117 | /** |
| 118 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 119 | * @hw: pointer to the HW structure |
| 120 | * @mem: ptr to mem struct to fill out |
| 121 | * @size: size of memory requested |
| 122 | * @alignment: what to align the allocation to |
| 123 | **/ |
| 124 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 125 | u64 size, u32 alignment) |
| 126 | { |
| 127 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 128 | |
| 129 | mem->size = ALIGN(size, alignment); |
| 130 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 131 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 132 | if (!mem->va) |
| 133 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 134 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 135 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /** |
| 139 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 140 | * @hw: pointer to the HW structure |
| 141 | * @mem: ptr to mem struct to free |
| 142 | **/ |
| 143 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 144 | { |
| 145 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 146 | |
| 147 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 148 | mem->va = NULL; |
| 149 | mem->pa = 0; |
| 150 | mem->size = 0; |
| 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 157 | * @hw: pointer to the HW structure |
| 158 | * @mem: ptr to mem struct to fill out |
| 159 | * @size: size of memory requested |
| 160 | **/ |
| 161 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 162 | u32 size) |
| 163 | { |
| 164 | mem->size = size; |
| 165 | mem->va = kzalloc(size, GFP_KERNEL); |
| 166 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 167 | if (!mem->va) |
| 168 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 169 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 170 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /** |
| 174 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 175 | * @hw: pointer to the HW structure |
| 176 | * @mem: ptr to mem struct to free |
| 177 | **/ |
| 178 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 179 | { |
| 180 | /* it's ok to kfree a NULL pointer */ |
| 181 | kfree(mem->va); |
| 182 | mem->va = NULL; |
| 183 | mem->size = 0; |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * i40e_get_lump - find a lump of free generic resource |
| 190 | * @pf: board private structure |
| 191 | * @pile: the pile of resource to search |
| 192 | * @needed: the number of items needed |
| 193 | * @id: an owner id to stick on the items assigned |
| 194 | * |
| 195 | * Returns the base item index of the lump, or negative for error |
| 196 | * |
| 197 | * The search_hint trick and lack of advanced fit-finding only work |
| 198 | * because we're highly likely to have all the same size lump requests. |
| 199 | * Linear search time and any fragmentation should be minimal. |
| 200 | **/ |
| 201 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 202 | u16 needed, u16 id) |
| 203 | { |
| 204 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 205 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 206 | |
| 207 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 208 | dev_info(&pf->pdev->dev, |
| 209 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 210 | pile, needed, id); |
| 211 | return -EINVAL; |
| 212 | } |
| 213 | |
| 214 | /* start the linear search with an imperfect hint */ |
| 215 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 216 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 217 | /* skip already allocated entries */ |
| 218 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 219 | i++; |
| 220 | continue; |
| 221 | } |
| 222 | |
| 223 | /* do we have enough in this lump? */ |
| 224 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 225 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 226 | break; |
| 227 | } |
| 228 | |
| 229 | if (j == needed) { |
| 230 | /* there was enough, so assign it to the requestor */ |
| 231 | for (j = 0; j < needed; j++) |
| 232 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 233 | ret = i; |
| 234 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 235 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 236 | } |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 237 | |
| 238 | /* not enough, so skip over it and continue looking */ |
| 239 | i += j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | return ret; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * i40e_put_lump - return a lump of generic resource |
| 247 | * @pile: the pile of resource to search |
| 248 | * @index: the base item index |
| 249 | * @id: the owner id of the items assigned |
| 250 | * |
| 251 | * Returns the count of items in the lump |
| 252 | **/ |
| 253 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 254 | { |
| 255 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 256 | int count = 0; |
| 257 | int i; |
| 258 | |
| 259 | if (!pile || index >= pile->num_entries) |
| 260 | return -EINVAL; |
| 261 | |
| 262 | for (i = index; |
| 263 | i < pile->num_entries && pile->list[i] == valid_id; |
| 264 | i++) { |
| 265 | pile->list[i] = 0; |
| 266 | count++; |
| 267 | } |
| 268 | |
| 269 | if (count && index < pile->search_hint) |
| 270 | pile->search_hint = index; |
| 271 | |
| 272 | return count; |
| 273 | } |
| 274 | |
| 275 | /** |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 276 | * i40e_find_vsi_from_id - searches for the vsi with the given id |
| 277 | * @pf - the pf structure to search for the vsi |
| 278 | * @id - id of the vsi it is searching for |
| 279 | **/ |
| 280 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) |
| 281 | { |
| 282 | int i; |
| 283 | |
| 284 | for (i = 0; i < pf->num_alloc_vsi; i++) |
| 285 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) |
| 286 | return pf->vsi[i]; |
| 287 | |
| 288 | return NULL; |
| 289 | } |
| 290 | |
| 291 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 292 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 293 | * @pf: board private structure |
| 294 | * |
| 295 | * If not already scheduled, this puts the task into the work queue |
| 296 | **/ |
| 297 | static void i40e_service_event_schedule(struct i40e_pf *pf) |
| 298 | { |
| 299 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 300 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && |
| 301 | !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 302 | queue_work(i40e_wq, &pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /** |
| 306 | * i40e_tx_timeout - Respond to a Tx Hang |
| 307 | * @netdev: network interface device structure |
| 308 | * |
| 309 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 310 | * device is munged, not just the one netdev port, so go for the full |
| 311 | * reset. |
| 312 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 313 | #ifdef I40E_FCOE |
| 314 | void i40e_tx_timeout(struct net_device *netdev) |
| 315 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 316 | static void i40e_tx_timeout(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 317 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 318 | { |
| 319 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 320 | struct i40e_vsi *vsi = np->vsi; |
| 321 | struct i40e_pf *pf = vsi->back; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 322 | struct i40e_ring *tx_ring = NULL; |
| 323 | unsigned int i, hung_queue = 0; |
| 324 | u32 head, val; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 325 | |
| 326 | pf->tx_timeout_count++; |
| 327 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 328 | /* find the stopped queue the same way the stack does */ |
| 329 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 330 | struct netdev_queue *q; |
| 331 | unsigned long trans_start; |
| 332 | |
| 333 | q = netdev_get_tx_queue(netdev, i); |
| 334 | trans_start = q->trans_start ? : netdev->trans_start; |
| 335 | if (netif_xmit_stopped(q) && |
| 336 | time_after(jiffies, |
| 337 | (trans_start + netdev->watchdog_timeo))) { |
| 338 | hung_queue = i; |
| 339 | break; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | if (i == netdev->num_tx_queues) { |
| 344 | netdev_info(netdev, "tx_timeout: no netdev hung queue found\n"); |
| 345 | } else { |
| 346 | /* now that we have an index, find the tx_ring struct */ |
| 347 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 348 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 349 | if (hung_queue == |
| 350 | vsi->tx_rings[i]->queue_index) { |
| 351 | tx_ring = vsi->tx_rings[i]; |
| 352 | break; |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 358 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 359 | pf->tx_timeout_recovery_level = 1; /* reset after some time */ |
| 360 | else if (time_before(jiffies, |
| 361 | (pf->tx_timeout_last_recovery + netdev->watchdog_timeo))) |
| 362 | return; /* don't do any new action before the next timeout */ |
| 363 | |
| 364 | if (tx_ring) { |
| 365 | head = i40e_get_head(tx_ring); |
| 366 | /* Read interrupt register */ |
| 367 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 368 | val = rd32(&pf->hw, |
| 369 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 370 | tx_ring->vsi->base_vector - 1)); |
| 371 | else |
| 372 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 373 | |
| 374 | 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", |
| 375 | vsi->seid, hung_queue, tx_ring->next_to_clean, |
| 376 | head, tx_ring->next_to_use, |
| 377 | readl(tx_ring->tail), val); |
| 378 | } |
| 379 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 380 | pf->tx_timeout_last_recovery = jiffies; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 381 | netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n", |
| 382 | pf->tx_timeout_recovery_level, hung_queue); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 383 | |
| 384 | switch (pf->tx_timeout_recovery_level) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 385 | case 1: |
| 386 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 387 | break; |
| 388 | case 2: |
| 389 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 390 | break; |
| 391 | case 3: |
| 392 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 393 | break; |
| 394 | default: |
| 395 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 396 | break; |
| 397 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 398 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 399 | i40e_service_event_schedule(pf); |
| 400 | pf->tx_timeout_recovery_level++; |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * i40e_release_rx_desc - Store the new tail and head values |
| 405 | * @rx_ring: ring to bump |
| 406 | * @val: new head index |
| 407 | **/ |
| 408 | static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val) |
| 409 | { |
| 410 | rx_ring->next_to_use = val; |
| 411 | |
| 412 | /* Force memory writes to complete before letting h/w |
| 413 | * know there are new descriptors to fetch. (Only |
| 414 | * applicable for weak-ordered memory model archs, |
| 415 | * such as IA-64). |
| 416 | */ |
| 417 | wmb(); |
| 418 | writel(val, rx_ring->tail); |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 423 | * @vsi: the VSI we care about |
| 424 | * |
| 425 | * Returns the address of the device statistics structure. |
| 426 | * The statistics are actually updated from the service task. |
| 427 | **/ |
| 428 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 429 | { |
| 430 | return &vsi->net_stats; |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 435 | * @netdev: network interface device structure |
| 436 | * |
| 437 | * Returns the address of the device statistics structure. |
| 438 | * The statistics are actually updated from the service task. |
| 439 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 440 | #ifdef I40E_FCOE |
| 441 | struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 442 | struct net_device *netdev, |
| 443 | struct rtnl_link_stats64 *stats) |
| 444 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 445 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 446 | struct net_device *netdev, |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 447 | struct rtnl_link_stats64 *stats) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 448 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 449 | { |
| 450 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 451 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 452 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 453 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 454 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 455 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 456 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 457 | return stats; |
| 458 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 459 | if (!vsi->tx_rings) |
| 460 | return stats; |
| 461 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 462 | rcu_read_lock(); |
| 463 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 464 | u64 bytes, packets; |
| 465 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 466 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 467 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 468 | if (!tx_ring) |
| 469 | continue; |
| 470 | |
| 471 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 472 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 473 | packets = tx_ring->stats.packets; |
| 474 | bytes = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 475 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 476 | |
| 477 | stats->tx_packets += packets; |
| 478 | stats->tx_bytes += bytes; |
| 479 | rx_ring = &tx_ring[1]; |
| 480 | |
| 481 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 482 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 483 | packets = rx_ring->stats.packets; |
| 484 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 485 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 486 | |
| 487 | stats->rx_packets += packets; |
| 488 | stats->rx_bytes += bytes; |
| 489 | } |
| 490 | rcu_read_unlock(); |
| 491 | |
Akeem G Abodunrin | a5282f4 | 2014-05-10 04:49:03 +0000 | [diff] [blame] | 492 | /* following stats updated by i40e_watchdog_subtask() */ |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 493 | stats->multicast = vsi_stats->multicast; |
| 494 | stats->tx_errors = vsi_stats->tx_errors; |
| 495 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 496 | stats->rx_errors = vsi_stats->rx_errors; |
Jesse Brandeburg | d8201e2 | 2015-07-23 16:54:35 -0400 | [diff] [blame] | 497 | stats->rx_dropped = vsi_stats->rx_dropped; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 498 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 499 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
| 500 | |
| 501 | return stats; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /** |
| 505 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 506 | * @vsi: the VSI to have its stats reset |
| 507 | **/ |
| 508 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 509 | { |
| 510 | struct rtnl_link_stats64 *ns; |
| 511 | int i; |
| 512 | |
| 513 | if (!vsi) |
| 514 | return; |
| 515 | |
| 516 | ns = i40e_get_vsi_stats_struct(vsi); |
| 517 | memset(ns, 0, sizeof(*ns)); |
| 518 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 519 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 520 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 521 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 522 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 523 | memset(&vsi->rx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 524 | sizeof(vsi->rx_rings[i]->stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 525 | memset(&vsi->rx_rings[i]->rx_stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 526 | sizeof(vsi->rx_rings[i]->rx_stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 527 | memset(&vsi->tx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 528 | sizeof(vsi->tx_rings[i]->stats)); |
| 529 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 530 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 531 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 532 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 533 | vsi->stat_offsets_loaded = false; |
| 534 | } |
| 535 | |
| 536 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 537 | * 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] | 538 | * @pf: the PF to be reset |
| 539 | **/ |
| 540 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 541 | { |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 542 | int i; |
| 543 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 544 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 545 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 546 | pf->stat_offsets_loaded = false; |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 547 | |
| 548 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 549 | if (pf->veb[i]) { |
| 550 | memset(&pf->veb[i]->stats, 0, |
| 551 | sizeof(pf->veb[i]->stats)); |
| 552 | memset(&pf->veb[i]->stats_offsets, 0, |
| 553 | sizeof(pf->veb[i]->stats_offsets)); |
| 554 | pf->veb[i]->stat_offsets_loaded = false; |
| 555 | } |
| 556 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /** |
| 560 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 561 | * @hw: ptr to the hardware info |
| 562 | * @hireg: the high 32 bit reg to read |
| 563 | * @loreg: the low 32 bit reg to read |
| 564 | * @offset_loaded: has the initial offset been loaded yet |
| 565 | * @offset: ptr to current offset value |
| 566 | * @stat: ptr to the stat |
| 567 | * |
| 568 | * Since the device stats are not reset at PFReset, they likely will not |
| 569 | * be zeroed when the driver starts. We'll save the first values read |
| 570 | * and use them as offsets to be subtracted from the raw values in order |
| 571 | * to report stats that count from zero. In the process, we also manage |
| 572 | * the potential roll-over. |
| 573 | **/ |
| 574 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 575 | bool offset_loaded, u64 *offset, u64 *stat) |
| 576 | { |
| 577 | u64 new_data; |
| 578 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 579 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 580 | new_data = rd32(hw, loreg); |
| 581 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 582 | } else { |
| 583 | new_data = rd64(hw, loreg); |
| 584 | } |
| 585 | if (!offset_loaded) |
| 586 | *offset = new_data; |
| 587 | if (likely(new_data >= *offset)) |
| 588 | *stat = new_data - *offset; |
| 589 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 590 | *stat = (new_data + BIT_ULL(48)) - *offset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 591 | *stat &= 0xFFFFFFFFFFFFULL; |
| 592 | } |
| 593 | |
| 594 | /** |
| 595 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 596 | * @hw: ptr to the hardware info |
| 597 | * @reg: the hw reg to read |
| 598 | * @offset_loaded: has the initial offset been loaded yet |
| 599 | * @offset: ptr to current offset value |
| 600 | * @stat: ptr to the stat |
| 601 | **/ |
| 602 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 603 | bool offset_loaded, u64 *offset, u64 *stat) |
| 604 | { |
| 605 | u32 new_data; |
| 606 | |
| 607 | new_data = rd32(hw, reg); |
| 608 | if (!offset_loaded) |
| 609 | *offset = new_data; |
| 610 | if (likely(new_data >= *offset)) |
| 611 | *stat = (u32)(new_data - *offset); |
| 612 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 613 | *stat = (u32)((new_data + BIT_ULL(32)) - *offset); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | /** |
| 617 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 618 | * @vsi: the VSI to be updated |
| 619 | **/ |
| 620 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 621 | { |
| 622 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 623 | struct i40e_pf *pf = vsi->back; |
| 624 | struct i40e_hw *hw = &pf->hw; |
| 625 | struct i40e_eth_stats *oes; |
| 626 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 627 | |
| 628 | es = &vsi->eth_stats; |
| 629 | oes = &vsi->eth_stats_offsets; |
| 630 | |
| 631 | /* Gather up the stats that the hw collects */ |
| 632 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 633 | vsi->stat_offsets_loaded, |
| 634 | &oes->tx_errors, &es->tx_errors); |
| 635 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 636 | vsi->stat_offsets_loaded, |
| 637 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 638 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 639 | vsi->stat_offsets_loaded, |
| 640 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 641 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 642 | vsi->stat_offsets_loaded, |
| 643 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 644 | |
| 645 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 646 | I40E_GLV_GORCL(stat_idx), |
| 647 | vsi->stat_offsets_loaded, |
| 648 | &oes->rx_bytes, &es->rx_bytes); |
| 649 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 650 | I40E_GLV_UPRCL(stat_idx), |
| 651 | vsi->stat_offsets_loaded, |
| 652 | &oes->rx_unicast, &es->rx_unicast); |
| 653 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 654 | I40E_GLV_MPRCL(stat_idx), |
| 655 | vsi->stat_offsets_loaded, |
| 656 | &oes->rx_multicast, &es->rx_multicast); |
| 657 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 658 | I40E_GLV_BPRCL(stat_idx), |
| 659 | vsi->stat_offsets_loaded, |
| 660 | &oes->rx_broadcast, &es->rx_broadcast); |
| 661 | |
| 662 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 663 | I40E_GLV_GOTCL(stat_idx), |
| 664 | vsi->stat_offsets_loaded, |
| 665 | &oes->tx_bytes, &es->tx_bytes); |
| 666 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 667 | I40E_GLV_UPTCL(stat_idx), |
| 668 | vsi->stat_offsets_loaded, |
| 669 | &oes->tx_unicast, &es->tx_unicast); |
| 670 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 671 | I40E_GLV_MPTCL(stat_idx), |
| 672 | vsi->stat_offsets_loaded, |
| 673 | &oes->tx_multicast, &es->tx_multicast); |
| 674 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 675 | I40E_GLV_BPTCL(stat_idx), |
| 676 | vsi->stat_offsets_loaded, |
| 677 | &oes->tx_broadcast, &es->tx_broadcast); |
| 678 | vsi->stat_offsets_loaded = true; |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * i40e_update_veb_stats - Update Switch component statistics |
| 683 | * @veb: the VEB being updated |
| 684 | **/ |
| 685 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 686 | { |
| 687 | struct i40e_pf *pf = veb->pf; |
| 688 | struct i40e_hw *hw = &pf->hw; |
| 689 | struct i40e_eth_stats *oes; |
| 690 | struct i40e_eth_stats *es; /* device's eth stats */ |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 691 | struct i40e_veb_tc_stats *veb_oes; |
| 692 | struct i40e_veb_tc_stats *veb_es; |
| 693 | int i, idx = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 694 | |
| 695 | idx = veb->stats_idx; |
| 696 | es = &veb->stats; |
| 697 | oes = &veb->stats_offsets; |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 698 | veb_es = &veb->tc_stats; |
| 699 | veb_oes = &veb->tc_stats_offsets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 700 | |
| 701 | /* Gather up the stats that the hw collects */ |
| 702 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 703 | veb->stat_offsets_loaded, |
| 704 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 705 | if (hw->revision_id > 0) |
| 706 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 707 | veb->stat_offsets_loaded, |
| 708 | &oes->rx_unknown_protocol, |
| 709 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 710 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 711 | veb->stat_offsets_loaded, |
| 712 | &oes->rx_bytes, &es->rx_bytes); |
| 713 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 714 | veb->stat_offsets_loaded, |
| 715 | &oes->rx_unicast, &es->rx_unicast); |
| 716 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 717 | veb->stat_offsets_loaded, |
| 718 | &oes->rx_multicast, &es->rx_multicast); |
| 719 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 720 | veb->stat_offsets_loaded, |
| 721 | &oes->rx_broadcast, &es->rx_broadcast); |
| 722 | |
| 723 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 724 | veb->stat_offsets_loaded, |
| 725 | &oes->tx_bytes, &es->tx_bytes); |
| 726 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 727 | veb->stat_offsets_loaded, |
| 728 | &oes->tx_unicast, &es->tx_unicast); |
| 729 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 730 | veb->stat_offsets_loaded, |
| 731 | &oes->tx_multicast, &es->tx_multicast); |
| 732 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 733 | veb->stat_offsets_loaded, |
| 734 | &oes->tx_broadcast, &es->tx_broadcast); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 735 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 736 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), |
| 737 | I40E_GLVEBTC_RPCL(i, idx), |
| 738 | veb->stat_offsets_loaded, |
| 739 | &veb_oes->tc_rx_packets[i], |
| 740 | &veb_es->tc_rx_packets[i]); |
| 741 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), |
| 742 | I40E_GLVEBTC_RBCL(i, idx), |
| 743 | veb->stat_offsets_loaded, |
| 744 | &veb_oes->tc_rx_bytes[i], |
| 745 | &veb_es->tc_rx_bytes[i]); |
| 746 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), |
| 747 | I40E_GLVEBTC_TPCL(i, idx), |
| 748 | veb->stat_offsets_loaded, |
| 749 | &veb_oes->tc_tx_packets[i], |
| 750 | &veb_es->tc_tx_packets[i]); |
| 751 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), |
| 752 | I40E_GLVEBTC_TBCL(i, idx), |
| 753 | veb->stat_offsets_loaded, |
| 754 | &veb_oes->tc_tx_bytes[i], |
| 755 | &veb_es->tc_tx_bytes[i]); |
| 756 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 757 | veb->stat_offsets_loaded = true; |
| 758 | } |
| 759 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 760 | #ifdef I40E_FCOE |
| 761 | /** |
| 762 | * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters. |
| 763 | * @vsi: the VSI that is capable of doing FCoE |
| 764 | **/ |
| 765 | static void i40e_update_fcoe_stats(struct i40e_vsi *vsi) |
| 766 | { |
| 767 | struct i40e_pf *pf = vsi->back; |
| 768 | struct i40e_hw *hw = &pf->hw; |
| 769 | struct i40e_fcoe_stats *ofs; |
| 770 | struct i40e_fcoe_stats *fs; /* device's eth stats */ |
| 771 | int idx; |
| 772 | |
| 773 | if (vsi->type != I40E_VSI_FCOE) |
| 774 | return; |
| 775 | |
| 776 | idx = (pf->pf_seid - I40E_BASE_PF_SEID) + I40E_FCOE_PF_STAT_OFFSET; |
| 777 | fs = &vsi->fcoe_stats; |
| 778 | ofs = &vsi->fcoe_stats_offsets; |
| 779 | |
| 780 | i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx), |
| 781 | vsi->fcoe_stat_offsets_loaded, |
| 782 | &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets); |
| 783 | i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx), |
| 784 | vsi->fcoe_stat_offsets_loaded, |
| 785 | &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords); |
| 786 | i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx), |
| 787 | vsi->fcoe_stat_offsets_loaded, |
| 788 | &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped); |
| 789 | i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx), |
| 790 | vsi->fcoe_stat_offsets_loaded, |
| 791 | &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets); |
| 792 | i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx), |
| 793 | vsi->fcoe_stat_offsets_loaded, |
| 794 | &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords); |
| 795 | i40e_stat_update32(hw, I40E_GL_FCOECRC(idx), |
| 796 | vsi->fcoe_stat_offsets_loaded, |
| 797 | &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc); |
| 798 | i40e_stat_update32(hw, I40E_GL_FCOELAST(idx), |
| 799 | vsi->fcoe_stat_offsets_loaded, |
| 800 | &ofs->fcoe_last_error, &fs->fcoe_last_error); |
| 801 | i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx), |
| 802 | vsi->fcoe_stat_offsets_loaded, |
| 803 | &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count); |
| 804 | |
| 805 | vsi->fcoe_stat_offsets_loaded = true; |
| 806 | } |
| 807 | |
| 808 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 809 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 810 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 811 | * @vsi: the VSI to be updated |
| 812 | * |
| 813 | * There are a few instances where we store the same stat in a |
| 814 | * couple of different structs. This is partly because we have |
| 815 | * the netdev stats that need to be filled out, which is slightly |
| 816 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 817 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 818 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 819 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 820 | { |
| 821 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 822 | struct rtnl_link_stats64 *ons; |
| 823 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 824 | struct i40e_eth_stats *oes; |
| 825 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 826 | u32 tx_restart, tx_busy; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 827 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 828 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 829 | u64 bytes, packets; |
| 830 | unsigned int start; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 831 | u64 tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 832 | u64 tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 833 | u64 rx_p, rx_b; |
| 834 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 835 | u16 q; |
| 836 | |
| 837 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 838 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 839 | return; |
| 840 | |
| 841 | ns = i40e_get_vsi_stats_struct(vsi); |
| 842 | ons = &vsi->net_stats_offsets; |
| 843 | es = &vsi->eth_stats; |
| 844 | oes = &vsi->eth_stats_offsets; |
| 845 | |
| 846 | /* Gather up the netdev and vsi stats that the driver collects |
| 847 | * on the fly during packet processing |
| 848 | */ |
| 849 | rx_b = rx_p = 0; |
| 850 | tx_b = tx_p = 0; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 851 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 852 | rx_page = 0; |
| 853 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 854 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 855 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 856 | /* locate Tx ring */ |
| 857 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 858 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 859 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 860 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 861 | packets = p->stats.packets; |
| 862 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 863 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 864 | tx_b += bytes; |
| 865 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 866 | tx_restart += p->tx_stats.restart_queue; |
| 867 | tx_busy += p->tx_stats.tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 868 | tx_linearize += p->tx_stats.tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 869 | tx_force_wb += p->tx_stats.tx_force_wb; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 870 | |
| 871 | /* Rx queue is part of the same block as Tx queue */ |
| 872 | p = &p[1]; |
| 873 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 874 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 875 | packets = p->stats.packets; |
| 876 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 877 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 878 | rx_b += bytes; |
| 879 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 880 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 881 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 882 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 883 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 884 | vsi->tx_restart = tx_restart; |
| 885 | vsi->tx_busy = tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 886 | vsi->tx_linearize = tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 887 | vsi->tx_force_wb = tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 888 | vsi->rx_page_failed = rx_page; |
| 889 | vsi->rx_buf_failed = rx_buf; |
| 890 | |
| 891 | ns->rx_packets = rx_p; |
| 892 | ns->rx_bytes = rx_b; |
| 893 | ns->tx_packets = tx_p; |
| 894 | ns->tx_bytes = tx_b; |
| 895 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 896 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 897 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 898 | ons->tx_errors = oes->tx_errors; |
| 899 | ns->tx_errors = es->tx_errors; |
| 900 | ons->multicast = oes->rx_multicast; |
| 901 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 902 | ons->rx_dropped = oes->rx_discards; |
| 903 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 904 | ons->tx_dropped = oes->tx_discards; |
| 905 | ns->tx_dropped = es->tx_discards; |
| 906 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 907 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 908 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 909 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 910 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 911 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 912 | } |
| 913 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 914 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 915 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 916 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 917 | * @pf: the PF to be updated |
| 918 | **/ |
| 919 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 920 | { |
| 921 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 922 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 923 | struct i40e_hw *hw = &pf->hw; |
| 924 | u32 val; |
| 925 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 926 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 927 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 928 | I40E_GLPRT_GORCL(hw->port), |
| 929 | pf->stat_offsets_loaded, |
| 930 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 931 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 932 | I40E_GLPRT_GOTCL(hw->port), |
| 933 | pf->stat_offsets_loaded, |
| 934 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 935 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 936 | pf->stat_offsets_loaded, |
| 937 | &osd->eth.rx_discards, |
| 938 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 939 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 940 | I40E_GLPRT_UPRCL(hw->port), |
| 941 | pf->stat_offsets_loaded, |
| 942 | &osd->eth.rx_unicast, |
| 943 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 944 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 945 | I40E_GLPRT_MPRCL(hw->port), |
| 946 | pf->stat_offsets_loaded, |
| 947 | &osd->eth.rx_multicast, |
| 948 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 949 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 950 | I40E_GLPRT_BPRCL(hw->port), |
| 951 | pf->stat_offsets_loaded, |
| 952 | &osd->eth.rx_broadcast, |
| 953 | &nsd->eth.rx_broadcast); |
| 954 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 955 | I40E_GLPRT_UPTCL(hw->port), |
| 956 | pf->stat_offsets_loaded, |
| 957 | &osd->eth.tx_unicast, |
| 958 | &nsd->eth.tx_unicast); |
| 959 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 960 | I40E_GLPRT_MPTCL(hw->port), |
| 961 | pf->stat_offsets_loaded, |
| 962 | &osd->eth.tx_multicast, |
| 963 | &nsd->eth.tx_multicast); |
| 964 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 965 | I40E_GLPRT_BPTCL(hw->port), |
| 966 | pf->stat_offsets_loaded, |
| 967 | &osd->eth.tx_broadcast, |
| 968 | &nsd->eth.tx_broadcast); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 969 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 970 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 971 | pf->stat_offsets_loaded, |
| 972 | &osd->tx_dropped_link_down, |
| 973 | &nsd->tx_dropped_link_down); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 974 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 975 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 976 | pf->stat_offsets_loaded, |
| 977 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 978 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 979 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 980 | pf->stat_offsets_loaded, |
| 981 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 982 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 983 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 984 | pf->stat_offsets_loaded, |
| 985 | &osd->mac_local_faults, |
| 986 | &nsd->mac_local_faults); |
| 987 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 988 | pf->stat_offsets_loaded, |
| 989 | &osd->mac_remote_faults, |
| 990 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 991 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 992 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 993 | pf->stat_offsets_loaded, |
| 994 | &osd->rx_length_errors, |
| 995 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 996 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 997 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 998 | pf->stat_offsets_loaded, |
| 999 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 1000 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 1001 | pf->stat_offsets_loaded, |
| 1002 | &osd->link_xon_tx, &nsd->link_xon_tx); |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 1003 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 1004 | pf->stat_offsets_loaded, |
| 1005 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1006 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 1007 | pf->stat_offsets_loaded, |
| 1008 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1009 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1010 | for (i = 0; i < 8; i++) { |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 1011 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 1012 | pf->stat_offsets_loaded, |
| 1013 | &osd->priority_xoff_rx[i], |
| 1014 | &nsd->priority_xoff_rx[i]); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1015 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1016 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1017 | &osd->priority_xon_rx[i], |
| 1018 | &nsd->priority_xon_rx[i]); |
| 1019 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1020 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1021 | &osd->priority_xon_tx[i], |
| 1022 | &nsd->priority_xon_tx[i]); |
| 1023 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1024 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1025 | &osd->priority_xoff_tx[i], |
| 1026 | &nsd->priority_xoff_tx[i]); |
| 1027 | i40e_stat_update32(hw, |
| 1028 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1029 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1030 | &osd->priority_xon_2_xoff[i], |
| 1031 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1034 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 1035 | I40E_GLPRT_PRC64L(hw->port), |
| 1036 | pf->stat_offsets_loaded, |
| 1037 | &osd->rx_size_64, &nsd->rx_size_64); |
| 1038 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 1039 | I40E_GLPRT_PRC127L(hw->port), |
| 1040 | pf->stat_offsets_loaded, |
| 1041 | &osd->rx_size_127, &nsd->rx_size_127); |
| 1042 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 1043 | I40E_GLPRT_PRC255L(hw->port), |
| 1044 | pf->stat_offsets_loaded, |
| 1045 | &osd->rx_size_255, &nsd->rx_size_255); |
| 1046 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 1047 | I40E_GLPRT_PRC511L(hw->port), |
| 1048 | pf->stat_offsets_loaded, |
| 1049 | &osd->rx_size_511, &nsd->rx_size_511); |
| 1050 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 1051 | I40E_GLPRT_PRC1023L(hw->port), |
| 1052 | pf->stat_offsets_loaded, |
| 1053 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 1054 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 1055 | I40E_GLPRT_PRC1522L(hw->port), |
| 1056 | pf->stat_offsets_loaded, |
| 1057 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 1058 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 1059 | I40E_GLPRT_PRC9522L(hw->port), |
| 1060 | pf->stat_offsets_loaded, |
| 1061 | &osd->rx_size_big, &nsd->rx_size_big); |
| 1062 | |
| 1063 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 1064 | I40E_GLPRT_PTC64L(hw->port), |
| 1065 | pf->stat_offsets_loaded, |
| 1066 | &osd->tx_size_64, &nsd->tx_size_64); |
| 1067 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 1068 | I40E_GLPRT_PTC127L(hw->port), |
| 1069 | pf->stat_offsets_loaded, |
| 1070 | &osd->tx_size_127, &nsd->tx_size_127); |
| 1071 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 1072 | I40E_GLPRT_PTC255L(hw->port), |
| 1073 | pf->stat_offsets_loaded, |
| 1074 | &osd->tx_size_255, &nsd->tx_size_255); |
| 1075 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 1076 | I40E_GLPRT_PTC511L(hw->port), |
| 1077 | pf->stat_offsets_loaded, |
| 1078 | &osd->tx_size_511, &nsd->tx_size_511); |
| 1079 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 1080 | I40E_GLPRT_PTC1023L(hw->port), |
| 1081 | pf->stat_offsets_loaded, |
| 1082 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 1083 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 1084 | I40E_GLPRT_PTC1522L(hw->port), |
| 1085 | pf->stat_offsets_loaded, |
| 1086 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1087 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1088 | I40E_GLPRT_PTC9522L(hw->port), |
| 1089 | pf->stat_offsets_loaded, |
| 1090 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1091 | |
| 1092 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1093 | pf->stat_offsets_loaded, |
| 1094 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1095 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1096 | pf->stat_offsets_loaded, |
| 1097 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1098 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1099 | pf->stat_offsets_loaded, |
| 1100 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1101 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1102 | pf->stat_offsets_loaded, |
| 1103 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1104 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1105 | /* FDIR stats */ |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1106 | i40e_stat_update32(hw, |
| 1107 | 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] | 1108 | pf->stat_offsets_loaded, |
| 1109 | &osd->fd_atr_match, &nsd->fd_atr_match); |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1110 | i40e_stat_update32(hw, |
| 1111 | 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] | 1112 | pf->stat_offsets_loaded, |
| 1113 | &osd->fd_sb_match, &nsd->fd_sb_match); |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 1114 | i40e_stat_update32(hw, |
| 1115 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), |
| 1116 | pf->stat_offsets_loaded, |
| 1117 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1118 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1119 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1120 | nsd->tx_lpi_status = |
| 1121 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1122 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1123 | nsd->rx_lpi_status = |
| 1124 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1125 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1126 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1127 | pf->stat_offsets_loaded, |
| 1128 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1129 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1130 | pf->stat_offsets_loaded, |
| 1131 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1132 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1133 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
| 1134 | !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) |
| 1135 | nsd->fd_sb_status = true; |
| 1136 | else |
| 1137 | nsd->fd_sb_status = false; |
| 1138 | |
| 1139 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
| 1140 | !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 1141 | nsd->fd_atr_status = true; |
| 1142 | else |
| 1143 | nsd->fd_atr_status = false; |
| 1144 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1145 | pf->stat_offsets_loaded = true; |
| 1146 | } |
| 1147 | |
| 1148 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1149 | * i40e_update_stats - Update the various statistics counters. |
| 1150 | * @vsi: the VSI to be updated |
| 1151 | * |
| 1152 | * Update the various stats for this VSI and its related entities. |
| 1153 | **/ |
| 1154 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1155 | { |
| 1156 | struct i40e_pf *pf = vsi->back; |
| 1157 | |
| 1158 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1159 | i40e_update_pf_stats(pf); |
| 1160 | |
| 1161 | i40e_update_vsi_stats(vsi); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1162 | #ifdef I40E_FCOE |
| 1163 | i40e_update_fcoe_stats(vsi); |
| 1164 | #endif |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1168 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1169 | * @vsi: the VSI to be searched |
| 1170 | * @macaddr: the MAC address |
| 1171 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1172 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1173 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1174 | * |
| 1175 | * Returns ptr to the filter object or NULL |
| 1176 | **/ |
| 1177 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
| 1178 | u8 *macaddr, s16 vlan, |
| 1179 | bool is_vf, bool is_netdev) |
| 1180 | { |
| 1181 | struct i40e_mac_filter *f; |
| 1182 | |
| 1183 | if (!vsi || !macaddr) |
| 1184 | return NULL; |
| 1185 | |
| 1186 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1187 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1188 | (vlan == f->vlan) && |
| 1189 | (!is_vf || f->is_vf) && |
| 1190 | (!is_netdev || f->is_netdev)) |
| 1191 | return f; |
| 1192 | } |
| 1193 | return NULL; |
| 1194 | } |
| 1195 | |
| 1196 | /** |
| 1197 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1198 | * @vsi: the VSI to be searched |
| 1199 | * @macaddr: the MAC address we are searching for |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1200 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1201 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1202 | * |
| 1203 | * Returns the first filter with the provided MAC address or NULL if |
| 1204 | * MAC address was not found |
| 1205 | **/ |
| 1206 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr, |
| 1207 | bool is_vf, bool is_netdev) |
| 1208 | { |
| 1209 | struct i40e_mac_filter *f; |
| 1210 | |
| 1211 | if (!vsi || !macaddr) |
| 1212 | return NULL; |
| 1213 | |
| 1214 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1215 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1216 | (!is_vf || f->is_vf) && |
| 1217 | (!is_netdev || f->is_netdev)) |
| 1218 | return f; |
| 1219 | } |
| 1220 | return NULL; |
| 1221 | } |
| 1222 | |
| 1223 | /** |
| 1224 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1225 | * @vsi: the VSI to be searched |
| 1226 | * |
| 1227 | * Returns true if VSI is in vlan mode or false otherwise |
| 1228 | **/ |
| 1229 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1230 | { |
| 1231 | struct i40e_mac_filter *f; |
| 1232 | |
| 1233 | /* Only -1 for all the filters denotes not in vlan mode |
| 1234 | * so we have to go through all the list in order to make sure |
| 1235 | */ |
| 1236 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Greg Rose | d9b68f8 | 2015-07-23 16:54:31 -0400 | [diff] [blame] | 1237 | if (f->vlan >= 0 || vsi->info.pvid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1238 | return true; |
| 1239 | } |
| 1240 | |
| 1241 | return false; |
| 1242 | } |
| 1243 | |
| 1244 | /** |
| 1245 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1246 | * @vsi: the VSI to be searched |
| 1247 | * @macaddr: the mac address to be filtered |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1248 | * @is_vf: true if it is a VF |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1249 | * @is_netdev: true if it is a netdev |
| 1250 | * |
| 1251 | * Goes through all the macvlan filters and adds a |
| 1252 | * macvlan filter for each unique vlan that already exists |
| 1253 | * |
| 1254 | * Returns first filter found on success, else NULL |
| 1255 | **/ |
| 1256 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1257 | bool is_vf, bool is_netdev) |
| 1258 | { |
| 1259 | struct i40e_mac_filter *f; |
| 1260 | |
| 1261 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Mitch Williams | ecbb44e | 2015-07-10 19:35:56 -0400 | [diff] [blame] | 1262 | if (vsi->info.pvid) |
| 1263 | f->vlan = le16_to_cpu(vsi->info.pvid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1264 | if (!i40e_find_filter(vsi, macaddr, f->vlan, |
| 1265 | is_vf, is_netdev)) { |
| 1266 | if (!i40e_add_filter(vsi, macaddr, f->vlan, |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 1267 | is_vf, is_netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1268 | return NULL; |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | return list_first_entry_or_null(&vsi->mac_filter_list, |
| 1273 | struct i40e_mac_filter, list); |
| 1274 | } |
| 1275 | |
| 1276 | /** |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1277 | * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS |
| 1278 | * @vsi: the VSI to be searched |
| 1279 | * @macaddr: the mac address to be removed |
| 1280 | * @is_vf: true if it is a VF |
| 1281 | * @is_netdev: true if it is a netdev |
| 1282 | * |
| 1283 | * Removes a given MAC address from a VSI, regardless of VLAN |
| 1284 | * |
| 1285 | * Returns 0 for success, or error |
| 1286 | **/ |
| 1287 | int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1288 | bool is_vf, bool is_netdev) |
| 1289 | { |
| 1290 | struct i40e_mac_filter *f = NULL; |
| 1291 | int changed = 0; |
| 1292 | |
| 1293 | WARN(!spin_is_locked(&vsi->mac_filter_list_lock), |
| 1294 | "Missing mac_filter_list_lock\n"); |
| 1295 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1296 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1297 | (is_vf == f->is_vf) && |
| 1298 | (is_netdev == f->is_netdev)) { |
| 1299 | f->counter--; |
| 1300 | f->changed = true; |
| 1301 | changed = 1; |
| 1302 | } |
| 1303 | } |
| 1304 | if (changed) { |
| 1305 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1306 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1307 | return 0; |
| 1308 | } |
| 1309 | return -ENOENT; |
| 1310 | } |
| 1311 | |
| 1312 | /** |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1313 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM |
| 1314 | * @vsi: the PF Main VSI - inappropriate for any other VSI |
| 1315 | * @macaddr: the MAC address |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1316 | * |
| 1317 | * Some older firmware configurations set up a default promiscuous VLAN |
| 1318 | * filter that needs to be removed. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1319 | **/ |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1320 | static int i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr) |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1321 | { |
| 1322 | struct i40e_aqc_remove_macvlan_element_data element; |
| 1323 | struct i40e_pf *pf = vsi->back; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1324 | i40e_status ret; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1325 | |
| 1326 | /* Only appropriate for the PF main VSI */ |
| 1327 | if (vsi->type != I40E_VSI_MAIN) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1328 | return -EINVAL; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1329 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1330 | memset(&element, 0, sizeof(element)); |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1331 | ether_addr_copy(element.mac_addr, macaddr); |
| 1332 | element.vlan_tag = 0; |
| 1333 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | |
| 1334 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1335 | ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1336 | if (ret) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1337 | return -ENOENT; |
| 1338 | |
| 1339 | return 0; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1343 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1344 | * @vsi: the VSI to be searched |
| 1345 | * @macaddr: the MAC address |
| 1346 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1347 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1348 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1349 | * |
| 1350 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1351 | * |
| 1352 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1353 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1354 | **/ |
| 1355 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
| 1356 | u8 *macaddr, s16 vlan, |
| 1357 | bool is_vf, bool is_netdev) |
| 1358 | { |
| 1359 | struct i40e_mac_filter *f; |
| 1360 | |
| 1361 | if (!vsi || !macaddr) |
| 1362 | return NULL; |
| 1363 | |
| 1364 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1365 | if (!f) { |
| 1366 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1367 | if (!f) |
| 1368 | goto add_filter_out; |
| 1369 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1370 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1371 | f->vlan = vlan; |
| 1372 | f->changed = true; |
| 1373 | |
| 1374 | INIT_LIST_HEAD(&f->list); |
Kiran Patil | 04d5a21 | 2015-12-09 15:50:23 -0800 | [diff] [blame] | 1375 | list_add_tail(&f->list, &vsi->mac_filter_list); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | /* increment counter and add a new flag if needed */ |
| 1379 | if (is_vf) { |
| 1380 | if (!f->is_vf) { |
| 1381 | f->is_vf = true; |
| 1382 | f->counter++; |
| 1383 | } |
| 1384 | } else if (is_netdev) { |
| 1385 | if (!f->is_netdev) { |
| 1386 | f->is_netdev = true; |
| 1387 | f->counter++; |
| 1388 | } |
| 1389 | } else { |
| 1390 | f->counter++; |
| 1391 | } |
| 1392 | |
| 1393 | /* changed tells sync_filters_subtask to |
| 1394 | * push the filter down to the firmware |
| 1395 | */ |
| 1396 | if (f->changed) { |
| 1397 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1398 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1399 | } |
| 1400 | |
| 1401 | add_filter_out: |
| 1402 | return f; |
| 1403 | } |
| 1404 | |
| 1405 | /** |
| 1406 | * i40e_del_filter - Remove a mac/vlan filter from the VSI |
| 1407 | * @vsi: the VSI to be searched |
| 1408 | * @macaddr: the MAC address |
| 1409 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1410 | * @is_vf: make sure it's a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1411 | * @is_netdev: make sure it's a netdev filter, else doesn't matter |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1412 | * |
| 1413 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1414 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1415 | **/ |
| 1416 | void i40e_del_filter(struct i40e_vsi *vsi, |
| 1417 | u8 *macaddr, s16 vlan, |
| 1418 | bool is_vf, bool is_netdev) |
| 1419 | { |
| 1420 | struct i40e_mac_filter *f; |
| 1421 | |
| 1422 | if (!vsi || !macaddr) |
| 1423 | return; |
| 1424 | |
| 1425 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1426 | if (!f || f->counter == 0) |
| 1427 | return; |
| 1428 | |
| 1429 | if (is_vf) { |
| 1430 | if (f->is_vf) { |
| 1431 | f->is_vf = false; |
| 1432 | f->counter--; |
| 1433 | } |
| 1434 | } else if (is_netdev) { |
| 1435 | if (f->is_netdev) { |
| 1436 | f->is_netdev = false; |
| 1437 | f->counter--; |
| 1438 | } |
| 1439 | } else { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1440 | /* make sure we don't remove a filter in use by VF or netdev */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1441 | int min_f = 0; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1442 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1443 | min_f += (f->is_vf ? 1 : 0); |
| 1444 | min_f += (f->is_netdev ? 1 : 0); |
| 1445 | |
| 1446 | if (f->counter > min_f) |
| 1447 | f->counter--; |
| 1448 | } |
| 1449 | |
| 1450 | /* counter == 0 tells sync_filters_subtask to |
| 1451 | * remove the filter from the firmware's list |
| 1452 | */ |
| 1453 | if (f->counter == 0) { |
| 1454 | f->changed = true; |
| 1455 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1456 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | /** |
| 1461 | * i40e_set_mac - NDO callback to set mac address |
| 1462 | * @netdev: network interface device structure |
| 1463 | * @p: pointer to an address structure |
| 1464 | * |
| 1465 | * Returns 0 on success, negative on failure |
| 1466 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1467 | #ifdef I40E_FCOE |
| 1468 | int i40e_set_mac(struct net_device *netdev, void *p) |
| 1469 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1470 | static int i40e_set_mac(struct net_device *netdev, void *p) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1471 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1472 | { |
| 1473 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1474 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1475 | struct i40e_pf *pf = vsi->back; |
| 1476 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1477 | struct sockaddr *addr = p; |
| 1478 | struct i40e_mac_filter *f; |
| 1479 | |
| 1480 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1481 | return -EADDRNOTAVAIL; |
| 1482 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1483 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1484 | netdev_info(netdev, "already using mac address %pM\n", |
| 1485 | addr->sa_data); |
| 1486 | return 0; |
| 1487 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1488 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1489 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1490 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1491 | return -EADDRNOTAVAIL; |
| 1492 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1493 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1494 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1495 | hw->mac.addr); |
| 1496 | else |
| 1497 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1498 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1499 | if (vsi->type == I40E_VSI_MAIN) { |
| 1500 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1501 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1502 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1503 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1504 | addr->sa_data, NULL); |
| 1505 | if (ret) { |
| 1506 | netdev_info(netdev, |
| 1507 | "Addr change for Main VSI failed: %d\n", |
| 1508 | ret); |
| 1509 | return -EADDRNOTAVAIL; |
| 1510 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1513 | if (ether_addr_equal(netdev->dev_addr, hw->mac.addr)) { |
| 1514 | struct i40e_aqc_remove_macvlan_element_data element; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1515 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1516 | memset(&element, 0, sizeof(element)); |
| 1517 | ether_addr_copy(element.mac_addr, netdev->dev_addr); |
| 1518 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1519 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1520 | } else { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1521 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1522 | i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 1523 | false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1524 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1527 | if (ether_addr_equal(addr->sa_data, hw->mac.addr)) { |
| 1528 | struct i40e_aqc_add_macvlan_element_data element; |
| 1529 | |
| 1530 | memset(&element, 0, sizeof(element)); |
| 1531 | ether_addr_copy(element.mac_addr, hw->mac.addr); |
| 1532 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 1533 | i40e_aq_add_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1534 | } else { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1535 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1536 | f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, |
| 1537 | false, false); |
| 1538 | if (f) |
| 1539 | f->is_laa = true; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1540 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1543 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1544 | |
| 1545 | return i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | /** |
| 1549 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1550 | * @vsi: the VSI being setup |
| 1551 | * @ctxt: VSI context structure |
| 1552 | * @enabled_tc: Enabled TCs bitmap |
| 1553 | * @is_add: True if called before Add VSI |
| 1554 | * |
| 1555 | * Setup VSI queue mapping for enabled traffic classes. |
| 1556 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1557 | #ifdef I40E_FCOE |
| 1558 | void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1559 | struct i40e_vsi_context *ctxt, |
| 1560 | u8 enabled_tc, |
| 1561 | bool is_add) |
| 1562 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1563 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1564 | struct i40e_vsi_context *ctxt, |
| 1565 | u8 enabled_tc, |
| 1566 | bool is_add) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1567 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1568 | { |
| 1569 | struct i40e_pf *pf = vsi->back; |
| 1570 | u16 sections = 0; |
| 1571 | u8 netdev_tc = 0; |
| 1572 | u16 numtc = 0; |
| 1573 | u16 qcount; |
| 1574 | u8 offset; |
| 1575 | u16 qmap; |
| 1576 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1577 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1578 | |
| 1579 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1580 | offset = 0; |
| 1581 | |
| 1582 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1583 | /* Find numtc from enabled TC bitmap */ |
| 1584 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1585 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1586 | numtc++; |
| 1587 | } |
| 1588 | if (!numtc) { |
| 1589 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1590 | numtc = 1; |
| 1591 | } |
| 1592 | } else { |
| 1593 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1594 | numtc = 1; |
| 1595 | } |
| 1596 | |
| 1597 | vsi->tc_config.numtc = numtc; |
| 1598 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1599 | /* Number of queues per enabled TC */ |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1600 | /* In MFP case we can have a much lower count of MSIx |
| 1601 | * vectors available and so we need to lower the used |
| 1602 | * q count. |
| 1603 | */ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1604 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 1605 | qcount = min_t(int, vsi->alloc_queue_pairs, pf->num_lan_msix); |
| 1606 | else |
| 1607 | qcount = vsi->alloc_queue_pairs; |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1608 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1609 | 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] | 1610 | |
| 1611 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1612 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1613 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1614 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1615 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1616 | int pow, num_qps; |
| 1617 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1618 | switch (vsi->type) { |
| 1619 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1620 | qcount = min_t(int, pf->alloc_rss_size, |
| 1621 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1622 | break; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1623 | #ifdef I40E_FCOE |
| 1624 | case I40E_VSI_FCOE: |
| 1625 | qcount = num_tc_qps; |
| 1626 | break; |
| 1627 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1628 | case I40E_VSI_FDIR: |
| 1629 | case I40E_VSI_SRIOV: |
| 1630 | case I40E_VSI_VMDQ2: |
| 1631 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1632 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1633 | WARN_ON(i != 0); |
| 1634 | break; |
| 1635 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1636 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1637 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1638 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1639 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1640 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1641 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1642 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1643 | pow++; |
| 1644 | num_qps >>= 1; |
| 1645 | } |
| 1646 | |
| 1647 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1648 | qmap = |
| 1649 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1650 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1651 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1652 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1653 | } else { |
| 1654 | /* TC is not enabled so set the offset to |
| 1655 | * default queue and allocate one queue |
| 1656 | * for the given TC. |
| 1657 | */ |
| 1658 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1659 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1660 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1661 | |
| 1662 | qmap = 0; |
| 1663 | } |
| 1664 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1665 | } |
| 1666 | |
| 1667 | /* Set actual Tx/Rx queue pairs */ |
| 1668 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1669 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1670 | if (vsi->req_queue_pairs > 0) |
| 1671 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1672 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1673 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1674 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1675 | |
| 1676 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1677 | if (is_add) { |
| 1678 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1679 | |
| 1680 | ctxt->info.up_enable_bits = enabled_tc; |
| 1681 | } |
| 1682 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1683 | ctxt->info.mapping_flags |= |
| 1684 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1685 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1686 | ctxt->info.queue_mapping[i] = |
| 1687 | cpu_to_le16(vsi->base_queue + i); |
| 1688 | } else { |
| 1689 | ctxt->info.mapping_flags |= |
| 1690 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1691 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1692 | } |
| 1693 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1694 | } |
| 1695 | |
| 1696 | /** |
| 1697 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1698 | * @netdev: network interface device structure |
| 1699 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1700 | #ifdef I40E_FCOE |
| 1701 | void i40e_set_rx_mode(struct net_device *netdev) |
| 1702 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1703 | static void i40e_set_rx_mode(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1704 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1705 | { |
| 1706 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1707 | struct i40e_mac_filter *f, *ftmp; |
| 1708 | struct i40e_vsi *vsi = np->vsi; |
| 1709 | struct netdev_hw_addr *uca; |
| 1710 | struct netdev_hw_addr *mca; |
| 1711 | struct netdev_hw_addr *ha; |
| 1712 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1713 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1714 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1715 | /* add addr if not already in the filter list */ |
| 1716 | netdev_for_each_uc_addr(uca, netdev) { |
| 1717 | if (!i40e_find_mac(vsi, uca->addr, false, true)) { |
| 1718 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1719 | i40e_put_mac_in_vlan(vsi, uca->addr, |
| 1720 | false, true); |
| 1721 | else |
| 1722 | i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY, |
| 1723 | false, true); |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | netdev_for_each_mc_addr(mca, netdev) { |
| 1728 | if (!i40e_find_mac(vsi, mca->addr, false, true)) { |
| 1729 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1730 | i40e_put_mac_in_vlan(vsi, mca->addr, |
| 1731 | false, true); |
| 1732 | else |
| 1733 | i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY, |
| 1734 | false, true); |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | /* remove filter if not in netdev list */ |
| 1739 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1740 | |
| 1741 | if (!f->is_netdev) |
| 1742 | continue; |
| 1743 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1744 | netdev_for_each_mc_addr(mca, netdev) |
| 1745 | if (ether_addr_equal(mca->addr, f->macaddr)) |
| 1746 | goto bottom_of_search_loop; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1747 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1748 | netdev_for_each_uc_addr(uca, netdev) |
| 1749 | if (ether_addr_equal(uca->addr, f->macaddr)) |
| 1750 | goto bottom_of_search_loop; |
| 1751 | |
| 1752 | for_each_dev_addr(netdev, ha) |
| 1753 | if (ether_addr_equal(ha->addr, f->macaddr)) |
| 1754 | goto bottom_of_search_loop; |
| 1755 | |
| 1756 | /* f->macaddr wasn't found in uc, mc, or ha list so delete it */ |
| 1757 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true); |
| 1758 | |
| 1759 | bottom_of_search_loop: |
| 1760 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1761 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1762 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1763 | |
| 1764 | /* check for other flag changes */ |
| 1765 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1766 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1767 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1768 | } |
| 1769 | } |
| 1770 | |
| 1771 | /** |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1772 | * i40e_mac_filter_entry_clone - Clones a MAC filter entry |
| 1773 | * @src: source MAC filter entry to be clones |
| 1774 | * |
| 1775 | * Returns the pointer to newly cloned MAC filter entry or NULL |
| 1776 | * in case of error |
| 1777 | **/ |
| 1778 | static struct i40e_mac_filter *i40e_mac_filter_entry_clone( |
| 1779 | struct i40e_mac_filter *src) |
| 1780 | { |
| 1781 | struct i40e_mac_filter *f; |
| 1782 | |
| 1783 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1784 | if (!f) |
| 1785 | return NULL; |
| 1786 | *f = *src; |
| 1787 | |
| 1788 | INIT_LIST_HEAD(&f->list); |
| 1789 | |
| 1790 | return f; |
| 1791 | } |
| 1792 | |
| 1793 | /** |
| 1794 | * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries |
| 1795 | * @vsi: pointer to vsi struct |
| 1796 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1797 | * those entries needs to be undone. |
| 1798 | * |
| 1799 | * MAC filter entries from list were slated to be removed from device. |
| 1800 | **/ |
| 1801 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1802 | struct list_head *from) |
| 1803 | { |
| 1804 | struct i40e_mac_filter *f, *ftmp; |
| 1805 | |
| 1806 | list_for_each_entry_safe(f, ftmp, from, list) { |
| 1807 | f->changed = true; |
| 1808 | /* Move the element back into MAC filter list*/ |
| 1809 | list_move_tail(&f->list, &vsi->mac_filter_list); |
| 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | /** |
| 1814 | * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries |
| 1815 | * @vsi: pointer to vsi struct |
| 1816 | * |
| 1817 | * MAC filter entries from list were slated to be added from device. |
| 1818 | **/ |
| 1819 | static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi) |
| 1820 | { |
| 1821 | struct i40e_mac_filter *f, *ftmp; |
| 1822 | |
| 1823 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1824 | if (!f->changed && f->counter) |
| 1825 | f->changed = true; |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | /** |
| 1830 | * i40e_cleanup_add_list - Deletes the element from add list and release |
| 1831 | * memory |
| 1832 | * @add_list: Pointer to list which contains MAC filter entries |
| 1833 | **/ |
| 1834 | static void i40e_cleanup_add_list(struct list_head *add_list) |
| 1835 | { |
| 1836 | struct i40e_mac_filter *f, *ftmp; |
| 1837 | |
| 1838 | list_for_each_entry_safe(f, ftmp, add_list, list) { |
| 1839 | list_del(&f->list); |
| 1840 | kfree(f); |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1845 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1846 | * @vsi: ptr to the VSI |
| 1847 | * |
| 1848 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1849 | * |
| 1850 | * Returns 0 or error value |
| 1851 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 1852 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1853 | { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1854 | struct list_head tmp_del_list, tmp_add_list; |
| 1855 | struct i40e_mac_filter *f, *ftmp, *fclone; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1856 | bool promisc_forced_on = false; |
| 1857 | bool add_happened = false; |
| 1858 | int filter_list_len = 0; |
| 1859 | u32 changed_flags = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1860 | i40e_status aq_ret = 0; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1861 | bool err_cond = false; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1862 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1863 | struct i40e_pf *pf; |
| 1864 | int num_add = 0; |
| 1865 | int num_del = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1866 | int aq_err = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1867 | u16 cmd_flags; |
| 1868 | |
| 1869 | /* empty array typed pointers, kcalloc later */ |
| 1870 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1871 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1872 | |
| 1873 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1874 | usleep_range(1000, 2000); |
| 1875 | pf = vsi->back; |
| 1876 | |
| 1877 | if (vsi->netdev) { |
| 1878 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1879 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1880 | } |
| 1881 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1882 | INIT_LIST_HEAD(&tmp_del_list); |
| 1883 | INIT_LIST_HEAD(&tmp_add_list); |
| 1884 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1885 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1886 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1887 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1888 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1889 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1890 | if (!f->changed) |
| 1891 | continue; |
| 1892 | |
| 1893 | if (f->counter != 0) |
| 1894 | continue; |
| 1895 | f->changed = false; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1896 | |
| 1897 | /* Move the element into temporary del_list */ |
| 1898 | list_move_tail(&f->list, &tmp_del_list); |
| 1899 | } |
| 1900 | |
| 1901 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1902 | if (!f->changed) |
| 1903 | continue; |
| 1904 | |
| 1905 | if (f->counter == 0) |
| 1906 | continue; |
| 1907 | f->changed = false; |
| 1908 | |
| 1909 | /* Clone MAC filter entry and add into temporary list */ |
| 1910 | fclone = i40e_mac_filter_entry_clone(f); |
| 1911 | if (!fclone) { |
| 1912 | err_cond = true; |
| 1913 | break; |
| 1914 | } |
| 1915 | list_add_tail(&fclone->list, &tmp_add_list); |
| 1916 | } |
| 1917 | |
| 1918 | /* if failed to clone MAC filter entry - undo */ |
| 1919 | if (err_cond) { |
| 1920 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 1921 | i40e_undo_add_filter_entries(vsi); |
| 1922 | } |
| 1923 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 1924 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1925 | if (err_cond) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1926 | i40e_cleanup_add_list(&tmp_add_list); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1927 | retval = -ENOMEM; |
| 1928 | goto out; |
| 1929 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | /* Now process 'del_list' outside the lock */ |
| 1933 | if (!list_empty(&tmp_del_list)) { |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1934 | int del_list_size; |
| 1935 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1936 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 1937 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1938 | del_list_size = filter_list_len * |
| 1939 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Jesse Brandeburg | 38c3cec | 2016-01-04 10:33:05 -0800 | [diff] [blame^] | 1940 | del_list = kzalloc(del_list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1941 | if (!del_list) { |
| 1942 | i40e_cleanup_add_list(&tmp_add_list); |
| 1943 | |
| 1944 | /* Undo VSI's MAC filter entry element updates */ |
| 1945 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1946 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 1947 | i40e_undo_add_filter_entries(vsi); |
| 1948 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1949 | retval = -ENOMEM; |
| 1950 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1954 | cmd_flags = 0; |
| 1955 | |
| 1956 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1957 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1958 | del_list[num_del].vlan_tag = |
| 1959 | cpu_to_le16((u16)(f->vlan == |
| 1960 | I40E_VLAN_ANY ? 0 : f->vlan)); |
| 1961 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1962 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1963 | del_list[num_del].flags = cmd_flags; |
| 1964 | num_del++; |
| 1965 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1966 | /* flush a full buffer */ |
| 1967 | if (num_del == filter_list_len) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1968 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, |
| 1969 | vsi->seid, |
| 1970 | del_list, |
| 1971 | num_del, |
| 1972 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1973 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1974 | num_del = 0; |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1975 | memset(del_list, 0, del_list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1976 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1977 | if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) { |
| 1978 | retval = -EIO; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1979 | dev_err(&pf->pdev->dev, |
| 1980 | "ignoring delete macvlan error, err %s, aq_err %s while flushing a full buffer\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1981 | i40e_stat_str(&pf->hw, aq_ret), |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1982 | i40e_aq_str(&pf->hw, aq_err)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1983 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1984 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1985 | /* Release memory for MAC filter entries which were |
| 1986 | * synced up with HW. |
| 1987 | */ |
| 1988 | list_del(&f->list); |
| 1989 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1990 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1991 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1992 | if (num_del) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1993 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, |
| 1994 | del_list, num_del, |
| 1995 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1996 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1997 | num_del = 0; |
| 1998 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1999 | if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2000 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2001 | "ignoring delete macvlan error, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2002 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2003 | i40e_aq_str(&pf->hw, aq_err)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | kfree(del_list); |
| 2007 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | if (!list_empty(&tmp_add_list)) { |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2011 | int add_list_size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2012 | |
| 2013 | /* do all the adds now */ |
| 2014 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 2015 | sizeof(struct i40e_aqc_add_macvlan_element_data), |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2016 | add_list_size = filter_list_len * |
| 2017 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Jesse Brandeburg | 38c3cec | 2016-01-04 10:33:05 -0800 | [diff] [blame^] | 2018 | add_list = kzalloc(add_list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2019 | if (!add_list) { |
| 2020 | /* Purge element from temporary lists */ |
| 2021 | i40e_cleanup_add_list(&tmp_add_list); |
| 2022 | |
| 2023 | /* Undo add filter entries from VSI MAC filter list */ |
| 2024 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2025 | i40e_undo_add_filter_entries(vsi); |
| 2026 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2027 | retval = -ENOMEM; |
| 2028 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2029 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2030 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2031 | list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2032 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2033 | add_happened = true; |
| 2034 | cmd_flags = 0; |
| 2035 | |
| 2036 | /* add to add array */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2037 | ether_addr_copy(add_list[num_add].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2038 | add_list[num_add].vlan_tag = |
| 2039 | cpu_to_le16( |
| 2040 | (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan)); |
| 2041 | add_list[num_add].queue_number = 0; |
| 2042 | |
| 2043 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2044 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2045 | num_add++; |
| 2046 | |
| 2047 | /* flush a full buffer */ |
| 2048 | if (num_add == filter_list_len) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2049 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 2050 | add_list, num_add, |
| 2051 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2052 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2053 | num_add = 0; |
| 2054 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2055 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2056 | break; |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2057 | memset(add_list, 0, add_list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2058 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2059 | /* Entries from tmp_add_list were cloned from MAC |
| 2060 | * filter list, hence clean those cloned entries |
| 2061 | */ |
| 2062 | list_del(&f->list); |
| 2063 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2064 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2065 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2066 | if (num_add) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2067 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 2068 | add_list, num_add, NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2069 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2070 | num_add = 0; |
| 2071 | } |
| 2072 | kfree(add_list); |
| 2073 | add_list = NULL; |
| 2074 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2075 | if (add_happened && aq_ret && aq_err != I40E_AQ_RC_EINVAL) { |
| 2076 | retval = i40e_aq_rc_to_posix(aq_ret, aq_err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2077 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2078 | "add filter failed, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2079 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2080 | i40e_aq_str(&pf->hw, aq_err)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2081 | if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) && |
| 2082 | !test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2083 | &vsi->state)) { |
| 2084 | promisc_forced_on = true; |
| 2085 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2086 | &vsi->state); |
| 2087 | dev_info(&pf->pdev->dev, "promiscuous mode forced on\n"); |
| 2088 | } |
| 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | /* check for changes in promiscuous modes */ |
| 2093 | if (changed_flags & IFF_ALLMULTI) { |
| 2094 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2095 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2096 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2097 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2098 | vsi->seid, |
| 2099 | cur_multipromisc, |
| 2100 | NULL); |
| 2101 | if (aq_ret) { |
| 2102 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2103 | pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2104 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2105 | "set multi promisc failed, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2106 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2107 | i40e_aq_str(&pf->hw, |
| 2108 | pf->hw.aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2109 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2110 | } |
| 2111 | if ((changed_flags & IFF_PROMISC) || promisc_forced_on) { |
| 2112 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2113 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2114 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 2115 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2116 | &vsi->state)); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2117 | if (vsi->type == I40E_VSI_MAIN && pf->lan_veb != I40E_NO_VEB) { |
| 2118 | /* set defport ON for Main VSI instead of true promisc |
| 2119 | * this way we will get all unicast/multicast and VLAN |
| 2120 | * promisc behavior but will not get VF or VMDq traffic |
| 2121 | * replicated on the Main VSI. |
| 2122 | */ |
| 2123 | if (pf->cur_promisc != cur_promisc) { |
| 2124 | pf->cur_promisc = cur_promisc; |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2125 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2126 | } |
| 2127 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2128 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2129 | &vsi->back->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2130 | vsi->seid, |
| 2131 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2132 | if (aq_ret) { |
| 2133 | retval = |
| 2134 | i40e_aq_rc_to_posix(aq_ret, |
| 2135 | pf->hw.aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2136 | dev_info(&pf->pdev->dev, |
| 2137 | "set unicast promisc failed, err %d, aq_err %d\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2138 | aq_ret, pf->hw.aq.asq_last_status); |
| 2139 | } |
| 2140 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2141 | &vsi->back->hw, |
| 2142 | vsi->seid, |
| 2143 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2144 | if (aq_ret) { |
| 2145 | retval = |
| 2146 | i40e_aq_rc_to_posix(aq_ret, |
| 2147 | pf->hw.aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2148 | dev_info(&pf->pdev->dev, |
| 2149 | "set multicast promisc failed, err %d, aq_err %d\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2150 | aq_ret, pf->hw.aq.asq_last_status); |
| 2151 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2152 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2153 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2154 | vsi->seid, |
| 2155 | cur_promisc, NULL); |
| 2156 | if (aq_ret) { |
| 2157 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2158 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2159 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2160 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2161 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2162 | i40e_aq_str(&pf->hw, |
| 2163 | pf->hw.aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2164 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2165 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2166 | out: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2167 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2168 | return retval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | /** |
| 2172 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2173 | * @pf: board private structure |
| 2174 | **/ |
| 2175 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2176 | { |
| 2177 | int v; |
| 2178 | |
| 2179 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2180 | return; |
| 2181 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2182 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2183 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2184 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2185 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2186 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2187 | |
| 2188 | if (ret) { |
| 2189 | /* come back and try again later */ |
| 2190 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2191 | break; |
| 2192 | } |
| 2193 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | /** |
| 2198 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2199 | * @netdev: network interface device structure |
| 2200 | * @new_mtu: new value for maximum frame size |
| 2201 | * |
| 2202 | * Returns 0 on success, negative on failure |
| 2203 | **/ |
| 2204 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2205 | { |
| 2206 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 61a46a4 | 2014-04-23 04:50:05 +0000 | [diff] [blame] | 2207 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2208 | struct i40e_vsi *vsi = np->vsi; |
| 2209 | |
| 2210 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 2211 | if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) |
| 2212 | return -EINVAL; |
| 2213 | |
| 2214 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2215 | netdev->mtu, new_mtu); |
| 2216 | netdev->mtu = new_mtu; |
| 2217 | if (netif_running(netdev)) |
| 2218 | i40e_vsi_reinit_locked(vsi); |
| 2219 | |
| 2220 | return 0; |
| 2221 | } |
| 2222 | |
| 2223 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2224 | * i40e_ioctl - Access the hwtstamp interface |
| 2225 | * @netdev: network interface device structure |
| 2226 | * @ifr: interface request data |
| 2227 | * @cmd: ioctl command |
| 2228 | **/ |
| 2229 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2230 | { |
| 2231 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2232 | struct i40e_pf *pf = np->vsi->back; |
| 2233 | |
| 2234 | switch (cmd) { |
| 2235 | case SIOCGHWTSTAMP: |
| 2236 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2237 | case SIOCSHWTSTAMP: |
| 2238 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2239 | default: |
| 2240 | return -EOPNOTSUPP; |
| 2241 | } |
| 2242 | } |
| 2243 | |
| 2244 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2245 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2246 | * @vsi: the vsi being adjusted |
| 2247 | **/ |
| 2248 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2249 | { |
| 2250 | struct i40e_vsi_context ctxt; |
| 2251 | i40e_status ret; |
| 2252 | |
| 2253 | if ((vsi->info.valid_sections & |
| 2254 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2255 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2256 | return; /* already enabled */ |
| 2257 | |
| 2258 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2259 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2260 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2261 | |
| 2262 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2263 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2264 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2265 | if (ret) { |
| 2266 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2267 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2268 | i40e_stat_str(&vsi->back->hw, ret), |
| 2269 | i40e_aq_str(&vsi->back->hw, |
| 2270 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | /** |
| 2275 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2276 | * @vsi: the vsi being adjusted |
| 2277 | **/ |
| 2278 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2279 | { |
| 2280 | struct i40e_vsi_context ctxt; |
| 2281 | i40e_status ret; |
| 2282 | |
| 2283 | if ((vsi->info.valid_sections & |
| 2284 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2285 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2286 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2287 | return; /* already disabled */ |
| 2288 | |
| 2289 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2290 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2291 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2292 | |
| 2293 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2294 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2295 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2296 | if (ret) { |
| 2297 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2298 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2299 | i40e_stat_str(&vsi->back->hw, ret), |
| 2300 | i40e_aq_str(&vsi->back->hw, |
| 2301 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2302 | } |
| 2303 | } |
| 2304 | |
| 2305 | /** |
| 2306 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2307 | * @netdev: network interface to be adjusted |
| 2308 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2309 | **/ |
| 2310 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2311 | { |
| 2312 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2313 | struct i40e_vsi *vsi = np->vsi; |
| 2314 | |
| 2315 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2316 | i40e_vlan_stripping_enable(vsi); |
| 2317 | else |
| 2318 | i40e_vlan_stripping_disable(vsi); |
| 2319 | } |
| 2320 | |
| 2321 | /** |
| 2322 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 2323 | * @vsi: the vsi being configured |
| 2324 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 2325 | **/ |
| 2326 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2327 | { |
| 2328 | struct i40e_mac_filter *f, *add_f; |
| 2329 | bool is_netdev, is_vf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2330 | |
| 2331 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2332 | is_netdev = !!(vsi->netdev); |
| 2333 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2334 | /* Locked once because all functions invoked below iterates list*/ |
| 2335 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2336 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2337 | if (is_netdev) { |
| 2338 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid, |
| 2339 | is_vf, is_netdev); |
| 2340 | if (!add_f) { |
| 2341 | dev_info(&vsi->back->pdev->dev, |
| 2342 | "Could not add vlan filter %d for %pM\n", |
| 2343 | vid, vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2344 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2345 | return -ENOMEM; |
| 2346 | } |
| 2347 | } |
| 2348 | |
| 2349 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2350 | add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2351 | if (!add_f) { |
| 2352 | dev_info(&vsi->back->pdev->dev, |
| 2353 | "Could not add vlan filter %d for %pM\n", |
| 2354 | vid, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2355 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2356 | return -ENOMEM; |
| 2357 | } |
| 2358 | } |
| 2359 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2360 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 2361 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 2362 | * with 0, so we now accept untagged and specified tagged traffic |
| 2363 | * (and not any taged and untagged) |
| 2364 | */ |
| 2365 | if (vid > 0) { |
| 2366 | if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 2367 | I40E_VLAN_ANY, |
| 2368 | is_vf, is_netdev)) { |
| 2369 | i40e_del_filter(vsi, vsi->netdev->dev_addr, |
| 2370 | I40E_VLAN_ANY, is_vf, is_netdev); |
| 2371 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0, |
| 2372 | is_vf, is_netdev); |
| 2373 | if (!add_f) { |
| 2374 | dev_info(&vsi->back->pdev->dev, |
| 2375 | "Could not add filter 0 for %pM\n", |
| 2376 | vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2377 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2378 | return -ENOMEM; |
| 2379 | } |
| 2380 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2381 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2382 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2383 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
| 2384 | if (vid > 0 && !vsi->info.pvid) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2385 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2386 | if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2387 | is_vf, is_netdev)) |
| 2388 | continue; |
| 2389 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2390 | is_vf, is_netdev); |
| 2391 | add_f = i40e_add_filter(vsi, f->macaddr, |
| 2392 | 0, is_vf, is_netdev); |
| 2393 | if (!add_f) { |
| 2394 | dev_info(&vsi->back->pdev->dev, |
| 2395 | "Could not add filter 0 for %pM\n", |
| 2396 | f->macaddr); |
| 2397 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2398 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2399 | } |
| 2400 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2403 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2404 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2405 | /* schedule our worker thread which will take care of |
| 2406 | * applying the new filter changes |
| 2407 | */ |
| 2408 | i40e_service_event_schedule(vsi->back); |
| 2409 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | /** |
| 2413 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 2414 | * @vsi: the vsi being configured |
| 2415 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2416 | * |
| 2417 | * Return: 0 on success or negative otherwise |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2418 | **/ |
| 2419 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2420 | { |
| 2421 | struct net_device *netdev = vsi->netdev; |
| 2422 | struct i40e_mac_filter *f, *add_f; |
| 2423 | bool is_vf, is_netdev; |
| 2424 | int filter_count = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2425 | |
| 2426 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2427 | is_netdev = !!(netdev); |
| 2428 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2429 | /* Locked once because all functions invoked below iterates list */ |
| 2430 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2431 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2432 | if (is_netdev) |
| 2433 | i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev); |
| 2434 | |
| 2435 | list_for_each_entry(f, &vsi->mac_filter_list, list) |
| 2436 | i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2437 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2438 | /* go through all the filters for this VSI and if there is only |
| 2439 | * vid == 0 it means there are no other filters, so vid 0 must |
| 2440 | * be replaced with -1. This signifies that we should from now |
| 2441 | * on accept any traffic (with any tag present, or untagged) |
| 2442 | */ |
| 2443 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2444 | if (is_netdev) { |
| 2445 | if (f->vlan && |
| 2446 | ether_addr_equal(netdev->dev_addr, f->macaddr)) |
| 2447 | filter_count++; |
| 2448 | } |
| 2449 | |
| 2450 | if (f->vlan) |
| 2451 | filter_count++; |
| 2452 | } |
| 2453 | |
| 2454 | if (!filter_count && is_netdev) { |
| 2455 | i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev); |
| 2456 | f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 2457 | is_vf, is_netdev); |
| 2458 | if (!f) { |
| 2459 | dev_info(&vsi->back->pdev->dev, |
| 2460 | "Could not add filter %d for %pM\n", |
| 2461 | I40E_VLAN_ANY, netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2462 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2463 | return -ENOMEM; |
| 2464 | } |
| 2465 | } |
| 2466 | |
| 2467 | if (!filter_count) { |
| 2468 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2469 | i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev); |
| 2470 | add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2471 | is_vf, is_netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2472 | if (!add_f) { |
| 2473 | dev_info(&vsi->back->pdev->dev, |
| 2474 | "Could not add filter %d for %pM\n", |
| 2475 | I40E_VLAN_ANY, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2476 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2477 | return -ENOMEM; |
| 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2482 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2483 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2484 | /* schedule our worker thread which will take care of |
| 2485 | * applying the new filter changes |
| 2486 | */ |
| 2487 | i40e_service_event_schedule(vsi->back); |
| 2488 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | /** |
| 2492 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2493 | * @netdev: network interface to be adjusted |
| 2494 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2495 | * |
| 2496 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2497 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2498 | #ifdef I40E_FCOE |
| 2499 | int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2500 | __always_unused __be16 proto, u16 vid) |
| 2501 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2502 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2503 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2504 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2505 | { |
| 2506 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2507 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2508 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2509 | |
| 2510 | if (vid > 4095) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2511 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2512 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2513 | netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid); |
| 2514 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2515 | /* If the network stack called us with vid = 0 then |
| 2516 | * it is asking to receive priority tagged packets with |
| 2517 | * vlan id 0. Our HW receives them by default when configured |
| 2518 | * to receive untagged packets so there is no need to add an |
| 2519 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2520 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2521 | if (vid) |
| 2522 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2523 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2524 | if (!ret && (vid < VLAN_N_VID)) |
| 2525 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2526 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2527 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | /** |
| 2531 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2532 | * @netdev: network interface to be adjusted |
| 2533 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2534 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2535 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2536 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2537 | #ifdef I40E_FCOE |
| 2538 | int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2539 | __always_unused __be16 proto, u16 vid) |
| 2540 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2541 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2542 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2543 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2544 | { |
| 2545 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2546 | struct i40e_vsi *vsi = np->vsi; |
| 2547 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2548 | netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid); |
| 2549 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2550 | /* return code is ignored as there is nothing a user |
| 2551 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2552 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2553 | */ |
| 2554 | i40e_vsi_kill_vlan(vsi, vid); |
| 2555 | |
| 2556 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2557 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2558 | return 0; |
| 2559 | } |
| 2560 | |
| 2561 | /** |
| 2562 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2563 | * @vsi: the vsi being brought back up |
| 2564 | **/ |
| 2565 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2566 | { |
| 2567 | u16 vid; |
| 2568 | |
| 2569 | if (!vsi->netdev) |
| 2570 | return; |
| 2571 | |
| 2572 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2573 | |
| 2574 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2575 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2576 | vid); |
| 2577 | } |
| 2578 | |
| 2579 | /** |
| 2580 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2581 | * @vsi: the vsi being adjusted |
| 2582 | * @vid: the vlan id to set as a PVID |
| 2583 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2584 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2585 | { |
| 2586 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2587 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2588 | |
| 2589 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2590 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2591 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2592 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2593 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2594 | |
| 2595 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2596 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2597 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2598 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2599 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2600 | "add pvid failed, err %s aq_err %s\n", |
| 2601 | i40e_stat_str(&vsi->back->hw, ret), |
| 2602 | i40e_aq_str(&vsi->back->hw, |
| 2603 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2604 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2605 | } |
| 2606 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2607 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | /** |
| 2611 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2612 | * @vsi: the vsi being adjusted |
| 2613 | * |
| 2614 | * Just use the vlan_rx_register() service to put it back to normal |
| 2615 | **/ |
| 2616 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2617 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2618 | i40e_vlan_stripping_disable(vsi); |
| 2619 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2620 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | /** |
| 2624 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2625 | * @vsi: ptr to the VSI |
| 2626 | * |
| 2627 | * If this function returns with an error, then it's possible one or |
| 2628 | * more of the rings is populated (while the rest are not). It is the |
| 2629 | * callers duty to clean those orphaned rings. |
| 2630 | * |
| 2631 | * Return 0 on success, negative on failure |
| 2632 | **/ |
| 2633 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2634 | { |
| 2635 | int i, err = 0; |
| 2636 | |
| 2637 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2638 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2639 | |
| 2640 | return err; |
| 2641 | } |
| 2642 | |
| 2643 | /** |
| 2644 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2645 | * @vsi: ptr to the VSI |
| 2646 | * |
| 2647 | * Free VSI's transmit software resources |
| 2648 | **/ |
| 2649 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2650 | { |
| 2651 | int i; |
| 2652 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2653 | if (!vsi->tx_rings) |
| 2654 | return; |
| 2655 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2656 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2657 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2658 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | /** |
| 2662 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2663 | * @vsi: ptr to the VSI |
| 2664 | * |
| 2665 | * If this function returns with an error, then it's possible one or |
| 2666 | * more of the rings is populated (while the rest are not). It is the |
| 2667 | * callers duty to clean those orphaned rings. |
| 2668 | * |
| 2669 | * Return 0 on success, negative on failure |
| 2670 | **/ |
| 2671 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2672 | { |
| 2673 | int i, err = 0; |
| 2674 | |
| 2675 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2676 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2677 | #ifdef I40E_FCOE |
| 2678 | i40e_fcoe_setup_ddp_resources(vsi); |
| 2679 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2680 | return err; |
| 2681 | } |
| 2682 | |
| 2683 | /** |
| 2684 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2685 | * @vsi: ptr to the VSI |
| 2686 | * |
| 2687 | * Free all receive software resources |
| 2688 | **/ |
| 2689 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2690 | { |
| 2691 | int i; |
| 2692 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2693 | if (!vsi->rx_rings) |
| 2694 | return; |
| 2695 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2696 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2697 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2698 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2699 | #ifdef I40E_FCOE |
| 2700 | i40e_fcoe_free_ddp_resources(vsi); |
| 2701 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2705 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2706 | * @ring: The Tx ring to configure |
| 2707 | * |
| 2708 | * This enables/disables XPS for a given Tx descriptor ring |
| 2709 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2710 | **/ |
| 2711 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2712 | { |
| 2713 | struct i40e_vsi *vsi = ring->vsi; |
| 2714 | cpumask_var_t mask; |
| 2715 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2716 | if (!ring->q_vector || !ring->netdev) |
| 2717 | return; |
| 2718 | |
| 2719 | /* Single TC mode enable XPS */ |
| 2720 | if (vsi->tc_config.numtc <= 1) { |
| 2721 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2722 | netif_set_xps_queue(ring->netdev, |
| 2723 | &ring->q_vector->affinity_mask, |
| 2724 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2725 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2726 | /* Disable XPS to allow selection based on TC */ |
| 2727 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2728 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2729 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2730 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2731 | |
| 2732 | /* schedule our worker thread which will take care of |
| 2733 | * applying the new filter changes |
| 2734 | */ |
| 2735 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2739 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2740 | * @ring: The Tx ring to configure |
| 2741 | * |
| 2742 | * Configure the Tx descriptor ring in the HMC context. |
| 2743 | **/ |
| 2744 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2745 | { |
| 2746 | struct i40e_vsi *vsi = ring->vsi; |
| 2747 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2748 | struct i40e_hw *hw = &vsi->back->hw; |
| 2749 | struct i40e_hmc_obj_txq tx_ctx; |
| 2750 | i40e_status err = 0; |
| 2751 | u32 qtx_ctl = 0; |
| 2752 | |
| 2753 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2754 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2755 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2756 | ring->atr_count = 0; |
| 2757 | } else { |
| 2758 | ring->atr_sample_rate = 0; |
| 2759 | } |
| 2760 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2761 | /* configure XPS */ |
| 2762 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2763 | |
| 2764 | /* clear the context structure first */ |
| 2765 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2766 | |
| 2767 | tx_ctx.new_context = 1; |
| 2768 | tx_ctx.base = (ring->dma / 128); |
| 2769 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2770 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2771 | I40E_FLAG_FD_ATR_ENABLED)); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2772 | #ifdef I40E_FCOE |
| 2773 | tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2774 | #endif |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2775 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2776 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2777 | if (vsi->type != I40E_VSI_FDIR) |
| 2778 | tx_ctx.head_wb_ena = 1; |
| 2779 | tx_ctx.head_wb_addr = ring->dma + |
| 2780 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2781 | |
| 2782 | /* As part of VSI creation/update, FW allocates certain |
| 2783 | * Tx arbitration queue sets for each TC enabled for |
| 2784 | * the VSI. The FW returns the handles to these queue |
| 2785 | * sets as part of the response buffer to Add VSI, |
| 2786 | * Update VSI, etc. AQ commands. It is expected that |
| 2787 | * these queue set handles be associated with the Tx |
| 2788 | * queues by the driver as part of the TX queue context |
| 2789 | * initialization. This has to be done regardless of |
| 2790 | * DCB as by default everything is mapped to TC0. |
| 2791 | */ |
| 2792 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2793 | tx_ctx.rdylist_act = 0; |
| 2794 | |
| 2795 | /* clear the context in the HMC */ |
| 2796 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2797 | if (err) { |
| 2798 | dev_info(&vsi->back->pdev->dev, |
| 2799 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2800 | ring->queue_index, pf_q, err); |
| 2801 | return -ENOMEM; |
| 2802 | } |
| 2803 | |
| 2804 | /* set the context in the HMC */ |
| 2805 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2806 | if (err) { |
| 2807 | dev_info(&vsi->back->pdev->dev, |
| 2808 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2809 | ring->queue_index, pf_q, err); |
| 2810 | return -ENOMEM; |
| 2811 | } |
| 2812 | |
| 2813 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2814 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2815 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2816 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2817 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2818 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2819 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2820 | } |
| 2821 | |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2822 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2823 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2824 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2825 | i40e_flush(hw); |
| 2826 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2827 | /* cache tail off for easier writes later */ |
| 2828 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2829 | |
| 2830 | return 0; |
| 2831 | } |
| 2832 | |
| 2833 | /** |
| 2834 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2835 | * @ring: The Rx ring to configure |
| 2836 | * |
| 2837 | * Configure the Rx descriptor ring in the HMC context. |
| 2838 | **/ |
| 2839 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2840 | { |
| 2841 | struct i40e_vsi *vsi = ring->vsi; |
| 2842 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2843 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2844 | struct i40e_hw *hw = &vsi->back->hw; |
| 2845 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2846 | i40e_status err = 0; |
| 2847 | |
| 2848 | ring->state = 0; |
| 2849 | |
| 2850 | /* clear the context structure first */ |
| 2851 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2852 | |
| 2853 | ring->rx_buf_len = vsi->rx_buf_len; |
| 2854 | ring->rx_hdr_len = vsi->rx_hdr_len; |
| 2855 | |
| 2856 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
| 2857 | rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT; |
| 2858 | |
| 2859 | rx_ctx.base = (ring->dma / 128); |
| 2860 | rx_ctx.qlen = ring->count; |
| 2861 | |
| 2862 | if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) { |
| 2863 | set_ring_16byte_desc_enabled(ring); |
| 2864 | rx_ctx.dsize = 0; |
| 2865 | } else { |
| 2866 | rx_ctx.dsize = 1; |
| 2867 | } |
| 2868 | |
| 2869 | rx_ctx.dtype = vsi->dtype; |
| 2870 | if (vsi->dtype) { |
| 2871 | set_ring_ps_enabled(ring); |
| 2872 | rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 | |
| 2873 | I40E_RX_SPLIT_IP | |
| 2874 | I40E_RX_SPLIT_TCP_UDP | |
| 2875 | I40E_RX_SPLIT_SCTP; |
| 2876 | } else { |
| 2877 | rx_ctx.hsplit_0 = 0; |
| 2878 | } |
| 2879 | |
| 2880 | rx_ctx.rxmax = min_t(u16, vsi->max_frame, |
| 2881 | (chain_len * ring->rx_buf_len)); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 2882 | if (hw->revision_id == 0) |
| 2883 | rx_ctx.lrxqthresh = 0; |
| 2884 | else |
| 2885 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2886 | rx_ctx.crcstrip = 1; |
| 2887 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 2888 | /* this controls whether VLAN is stripped from inner headers */ |
| 2889 | rx_ctx.showiv = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2890 | #ifdef I40E_FCOE |
| 2891 | rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2892 | #endif |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 2893 | /* set the prefena field to 1 because the manual says to */ |
| 2894 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2895 | |
| 2896 | /* clear the context in the HMC */ |
| 2897 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 2898 | if (err) { |
| 2899 | dev_info(&vsi->back->pdev->dev, |
| 2900 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2901 | ring->queue_index, pf_q, err); |
| 2902 | return -ENOMEM; |
| 2903 | } |
| 2904 | |
| 2905 | /* set the context in the HMC */ |
| 2906 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 2907 | if (err) { |
| 2908 | dev_info(&vsi->back->pdev->dev, |
| 2909 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2910 | ring->queue_index, pf_q, err); |
| 2911 | return -ENOMEM; |
| 2912 | } |
| 2913 | |
| 2914 | /* cache tail for quicker writes, and clear the reg before use */ |
| 2915 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 2916 | writel(0, ring->tail); |
| 2917 | |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 2918 | if (ring_is_ps_enabled(ring)) { |
| 2919 | i40e_alloc_rx_headers(ring); |
| 2920 | i40e_alloc_rx_buffers_ps(ring, I40E_DESC_UNUSED(ring)); |
| 2921 | } else { |
| 2922 | i40e_alloc_rx_buffers_1buf(ring, I40E_DESC_UNUSED(ring)); |
| 2923 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2924 | |
| 2925 | return 0; |
| 2926 | } |
| 2927 | |
| 2928 | /** |
| 2929 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 2930 | * @vsi: VSI structure describing this set of rings and resources |
| 2931 | * |
| 2932 | * Configure the Tx VSI for operation. |
| 2933 | **/ |
| 2934 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 2935 | { |
| 2936 | int err = 0; |
| 2937 | u16 i; |
| 2938 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2939 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 2940 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2941 | |
| 2942 | return err; |
| 2943 | } |
| 2944 | |
| 2945 | /** |
| 2946 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 2947 | * @vsi: the VSI being configured |
| 2948 | * |
| 2949 | * Configure the Rx VSI for operation. |
| 2950 | **/ |
| 2951 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 2952 | { |
| 2953 | int err = 0; |
| 2954 | u16 i; |
| 2955 | |
| 2956 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 2957 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 2958 | + ETH_FCS_LEN + VLAN_HLEN; |
| 2959 | else |
| 2960 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 2961 | |
| 2962 | /* figure out correct receive buffer length */ |
| 2963 | switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED | |
| 2964 | I40E_FLAG_RX_PS_ENABLED)) { |
| 2965 | case I40E_FLAG_RX_1BUF_ENABLED: |
| 2966 | vsi->rx_hdr_len = 0; |
| 2967 | vsi->rx_buf_len = vsi->max_frame; |
| 2968 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 2969 | break; |
| 2970 | case I40E_FLAG_RX_PS_ENABLED: |
| 2971 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2972 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2973 | vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT; |
| 2974 | break; |
| 2975 | default: |
| 2976 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2977 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2978 | vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS; |
| 2979 | break; |
| 2980 | } |
| 2981 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2982 | #ifdef I40E_FCOE |
| 2983 | /* setup rx buffer for FCoE */ |
| 2984 | if ((vsi->type == I40E_VSI_FCOE) && |
| 2985 | (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) { |
| 2986 | vsi->rx_hdr_len = 0; |
| 2987 | vsi->rx_buf_len = I40E_RXBUFFER_3072; |
| 2988 | vsi->max_frame = I40E_RXBUFFER_3072; |
| 2989 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 2990 | } |
| 2991 | |
| 2992 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2993 | /* round up for the chip's needs */ |
| 2994 | vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2995 | BIT_ULL(I40E_RXQ_CTX_HBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2996 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2997 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2998 | |
| 2999 | /* set up individual rings */ |
| 3000 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3001 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3002 | |
| 3003 | return err; |
| 3004 | } |
| 3005 | |
| 3006 | /** |
| 3007 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3008 | * @vsi: ptr to the VSI |
| 3009 | **/ |
| 3010 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3011 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3012 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3013 | u16 qoffset, qcount; |
| 3014 | int i, n; |
| 3015 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3016 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3017 | /* Reset the TC information */ |
| 3018 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3019 | rx_ring = vsi->rx_rings[i]; |
| 3020 | tx_ring = vsi->tx_rings[i]; |
| 3021 | rx_ring->dcb_tc = 0; |
| 3022 | tx_ring->dcb_tc = 0; |
| 3023 | } |
| 3024 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3025 | |
| 3026 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3027 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3028 | continue; |
| 3029 | |
| 3030 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3031 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3032 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3033 | rx_ring = vsi->rx_rings[i]; |
| 3034 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3035 | rx_ring->dcb_tc = n; |
| 3036 | tx_ring->dcb_tc = n; |
| 3037 | } |
| 3038 | } |
| 3039 | } |
| 3040 | |
| 3041 | /** |
| 3042 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3043 | * @vsi: ptr to the VSI |
| 3044 | **/ |
| 3045 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3046 | { |
| 3047 | if (vsi->netdev) |
| 3048 | i40e_set_rx_mode(vsi->netdev); |
| 3049 | } |
| 3050 | |
| 3051 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3052 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3053 | * @vsi: Pointer to the targeted VSI |
| 3054 | * |
| 3055 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3056 | * filters were saved. |
| 3057 | **/ |
| 3058 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3059 | { |
| 3060 | struct i40e_fdir_filter *filter; |
| 3061 | struct i40e_pf *pf = vsi->back; |
| 3062 | struct hlist_node *node; |
| 3063 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3064 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3065 | return; |
| 3066 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3067 | hlist_for_each_entry_safe(filter, node, |
| 3068 | &pf->fdir_filter_list, fdir_node) { |
| 3069 | i40e_add_del_fdir(vsi, filter, true); |
| 3070 | } |
| 3071 | } |
| 3072 | |
| 3073 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3074 | * i40e_vsi_configure - Set up the VSI for action |
| 3075 | * @vsi: the VSI being configured |
| 3076 | **/ |
| 3077 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3078 | { |
| 3079 | int err; |
| 3080 | |
| 3081 | i40e_set_vsi_rx_mode(vsi); |
| 3082 | i40e_restore_vlan(vsi); |
| 3083 | i40e_vsi_config_dcb_rings(vsi); |
| 3084 | err = i40e_vsi_configure_tx(vsi); |
| 3085 | if (!err) |
| 3086 | err = i40e_vsi_configure_rx(vsi); |
| 3087 | |
| 3088 | return err; |
| 3089 | } |
| 3090 | |
| 3091 | /** |
| 3092 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3093 | * @vsi: the VSI being configured |
| 3094 | **/ |
| 3095 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3096 | { |
| 3097 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3098 | struct i40e_hw *hw = &pf->hw; |
| 3099 | u16 vector; |
| 3100 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3101 | u32 qp; |
| 3102 | |
| 3103 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3104 | * and PFINT_LNKLSTn registers, e.g.: |
| 3105 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3106 | */ |
| 3107 | qp = vsi->base_queue; |
| 3108 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3109 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3110 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3111 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3112 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3113 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
| 3114 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3115 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3116 | q_vector->rx.itr); |
| 3117 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); |
| 3118 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3119 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3120 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3121 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
| 3122 | INTRL_USEC_TO_REG(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3123 | |
| 3124 | /* Linked list for the queuepairs assigned to this vector */ |
| 3125 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3126 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3127 | u32 val; |
| 3128 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3129 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3130 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3131 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3132 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 3133 | (I40E_QUEUE_TYPE_TX |
| 3134 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 3135 | |
| 3136 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3137 | |
| 3138 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3139 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3140 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3141 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 3142 | (I40E_QUEUE_TYPE_RX |
| 3143 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3144 | |
| 3145 | /* Terminate the linked list */ |
| 3146 | if (q == (q_vector->num_ringpairs - 1)) |
| 3147 | val |= (I40E_QUEUE_END_OF_LIST |
| 3148 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3149 | |
| 3150 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3151 | qp++; |
| 3152 | } |
| 3153 | } |
| 3154 | |
| 3155 | i40e_flush(hw); |
| 3156 | } |
| 3157 | |
| 3158 | /** |
| 3159 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3160 | * @hw: ptr to the hardware info |
| 3161 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3162 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3163 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3164 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3165 | u32 val; |
| 3166 | |
| 3167 | /* clear things first */ |
| 3168 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3169 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3170 | |
| 3171 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3172 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3173 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3174 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3175 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3176 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3177 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3178 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3179 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3180 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3181 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3182 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3183 | if (pf->flags & I40E_FLAG_PTP) |
| 3184 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3185 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3186 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3187 | |
| 3188 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3189 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3190 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3191 | |
| 3192 | /* OTHER_ITR_IDX = 0 */ |
| 3193 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3194 | } |
| 3195 | |
| 3196 | /** |
| 3197 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3198 | * @vsi: the VSI being configured |
| 3199 | **/ |
| 3200 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3201 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3202 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3203 | struct i40e_pf *pf = vsi->back; |
| 3204 | struct i40e_hw *hw = &pf->hw; |
| 3205 | u32 val; |
| 3206 | |
| 3207 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3208 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3209 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
| 3210 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3211 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
| 3212 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); |
| 3213 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3214 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3215 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3216 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3217 | |
| 3218 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3219 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3220 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3221 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3222 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3223 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3224 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3225 | |
| 3226 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3227 | |
| 3228 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3229 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3230 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3231 | |
| 3232 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3233 | i40e_flush(hw); |
| 3234 | } |
| 3235 | |
| 3236 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3237 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3238 | * @pf: board private structure |
| 3239 | **/ |
| 3240 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3241 | { |
| 3242 | struct i40e_hw *hw = &pf->hw; |
| 3243 | |
| 3244 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3245 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3246 | i40e_flush(hw); |
| 3247 | } |
| 3248 | |
| 3249 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3250 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3251 | * @pf: board private structure |
| 3252 | **/ |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3253 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3254 | { |
| 3255 | struct i40e_hw *hw = &pf->hw; |
| 3256 | u32 val; |
| 3257 | |
| 3258 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
| 3259 | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK | |
| 3260 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3261 | |
| 3262 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3263 | i40e_flush(hw); |
| 3264 | } |
| 3265 | |
| 3266 | /** |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 3267 | * i40e_irq_dynamic_disable - Disable default interrupt generation settings |
| 3268 | * @vsi: pointer to a vsi |
Greg Rose | 0314777 | 2015-01-24 09:58:29 +0000 | [diff] [blame] | 3269 | * @vector: disable a particular Hw Interrupt vector |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 3270 | **/ |
| 3271 | void i40e_irq_dynamic_disable(struct i40e_vsi *vsi, int vector) |
| 3272 | { |
| 3273 | struct i40e_pf *pf = vsi->back; |
| 3274 | struct i40e_hw *hw = &pf->hw; |
| 3275 | u32 val; |
| 3276 | |
| 3277 | val = I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT; |
| 3278 | wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val); |
| 3279 | i40e_flush(hw); |
| 3280 | } |
| 3281 | |
| 3282 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3283 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3284 | * @irq: interrupt number |
| 3285 | * @data: pointer to a q_vector |
| 3286 | **/ |
| 3287 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3288 | { |
| 3289 | struct i40e_q_vector *q_vector = data; |
| 3290 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3291 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3292 | return IRQ_HANDLED; |
| 3293 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3294 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3295 | |
| 3296 | return IRQ_HANDLED; |
| 3297 | } |
| 3298 | |
| 3299 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3300 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3301 | * @vsi: the VSI being configured |
| 3302 | * @basename: name for the vector |
| 3303 | * |
| 3304 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3305 | **/ |
| 3306 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3307 | { |
| 3308 | int q_vectors = vsi->num_q_vectors; |
| 3309 | struct i40e_pf *pf = vsi->back; |
| 3310 | int base = vsi->base_vector; |
| 3311 | int rx_int_idx = 0; |
| 3312 | int tx_int_idx = 0; |
| 3313 | int vector, err; |
| 3314 | |
| 3315 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3316 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3317 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3318 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3319 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3320 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3321 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3322 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3323 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3324 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3325 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3326 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3327 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3328 | } else { |
| 3329 | /* skip this unused q_vector */ |
| 3330 | continue; |
| 3331 | } |
| 3332 | err = request_irq(pf->msix_entries[base + vector].vector, |
| 3333 | vsi->irq_handler, |
| 3334 | 0, |
| 3335 | q_vector->name, |
| 3336 | q_vector); |
| 3337 | if (err) { |
| 3338 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3339 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3340 | goto free_queue_irqs; |
| 3341 | } |
| 3342 | /* assign the mask for this irq */ |
| 3343 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3344 | &q_vector->affinity_mask); |
| 3345 | } |
| 3346 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3347 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3348 | return 0; |
| 3349 | |
| 3350 | free_queue_irqs: |
| 3351 | while (vector) { |
| 3352 | vector--; |
| 3353 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3354 | NULL); |
| 3355 | free_irq(pf->msix_entries[base + vector].vector, |
| 3356 | &(vsi->q_vectors[vector])); |
| 3357 | } |
| 3358 | return err; |
| 3359 | } |
| 3360 | |
| 3361 | /** |
| 3362 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3363 | * @vsi: the VSI being un-configured |
| 3364 | **/ |
| 3365 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3366 | { |
| 3367 | struct i40e_pf *pf = vsi->back; |
| 3368 | struct i40e_hw *hw = &pf->hw; |
| 3369 | int base = vsi->base_vector; |
| 3370 | int i; |
| 3371 | |
| 3372 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3373 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3374 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3378 | for (i = vsi->base_vector; |
| 3379 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3380 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3381 | |
| 3382 | i40e_flush(hw); |
| 3383 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3384 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3385 | } else { |
| 3386 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3387 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3388 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3389 | i40e_flush(hw); |
| 3390 | synchronize_irq(pf->pdev->irq); |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | /** |
| 3395 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3396 | * @vsi: the VSI being configured |
| 3397 | **/ |
| 3398 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3399 | { |
| 3400 | struct i40e_pf *pf = vsi->back; |
| 3401 | int i; |
| 3402 | |
| 3403 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3404 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3405 | i40e_irq_dynamic_enable(vsi, i); |
| 3406 | } else { |
| 3407 | i40e_irq_dynamic_enable_icr0(pf); |
| 3408 | } |
| 3409 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3410 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3411 | return 0; |
| 3412 | } |
| 3413 | |
| 3414 | /** |
| 3415 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3416 | * @pf: board private structure |
| 3417 | **/ |
| 3418 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3419 | { |
| 3420 | /* Disable ICR 0 */ |
| 3421 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3422 | i40e_flush(&pf->hw); |
| 3423 | } |
| 3424 | |
| 3425 | /** |
| 3426 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3427 | * @irq: interrupt number |
| 3428 | * @data: pointer to a q_vector |
| 3429 | * |
| 3430 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3431 | * with both queue and non-queue interrupts. This is also used in |
| 3432 | * MSIX mode to handle the non-queue interrupts. |
| 3433 | **/ |
| 3434 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3435 | { |
| 3436 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3437 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3438 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3439 | u32 icr0, icr0_remaining; |
| 3440 | u32 val, ena_mask; |
| 3441 | |
| 3442 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3443 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3444 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3445 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3446 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3447 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3448 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3449 | /* if interrupt but no bits showing, must be SWINT */ |
| 3450 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3451 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3452 | pf->sw_int_count++; |
| 3453 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3454 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 3455 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
| 3456 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3457 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3458 | dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
| 3459 | } |
| 3460 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3461 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3462 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3463 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3464 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3465 | |
| 3466 | /* temporarily disable queue cause for NAPI processing */ |
| 3467 | u32 qval = rd32(hw, I40E_QINT_RQCTL(0)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3468 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3469 | qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK; |
| 3470 | wr32(hw, I40E_QINT_RQCTL(0), qval); |
| 3471 | |
| 3472 | qval = rd32(hw, I40E_QINT_TQCTL(0)); |
| 3473 | qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK; |
| 3474 | wr32(hw, I40E_QINT_TQCTL(0), qval); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3475 | |
| 3476 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3477 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3478 | } |
| 3479 | |
| 3480 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3481 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3482 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 3483 | } |
| 3484 | |
| 3485 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3486 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3487 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3488 | } |
| 3489 | |
| 3490 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3491 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3492 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3493 | } |
| 3494 | |
| 3495 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3496 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3497 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3498 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3499 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3500 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3501 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3502 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3503 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3504 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3505 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3506 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3507 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3508 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3509 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3510 | } |
| 3511 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3512 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3513 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3514 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3515 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3516 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3517 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3518 | } |
| 3519 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3520 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3521 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3522 | |
| 3523 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3524 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3525 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3526 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3527 | } |
| 3528 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3529 | /* If a critical error is pending we have no choice but to reset the |
| 3530 | * device. |
| 3531 | * Report and mask out any remaining unexpected interrupts. |
| 3532 | */ |
| 3533 | icr0_remaining = icr0 & ena_mask; |
| 3534 | if (icr0_remaining) { |
| 3535 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3536 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3537 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3538 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3539 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3540 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3541 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3542 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3543 | } |
| 3544 | ena_mask &= ~icr0_remaining; |
| 3545 | } |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3546 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3547 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3548 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3549 | /* re-enable interrupt causes */ |
| 3550 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3551 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3552 | i40e_service_event_schedule(pf); |
| 3553 | i40e_irq_dynamic_enable_icr0(pf); |
| 3554 | } |
| 3555 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3556 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3560 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3561 | * @tx_ring: tx ring to clean |
| 3562 | * @budget: how many cleans we're allowed |
| 3563 | * |
| 3564 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3565 | **/ |
| 3566 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3567 | { |
| 3568 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3569 | u16 i = tx_ring->next_to_clean; |
| 3570 | struct i40e_tx_buffer *tx_buf; |
| 3571 | struct i40e_tx_desc *tx_desc; |
| 3572 | |
| 3573 | tx_buf = &tx_ring->tx_bi[i]; |
| 3574 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3575 | i -= tx_ring->count; |
| 3576 | |
| 3577 | do { |
| 3578 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3579 | |
| 3580 | /* if next_to_watch is not set then there is no work pending */ |
| 3581 | if (!eop_desc) |
| 3582 | break; |
| 3583 | |
| 3584 | /* prevent any other reads prior to eop_desc */ |
| 3585 | read_barrier_depends(); |
| 3586 | |
| 3587 | /* if the descriptor isn't done, no work yet to do */ |
| 3588 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3589 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3590 | break; |
| 3591 | |
| 3592 | /* clear next_to_watch to prevent false hangs */ |
| 3593 | tx_buf->next_to_watch = NULL; |
| 3594 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3595 | tx_desc->buffer_addr = 0; |
| 3596 | tx_desc->cmd_type_offset_bsz = 0; |
| 3597 | /* move past filter desc */ |
| 3598 | tx_buf++; |
| 3599 | tx_desc++; |
| 3600 | i++; |
| 3601 | if (unlikely(!i)) { |
| 3602 | i -= tx_ring->count; |
| 3603 | tx_buf = tx_ring->tx_bi; |
| 3604 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3605 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3606 | /* unmap skb header data */ |
| 3607 | dma_unmap_single(tx_ring->dev, |
| 3608 | dma_unmap_addr(tx_buf, dma), |
| 3609 | dma_unmap_len(tx_buf, len), |
| 3610 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3611 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3612 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3613 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3614 | tx_buf->raw_buf = NULL; |
| 3615 | tx_buf->tx_flags = 0; |
| 3616 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3617 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3618 | tx_desc->buffer_addr = 0; |
| 3619 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3620 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3621 | /* 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] | 3622 | tx_buf++; |
| 3623 | tx_desc++; |
| 3624 | i++; |
| 3625 | if (unlikely(!i)) { |
| 3626 | i -= tx_ring->count; |
| 3627 | tx_buf = tx_ring->tx_bi; |
| 3628 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3629 | } |
| 3630 | |
| 3631 | /* update budget accounting */ |
| 3632 | budget--; |
| 3633 | } while (likely(budget)); |
| 3634 | |
| 3635 | i += tx_ring->count; |
| 3636 | tx_ring->next_to_clean = i; |
| 3637 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3638 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3639 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3640 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3641 | return budget > 0; |
| 3642 | } |
| 3643 | |
| 3644 | /** |
| 3645 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3646 | * @irq: interrupt number |
| 3647 | * @data: pointer to a q_vector |
| 3648 | **/ |
| 3649 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3650 | { |
| 3651 | struct i40e_q_vector *q_vector = data; |
| 3652 | struct i40e_vsi *vsi; |
| 3653 | |
| 3654 | if (!q_vector->tx.ring) |
| 3655 | return IRQ_HANDLED; |
| 3656 | |
| 3657 | vsi = q_vector->tx.ring->vsi; |
| 3658 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3659 | |
| 3660 | return IRQ_HANDLED; |
| 3661 | } |
| 3662 | |
| 3663 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3664 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3665 | * @vsi: the VSI being configured |
| 3666 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3667 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3668 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3669 | 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] | 3670 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3671 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3672 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3673 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3674 | |
| 3675 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3676 | tx_ring->next = q_vector->tx.ring; |
| 3677 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3678 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3679 | |
| 3680 | rx_ring->q_vector = q_vector; |
| 3681 | rx_ring->next = q_vector->rx.ring; |
| 3682 | q_vector->rx.ring = rx_ring; |
| 3683 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | /** |
| 3687 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3688 | * @vsi: the VSI being configured |
| 3689 | * |
| 3690 | * This function maps descriptor rings to the queue-specific vectors |
| 3691 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3692 | * one vector per queue pair, but on a constrained vector budget, we |
| 3693 | * group the queue pairs as "efficiently" as possible. |
| 3694 | **/ |
| 3695 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3696 | { |
| 3697 | int qp_remaining = vsi->num_queue_pairs; |
| 3698 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3699 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3700 | int v_start = 0; |
| 3701 | int qp_idx = 0; |
| 3702 | |
| 3703 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3704 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3705 | * It is also important to go through all the vectors available to be |
| 3706 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3707 | * are cleared. This is especially important when decreasing the |
| 3708 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3709 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3710 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3711 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3712 | |
| 3713 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3714 | |
| 3715 | q_vector->num_ringpairs = num_ringpairs; |
| 3716 | |
| 3717 | q_vector->rx.count = 0; |
| 3718 | q_vector->tx.count = 0; |
| 3719 | q_vector->rx.ring = NULL; |
| 3720 | q_vector->tx.ring = NULL; |
| 3721 | |
| 3722 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3723 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3724 | qp_idx++; |
| 3725 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3726 | } |
| 3727 | } |
| 3728 | } |
| 3729 | |
| 3730 | /** |
| 3731 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3732 | * @vsi: the VSI being configured |
| 3733 | * @basename: name for the vector |
| 3734 | **/ |
| 3735 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3736 | { |
| 3737 | struct i40e_pf *pf = vsi->back; |
| 3738 | int err; |
| 3739 | |
| 3740 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3741 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3742 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3743 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3744 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3745 | else |
| 3746 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3747 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3748 | |
| 3749 | if (err) |
| 3750 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3751 | |
| 3752 | return err; |
| 3753 | } |
| 3754 | |
| 3755 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3756 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3757 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3758 | * @netdev: network interface device structure |
| 3759 | * |
| 3760 | * This is used by netconsole to send skbs without having to re-enable |
| 3761 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3762 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3763 | #ifdef I40E_FCOE |
| 3764 | void i40e_netpoll(struct net_device *netdev) |
| 3765 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3766 | static void i40e_netpoll(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3767 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3768 | { |
| 3769 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3770 | struct i40e_vsi *vsi = np->vsi; |
| 3771 | struct i40e_pf *pf = vsi->back; |
| 3772 | int i; |
| 3773 | |
| 3774 | /* if interface is down do nothing */ |
| 3775 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3776 | return; |
| 3777 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3778 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3779 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3780 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3781 | } else { |
| 3782 | i40e_intr(pf->pdev->irq, netdev); |
| 3783 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3784 | } |
| 3785 | #endif |
| 3786 | |
| 3787 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3788 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3789 | * @pf: the PF being configured |
| 3790 | * @pf_q: the PF queue |
| 3791 | * @enable: enable or disable state of the queue |
| 3792 | * |
| 3793 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3794 | * enabled or disabled state. |
| 3795 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3796 | * multiple retries; else will return 0 in case of success. |
| 3797 | **/ |
| 3798 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3799 | { |
| 3800 | int i; |
| 3801 | u32 tx_reg; |
| 3802 | |
| 3803 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3804 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3805 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3806 | break; |
| 3807 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3808 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3809 | } |
| 3810 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3811 | return -ETIMEDOUT; |
| 3812 | |
| 3813 | return 0; |
| 3814 | } |
| 3815 | |
| 3816 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3817 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3818 | * @vsi: the VSI being configured |
| 3819 | * @enable: start or stop the rings |
| 3820 | **/ |
| 3821 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3822 | { |
| 3823 | struct i40e_pf *pf = vsi->back; |
| 3824 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3825 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3826 | u32 tx_reg; |
| 3827 | |
| 3828 | pf_q = vsi->base_queue; |
| 3829 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3830 | |
| 3831 | /* warn the TX unit of coming changes */ |
| 3832 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3833 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3834 | usleep_range(10, 20); |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3835 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3836 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3837 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3838 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3839 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3840 | break; |
| 3841 | usleep_range(1000, 2000); |
| 3842 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3843 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3844 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3845 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3846 | |
| 3847 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3848 | if (enable) { |
| 3849 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3850 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3851 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3852 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3853 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3854 | |
| 3855 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 3856 | /* No waiting for the Tx queue to disable */ |
| 3857 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3858 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3859 | |
| 3860 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3861 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 3862 | if (ret) { |
| 3863 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3864 | "VSI seid %d Tx ring %d %sable timeout\n", |
| 3865 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3866 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3867 | } |
| 3868 | } |
| 3869 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3870 | if (hw->revision_id == 0) |
| 3871 | mdelay(50); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3872 | return ret; |
| 3873 | } |
| 3874 | |
| 3875 | /** |
| 3876 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 3877 | * @pf: the PF being configured |
| 3878 | * @pf_q: the PF queue |
| 3879 | * @enable: enable or disable state of the queue |
| 3880 | * |
| 3881 | * This routine will wait for the given Rx queue of the PF to reach the |
| 3882 | * enabled or disabled state. |
| 3883 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3884 | * multiple retries; else will return 0 in case of success. |
| 3885 | **/ |
| 3886 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3887 | { |
| 3888 | int i; |
| 3889 | u32 rx_reg; |
| 3890 | |
| 3891 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3892 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 3893 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3894 | break; |
| 3895 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3896 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3897 | } |
| 3898 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3899 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3900 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3901 | return 0; |
| 3902 | } |
| 3903 | |
| 3904 | /** |
| 3905 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 3906 | * @vsi: the VSI being configured |
| 3907 | * @enable: start or stop the rings |
| 3908 | **/ |
| 3909 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 3910 | { |
| 3911 | struct i40e_pf *pf = vsi->back; |
| 3912 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3913 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3914 | u32 rx_reg; |
| 3915 | |
| 3916 | pf_q = vsi->base_queue; |
| 3917 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3918 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3919 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3920 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3921 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3922 | break; |
| 3923 | usleep_range(1000, 2000); |
| 3924 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3925 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3926 | /* Skip if the queue is already in the requested state */ |
| 3927 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3928 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3929 | |
| 3930 | /* turn on/off the queue */ |
| 3931 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3932 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3933 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3934 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3935 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
| 3936 | |
| 3937 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3938 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 3939 | if (ret) { |
| 3940 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3941 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 3942 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3943 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3944 | } |
| 3945 | } |
| 3946 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3947 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | /** |
| 3951 | * i40e_vsi_control_rings - Start or stop a VSI's rings |
| 3952 | * @vsi: the VSI being configured |
| 3953 | * @enable: start or stop the rings |
| 3954 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 3955 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3956 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3957 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3958 | |
| 3959 | /* do rx first for enable and last for disable */ |
| 3960 | if (request) { |
| 3961 | ret = i40e_vsi_control_rx(vsi, request); |
| 3962 | if (ret) |
| 3963 | return ret; |
| 3964 | ret = i40e_vsi_control_tx(vsi, request); |
| 3965 | } else { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3966 | /* Ignore return value, we need to shutdown whatever we can */ |
| 3967 | i40e_vsi_control_tx(vsi, request); |
| 3968 | i40e_vsi_control_rx(vsi, request); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | return ret; |
| 3972 | } |
| 3973 | |
| 3974 | /** |
| 3975 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 3976 | * @vsi: the VSI being configured |
| 3977 | **/ |
| 3978 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 3979 | { |
| 3980 | struct i40e_pf *pf = vsi->back; |
| 3981 | struct i40e_hw *hw = &pf->hw; |
| 3982 | int base = vsi->base_vector; |
| 3983 | u32 val, qp; |
| 3984 | int i; |
| 3985 | |
| 3986 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3987 | if (!vsi->q_vectors) |
| 3988 | return; |
| 3989 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3990 | if (!vsi->irqs_ready) |
| 3991 | return; |
| 3992 | |
| 3993 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3994 | for (i = 0; i < vsi->num_q_vectors; i++) { |
| 3995 | u16 vector = i + base; |
| 3996 | |
| 3997 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 3998 | if (!vsi->q_vectors[i] || |
| 3999 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4000 | continue; |
| 4001 | |
| 4002 | /* clear the affinity_mask in the IRQ descriptor */ |
| 4003 | irq_set_affinity_hint(pf->msix_entries[vector].vector, |
| 4004 | NULL); |
| 4005 | free_irq(pf->msix_entries[vector].vector, |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4006 | vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4007 | |
| 4008 | /* Tear down the interrupt queue link list |
| 4009 | * |
| 4010 | * We know that they come in pairs and always |
| 4011 | * the Rx first, then the Tx. To clear the |
| 4012 | * link list, stick the EOL value into the |
| 4013 | * next_q field of the registers. |
| 4014 | */ |
| 4015 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4016 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4017 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4018 | val |= I40E_QUEUE_END_OF_LIST |
| 4019 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4020 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4021 | |
| 4022 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4023 | u32 next; |
| 4024 | |
| 4025 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4026 | |
| 4027 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4028 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4029 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4030 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4031 | |
| 4032 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4033 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4034 | |
| 4035 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4036 | |
| 4037 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4038 | |
| 4039 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4040 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4041 | |
| 4042 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4043 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4044 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4045 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4046 | |
| 4047 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4048 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4049 | |
| 4050 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4051 | qp = next; |
| 4052 | } |
| 4053 | } |
| 4054 | } else { |
| 4055 | free_irq(pf->pdev->irq, pf); |
| 4056 | |
| 4057 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4058 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4059 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4060 | val |= I40E_QUEUE_END_OF_LIST |
| 4061 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4062 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4063 | |
| 4064 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4065 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4066 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4067 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4068 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4069 | |
| 4070 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4071 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4072 | |
| 4073 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4074 | |
| 4075 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4076 | |
| 4077 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4078 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4079 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4080 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4081 | |
| 4082 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4083 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4084 | |
| 4085 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4086 | } |
| 4087 | } |
| 4088 | |
| 4089 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4090 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4091 | * @vsi: the VSI being configured |
| 4092 | * @v_idx: Index of vector to be freed |
| 4093 | * |
| 4094 | * This function frees the memory allocated to the q_vector. In addition if |
| 4095 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4096 | * to freeing the q_vector. |
| 4097 | **/ |
| 4098 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4099 | { |
| 4100 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4101 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4102 | |
| 4103 | if (!q_vector) |
| 4104 | return; |
| 4105 | |
| 4106 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4107 | i40e_for_each_ring(ring, q_vector->tx) |
| 4108 | ring->q_vector = NULL; |
| 4109 | |
| 4110 | i40e_for_each_ring(ring, q_vector->rx) |
| 4111 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4112 | |
| 4113 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4114 | if (vsi->netdev) |
| 4115 | netif_napi_del(&q_vector->napi); |
| 4116 | |
| 4117 | vsi->q_vectors[v_idx] = NULL; |
| 4118 | |
| 4119 | kfree_rcu(q_vector, rcu); |
| 4120 | } |
| 4121 | |
| 4122 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4123 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4124 | * @vsi: the VSI being un-configured |
| 4125 | * |
| 4126 | * This frees the memory allocated to the q_vectors and |
| 4127 | * deletes references to the NAPI struct. |
| 4128 | **/ |
| 4129 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4130 | { |
| 4131 | int v_idx; |
| 4132 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4133 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4134 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | /** |
| 4138 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4139 | * @pf: board private structure |
| 4140 | **/ |
| 4141 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4142 | { |
| 4143 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4144 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4145 | pci_disable_msix(pf->pdev); |
| 4146 | kfree(pf->msix_entries); |
| 4147 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4148 | kfree(pf->irq_pile); |
| 4149 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4150 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4151 | pci_disable_msi(pf->pdev); |
| 4152 | } |
| 4153 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4154 | } |
| 4155 | |
| 4156 | /** |
| 4157 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4158 | * @pf: board private structure |
| 4159 | * |
| 4160 | * We go through and clear interrupt specific resources and reset the structure |
| 4161 | * to pre-load conditions |
| 4162 | **/ |
| 4163 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4164 | { |
| 4165 | int i; |
| 4166 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4167 | i40e_stop_misc_vector(pf); |
| 4168 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4169 | synchronize_irq(pf->msix_entries[0].vector); |
| 4170 | free_irq(pf->msix_entries[0].vector, pf); |
| 4171 | } |
| 4172 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4173 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4174 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4175 | if (pf->vsi[i]) |
| 4176 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4177 | i40e_reset_interrupt_capability(pf); |
| 4178 | } |
| 4179 | |
| 4180 | /** |
| 4181 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4182 | * @vsi: the VSI being configured |
| 4183 | **/ |
| 4184 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4185 | { |
| 4186 | int q_idx; |
| 4187 | |
| 4188 | if (!vsi->netdev) |
| 4189 | return; |
| 4190 | |
| 4191 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4192 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4193 | } |
| 4194 | |
| 4195 | /** |
| 4196 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4197 | * @vsi: the VSI being configured |
| 4198 | **/ |
| 4199 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4200 | { |
| 4201 | int q_idx; |
| 4202 | |
| 4203 | if (!vsi->netdev) |
| 4204 | return; |
| 4205 | |
| 4206 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4207 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4211 | * i40e_vsi_close - Shut down a VSI |
| 4212 | * @vsi: the vsi to be quelled |
| 4213 | **/ |
| 4214 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4215 | { |
| 4216 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4217 | i40e_down(vsi); |
| 4218 | i40e_vsi_free_irq(vsi); |
| 4219 | i40e_vsi_free_tx_resources(vsi); |
| 4220 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4221 | vsi->current_netdev_flags = 0; |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4222 | } |
| 4223 | |
| 4224 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4225 | * i40e_quiesce_vsi - Pause a given VSI |
| 4226 | * @vsi: the VSI being paused |
| 4227 | **/ |
| 4228 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4229 | { |
| 4230 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4231 | return; |
| 4232 | |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4233 | /* No need to disable FCoE VSI when Tx suspended */ |
| 4234 | if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) && |
| 4235 | vsi->type == I40E_VSI_FCOE) { |
| 4236 | dev_dbg(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4237 | "VSI seid %d skipping FCoE VSI disable\n", vsi->seid); |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4238 | return; |
| 4239 | } |
| 4240 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4241 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4242 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4243 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4244 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4245 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | /** |
| 4249 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4250 | * @vsi: the VSI being resumed |
| 4251 | **/ |
| 4252 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4253 | { |
| 4254 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 4255 | return; |
| 4256 | |
| 4257 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4258 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4259 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4260 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4261 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | /** |
| 4265 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4266 | * @pf: the PF |
| 4267 | **/ |
| 4268 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4269 | { |
| 4270 | int v; |
| 4271 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4272 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4273 | if (pf->vsi[v]) |
| 4274 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4275 | } |
| 4276 | } |
| 4277 | |
| 4278 | /** |
| 4279 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4280 | * @pf: the PF |
| 4281 | **/ |
| 4282 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4283 | { |
| 4284 | int v; |
| 4285 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4286 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4287 | if (pf->vsi[v]) |
| 4288 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4289 | } |
| 4290 | } |
| 4291 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4292 | #ifdef CONFIG_I40E_DCB |
| 4293 | /** |
| 4294 | * i40e_vsi_wait_txq_disabled - Wait for VSI's queues to be disabled |
| 4295 | * @vsi: the VSI being configured |
| 4296 | * |
| 4297 | * This function waits for the given VSI's Tx queues to be disabled. |
| 4298 | **/ |
| 4299 | static int i40e_vsi_wait_txq_disabled(struct i40e_vsi *vsi) |
| 4300 | { |
| 4301 | struct i40e_pf *pf = vsi->back; |
| 4302 | int i, pf_q, ret; |
| 4303 | |
| 4304 | pf_q = vsi->base_queue; |
| 4305 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4306 | /* Check and wait for the disable status of the queue */ |
| 4307 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4308 | if (ret) { |
| 4309 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4310 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4311 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4312 | return ret; |
| 4313 | } |
| 4314 | } |
| 4315 | |
| 4316 | return 0; |
| 4317 | } |
| 4318 | |
| 4319 | /** |
| 4320 | * i40e_pf_wait_txq_disabled - Wait for all queues of PF VSIs to be disabled |
| 4321 | * @pf: the PF |
| 4322 | * |
| 4323 | * This function waits for the Tx queues to be in disabled state for all the |
| 4324 | * VSIs that are managed by this PF. |
| 4325 | **/ |
| 4326 | static int i40e_pf_wait_txq_disabled(struct i40e_pf *pf) |
| 4327 | { |
| 4328 | int v, ret = 0; |
| 4329 | |
| 4330 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4331 | /* No need to wait for FCoE VSI queues */ |
| 4332 | if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) { |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4333 | ret = i40e_vsi_wait_txq_disabled(pf->vsi[v]); |
| 4334 | if (ret) |
| 4335 | break; |
| 4336 | } |
| 4337 | } |
| 4338 | |
| 4339 | return ret; |
| 4340 | } |
| 4341 | |
| 4342 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4343 | |
| 4344 | /** |
| 4345 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4346 | * @q_idx: TX queue number |
| 4347 | * @vsi: Pointer to VSI struct |
| 4348 | * |
| 4349 | * This function checks specified queue for given VSI. Detects hung condition. |
| 4350 | * Sets hung bit since it is two step process. Before next run of service task |
| 4351 | * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not, |
| 4352 | * hung condition remain unchanged and during subsequent run, this function |
| 4353 | * issues SW interrupt to recover from hung condition. |
| 4354 | **/ |
| 4355 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4356 | { |
| 4357 | struct i40e_ring *tx_ring = NULL; |
| 4358 | struct i40e_pf *pf; |
| 4359 | u32 head, val, tx_pending; |
| 4360 | int i; |
| 4361 | |
| 4362 | pf = vsi->back; |
| 4363 | |
| 4364 | /* now that we have an index, find the tx_ring struct */ |
| 4365 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4366 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4367 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4368 | tx_ring = vsi->tx_rings[i]; |
| 4369 | break; |
| 4370 | } |
| 4371 | } |
| 4372 | } |
| 4373 | |
| 4374 | if (!tx_ring) |
| 4375 | return; |
| 4376 | |
| 4377 | /* Read interrupt register */ |
| 4378 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4379 | val = rd32(&pf->hw, |
| 4380 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4381 | tx_ring->vsi->base_vector - 1)); |
| 4382 | else |
| 4383 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4384 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4385 | /* Bail out if interrupts are disabled because napi_poll |
| 4386 | * execution in-progress or will get scheduled soon. |
| 4387 | * napi_poll cleans TX and RX queues and updates 'next_to_clean'. |
| 4388 | */ |
| 4389 | if (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK)) |
| 4390 | return; |
| 4391 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4392 | head = i40e_get_head(tx_ring); |
| 4393 | |
| 4394 | tx_pending = i40e_get_tx_pending(tx_ring); |
| 4395 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4396 | /* HW is done executing descriptors, updated HEAD write back, |
| 4397 | * but SW hasn't processed those descriptors. If interrupt is |
| 4398 | * not generated from this point ON, it could result into |
| 4399 | * dev_watchdog detecting timeout on those netdev_queue, |
| 4400 | * hence proactively trigger SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4401 | */ |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4402 | if (tx_pending) { |
| 4403 | /* NAPI Poll didn't run and clear since it was set */ |
| 4404 | if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4405 | &tx_ring->q_vector->hung_detected)) { |
| 4406 | netdev_info(vsi->netdev, "VSI_seid %d, Hung TX queue %d, tx_pending: %d, NTC:0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x\n", |
| 4407 | vsi->seid, q_idx, tx_pending, |
| 4408 | tx_ring->next_to_clean, head, |
| 4409 | tx_ring->next_to_use, |
| 4410 | readl(tx_ring->tail)); |
| 4411 | netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n", |
| 4412 | vsi->seid, q_idx, val); |
| 4413 | i40e_force_wb(vsi, tx_ring->q_vector); |
| 4414 | } else { |
| 4415 | /* First Chance - detected possible hung */ |
| 4416 | set_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4417 | &tx_ring->q_vector->hung_detected); |
| 4418 | } |
| 4419 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | /** |
| 4423 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4424 | * @pf: pointer to PF struct |
| 4425 | * |
| 4426 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4427 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4428 | * SW interrupt. |
| 4429 | **/ |
| 4430 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4431 | { |
| 4432 | struct net_device *netdev; |
| 4433 | struct i40e_vsi *vsi; |
| 4434 | int i; |
| 4435 | |
| 4436 | /* Only for LAN VSI */ |
| 4437 | vsi = pf->vsi[pf->lan_vsi]; |
| 4438 | |
| 4439 | if (!vsi) |
| 4440 | return; |
| 4441 | |
| 4442 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
| 4443 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 4444 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4445 | return; |
| 4446 | |
| 4447 | /* Make sure type is MAIN VSI */ |
| 4448 | if (vsi->type != I40E_VSI_MAIN) |
| 4449 | return; |
| 4450 | |
| 4451 | netdev = vsi->netdev; |
| 4452 | if (!netdev) |
| 4453 | return; |
| 4454 | |
| 4455 | /* Bail out if netif_carrier is not OK */ |
| 4456 | if (!netif_carrier_ok(netdev)) |
| 4457 | return; |
| 4458 | |
| 4459 | /* Go thru' TX queues for netdev */ |
| 4460 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4461 | struct netdev_queue *q; |
| 4462 | |
| 4463 | q = netdev_get_tx_queue(netdev, i); |
| 4464 | if (q) |
| 4465 | i40e_detect_recover_hung_queue(i, vsi); |
| 4466 | } |
| 4467 | } |
| 4468 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4469 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4470 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4471 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4472 | * |
| 4473 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4474 | * and LAN TC. |
| 4475 | **/ |
| 4476 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4477 | { |
| 4478 | struct i40e_dcb_app_priority_table app; |
| 4479 | struct i40e_hw *hw = &pf->hw; |
| 4480 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4481 | u8 tc, i; |
| 4482 | /* Get the iSCSI APP TLV */ |
| 4483 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4484 | |
| 4485 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4486 | app = dcbcfg->app[i]; |
| 4487 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4488 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4489 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4490 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4491 | break; |
| 4492 | } |
| 4493 | } |
| 4494 | |
| 4495 | return enabled_tc; |
| 4496 | } |
| 4497 | |
| 4498 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4499 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4500 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4501 | * |
| 4502 | * Return the number of TCs from given DCBx configuration |
| 4503 | **/ |
| 4504 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4505 | { |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4506 | u8 num_tc = 0; |
| 4507 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4508 | |
| 4509 | /* Scan the ETS Config Priority Table to find |
| 4510 | * traffic class enabled for a given priority |
| 4511 | * and use the traffic class index to get the |
| 4512 | * number of traffic classes enabled |
| 4513 | */ |
| 4514 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4515 | if (dcbcfg->etscfg.prioritytable[i] > num_tc) |
| 4516 | num_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4517 | } |
| 4518 | |
| 4519 | /* Traffic class index starts from zero so |
| 4520 | * increment to return the actual count |
| 4521 | */ |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4522 | return num_tc + 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4523 | } |
| 4524 | |
| 4525 | /** |
| 4526 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4527 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4528 | * |
| 4529 | * Query the current DCB configuration and return the number of |
| 4530 | * traffic classes enabled from the given DCBX config |
| 4531 | **/ |
| 4532 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4533 | { |
| 4534 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4535 | u8 enabled_tc = 1; |
| 4536 | u8 i; |
| 4537 | |
| 4538 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4539 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4540 | |
| 4541 | return enabled_tc; |
| 4542 | } |
| 4543 | |
| 4544 | /** |
| 4545 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4546 | * @pf: PF being queried |
| 4547 | * |
| 4548 | * Return number of traffic classes enabled for the given PF |
| 4549 | **/ |
| 4550 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4551 | { |
| 4552 | struct i40e_hw *hw = &pf->hw; |
| 4553 | u8 i, enabled_tc; |
| 4554 | u8 num_tc = 0; |
| 4555 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4556 | |
| 4557 | /* If DCB is not enabled then always in single TC */ |
| 4558 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4559 | return 1; |
| 4560 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4561 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4562 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4563 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4564 | |
| 4565 | /* MFP mode return count of enabled TCs for this PF */ |
| 4566 | if (pf->hw.func_caps.iscsi) |
| 4567 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4568 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4569 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4570 | |
| 4571 | /* At least have TC0 */ |
| 4572 | enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 4573 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4574 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4575 | num_tc++; |
| 4576 | } |
| 4577 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4578 | } |
| 4579 | |
| 4580 | /** |
| 4581 | * i40e_pf_get_default_tc - Get bitmap for first enabled TC |
| 4582 | * @pf: PF being queried |
| 4583 | * |
| 4584 | * Return a bitmap for first enabled traffic class for this PF. |
| 4585 | **/ |
| 4586 | static u8 i40e_pf_get_default_tc(struct i40e_pf *pf) |
| 4587 | { |
| 4588 | u8 enabled_tc = pf->hw.func_caps.enabled_tcmap; |
| 4589 | u8 i = 0; |
| 4590 | |
| 4591 | if (!enabled_tc) |
| 4592 | return 0x1; /* TC0 */ |
| 4593 | |
| 4594 | /* Find the first enabled TC */ |
| 4595 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4596 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4597 | break; |
| 4598 | } |
| 4599 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4600 | return BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | /** |
| 4604 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4605 | * @pf: PF being queried |
| 4606 | * |
| 4607 | * Return a bitmap for enabled traffic classes for this PF. |
| 4608 | **/ |
| 4609 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4610 | { |
| 4611 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4612 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4613 | return i40e_pf_get_default_tc(pf); |
| 4614 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4615 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4616 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4617 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4618 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4619 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4620 | if (pf->hw.func_caps.iscsi) |
| 4621 | return i40e_get_iscsi_tc_map(pf); |
| 4622 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4623 | return i40e_pf_get_default_tc(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | /** |
| 4627 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4628 | * @vsi: the VSI being queried |
| 4629 | * |
| 4630 | * Returns 0 on success, negative value on failure |
| 4631 | **/ |
| 4632 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4633 | { |
| 4634 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4635 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4636 | struct i40e_pf *pf = vsi->back; |
| 4637 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4638 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4639 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4640 | int i; |
| 4641 | |
| 4642 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4643 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4644 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4645 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4646 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4647 | i40e_stat_str(&pf->hw, ret), |
| 4648 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4649 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4650 | } |
| 4651 | |
| 4652 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4653 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4654 | NULL); |
| 4655 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4656 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4657 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4658 | i40e_stat_str(&pf->hw, ret), |
| 4659 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4660 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4661 | } |
| 4662 | |
| 4663 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4664 | dev_info(&pf->pdev->dev, |
| 4665 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4666 | bw_config.tc_valid_bits, |
| 4667 | bw_ets_config.tc_valid_bits); |
| 4668 | /* Still continuing */ |
| 4669 | } |
| 4670 | |
| 4671 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4672 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4673 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4674 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4675 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4676 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4677 | vsi->bw_ets_limit_credits[i] = |
| 4678 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4679 | /* 3 bits out of 4 for each TC */ |
| 4680 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4681 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4682 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4683 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | /** |
| 4687 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4688 | * @vsi: the VSI being configured |
| 4689 | * @enabled_tc: TC bitmap |
| 4690 | * @bw_credits: BW shared credits per TC |
| 4691 | * |
| 4692 | * Returns 0 on success, negative value on failure |
| 4693 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4694 | 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] | 4695 | u8 *bw_share) |
| 4696 | { |
| 4697 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4698 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4699 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4700 | |
| 4701 | bw_data.tc_valid_bits = enabled_tc; |
| 4702 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4703 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4704 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4705 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4706 | NULL); |
| 4707 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4708 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4709 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4710 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4711 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4715 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4716 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4717 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | /** |
| 4721 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4722 | * @vsi: the VSI being configured |
| 4723 | * @enabled_tc: TC map to be enabled |
| 4724 | * |
| 4725 | **/ |
| 4726 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4727 | { |
| 4728 | struct net_device *netdev = vsi->netdev; |
| 4729 | struct i40e_pf *pf = vsi->back; |
| 4730 | struct i40e_hw *hw = &pf->hw; |
| 4731 | u8 netdev_tc = 0; |
| 4732 | int i; |
| 4733 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4734 | |
| 4735 | if (!netdev) |
| 4736 | return; |
| 4737 | |
| 4738 | if (!enabled_tc) { |
| 4739 | netdev_reset_tc(netdev); |
| 4740 | return; |
| 4741 | } |
| 4742 | |
| 4743 | /* Set up actual enabled TCs on the VSI */ |
| 4744 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 4745 | return; |
| 4746 | |
| 4747 | /* set per TC queues for the VSI */ |
| 4748 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4749 | /* Only set TC queues for enabled tcs |
| 4750 | * |
| 4751 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 4752 | * enabled_tc bitmap would be 0x00001001; the driver |
| 4753 | * will set the numtc for netdev as 2 that will be |
| 4754 | * referenced by the netdev layer as TC 0 and 1. |
| 4755 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4756 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4757 | netdev_set_tc_queue(netdev, |
| 4758 | vsi->tc_config.tc_info[i].netdev_tc, |
| 4759 | vsi->tc_config.tc_info[i].qcount, |
| 4760 | vsi->tc_config.tc_info[i].qoffset); |
| 4761 | } |
| 4762 | |
| 4763 | /* Assign UP2TC map for the VSI */ |
| 4764 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4765 | /* Get the actual TC# for the UP */ |
| 4766 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4767 | /* Get the mapped netdev TC# for the UP */ |
| 4768 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 4769 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 4770 | } |
| 4771 | } |
| 4772 | |
| 4773 | /** |
| 4774 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 4775 | * @vsi: the VSI being configured |
| 4776 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 4777 | **/ |
| 4778 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 4779 | struct i40e_vsi_context *ctxt) |
| 4780 | { |
| 4781 | /* copy just the sections touched not the entire info |
| 4782 | * since not all sections are valid as returned by |
| 4783 | * update vsi params |
| 4784 | */ |
| 4785 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 4786 | memcpy(&vsi->info.queue_mapping, |
| 4787 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 4788 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 4789 | sizeof(vsi->info.tc_mapping)); |
| 4790 | } |
| 4791 | |
| 4792 | /** |
| 4793 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 4794 | * @vsi: VSI to be configured |
| 4795 | * @enabled_tc: TC bitmap |
| 4796 | * |
| 4797 | * This configures a particular VSI for TCs that are mapped to the |
| 4798 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 4799 | * VSIs to configure TC for a particular VSI. |
| 4800 | * |
| 4801 | * NOTE: |
| 4802 | * It is expected that the VSI queues have been quisced before calling |
| 4803 | * this function. |
| 4804 | **/ |
| 4805 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4806 | { |
| 4807 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 4808 | struct i40e_vsi_context ctxt; |
| 4809 | int ret = 0; |
| 4810 | int i; |
| 4811 | |
| 4812 | /* Check if enabled_tc is same as existing or new TCs */ |
| 4813 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 4814 | return ret; |
| 4815 | |
| 4816 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 4817 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4818 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4819 | bw_share[i] = 1; |
| 4820 | } |
| 4821 | |
| 4822 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 4823 | if (ret) { |
| 4824 | dev_info(&vsi->back->pdev->dev, |
| 4825 | "Failed configuring TC map %d for VSI %d\n", |
| 4826 | enabled_tc, vsi->seid); |
| 4827 | goto out; |
| 4828 | } |
| 4829 | |
| 4830 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 4831 | ctxt.seid = vsi->seid; |
| 4832 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 4833 | ctxt.vf_num = 0; |
| 4834 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 4835 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4836 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 4837 | |
| 4838 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 4839 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 4840 | if (ret) { |
| 4841 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4842 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 4843 | i40e_stat_str(&vsi->back->hw, ret), |
| 4844 | i40e_aq_str(&vsi->back->hw, |
| 4845 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4846 | goto out; |
| 4847 | } |
| 4848 | /* update the local VSI info with updated queue map */ |
| 4849 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 4850 | vsi->info.valid_sections = 0; |
| 4851 | |
| 4852 | /* Update current VSI BW information */ |
| 4853 | ret = i40e_vsi_get_bw_info(vsi); |
| 4854 | if (ret) { |
| 4855 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4856 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 4857 | i40e_stat_str(&vsi->back->hw, ret), |
| 4858 | i40e_aq_str(&vsi->back->hw, |
| 4859 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4860 | goto out; |
| 4861 | } |
| 4862 | |
| 4863 | /* Update the netdev TC setup */ |
| 4864 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 4865 | out: |
| 4866 | return ret; |
| 4867 | } |
| 4868 | |
| 4869 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4870 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 4871 | * @veb: given VEB |
| 4872 | * @enabled_tc: TC bitmap |
| 4873 | * |
| 4874 | * Configures given TC bitmap for VEB (switching) element |
| 4875 | **/ |
| 4876 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 4877 | { |
| 4878 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 4879 | struct i40e_pf *pf = veb->pf; |
| 4880 | int ret = 0; |
| 4881 | int i; |
| 4882 | |
| 4883 | /* No TCs or already enabled TCs just return */ |
| 4884 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 4885 | return ret; |
| 4886 | |
| 4887 | bw_data.tc_valid_bits = enabled_tc; |
| 4888 | /* bw_data.absolute_credits is not set (relative) */ |
| 4889 | |
| 4890 | /* Enable ETS TCs with equal BW Share for now */ |
| 4891 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4892 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4893 | bw_data.tc_bw_share_credits[i] = 1; |
| 4894 | } |
| 4895 | |
| 4896 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 4897 | &bw_data, NULL); |
| 4898 | if (ret) { |
| 4899 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4900 | "VEB bw config failed, err %s aq_err %s\n", |
| 4901 | i40e_stat_str(&pf->hw, ret), |
| 4902 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4903 | goto out; |
| 4904 | } |
| 4905 | |
| 4906 | /* Update the BW information */ |
| 4907 | ret = i40e_veb_get_bw_info(veb); |
| 4908 | if (ret) { |
| 4909 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4910 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 4911 | i40e_stat_str(&pf->hw, ret), |
| 4912 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4913 | } |
| 4914 | |
| 4915 | out: |
| 4916 | return ret; |
| 4917 | } |
| 4918 | |
| 4919 | #ifdef CONFIG_I40E_DCB |
| 4920 | /** |
| 4921 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 4922 | * @pf: PF struct |
| 4923 | * |
| 4924 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 4925 | * the caller would've quiesce all the VSIs before calling |
| 4926 | * this function |
| 4927 | **/ |
| 4928 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 4929 | { |
| 4930 | u8 tc_map = 0; |
| 4931 | int ret; |
| 4932 | u8 v; |
| 4933 | |
| 4934 | /* Enable the TCs available on PF to all VEBs */ |
| 4935 | tc_map = i40e_pf_get_tc_map(pf); |
| 4936 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 4937 | if (!pf->veb[v]) |
| 4938 | continue; |
| 4939 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 4940 | if (ret) { |
| 4941 | dev_info(&pf->pdev->dev, |
| 4942 | "Failed configuring TC for VEB seid=%d\n", |
| 4943 | pf->veb[v]->seid); |
| 4944 | /* Will try to configure as many components */ |
| 4945 | } |
| 4946 | } |
| 4947 | |
| 4948 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4949 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4950 | if (!pf->vsi[v]) |
| 4951 | continue; |
| 4952 | |
| 4953 | /* - Enable all TCs for the LAN VSI |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4954 | #ifdef I40E_FCOE |
| 4955 | * - For FCoE VSI only enable the TC configured |
| 4956 | * as per the APP TLV |
| 4957 | #endif |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4958 | * - For all others keep them at TC0 for now |
| 4959 | */ |
| 4960 | if (v == pf->lan_vsi) |
| 4961 | tc_map = i40e_pf_get_tc_map(pf); |
| 4962 | else |
| 4963 | tc_map = i40e_pf_get_default_tc(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4964 | #ifdef I40E_FCOE |
| 4965 | if (pf->vsi[v]->type == I40E_VSI_FCOE) |
| 4966 | tc_map = i40e_get_fcoe_tc_map(pf); |
| 4967 | #endif /* #ifdef I40E_FCOE */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4968 | |
| 4969 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 4970 | if (ret) { |
| 4971 | dev_info(&pf->pdev->dev, |
| 4972 | "Failed configuring TC for VSI seid=%d\n", |
| 4973 | pf->vsi[v]->seid); |
| 4974 | /* Will try to configure as many components */ |
| 4975 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 4976 | /* Re-configure VSI vectors based on updated TC map */ |
| 4977 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4978 | if (pf->vsi[v]->netdev) |
| 4979 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 4980 | } |
| 4981 | } |
| 4982 | } |
| 4983 | |
| 4984 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 4985 | * i40e_resume_port_tx - Resume port Tx |
| 4986 | * @pf: PF struct |
| 4987 | * |
| 4988 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 4989 | * resume. |
| 4990 | **/ |
| 4991 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 4992 | { |
| 4993 | struct i40e_hw *hw = &pf->hw; |
| 4994 | int ret; |
| 4995 | |
| 4996 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 4997 | if (ret) { |
| 4998 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4999 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 5000 | i40e_stat_str(&pf->hw, ret), |
| 5001 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5002 | /* Schedule PF reset to recover */ |
| 5003 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5004 | i40e_service_event_schedule(pf); |
| 5005 | } |
| 5006 | |
| 5007 | return ret; |
| 5008 | } |
| 5009 | |
| 5010 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5011 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 5012 | * @pf: PF being configured |
| 5013 | * |
| 5014 | * Query the current DCB configuration and cache it |
| 5015 | * in the hardware structure |
| 5016 | **/ |
| 5017 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 5018 | { |
| 5019 | struct i40e_hw *hw = &pf->hw; |
| 5020 | int err = 0; |
| 5021 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5022 | /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */ |
| 5023 | if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) || |
| 5024 | (pf->hw.aq.fw_maj_ver < 4)) |
| 5025 | goto out; |
| 5026 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5027 | /* Get the initial DCB configuration */ |
| 5028 | err = i40e_init_dcb(hw); |
| 5029 | if (!err) { |
| 5030 | /* Device/Function is not DCBX capable */ |
| 5031 | if ((!hw->func_caps.dcb) || |
| 5032 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5033 | dev_info(&pf->pdev->dev, |
| 5034 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 5035 | |
| 5036 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 5037 | goto out; |
| 5038 | |
| 5039 | } else { |
| 5040 | /* When status is not DISABLED then DCBX in FW */ |
| 5041 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5042 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5043 | |
| 5044 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
| 5045 | /* Enable DCB tagging only when more than one TC */ |
| 5046 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5047 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5048 | dev_dbg(&pf->pdev->dev, |
| 5049 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5050 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5051 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5052 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5053 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5054 | i40e_stat_str(&pf->hw, err), |
| 5055 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5056 | } |
| 5057 | |
| 5058 | out: |
| 5059 | return err; |
| 5060 | } |
| 5061 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5062 | #define SPEED_SIZE 14 |
| 5063 | #define FC_SIZE 8 |
| 5064 | /** |
| 5065 | * i40e_print_link_message - print link up or down |
| 5066 | * @vsi: the VSI for which link needs a message |
| 5067 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5068 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5069 | { |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5070 | char *speed = "Unknown"; |
| 5071 | char *fc = "Unknown"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5072 | |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5073 | if (vsi->current_isup == isup) |
| 5074 | return; |
| 5075 | vsi->current_isup = isup; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5076 | if (!isup) { |
| 5077 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5078 | return; |
| 5079 | } |
| 5080 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5081 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5082 | * least 10GB |
| 5083 | */ |
| 5084 | if (vsi->back->hw.func_caps.npar_enable && |
| 5085 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5086 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5087 | netdev_warn(vsi->netdev, |
| 5088 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5089 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5090 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5091 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5092 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5093 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5094 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5095 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5096 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5097 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5098 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5099 | break; |
| 5100 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5101 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5102 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5103 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5104 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5105 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5106 | default: |
| 5107 | break; |
| 5108 | } |
| 5109 | |
| 5110 | switch (vsi->back->hw.fc.current_mode) { |
| 5111 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5112 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5113 | break; |
| 5114 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5115 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5116 | break; |
| 5117 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5118 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5119 | break; |
| 5120 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5121 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5122 | break; |
| 5123 | } |
| 5124 | |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5125 | netdev_info(vsi->netdev, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n", |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5126 | speed, fc); |
| 5127 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5128 | |
| 5129 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5130 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5131 | * @vsi: the VSI being configured |
| 5132 | **/ |
| 5133 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5134 | { |
| 5135 | struct i40e_pf *pf = vsi->back; |
| 5136 | int err; |
| 5137 | |
| 5138 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5139 | i40e_vsi_configure_msix(vsi); |
| 5140 | else |
| 5141 | i40e_configure_msi_and_legacy(vsi); |
| 5142 | |
| 5143 | /* start rings */ |
| 5144 | err = i40e_vsi_control_rings(vsi, true); |
| 5145 | if (err) |
| 5146 | return err; |
| 5147 | |
| 5148 | clear_bit(__I40E_DOWN, &vsi->state); |
| 5149 | i40e_napi_enable_all(vsi); |
| 5150 | i40e_vsi_enable_irq(vsi); |
| 5151 | |
| 5152 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5153 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5154 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5155 | netif_tx_start_all_queues(vsi->netdev); |
| 5156 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5157 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5158 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5159 | /* need to check for qualified module here*/ |
| 5160 | if ((pf->hw.phy.link_info.link_info & |
| 5161 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5162 | (!(pf->hw.phy.link_info.an_info & |
| 5163 | I40E_AQ_QUALIFIED_MODULE))) |
| 5164 | netdev_err(vsi->netdev, |
| 5165 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5166 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5167 | |
| 5168 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5169 | if (vsi->type == I40E_VSI_FDIR) { |
| 5170 | /* reset fd counters */ |
| 5171 | pf->fd_add_err = pf->fd_atr_cnt = 0; |
| 5172 | if (pf->fd_tcp_rule > 0) { |
| 5173 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5174 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5175 | 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] | 5176 | pf->fd_tcp_rule = 0; |
| 5177 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5178 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5179 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5180 | i40e_service_event_schedule(pf); |
| 5181 | |
| 5182 | return 0; |
| 5183 | } |
| 5184 | |
| 5185 | /** |
| 5186 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5187 | * @vsi: the VSI being configured |
| 5188 | * |
| 5189 | * Rebuild the ring structs after some configuration |
| 5190 | * has changed, e.g. MTU size. |
| 5191 | **/ |
| 5192 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5193 | { |
| 5194 | struct i40e_pf *pf = vsi->back; |
| 5195 | |
| 5196 | WARN_ON(in_interrupt()); |
| 5197 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5198 | usleep_range(1000, 2000); |
| 5199 | i40e_down(vsi); |
| 5200 | |
| 5201 | /* Give a VF some time to respond to the reset. The |
| 5202 | * two second wait is based upon the watchdog cycle in |
| 5203 | * the VF driver. |
| 5204 | */ |
| 5205 | if (vsi->type == I40E_VSI_SRIOV) |
| 5206 | msleep(2000); |
| 5207 | i40e_up(vsi); |
| 5208 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 5209 | } |
| 5210 | |
| 5211 | /** |
| 5212 | * i40e_up - Bring the connection back up after being down |
| 5213 | * @vsi: the VSI being configured |
| 5214 | **/ |
| 5215 | int i40e_up(struct i40e_vsi *vsi) |
| 5216 | { |
| 5217 | int err; |
| 5218 | |
| 5219 | err = i40e_vsi_configure(vsi); |
| 5220 | if (!err) |
| 5221 | err = i40e_up_complete(vsi); |
| 5222 | |
| 5223 | return err; |
| 5224 | } |
| 5225 | |
| 5226 | /** |
| 5227 | * i40e_down - Shutdown the connection processing |
| 5228 | * @vsi: the VSI being stopped |
| 5229 | **/ |
| 5230 | void i40e_down(struct i40e_vsi *vsi) |
| 5231 | { |
| 5232 | int i; |
| 5233 | |
| 5234 | /* It is assumed that the caller of this function |
| 5235 | * sets the vsi->state __I40E_DOWN bit. |
| 5236 | */ |
| 5237 | if (vsi->netdev) { |
| 5238 | netif_carrier_off(vsi->netdev); |
| 5239 | netif_tx_disable(vsi->netdev); |
| 5240 | } |
| 5241 | i40e_vsi_disable_irq(vsi); |
| 5242 | i40e_vsi_control_rings(vsi, false); |
| 5243 | i40e_napi_disable_all(vsi); |
| 5244 | |
| 5245 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5246 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 5247 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5248 | } |
| 5249 | } |
| 5250 | |
| 5251 | /** |
| 5252 | * i40e_setup_tc - configure multiple traffic classes |
| 5253 | * @netdev: net device to configure |
| 5254 | * @tc: number of traffic classes to enable |
| 5255 | **/ |
| 5256 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5257 | { |
| 5258 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5259 | struct i40e_vsi *vsi = np->vsi; |
| 5260 | struct i40e_pf *pf = vsi->back; |
| 5261 | u8 enabled_tc = 0; |
| 5262 | int ret = -EINVAL; |
| 5263 | int i; |
| 5264 | |
| 5265 | /* Check if DCB enabled to continue */ |
| 5266 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5267 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5268 | goto exit; |
| 5269 | } |
| 5270 | |
| 5271 | /* Check if MFP enabled */ |
| 5272 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5273 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5274 | goto exit; |
| 5275 | } |
| 5276 | |
| 5277 | /* Check whether tc count is within enabled limit */ |
| 5278 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5279 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5280 | goto exit; |
| 5281 | } |
| 5282 | |
| 5283 | /* Generate TC map for number of tc requested */ |
| 5284 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5285 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5286 | |
| 5287 | /* Requesting same TC configuration as already enabled */ |
| 5288 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5289 | return 0; |
| 5290 | |
| 5291 | /* Quiesce VSI queues */ |
| 5292 | i40e_quiesce_vsi(vsi); |
| 5293 | |
| 5294 | /* Configure VSI for enabled TCs */ |
| 5295 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5296 | if (ret) { |
| 5297 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5298 | vsi->seid); |
| 5299 | goto exit; |
| 5300 | } |
| 5301 | |
| 5302 | /* Unquiesce VSI */ |
| 5303 | i40e_unquiesce_vsi(vsi); |
| 5304 | |
| 5305 | exit: |
| 5306 | return ret; |
| 5307 | } |
| 5308 | |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5309 | #ifdef I40E_FCOE |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5310 | int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5311 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5312 | #else |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5313 | static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5314 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5315 | #endif |
| 5316 | { |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5317 | if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5318 | return -EINVAL; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5319 | return i40e_setup_tc(netdev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5320 | } |
| 5321 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5322 | /** |
| 5323 | * i40e_open - Called when a network interface is made active |
| 5324 | * @netdev: network interface device structure |
| 5325 | * |
| 5326 | * The open entry point is called when a network interface is made |
| 5327 | * active by the system (IFF_UP). At this point all resources needed |
| 5328 | * for transmit and receive operations are allocated, the interrupt |
| 5329 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5330 | * enabled, and the stack is notified that the interface is ready. |
| 5331 | * |
| 5332 | * Returns 0 on success, negative value on failure |
| 5333 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5334 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5335 | { |
| 5336 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5337 | struct i40e_vsi *vsi = np->vsi; |
| 5338 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5339 | int err; |
| 5340 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5341 | /* disallow open during test or if eeprom is broken */ |
| 5342 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 5343 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5344 | return -EBUSY; |
| 5345 | |
| 5346 | netif_carrier_off(netdev); |
| 5347 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5348 | err = i40e_vsi_open(vsi); |
| 5349 | if (err) |
| 5350 | return err; |
| 5351 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5352 | /* configure global TSO hardware offload settings */ |
| 5353 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5354 | TCP_FLAG_FIN) >> 16); |
| 5355 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5356 | TCP_FLAG_FIN | |
| 5357 | TCP_FLAG_CWR) >> 16); |
| 5358 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5359 | |
Singhai, Anjali | 6633d38 | 2015-12-03 23:49:31 -0800 | [diff] [blame] | 5360 | #ifdef CONFIG_I40E_VXLAN |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5361 | vxlan_get_rx_port(netdev); |
| 5362 | #endif |
Singhai, Anjali | cd86660 | 2015-12-14 12:21:21 -0800 | [diff] [blame] | 5363 | #ifdef CONFIG_I40E_GENEVE |
| 5364 | geneve_get_rx_port(netdev); |
| 5365 | #endif |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5366 | |
| 5367 | return 0; |
| 5368 | } |
| 5369 | |
| 5370 | /** |
| 5371 | * i40e_vsi_open - |
| 5372 | * @vsi: the VSI to open |
| 5373 | * |
| 5374 | * Finish initialization of the VSI. |
| 5375 | * |
| 5376 | * Returns 0 on success, negative value on failure |
| 5377 | **/ |
| 5378 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5379 | { |
| 5380 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5381 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5382 | int err; |
| 5383 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5384 | /* allocate descriptors */ |
| 5385 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5386 | if (err) |
| 5387 | goto err_setup_tx; |
| 5388 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5389 | if (err) |
| 5390 | goto err_setup_rx; |
| 5391 | |
| 5392 | err = i40e_vsi_configure(vsi); |
| 5393 | if (err) |
| 5394 | goto err_setup_rx; |
| 5395 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5396 | if (vsi->netdev) { |
| 5397 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5398 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5399 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5400 | if (err) |
| 5401 | goto err_setup_rx; |
| 5402 | |
| 5403 | /* Notify the stack of the actual queue counts. */ |
| 5404 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5405 | vsi->num_queue_pairs); |
| 5406 | if (err) |
| 5407 | goto err_set_queues; |
| 5408 | |
| 5409 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5410 | vsi->num_queue_pairs); |
| 5411 | if (err) |
| 5412 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5413 | |
| 5414 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5415 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5416 | dev_driver_string(&pf->pdev->dev), |
| 5417 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5418 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5419 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5420 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5421 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5422 | goto err_setup_rx; |
| 5423 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5424 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5425 | err = i40e_up_complete(vsi); |
| 5426 | if (err) |
| 5427 | goto err_up_complete; |
| 5428 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5429 | return 0; |
| 5430 | |
| 5431 | err_up_complete: |
| 5432 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5433 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5434 | i40e_vsi_free_irq(vsi); |
| 5435 | err_setup_rx: |
| 5436 | i40e_vsi_free_rx_resources(vsi); |
| 5437 | err_setup_tx: |
| 5438 | i40e_vsi_free_tx_resources(vsi); |
| 5439 | if (vsi == pf->vsi[pf->lan_vsi]) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5440 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5441 | |
| 5442 | return err; |
| 5443 | } |
| 5444 | |
| 5445 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5446 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5447 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5448 | * |
| 5449 | * This function destroys the hlist where all the Flow Director |
| 5450 | * filters were saved. |
| 5451 | **/ |
| 5452 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5453 | { |
| 5454 | struct i40e_fdir_filter *filter; |
| 5455 | struct hlist_node *node2; |
| 5456 | |
| 5457 | hlist_for_each_entry_safe(filter, node2, |
| 5458 | &pf->fdir_filter_list, fdir_node) { |
| 5459 | hlist_del(&filter->fdir_node); |
| 5460 | kfree(filter); |
| 5461 | } |
| 5462 | pf->fdir_pf_active_filters = 0; |
| 5463 | } |
| 5464 | |
| 5465 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5466 | * i40e_close - Disables a network interface |
| 5467 | * @netdev: network interface device structure |
| 5468 | * |
| 5469 | * The close entry point is called when an interface is de-activated |
| 5470 | * by the OS. The hardware is still under the driver's control, but |
| 5471 | * this netdev interface is disabled. |
| 5472 | * |
| 5473 | * Returns 0, this is not allowed to fail |
| 5474 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5475 | #ifdef I40E_FCOE |
| 5476 | int i40e_close(struct net_device *netdev) |
| 5477 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5478 | static int i40e_close(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5479 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5480 | { |
| 5481 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5482 | struct i40e_vsi *vsi = np->vsi; |
| 5483 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5484 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5485 | |
| 5486 | return 0; |
| 5487 | } |
| 5488 | |
| 5489 | /** |
| 5490 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5491 | * @pf: board private structure |
| 5492 | * @reset_flags: which reset is requested |
| 5493 | * |
| 5494 | * The essential difference in resets is that the PF Reset |
| 5495 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5496 | * firmware, and doesn't bother the other PFs on the chip. |
| 5497 | **/ |
| 5498 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5499 | { |
| 5500 | u32 val; |
| 5501 | |
| 5502 | WARN_ON(in_interrupt()); |
| 5503 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5504 | if (i40e_check_asq_alive(&pf->hw)) |
| 5505 | i40e_vc_notify_reset(pf); |
| 5506 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5507 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5508 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5509 | |
| 5510 | /* Request a Global Reset |
| 5511 | * |
| 5512 | * This will start the chip's countdown to the actual full |
| 5513 | * chip reset event, and a warning interrupt to be sent |
| 5514 | * to all PFs, including the requestor. Our handler |
| 5515 | * for the warning interrupt will deal with the shutdown |
| 5516 | * and recovery of the switch setup. |
| 5517 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5518 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5519 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5520 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5521 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5522 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5523 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5524 | |
| 5525 | /* Request a Core Reset |
| 5526 | * |
| 5527 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5528 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5529 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5530 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5531 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5532 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5533 | i40e_flush(&pf->hw); |
| 5534 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5535 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5536 | |
| 5537 | /* Request a PF Reset |
| 5538 | * |
| 5539 | * Resets only the PF-specific registers |
| 5540 | * |
| 5541 | * This goes directly to the tear-down and rebuild of |
| 5542 | * the switch, since we need to do all the recovery as |
| 5543 | * for the Core Reset. |
| 5544 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5545 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5546 | i40e_handle_reset_warning(pf); |
| 5547 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5548 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5549 | int v; |
| 5550 | |
| 5551 | /* Find the VSI(s) that requested a re-init */ |
| 5552 | dev_info(&pf->pdev->dev, |
| 5553 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5554 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5555 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5556 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5557 | if (vsi != NULL && |
| 5558 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5559 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5560 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5561 | } |
| 5562 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5563 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5564 | int v; |
| 5565 | |
| 5566 | /* Find the VSI(s) that needs to be brought down */ |
| 5567 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5568 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5569 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5570 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5571 | if (vsi != NULL && |
| 5572 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5573 | set_bit(__I40E_DOWN, &vsi->state); |
| 5574 | i40e_down(vsi); |
| 5575 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5576 | } |
| 5577 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5578 | } else { |
| 5579 | dev_info(&pf->pdev->dev, |
| 5580 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5581 | } |
| 5582 | } |
| 5583 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5584 | #ifdef CONFIG_I40E_DCB |
| 5585 | /** |
| 5586 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5587 | * @pf: board private structure |
| 5588 | * @old_cfg: current DCB config |
| 5589 | * @new_cfg: new DCB config |
| 5590 | **/ |
| 5591 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5592 | struct i40e_dcbx_config *old_cfg, |
| 5593 | struct i40e_dcbx_config *new_cfg) |
| 5594 | { |
| 5595 | bool need_reconfig = false; |
| 5596 | |
| 5597 | /* Check if ETS configuration has changed */ |
| 5598 | if (memcmp(&new_cfg->etscfg, |
| 5599 | &old_cfg->etscfg, |
| 5600 | sizeof(new_cfg->etscfg))) { |
| 5601 | /* If Priority Table has changed reconfig is needed */ |
| 5602 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5603 | &old_cfg->etscfg.prioritytable, |
| 5604 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5605 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5606 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5607 | } |
| 5608 | |
| 5609 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5610 | &old_cfg->etscfg.tcbwtable, |
| 5611 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5612 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5613 | |
| 5614 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5615 | &old_cfg->etscfg.tsatable, |
| 5616 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5617 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5618 | } |
| 5619 | |
| 5620 | /* Check if PFC configuration has changed */ |
| 5621 | if (memcmp(&new_cfg->pfc, |
| 5622 | &old_cfg->pfc, |
| 5623 | sizeof(new_cfg->pfc))) { |
| 5624 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5625 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5626 | } |
| 5627 | |
| 5628 | /* Check if APP Table has changed */ |
| 5629 | if (memcmp(&new_cfg->app, |
| 5630 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5631 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5632 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5633 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5634 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5635 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5636 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5637 | return need_reconfig; |
| 5638 | } |
| 5639 | |
| 5640 | /** |
| 5641 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5642 | * @pf: board private structure |
| 5643 | * @e: event info posted on ARQ |
| 5644 | **/ |
| 5645 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5646 | struct i40e_arq_event_info *e) |
| 5647 | { |
| 5648 | struct i40e_aqc_lldp_get_mib *mib = |
| 5649 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5650 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5651 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5652 | bool need_reconfig = false; |
| 5653 | int ret = 0; |
| 5654 | u8 type; |
| 5655 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5656 | /* Not DCB capable or capability disabled */ |
| 5657 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
| 5658 | return ret; |
| 5659 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5660 | /* Ignore if event is not for Nearest Bridge */ |
| 5661 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5662 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5663 | 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] | 5664 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5665 | return ret; |
| 5666 | |
| 5667 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5668 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5669 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5670 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5671 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5672 | /* Update the remote cached instance and return */ |
| 5673 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5674 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5675 | &hw->remote_dcbx_config); |
| 5676 | goto exit; |
| 5677 | } |
| 5678 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5679 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5680 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5681 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5682 | /* Reset the old DCBx configuration data */ |
| 5683 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5684 | /* Get updated DCBX data from firmware */ |
| 5685 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5686 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5687 | dev_info(&pf->pdev->dev, |
| 5688 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 5689 | i40e_stat_str(&pf->hw, ret), |
| 5690 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5691 | goto exit; |
| 5692 | } |
| 5693 | |
| 5694 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5695 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5696 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5697 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5698 | goto exit; |
| 5699 | } |
| 5700 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5701 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5702 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5703 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5704 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5705 | |
| 5706 | if (!need_reconfig) |
| 5707 | goto exit; |
| 5708 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5709 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5710 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5711 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5712 | else |
| 5713 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5714 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5715 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5716 | /* Reconfiguration needed quiesce all VSIs */ |
| 5717 | i40e_pf_quiesce_all_vsi(pf); |
| 5718 | |
| 5719 | /* Changes in configuration update VEB/VSI */ |
| 5720 | i40e_dcb_reconfigure(pf); |
| 5721 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5722 | ret = i40e_resume_port_tx(pf); |
| 5723 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5724 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5725 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5726 | if (ret) |
| 5727 | goto exit; |
| 5728 | |
| 5729 | /* Wait for the PF's Tx queues to be disabled */ |
| 5730 | ret = i40e_pf_wait_txq_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5731 | if (ret) { |
| 5732 | /* Schedule PF reset to recover */ |
| 5733 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5734 | i40e_service_event_schedule(pf); |
| 5735 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5736 | i40e_pf_unquiesce_all_vsi(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5737 | } |
| 5738 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5739 | exit: |
| 5740 | return ret; |
| 5741 | } |
| 5742 | #endif /* CONFIG_I40E_DCB */ |
| 5743 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5744 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5745 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 5746 | * @pf: board private structure |
| 5747 | * @reset_flags: which reset is requested |
| 5748 | * |
| 5749 | **/ |
| 5750 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 5751 | { |
| 5752 | rtnl_lock(); |
| 5753 | i40e_do_reset(pf, reset_flags); |
| 5754 | rtnl_unlock(); |
| 5755 | } |
| 5756 | |
| 5757 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5758 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 5759 | * @pf: board private structure |
| 5760 | * @e: event info posted on ARQ |
| 5761 | * |
| 5762 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 5763 | * and VF queues |
| 5764 | **/ |
| 5765 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 5766 | struct i40e_arq_event_info *e) |
| 5767 | { |
| 5768 | struct i40e_aqc_lan_overflow *data = |
| 5769 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 5770 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 5771 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 5772 | struct i40e_hw *hw = &pf->hw; |
| 5773 | struct i40e_vf *vf; |
| 5774 | u16 vf_id; |
| 5775 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5776 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 5777 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5778 | |
| 5779 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 5780 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 5781 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 5782 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 5783 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 5784 | vf_id -= hw->func_caps.vf_base_id; |
| 5785 | vf = &pf->vf[vf_id]; |
| 5786 | i40e_vc_notify_vf_reset(vf); |
| 5787 | /* Allow VF to process pending reset notification */ |
| 5788 | msleep(20); |
| 5789 | i40e_reset_vf(vf, false); |
| 5790 | } |
| 5791 | } |
| 5792 | |
| 5793 | /** |
| 5794 | * i40e_service_event_complete - Finish up the service event |
| 5795 | * @pf: board private structure |
| 5796 | **/ |
| 5797 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 5798 | { |
Shannon Nelson | b875f99 | 2015-10-21 19:47:03 -0400 | [diff] [blame] | 5799 | WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5800 | |
| 5801 | /* flush memory to make sure state is correct before next watchog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5802 | smp_mb__before_atomic(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5803 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 5804 | } |
| 5805 | |
| 5806 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5807 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 5808 | * @pf: board private structure |
| 5809 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5810 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5811 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5812 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5813 | |
| 5814 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5815 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 5816 | return fcnt_prog; |
| 5817 | } |
| 5818 | |
| 5819 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5820 | * 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] | 5821 | * @pf: board private structure |
| 5822 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5823 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5824 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5825 | u32 val, fcnt_prog; |
| 5826 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5827 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5828 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 5829 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 5830 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 5831 | return fcnt_prog; |
| 5832 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5833 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5834 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5835 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 5836 | * @pf: board private structure |
| 5837 | **/ |
| 5838 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 5839 | { |
| 5840 | u32 val, fcnt_prog; |
| 5841 | |
| 5842 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 5843 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 5844 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 5845 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 5846 | return fcnt_prog; |
| 5847 | } |
| 5848 | |
| 5849 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5850 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 5851 | * @pf: board private structure |
| 5852 | **/ |
| 5853 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 5854 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5855 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5856 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5857 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5858 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5859 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 5860 | return; |
| 5861 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5862 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 5863 | * to re-enable |
| 5864 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5865 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5866 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5867 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 5868 | (pf->fd_add_err == 0) || |
| 5869 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5870 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 5871 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 5872 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5873 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5874 | 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] | 5875 | } |
| 5876 | } |
| 5877 | /* Wait for some more space to be available to turn on ATR */ |
| 5878 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 5879 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 5880 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
| 5881 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5882 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5883 | dev_info(&pf->pdev->dev, "ATR 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] | 5884 | } |
| 5885 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5886 | |
| 5887 | /* if hw had a problem adding a filter, delete it */ |
| 5888 | if (pf->fd_inv > 0) { |
| 5889 | hlist_for_each_entry_safe(filter, node, |
| 5890 | &pf->fdir_filter_list, fdir_node) { |
| 5891 | if (filter->fd_id == pf->fd_inv) { |
| 5892 | hlist_del(&filter->fdir_node); |
| 5893 | kfree(filter); |
| 5894 | pf->fdir_pf_active_filters--; |
| 5895 | } |
| 5896 | } |
| 5897 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5898 | } |
| 5899 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5900 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5901 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5902 | /** |
| 5903 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 5904 | * @pf: board private structure |
| 5905 | **/ |
| 5906 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 5907 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5908 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5909 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5910 | bool disable_atr = false; |
| 5911 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5912 | int reg; |
| 5913 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 5914 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 5915 | return; |
| 5916 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5917 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 5918 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 5919 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5920 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5921 | /* If the flush is happening too quick and we have mostly SB rules we |
| 5922 | * should not re-enable ATR for some time. |
| 5923 | */ |
| 5924 | min_flush_time = pf->fd_flush_timestamp + |
| 5925 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 5926 | 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] | 5927 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5928 | if (!(time_after(jiffies, min_flush_time)) && |
| 5929 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 5930 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5931 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 5932 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5933 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5934 | |
| 5935 | pf->fd_flush_timestamp = jiffies; |
| 5936 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
| 5937 | /* flush all filters */ |
| 5938 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 5939 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 5940 | i40e_flush(&pf->hw); |
| 5941 | pf->fd_flush_cnt++; |
| 5942 | pf->fd_add_err = 0; |
| 5943 | do { |
| 5944 | /* Check FD flush status every 5-6msec */ |
| 5945 | usleep_range(5000, 6000); |
| 5946 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 5947 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 5948 | break; |
| 5949 | } while (flush_wait_retry--); |
| 5950 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 5951 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 5952 | } else { |
| 5953 | /* replay sideband filters */ |
| 5954 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
| 5955 | if (!disable_atr) |
| 5956 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 5957 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
| 5958 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5959 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 5960 | } |
| 5961 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | /** |
| 5965 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 5966 | * @pf: board private structure |
| 5967 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5968 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5969 | { |
| 5970 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 5971 | } |
| 5972 | |
| 5973 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 5974 | * being applied really fast; before we see the first |
| 5975 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 5976 | * reacting will make sure we don't cause flush too often. |
| 5977 | */ |
| 5978 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 5979 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5980 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5981 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 5982 | * @pf: board private structure |
| 5983 | **/ |
| 5984 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 5985 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5986 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5987 | /* if interface is down do nothing */ |
| 5988 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 5989 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5990 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 5991 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 5992 | return; |
| 5993 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5994 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5995 | i40e_fdir_flush_and_replay(pf); |
| 5996 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5997 | i40e_fdir_check_and_reenable(pf); |
| 5998 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5999 | } |
| 6000 | |
| 6001 | /** |
| 6002 | * i40e_vsi_link_event - notify VSI of a link event |
| 6003 | * @vsi: vsi to be notified |
| 6004 | * @link_up: link up or down |
| 6005 | **/ |
| 6006 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 6007 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 6008 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6009 | return; |
| 6010 | |
| 6011 | switch (vsi->type) { |
| 6012 | case I40E_VSI_MAIN: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6013 | #ifdef I40E_FCOE |
| 6014 | case I40E_VSI_FCOE: |
| 6015 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6016 | if (!vsi->netdev || !vsi->netdev_registered) |
| 6017 | break; |
| 6018 | |
| 6019 | if (link_up) { |
| 6020 | netif_carrier_on(vsi->netdev); |
| 6021 | netif_tx_wake_all_queues(vsi->netdev); |
| 6022 | } else { |
| 6023 | netif_carrier_off(vsi->netdev); |
| 6024 | netif_tx_stop_all_queues(vsi->netdev); |
| 6025 | } |
| 6026 | break; |
| 6027 | |
| 6028 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6029 | case I40E_VSI_VMDQ2: |
| 6030 | case I40E_VSI_CTRL: |
| 6031 | case I40E_VSI_MIRROR: |
| 6032 | default: |
| 6033 | /* there is no notification for other VSIs */ |
| 6034 | break; |
| 6035 | } |
| 6036 | } |
| 6037 | |
| 6038 | /** |
| 6039 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6040 | * @veb: veb to be notified |
| 6041 | * @link_up: link up or down |
| 6042 | **/ |
| 6043 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6044 | { |
| 6045 | struct i40e_pf *pf; |
| 6046 | int i; |
| 6047 | |
| 6048 | if (!veb || !veb->pf) |
| 6049 | return; |
| 6050 | pf = veb->pf; |
| 6051 | |
| 6052 | /* depth first... */ |
| 6053 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6054 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6055 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6056 | |
| 6057 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6058 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6059 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6060 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6061 | } |
| 6062 | |
| 6063 | /** |
| 6064 | * i40e_link_event - Update netif_carrier status |
| 6065 | * @pf: board private structure |
| 6066 | **/ |
| 6067 | static void i40e_link_event(struct i40e_pf *pf) |
| 6068 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6069 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6070 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6071 | i40e_status status; |
| 6072 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6073 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6074 | /* save off old link status information */ |
| 6075 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6076 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6077 | /* set this to force the get_link_status call to refresh state */ |
| 6078 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6079 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6080 | 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] | 6081 | |
| 6082 | status = i40e_get_link_status(&pf->hw, &new_link); |
| 6083 | if (status) { |
| 6084 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6085 | status); |
| 6086 | return; |
| 6087 | } |
| 6088 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6089 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6090 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6091 | |
| 6092 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6093 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6094 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 6095 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6096 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6097 | |
| 6098 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 6099 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6100 | |
| 6101 | /* Notify the base of the switch tree connected to |
| 6102 | * the link. Floating VEBs are not notified. |
| 6103 | */ |
| 6104 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6105 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6106 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6107 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6108 | |
| 6109 | if (pf->vf) |
| 6110 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6111 | |
| 6112 | if (pf->flags & I40E_FLAG_PTP) |
| 6113 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6114 | } |
| 6115 | |
| 6116 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6117 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6118 | * @pf: board private structure |
| 6119 | **/ |
| 6120 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6121 | { |
| 6122 | int i; |
| 6123 | |
| 6124 | /* if interface is down do nothing */ |
| 6125 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 6126 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6127 | return; |
| 6128 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6129 | /* make sure we don't do these things too often */ |
| 6130 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6131 | pf->service_timer_period))) |
| 6132 | return; |
| 6133 | pf->service_timer_previous = jiffies; |
| 6134 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6135 | if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) |
| 6136 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6137 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6138 | /* Update the stats for active netdevs so the network stack |
| 6139 | * can look at updated numbers whenever it cares to |
| 6140 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6141 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6142 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6143 | i40e_update_stats(pf->vsi[i]); |
| 6144 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6145 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6146 | /* Update the stats for the active switching components */ |
| 6147 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6148 | if (pf->veb[i]) |
| 6149 | i40e_update_veb_stats(pf->veb[i]); |
| 6150 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6151 | |
| 6152 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | /** |
| 6156 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6157 | * @pf: board private structure |
| 6158 | **/ |
| 6159 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6160 | { |
| 6161 | u32 reset_flags = 0; |
| 6162 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6163 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6164 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6165 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6166 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 6167 | } |
| 6168 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6169 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6170 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6171 | } |
| 6172 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6173 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6174 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 6175 | } |
| 6176 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6177 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6178 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 6179 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6180 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6181 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6182 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 6183 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6184 | |
| 6185 | /* If there's a recovery already waiting, it takes |
| 6186 | * precedence before starting a new reset sequence. |
| 6187 | */ |
| 6188 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 6189 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6190 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6191 | } |
| 6192 | |
| 6193 | /* If we're already down or resetting, just bail */ |
| 6194 | if (reset_flags && |
| 6195 | !test_bit(__I40E_DOWN, &pf->state) && |
| 6196 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6197 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6198 | |
| 6199 | unlock: |
| 6200 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | /** |
| 6204 | * i40e_handle_link_event - Handle link event |
| 6205 | * @pf: board private structure |
| 6206 | * @e: event info posted on ARQ |
| 6207 | **/ |
| 6208 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6209 | struct i40e_arq_event_info *e) |
| 6210 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6211 | struct i40e_aqc_get_link_status *status = |
| 6212 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6213 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6214 | /* Do a new status request to re-enable LSE reporting |
| 6215 | * and load new status information into the hw struct |
| 6216 | * This completely ignores any state information |
| 6217 | * in the ARQ event info, instead choosing to always |
| 6218 | * issue the AQ update link status command. |
| 6219 | */ |
| 6220 | i40e_link_event(pf); |
| 6221 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6222 | /* check for unqualified module, if link is down */ |
| 6223 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6224 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6225 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6226 | dev_err(&pf->pdev->dev, |
| 6227 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | /** |
| 6231 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6232 | * @pf: board private structure |
| 6233 | **/ |
| 6234 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6235 | { |
| 6236 | struct i40e_arq_event_info event; |
| 6237 | struct i40e_hw *hw = &pf->hw; |
| 6238 | u16 pending, i = 0; |
| 6239 | i40e_status ret; |
| 6240 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6241 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6242 | u32 val; |
| 6243 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6244 | /* Do not run clean AQ when PF reset fails */ |
| 6245 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 6246 | return; |
| 6247 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6248 | /* check for error indications */ |
| 6249 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6250 | oldval = val; |
| 6251 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6252 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6253 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6254 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6255 | } |
| 6256 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6257 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6258 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6259 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6260 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6261 | } |
| 6262 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6263 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6264 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6265 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6266 | } |
| 6267 | if (oldval != val) |
| 6268 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6269 | |
| 6270 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6271 | oldval = val; |
| 6272 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6273 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6274 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6275 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6276 | } |
| 6277 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6278 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6279 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6280 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6281 | } |
| 6282 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6283 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6284 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6285 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6286 | } |
| 6287 | if (oldval != val) |
| 6288 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6289 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6290 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6291 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6292 | if (!event.msg_buf) |
| 6293 | return; |
| 6294 | |
| 6295 | do { |
| 6296 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6297 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6298 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6299 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6300 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6301 | break; |
| 6302 | } |
| 6303 | |
| 6304 | opcode = le16_to_cpu(event.desc.opcode); |
| 6305 | switch (opcode) { |
| 6306 | |
| 6307 | case i40e_aqc_opc_get_link_status: |
| 6308 | i40e_handle_link_event(pf, &event); |
| 6309 | break; |
| 6310 | case i40e_aqc_opc_send_msg_to_pf: |
| 6311 | ret = i40e_vc_process_vf_msg(pf, |
| 6312 | le16_to_cpu(event.desc.retval), |
| 6313 | le32_to_cpu(event.desc.cookie_high), |
| 6314 | le32_to_cpu(event.desc.cookie_low), |
| 6315 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6316 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6317 | break; |
| 6318 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6319 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6320 | #ifdef CONFIG_I40E_DCB |
| 6321 | rtnl_lock(); |
| 6322 | ret = i40e_handle_lldp_event(pf, &event); |
| 6323 | rtnl_unlock(); |
| 6324 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6325 | break; |
| 6326 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6327 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6328 | i40e_handle_lan_overflow_event(pf, &event); |
| 6329 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6330 | case i40e_aqc_opc_send_msg_to_peer: |
| 6331 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6332 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6333 | case i40e_aqc_opc_nvm_erase: |
| 6334 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6335 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6336 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "ARQ NVM operation completed\n"); |
| 6337 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6338 | default: |
| 6339 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6340 | "ARQ Error: Unknown event 0x%04x received\n", |
| 6341 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6342 | break; |
| 6343 | } |
| 6344 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 6345 | |
| 6346 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 6347 | /* re-enable Admin queue interrupt cause */ |
| 6348 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6349 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6350 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6351 | i40e_flush(hw); |
| 6352 | |
| 6353 | kfree(event.msg_buf); |
| 6354 | } |
| 6355 | |
| 6356 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6357 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6358 | * @pf: board private structure |
| 6359 | **/ |
| 6360 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6361 | { |
| 6362 | int err; |
| 6363 | |
| 6364 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6365 | if (err) { |
| 6366 | /* retry in case of garbage read */ |
| 6367 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6368 | if (err) { |
| 6369 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6370 | err); |
| 6371 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6372 | } |
| 6373 | } |
| 6374 | |
| 6375 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 6376 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 6377 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6378 | } |
| 6379 | } |
| 6380 | |
| 6381 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6382 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6383 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6384 | * |
| 6385 | * enable switch loop back or die - no point in a return value |
| 6386 | **/ |
| 6387 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6388 | { |
| 6389 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6390 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6391 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6392 | |
| 6393 | ctxt.seid = pf->main_vsi_seid; |
| 6394 | ctxt.pf_num = pf->hw.pf_id; |
| 6395 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6396 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6397 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6398 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6399 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6400 | i40e_stat_str(&pf->hw, ret), |
| 6401 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6402 | return; |
| 6403 | } |
| 6404 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6405 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6406 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6407 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6408 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6409 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6410 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6411 | "update vsi switch failed, err %s aq_err %s\n", |
| 6412 | i40e_stat_str(&pf->hw, ret), |
| 6413 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6414 | } |
| 6415 | } |
| 6416 | |
| 6417 | /** |
| 6418 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6419 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6420 | * |
| 6421 | * disable switch loop back or die - no point in a return value |
| 6422 | **/ |
| 6423 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6424 | { |
| 6425 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6426 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6427 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6428 | |
| 6429 | ctxt.seid = pf->main_vsi_seid; |
| 6430 | ctxt.pf_num = pf->hw.pf_id; |
| 6431 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6432 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6433 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6434 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6435 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6436 | i40e_stat_str(&pf->hw, ret), |
| 6437 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6438 | return; |
| 6439 | } |
| 6440 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6441 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6442 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6443 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6444 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6445 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6446 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6447 | "update vsi switch failed, err %s aq_err %s\n", |
| 6448 | i40e_stat_str(&pf->hw, ret), |
| 6449 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6450 | } |
| 6451 | } |
| 6452 | |
| 6453 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6454 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6455 | * @veb: pointer to the bridge instance |
| 6456 | * |
| 6457 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6458 | * specified HW bridge instance. It is expected this function is called |
| 6459 | * when a new HW bridge is instantiated. |
| 6460 | **/ |
| 6461 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6462 | { |
| 6463 | struct i40e_pf *pf = veb->pf; |
| 6464 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6465 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6466 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6467 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6468 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6469 | i40e_disable_pf_switch_lb(pf); |
| 6470 | else |
| 6471 | i40e_enable_pf_switch_lb(pf); |
| 6472 | } |
| 6473 | |
| 6474 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6475 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6476 | * @veb: pointer to the VEB instance |
| 6477 | * |
| 6478 | * This is a recursive function that first builds the attached VSIs then |
| 6479 | * recurses in to build the next layer of VEB. We track the connections |
| 6480 | * through our own index numbers because the seid's from the HW could |
| 6481 | * change across the reset. |
| 6482 | **/ |
| 6483 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6484 | { |
| 6485 | struct i40e_vsi *ctl_vsi = NULL; |
| 6486 | struct i40e_pf *pf = veb->pf; |
| 6487 | int v, veb_idx; |
| 6488 | int ret; |
| 6489 | |
| 6490 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6491 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6492 | if (pf->vsi[v] && |
| 6493 | pf->vsi[v]->veb_idx == veb->idx && |
| 6494 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6495 | ctl_vsi = pf->vsi[v]; |
| 6496 | break; |
| 6497 | } |
| 6498 | } |
| 6499 | if (!ctl_vsi) { |
| 6500 | dev_info(&pf->pdev->dev, |
| 6501 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6502 | ret = -ENOENT; |
| 6503 | goto end_reconstitute; |
| 6504 | } |
| 6505 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6506 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6507 | ret = i40e_add_vsi(ctl_vsi); |
| 6508 | if (ret) { |
| 6509 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6510 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6511 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6512 | goto end_reconstitute; |
| 6513 | } |
| 6514 | i40e_vsi_reset_stats(ctl_vsi); |
| 6515 | |
| 6516 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6517 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6518 | if (ret) |
| 6519 | goto end_reconstitute; |
| 6520 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6521 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6522 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6523 | else |
| 6524 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6525 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6526 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6527 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6528 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6529 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6530 | continue; |
| 6531 | |
| 6532 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6533 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6534 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6535 | vsi->uplink_seid = veb->seid; |
| 6536 | ret = i40e_add_vsi(vsi); |
| 6537 | if (ret) { |
| 6538 | dev_info(&pf->pdev->dev, |
| 6539 | "rebuild of vsi_idx %d failed: %d\n", |
| 6540 | v, ret); |
| 6541 | goto end_reconstitute; |
| 6542 | } |
| 6543 | i40e_vsi_reset_stats(vsi); |
| 6544 | } |
| 6545 | } |
| 6546 | |
| 6547 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6548 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6549 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6550 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6551 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6552 | if (ret) |
| 6553 | break; |
| 6554 | } |
| 6555 | } |
| 6556 | |
| 6557 | end_reconstitute: |
| 6558 | return ret; |
| 6559 | } |
| 6560 | |
| 6561 | /** |
| 6562 | * i40e_get_capabilities - get info about the HW |
| 6563 | * @pf: the PF struct |
| 6564 | **/ |
| 6565 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6566 | { |
| 6567 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6568 | u16 data_size; |
| 6569 | int buf_len; |
| 6570 | int err; |
| 6571 | |
| 6572 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6573 | do { |
| 6574 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6575 | if (!cap_buf) |
| 6576 | return -ENOMEM; |
| 6577 | |
| 6578 | /* this loads the data into the hw struct for us */ |
| 6579 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6580 | &data_size, |
| 6581 | i40e_aqc_opc_list_func_capabilities, |
| 6582 | NULL); |
| 6583 | /* data loaded, buffer no longer needed */ |
| 6584 | kfree(cap_buf); |
| 6585 | |
| 6586 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6587 | /* retry with a larger buffer */ |
| 6588 | buf_len = data_size; |
| 6589 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6590 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6591 | "capability discovery failed, err %s aq_err %s\n", |
| 6592 | i40e_stat_str(&pf->hw, err), |
| 6593 | i40e_aq_str(&pf->hw, |
| 6594 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6595 | return -ENODEV; |
| 6596 | } |
| 6597 | } while (err); |
| 6598 | |
| 6599 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6600 | dev_info(&pf->pdev->dev, |
| 6601 | "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", |
| 6602 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6603 | pf->hw.func_caps.num_msix_vectors, |
| 6604 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6605 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6606 | pf->hw.func_caps.fd_filters_best_effort, |
| 6607 | pf->hw.func_caps.num_tx_qp, |
| 6608 | pf->hw.func_caps.num_vsis); |
| 6609 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6610 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6611 | + pf->hw.func_caps.num_vfs) |
| 6612 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6613 | dev_info(&pf->pdev->dev, |
| 6614 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6615 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6616 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6617 | } |
| 6618 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6619 | return 0; |
| 6620 | } |
| 6621 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6622 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6623 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6624 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6625 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6626 | * @pf: board private structure |
| 6627 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6628 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6629 | { |
| 6630 | struct i40e_vsi *vsi; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6631 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6632 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6633 | /* quick workaround for an NVM issue that leaves a critical register |
| 6634 | * uninitialized |
| 6635 | */ |
| 6636 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6637 | static const u32 hkey[] = { |
| 6638 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6639 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6640 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6641 | 0x95b3a76d}; |
| 6642 | |
| 6643 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6644 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6645 | } |
| 6646 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6647 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6648 | return; |
| 6649 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6650 | /* find existing VSI and see if it needs configuring */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6651 | vsi = NULL; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6652 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6653 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6654 | vsi = pf->vsi[i]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6655 | break; |
| 6656 | } |
| 6657 | } |
| 6658 | |
| 6659 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6660 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6661 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6662 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6663 | if (!vsi) { |
| 6664 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6665 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6666 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6667 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6668 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6669 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6670 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6671 | } |
| 6672 | |
| 6673 | /** |
| 6674 | * i40e_fdir_teardown - release the Flow Director resources |
| 6675 | * @pf: board private structure |
| 6676 | **/ |
| 6677 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6678 | { |
| 6679 | int i; |
| 6680 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6681 | i40e_fdir_filter_exit(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6682 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6683 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 6684 | i40e_vsi_release(pf->vsi[i]); |
| 6685 | break; |
| 6686 | } |
| 6687 | } |
| 6688 | } |
| 6689 | |
| 6690 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6691 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6692 | * @pf: board private structure |
| 6693 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6694 | * 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] | 6695 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6696 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6697 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6698 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6699 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6700 | u32 v; |
| 6701 | |
| 6702 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6703 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6704 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6705 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6706 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6707 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6708 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6709 | i40e_pf_quiesce_all_vsi(pf); |
| 6710 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6711 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6712 | if (pf->vsi[v]) |
| 6713 | pf->vsi[v]->seid = 0; |
| 6714 | } |
| 6715 | |
| 6716 | i40e_shutdown_adminq(&pf->hw); |
| 6717 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6718 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6719 | if (hw->hmc.hmc_obj) { |
| 6720 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6721 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6722 | dev_warn(&pf->pdev->dev, |
| 6723 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6724 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6725 | } |
| 6726 | |
| 6727 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6728 | * i40e_send_version - update firmware with driver version |
| 6729 | * @pf: PF struct |
| 6730 | */ |
| 6731 | static void i40e_send_version(struct i40e_pf *pf) |
| 6732 | { |
| 6733 | struct i40e_driver_version dv; |
| 6734 | |
| 6735 | dv.major_version = DRV_VERSION_MAJOR; |
| 6736 | dv.minor_version = DRV_VERSION_MINOR; |
| 6737 | dv.build_version = DRV_VERSION_BUILD; |
| 6738 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 6739 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6740 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 6741 | } |
| 6742 | |
| 6743 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 6744 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6745 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6746 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6747 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6748 | 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] | 6749 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6750 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6751 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6752 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6753 | u32 val; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6754 | u32 v; |
| 6755 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6756 | /* Now we wait for GRST to settle out. |
| 6757 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 6758 | * because the reset will make them disappear. |
| 6759 | */ |
| 6760 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6761 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6762 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6763 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 6764 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6765 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6766 | pf->pfr_count++; |
| 6767 | |
| 6768 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6769 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6770 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6771 | |
| 6772 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 6773 | ret = i40e_init_adminq(&pf->hw); |
| 6774 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6775 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 6776 | i40e_stat_str(&pf->hw, ret), |
| 6777 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6778 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6779 | } |
| 6780 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6781 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 6782 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6783 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6784 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 6785 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6786 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6787 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6788 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6789 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6790 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 6791 | hw->func_caps.num_rx_qp, |
| 6792 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 6793 | if (ret) { |
| 6794 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 6795 | goto end_core_reset; |
| 6796 | } |
| 6797 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 6798 | if (ret) { |
| 6799 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 6800 | goto end_core_reset; |
| 6801 | } |
| 6802 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6803 | #ifdef CONFIG_I40E_DCB |
| 6804 | ret = i40e_init_pf_dcb(pf); |
| 6805 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6806 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 6807 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 6808 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6809 | } |
| 6810 | #endif /* CONFIG_I40E_DCB */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6811 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 6812 | i40e_init_pf_fcoe(pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6813 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6814 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6815 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6816 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6817 | if (ret) |
| 6818 | goto end_core_reset; |
| 6819 | |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6820 | /* driver is only interested in link up/down and module qualification |
| 6821 | * reports from firmware |
| 6822 | */ |
| 6823 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
| 6824 | I40E_AQ_EVENT_LINK_UPDOWN | |
| 6825 | I40E_AQ_EVENT_MODULE_QUAL_FAIL, NULL); |
| 6826 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6827 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 6828 | i40e_stat_str(&pf->hw, ret), |
| 6829 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6830 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6831 | /* make sure our flow control settings are restored */ |
| 6832 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 6833 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 6834 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 6835 | i40e_stat_str(&pf->hw, ret), |
| 6836 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6837 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6838 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 6839 | * They are still in our local switch element arrays, so only |
| 6840 | * need to rebuild the switch model in the HW. |
| 6841 | * |
| 6842 | * If there were VEBs but the reconstitution failed, we'll try |
| 6843 | * try to recover minimal use by getting the basic PF VSI working. |
| 6844 | */ |
| 6845 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6846 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6847 | /* find the one VEB connected to the MAC, and find orphans */ |
| 6848 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6849 | if (!pf->veb[v]) |
| 6850 | continue; |
| 6851 | |
| 6852 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 6853 | pf->veb[v]->uplink_seid == 0) { |
| 6854 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 6855 | |
| 6856 | if (!ret) |
| 6857 | continue; |
| 6858 | |
| 6859 | /* If Main VEB failed, we're in deep doodoo, |
| 6860 | * so give up rebuilding the switch and set up |
| 6861 | * for minimal rebuild of PF VSI. |
| 6862 | * If orphan failed, we'll report the error |
| 6863 | * but try to keep going. |
| 6864 | */ |
| 6865 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 6866 | dev_info(&pf->pdev->dev, |
| 6867 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 6868 | ret); |
| 6869 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 6870 | = pf->mac_seid; |
| 6871 | break; |
| 6872 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 6873 | dev_info(&pf->pdev->dev, |
| 6874 | "rebuild of orphan VEB failed: %d\n", |
| 6875 | ret); |
| 6876 | } |
| 6877 | } |
| 6878 | } |
| 6879 | } |
| 6880 | |
| 6881 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 6882 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6883 | /* no VEB, so rebuild only the Main VSI */ |
| 6884 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 6885 | if (ret) { |
| 6886 | dev_info(&pf->pdev->dev, |
| 6887 | "rebuild of Main VSI failed: %d\n", ret); |
| 6888 | goto end_core_reset; |
| 6889 | } |
| 6890 | } |
| 6891 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6892 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 6893 | * of TSO, so that we avoid the MDD being fired and causing |
| 6894 | * a reset in the case of small MSS+TSO. |
| 6895 | */ |
| 6896 | #define I40E_REG_MSS 0x000E64DC |
| 6897 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 6898 | #define I40E_64BYTE_MSS 0x400000 |
| 6899 | val = rd32(hw, I40E_REG_MSS); |
| 6900 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 6901 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 6902 | val |= I40E_64BYTE_MSS; |
| 6903 | wr32(hw, I40E_REG_MSS, val); |
| 6904 | } |
| 6905 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 6906 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 6907 | msleep(75); |
| 6908 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 6909 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6910 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 6911 | i40e_stat_str(&pf->hw, ret), |
| 6912 | i40e_aq_str(&pf->hw, |
| 6913 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6914 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6915 | /* reinit the misc interrupt */ |
| 6916 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 6917 | ret = i40e_setup_misc_vector(pf); |
| 6918 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 6919 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 6920 | * transmitted. By doing so we stop a malicious VF from sending out |
| 6921 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 6922 | * PF/VF VSIs. |
| 6923 | * The FW can still send Flow control frames if enabled. |
| 6924 | */ |
| 6925 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 6926 | pf->main_vsi_seid); |
| 6927 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6928 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 6929 | i40e_pf_unquiesce_all_vsi(pf); |
| 6930 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 6931 | if (pf->num_alloc_vfs) { |
| 6932 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 6933 | i40e_reset_vf(&pf->vf[v], true); |
| 6934 | } |
| 6935 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6936 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6937 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6938 | |
| 6939 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6940 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 6941 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6942 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 6943 | } |
| 6944 | |
| 6945 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6946 | * 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] | 6947 | * @pf: board private structure |
| 6948 | * |
| 6949 | * Close up the VFs and other things in prep for a Core Reset, |
| 6950 | * then get ready to rebuild the world. |
| 6951 | **/ |
| 6952 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 6953 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6954 | i40e_prep_for_reset(pf); |
| 6955 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6956 | } |
| 6957 | |
| 6958 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6959 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6960 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6961 | * |
| 6962 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 6963 | **/ |
| 6964 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 6965 | { |
| 6966 | struct i40e_hw *hw = &pf->hw; |
| 6967 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 6968 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6969 | struct i40e_vf *vf; |
| 6970 | u32 reg; |
| 6971 | int i; |
| 6972 | |
| 6973 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 6974 | return; |
| 6975 | |
| 6976 | /* find what triggered the MDD event */ |
| 6977 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 6978 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6979 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 6980 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6981 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6982 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 6983 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6984 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6985 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 6986 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 6987 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6988 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6989 | 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] | 6990 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6991 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 6992 | mdd_detected = true; |
| 6993 | } |
| 6994 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 6995 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6996 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 6997 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 6998 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6999 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7000 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 7001 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 7002 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7003 | if (netif_msg_rx_err(pf)) |
| 7004 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 7005 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7006 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 7007 | mdd_detected = true; |
| 7008 | } |
| 7009 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7010 | if (mdd_detected) { |
| 7011 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 7012 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 7013 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7014 | 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] | 7015 | pf_mdd_detected = true; |
| 7016 | } |
| 7017 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 7018 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 7019 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7020 | 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] | 7021 | pf_mdd_detected = true; |
| 7022 | } |
| 7023 | /* Queue belongs to the PF, initiate a reset */ |
| 7024 | if (pf_mdd_detected) { |
| 7025 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 7026 | i40e_service_event_schedule(pf); |
| 7027 | } |
| 7028 | } |
| 7029 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7030 | /* see if one of the VFs needs its hand slapped */ |
| 7031 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7032 | vf = &(pf->vf[i]); |
| 7033 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7034 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7035 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7036 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7037 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7038 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7039 | } |
| 7040 | |
| 7041 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7042 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7043 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7044 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7045 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7046 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7047 | } |
| 7048 | |
| 7049 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7050 | dev_info(&pf->pdev->dev, |
| 7051 | "Too many MDD events on VF %d, disabled\n", i); |
| 7052 | dev_info(&pf->pdev->dev, |
| 7053 | "Use PF Control I/F to re-enable the VF\n"); |
| 7054 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 7055 | } |
| 7056 | } |
| 7057 | |
| 7058 | /* re-enable mdd interrupt cause */ |
| 7059 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 7060 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7061 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7062 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7063 | i40e_flush(hw); |
| 7064 | } |
| 7065 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7066 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7067 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7068 | * @pf: board private structure |
| 7069 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7070 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7071 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7072 | #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7073 | struct i40e_hw *hw = &pf->hw; |
| 7074 | i40e_status ret; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7075 | __be16 port; |
| 7076 | int i; |
| 7077 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7078 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7079 | return; |
| 7080 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7081 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7082 | |
| 7083 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7084 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7085 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
| 7086 | port = pf->udp_ports[i].index; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7087 | if (port) |
| 7088 | ret = i40e_aq_add_udp_tunnel(hw, ntohs(port), |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7089 | pf->udp_ports[i].type, |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7090 | NULL, NULL); |
| 7091 | else |
| 7092 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7093 | |
| 7094 | if (ret) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7095 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7096 | "%s vxlan port %d, index %d failed, err %s aq_err %s\n", |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7097 | port ? "add" : "delete", |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7098 | ntohs(port), i, |
| 7099 | i40e_stat_str(&pf->hw, ret), |
| 7100 | i40e_aq_str(&pf->hw, |
| 7101 | pf->hw.aq.asq_last_status)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7102 | pf->udp_ports[i].index = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7103 | } |
| 7104 | } |
| 7105 | } |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7106 | #endif |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7107 | } |
| 7108 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7109 | /** |
| 7110 | * i40e_service_task - Run the driver's async subtasks |
| 7111 | * @work: pointer to work_struct containing our data |
| 7112 | **/ |
| 7113 | static void i40e_service_task(struct work_struct *work) |
| 7114 | { |
| 7115 | struct i40e_pf *pf = container_of(work, |
| 7116 | struct i40e_pf, |
| 7117 | service_task); |
| 7118 | unsigned long start_time = jiffies; |
| 7119 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7120 | /* don't bother with service tasks if a reset is in progress */ |
| 7121 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7122 | i40e_service_event_complete(pf); |
| 7123 | return; |
| 7124 | } |
| 7125 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7126 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7127 | i40e_reset_subtask(pf); |
| 7128 | i40e_handle_mdd_event(pf); |
| 7129 | i40e_vc_process_vflr_event(pf); |
| 7130 | i40e_watchdog_subtask(pf); |
| 7131 | i40e_fdir_reinit_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7132 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7133 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7134 | i40e_clean_adminq_subtask(pf); |
| 7135 | |
| 7136 | i40e_service_event_complete(pf); |
| 7137 | |
| 7138 | /* If the tasks have taken longer than one timer cycle or there |
| 7139 | * is more work to be done, reschedule the service task now |
| 7140 | * rather than wait for the timer to tick again. |
| 7141 | */ |
| 7142 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 7143 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 7144 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 7145 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 7146 | i40e_service_event_schedule(pf); |
| 7147 | } |
| 7148 | |
| 7149 | /** |
| 7150 | * i40e_service_timer - timer callback |
| 7151 | * @data: pointer to PF struct |
| 7152 | **/ |
| 7153 | static void i40e_service_timer(unsigned long data) |
| 7154 | { |
| 7155 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7156 | |
| 7157 | mod_timer(&pf->service_timer, |
| 7158 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7159 | i40e_service_event_schedule(pf); |
| 7160 | } |
| 7161 | |
| 7162 | /** |
| 7163 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7164 | * @vsi: the VSI being configured |
| 7165 | **/ |
| 7166 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7167 | { |
| 7168 | struct i40e_pf *pf = vsi->back; |
| 7169 | |
| 7170 | switch (vsi->type) { |
| 7171 | case I40E_VSI_MAIN: |
| 7172 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7173 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7174 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7175 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7176 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7177 | else |
| 7178 | vsi->num_q_vectors = 1; |
| 7179 | |
| 7180 | break; |
| 7181 | |
| 7182 | case I40E_VSI_FDIR: |
| 7183 | vsi->alloc_queue_pairs = 1; |
| 7184 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7185 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7186 | vsi->num_q_vectors = 1; |
| 7187 | break; |
| 7188 | |
| 7189 | case I40E_VSI_VMDQ2: |
| 7190 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7191 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7192 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7193 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7194 | break; |
| 7195 | |
| 7196 | case I40E_VSI_SRIOV: |
| 7197 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7198 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7199 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7200 | break; |
| 7201 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7202 | #ifdef I40E_FCOE |
| 7203 | case I40E_VSI_FCOE: |
| 7204 | vsi->alloc_queue_pairs = pf->num_fcoe_qps; |
| 7205 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7206 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7207 | vsi->num_q_vectors = pf->num_fcoe_msix; |
| 7208 | break; |
| 7209 | |
| 7210 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7211 | default: |
| 7212 | WARN_ON(1); |
| 7213 | return -ENODATA; |
| 7214 | } |
| 7215 | |
| 7216 | return 0; |
| 7217 | } |
| 7218 | |
| 7219 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7220 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7221 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7222 | * @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] | 7223 | * |
| 7224 | * On error: returns error code (negative) |
| 7225 | * On success: returns 0 |
| 7226 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7227 | 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] | 7228 | { |
| 7229 | int size; |
| 7230 | int ret = 0; |
| 7231 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7232 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7233 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 7234 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7235 | if (!vsi->tx_rings) |
| 7236 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7237 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 7238 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7239 | if (alloc_qvectors) { |
| 7240 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7241 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7242 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7243 | if (!vsi->q_vectors) { |
| 7244 | ret = -ENOMEM; |
| 7245 | goto err_vectors; |
| 7246 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7247 | } |
| 7248 | return ret; |
| 7249 | |
| 7250 | err_vectors: |
| 7251 | kfree(vsi->tx_rings); |
| 7252 | return ret; |
| 7253 | } |
| 7254 | |
| 7255 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7256 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7257 | * @pf: board private structure |
| 7258 | * @type: type of VSI |
| 7259 | * |
| 7260 | * On error: returns error code (negative) |
| 7261 | * On success: returns vsi index in PF (positive) |
| 7262 | **/ |
| 7263 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7264 | { |
| 7265 | int ret = -ENODEV; |
| 7266 | struct i40e_vsi *vsi; |
| 7267 | int vsi_idx; |
| 7268 | int i; |
| 7269 | |
| 7270 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7271 | mutex_lock(&pf->switch_mutex); |
| 7272 | |
| 7273 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7274 | * been happening. We can afford to do a quick scan to look |
| 7275 | * for any free VSIs in the list. |
| 7276 | * |
| 7277 | * find next empty vsi slot, looping back around if necessary |
| 7278 | */ |
| 7279 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7280 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7281 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7282 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7283 | i = 0; |
| 7284 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7285 | i++; |
| 7286 | } |
| 7287 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7288 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7289 | vsi_idx = i; /* Found one! */ |
| 7290 | } else { |
| 7291 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7292 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7293 | } |
| 7294 | pf->next_vsi = ++i; |
| 7295 | |
| 7296 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7297 | if (!vsi) { |
| 7298 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7299 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7300 | } |
| 7301 | vsi->type = type; |
| 7302 | vsi->back = pf; |
| 7303 | set_bit(__I40E_DOWN, &vsi->state); |
| 7304 | vsi->flags = 0; |
| 7305 | vsi->idx = vsi_idx; |
| 7306 | vsi->rx_itr_setting = pf->rx_itr_default; |
| 7307 | vsi->tx_itr_setting = pf->tx_itr_default; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7308 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7309 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7310 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7311 | vsi->netdev_registered = false; |
| 7312 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
| 7313 | INIT_LIST_HEAD(&vsi->mac_filter_list); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7314 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7315 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7316 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7317 | if (ret) |
| 7318 | goto err_rings; |
| 7319 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7320 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7321 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7322 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7323 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7324 | /* Setup default MSIX irq handler for VSI */ |
| 7325 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7326 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7327 | /* Initialize VSI lock */ |
| 7328 | spin_lock_init(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7329 | pf->vsi[vsi_idx] = vsi; |
| 7330 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7331 | goto unlock_pf; |
| 7332 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7333 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7334 | pf->next_vsi = i - 1; |
| 7335 | kfree(vsi); |
| 7336 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7337 | mutex_unlock(&pf->switch_mutex); |
| 7338 | return ret; |
| 7339 | } |
| 7340 | |
| 7341 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7342 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7343 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7344 | * @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] | 7345 | * |
| 7346 | * On error: returns error code (negative) |
| 7347 | * On success: returns 0 |
| 7348 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7349 | 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] | 7350 | { |
| 7351 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7352 | if (free_qvectors) { |
| 7353 | kfree(vsi->q_vectors); |
| 7354 | vsi->q_vectors = NULL; |
| 7355 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7356 | kfree(vsi->tx_rings); |
| 7357 | vsi->tx_rings = NULL; |
| 7358 | vsi->rx_rings = NULL; |
| 7359 | } |
| 7360 | |
| 7361 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7362 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7363 | * and lookup table |
| 7364 | * @vsi: Pointer to VSI structure |
| 7365 | */ |
| 7366 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7367 | { |
| 7368 | if (!vsi) |
| 7369 | return; |
| 7370 | |
| 7371 | kfree(vsi->rss_hkey_user); |
| 7372 | vsi->rss_hkey_user = NULL; |
| 7373 | |
| 7374 | kfree(vsi->rss_lut_user); |
| 7375 | vsi->rss_lut_user = NULL; |
| 7376 | } |
| 7377 | |
| 7378 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7379 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7380 | * @vsi: the VSI being un-configured |
| 7381 | **/ |
| 7382 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7383 | { |
| 7384 | struct i40e_pf *pf; |
| 7385 | |
| 7386 | if (!vsi) |
| 7387 | return 0; |
| 7388 | |
| 7389 | if (!vsi->back) |
| 7390 | goto free_vsi; |
| 7391 | pf = vsi->back; |
| 7392 | |
| 7393 | mutex_lock(&pf->switch_mutex); |
| 7394 | if (!pf->vsi[vsi->idx]) { |
| 7395 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7396 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7397 | goto unlock_vsi; |
| 7398 | } |
| 7399 | |
| 7400 | if (pf->vsi[vsi->idx] != vsi) { |
| 7401 | dev_err(&pf->pdev->dev, |
| 7402 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7403 | pf->vsi[vsi->idx]->idx, |
| 7404 | pf->vsi[vsi->idx], |
| 7405 | pf->vsi[vsi->idx]->type, |
| 7406 | vsi->idx, vsi, vsi->type); |
| 7407 | goto unlock_vsi; |
| 7408 | } |
| 7409 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7410 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7411 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7412 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7413 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7414 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7415 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7416 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7417 | pf->vsi[vsi->idx] = NULL; |
| 7418 | if (vsi->idx < pf->next_vsi) |
| 7419 | pf->next_vsi = vsi->idx; |
| 7420 | |
| 7421 | unlock_vsi: |
| 7422 | mutex_unlock(&pf->switch_mutex); |
| 7423 | free_vsi: |
| 7424 | kfree(vsi); |
| 7425 | |
| 7426 | return 0; |
| 7427 | } |
| 7428 | |
| 7429 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7430 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7431 | * @vsi: the VSI being cleaned |
| 7432 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7433 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7434 | { |
| 7435 | int i; |
| 7436 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7437 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7438 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7439 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7440 | vsi->tx_rings[i] = NULL; |
| 7441 | vsi->rx_rings[i] = NULL; |
| 7442 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7443 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7444 | } |
| 7445 | |
| 7446 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7447 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7448 | * @vsi: the VSI being configured |
| 7449 | **/ |
| 7450 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7451 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7452 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7453 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7454 | int i; |
| 7455 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7456 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7457 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7458 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7459 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7460 | if (!tx_ring) |
| 7461 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7462 | |
| 7463 | tx_ring->queue_index = i; |
| 7464 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7465 | tx_ring->ring_active = false; |
| 7466 | tx_ring->vsi = vsi; |
| 7467 | tx_ring->netdev = vsi->netdev; |
| 7468 | tx_ring->dev = &pf->pdev->dev; |
| 7469 | tx_ring->count = vsi->num_desc; |
| 7470 | tx_ring->size = 0; |
| 7471 | tx_ring->dcb_tc = 0; |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 7472 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 7473 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
Anjali Singhai Jain | 527274c | 2015-06-05 12:20:31 -0400 | [diff] [blame] | 7474 | if (vsi->back->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE) |
| 7475 | tx_ring->flags |= I40E_TXR_FLAGS_OUTER_UDP_CSUM; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7476 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7477 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7478 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7479 | rx_ring->queue_index = i; |
| 7480 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7481 | rx_ring->ring_active = false; |
| 7482 | rx_ring->vsi = vsi; |
| 7483 | rx_ring->netdev = vsi->netdev; |
| 7484 | rx_ring->dev = &pf->pdev->dev; |
| 7485 | rx_ring->count = vsi->num_desc; |
| 7486 | rx_ring->size = 0; |
| 7487 | rx_ring->dcb_tc = 0; |
| 7488 | if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) |
| 7489 | set_ring_16byte_desc_enabled(rx_ring); |
| 7490 | else |
| 7491 | clear_ring_16byte_desc_enabled(rx_ring); |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7492 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7493 | } |
| 7494 | |
| 7495 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7496 | |
| 7497 | err_out: |
| 7498 | i40e_vsi_clear_rings(vsi); |
| 7499 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7500 | } |
| 7501 | |
| 7502 | /** |
| 7503 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7504 | * @pf: board private structure |
| 7505 | * @vectors: the number of MSI-X vectors to request |
| 7506 | * |
| 7507 | * Returns the number of vectors reserved, or error |
| 7508 | **/ |
| 7509 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7510 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7511 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7512 | I40E_MIN_MSIX, vectors); |
| 7513 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7514 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7515 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7516 | vectors = 0; |
| 7517 | } |
| 7518 | |
| 7519 | return vectors; |
| 7520 | } |
| 7521 | |
| 7522 | /** |
| 7523 | * i40e_init_msix - Setup the MSIX capability |
| 7524 | * @pf: board private structure |
| 7525 | * |
| 7526 | * Work with the OS to set up the MSIX vectors needed. |
| 7527 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7528 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7529 | **/ |
| 7530 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7531 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7532 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7533 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7534 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7535 | int v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7536 | |
| 7537 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7538 | return -ENODEV; |
| 7539 | |
| 7540 | /* The number of vectors we'll request will be comprised of: |
| 7541 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7542 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7543 | * - Queues being used for RSS. |
| 7544 | * We don't need as many as max_rss_size vectors. |
| 7545 | * use rss_size instead in the calculation since that |
| 7546 | * is governed by number of cpus in the system. |
| 7547 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7548 | * - The number of VMDq pairs |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7549 | #ifdef I40E_FCOE |
| 7550 | * - The number of FCOE qps. |
| 7551 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7552 | * Once we count this up, try the request. |
| 7553 | * |
| 7554 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7555 | * and try again. If that still fails, we punt. |
| 7556 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7557 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7558 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7559 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7560 | /* reserve one vector for miscellaneous handler */ |
| 7561 | if (vectors_left) { |
| 7562 | v_budget++; |
| 7563 | vectors_left--; |
| 7564 | } |
| 7565 | |
| 7566 | /* reserve vectors for the main PF traffic queues */ |
| 7567 | pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left); |
| 7568 | vectors_left -= pf->num_lan_msix; |
| 7569 | v_budget += pf->num_lan_msix; |
| 7570 | |
| 7571 | /* reserve one vector for sideband flow director */ |
| 7572 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7573 | if (vectors_left) { |
| 7574 | v_budget++; |
| 7575 | vectors_left--; |
| 7576 | } else { |
| 7577 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7578 | } |
| 7579 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7580 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7581 | #ifdef I40E_FCOE |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7582 | /* can we reserve enough for FCoE? */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7583 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7584 | if (!vectors_left) |
| 7585 | pf->num_fcoe_msix = 0; |
| 7586 | else if (vectors_left >= pf->num_fcoe_qps) |
| 7587 | pf->num_fcoe_msix = pf->num_fcoe_qps; |
| 7588 | else |
| 7589 | pf->num_fcoe_msix = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7590 | v_budget += pf->num_fcoe_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7591 | vectors_left -= pf->num_fcoe_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7592 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7593 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7594 | #endif |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7595 | /* any vectors left over go for VMDq support */ |
| 7596 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7597 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7598 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7599 | |
| 7600 | /* if we're short on vectors for what's desired, we limit |
| 7601 | * the queues per vmdq. If this is still more than are |
| 7602 | * available, the user will need to change the number of |
| 7603 | * queues/vectors used by the PF later with the ethtool |
| 7604 | * channels command |
| 7605 | */ |
| 7606 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7607 | pf->num_vmdq_qps = 1; |
| 7608 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
| 7609 | |
| 7610 | v_budget += vmdq_vecs; |
| 7611 | vectors_left -= vmdq_vecs; |
| 7612 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7613 | |
| 7614 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7615 | GFP_KERNEL); |
| 7616 | if (!pf->msix_entries) |
| 7617 | return -ENOMEM; |
| 7618 | |
| 7619 | for (i = 0; i < v_budget; i++) |
| 7620 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7621 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7622 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7623 | if (v_actual != v_budget) { |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7624 | /* If we have limited resources, we will start with no vectors |
| 7625 | * for the special features and then allocate vectors to some |
| 7626 | * of these features based on the policy and at the end disable |
| 7627 | * the features that did not get any vectors. |
| 7628 | */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7629 | #ifdef I40E_FCOE |
| 7630 | pf->num_fcoe_qps = 0; |
| 7631 | pf->num_fcoe_msix = 0; |
| 7632 | #endif |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7633 | pf->num_vmdq_msix = 0; |
| 7634 | } |
| 7635 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7636 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7637 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7638 | kfree(pf->msix_entries); |
| 7639 | pf->msix_entries = NULL; |
| 7640 | return -ENODEV; |
| 7641 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7642 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7643 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7644 | pf->num_vmdq_vsis = 0; |
| 7645 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7646 | pf->num_lan_qps = 1; |
| 7647 | pf->num_lan_msix = 1; |
| 7648 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7649 | } else if (v_actual != v_budget) { |
| 7650 | int vec; |
| 7651 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7652 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7653 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7654 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7655 | /* Scale vector usage down */ |
| 7656 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7657 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7658 | pf->num_vmdq_qps = 1; |
| 7659 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7660 | |
| 7661 | /* partition out the remaining vectors */ |
| 7662 | switch (vec) { |
| 7663 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7664 | pf->num_lan_msix = 1; |
| 7665 | break; |
| 7666 | case 3: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7667 | #ifdef I40E_FCOE |
| 7668 | /* give one vector to FCoE */ |
| 7669 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7670 | pf->num_lan_msix = 1; |
| 7671 | pf->num_fcoe_msix = 1; |
| 7672 | } |
| 7673 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7674 | pf->num_lan_msix = 2; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7675 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7676 | break; |
| 7677 | default: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7678 | #ifdef I40E_FCOE |
| 7679 | /* give one vector to FCoE */ |
| 7680 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7681 | pf->num_fcoe_msix = 1; |
| 7682 | vec--; |
| 7683 | } |
| 7684 | #endif |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7685 | /* give the rest to the PF */ |
| 7686 | pf->num_lan_msix = min_t(int, vec, pf->num_lan_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7687 | break; |
| 7688 | } |
| 7689 | } |
| 7690 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7691 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7692 | (pf->num_vmdq_msix == 0)) { |
| 7693 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 7694 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 7695 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7696 | #ifdef I40E_FCOE |
| 7697 | |
| 7698 | if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { |
| 7699 | dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n"); |
| 7700 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 7701 | } |
| 7702 | #endif |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7703 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7704 | } |
| 7705 | |
| 7706 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7707 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7708 | * @vsi: the VSI being configured |
| 7709 | * @v_idx: index of the vector in the vsi struct |
| 7710 | * |
| 7711 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 7712 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7713 | static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7714 | { |
| 7715 | struct i40e_q_vector *q_vector; |
| 7716 | |
| 7717 | /* allocate q_vector */ |
| 7718 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 7719 | if (!q_vector) |
| 7720 | return -ENOMEM; |
| 7721 | |
| 7722 | q_vector->vsi = vsi; |
| 7723 | q_vector->v_idx = v_idx; |
| 7724 | cpumask_set_cpu(v_idx, &q_vector->affinity_mask); |
| 7725 | if (vsi->netdev) |
| 7726 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 7727 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7728 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 7729 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 7730 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 7731 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7732 | /* tie q_vector and vsi together */ |
| 7733 | vsi->q_vectors[v_idx] = q_vector; |
| 7734 | |
| 7735 | return 0; |
| 7736 | } |
| 7737 | |
| 7738 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7739 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7740 | * @vsi: the VSI being configured |
| 7741 | * |
| 7742 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 7743 | * return -ENOMEM. |
| 7744 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7745 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7746 | { |
| 7747 | struct i40e_pf *pf = vsi->back; |
| 7748 | int v_idx, num_q_vectors; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7749 | int err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7750 | |
| 7751 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 7752 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7753 | num_q_vectors = vsi->num_q_vectors; |
| 7754 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 7755 | num_q_vectors = 1; |
| 7756 | else |
| 7757 | return -EINVAL; |
| 7758 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7759 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7760 | err = i40e_vsi_alloc_q_vector(vsi, v_idx); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7761 | if (err) |
| 7762 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7763 | } |
| 7764 | |
| 7765 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7766 | |
| 7767 | err_out: |
| 7768 | while (v_idx--) |
| 7769 | i40e_free_q_vector(vsi, v_idx); |
| 7770 | |
| 7771 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7772 | } |
| 7773 | |
| 7774 | /** |
| 7775 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 7776 | * @pf: board private structure to initialize |
| 7777 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7778 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7779 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7780 | int vectors = 0; |
| 7781 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7782 | |
| 7783 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7784 | vectors = i40e_init_msix(pf); |
| 7785 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7786 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7787 | #ifdef I40E_FCOE |
| 7788 | I40E_FLAG_FCOE_ENABLED | |
| 7789 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7790 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7791 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7792 | I40E_FLAG_SRIOV_ENABLED | |
| 7793 | I40E_FLAG_FD_SB_ENABLED | |
| 7794 | I40E_FLAG_FD_ATR_ENABLED | |
| 7795 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7796 | |
| 7797 | /* rework the queue expectations without MSIX */ |
| 7798 | i40e_determine_queue_usage(pf); |
| 7799 | } |
| 7800 | } |
| 7801 | |
| 7802 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 7803 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7804 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7805 | vectors = pci_enable_msi(pf->pdev); |
| 7806 | if (vectors < 0) { |
| 7807 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 7808 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7809 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 7810 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7811 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7812 | } |
| 7813 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 7814 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7815 | 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] | 7816 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7817 | /* set up vector assignment tracking */ |
| 7818 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 7819 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7820 | if (!pf->irq_pile) { |
| 7821 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 7822 | return -ENOMEM; |
| 7823 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7824 | pf->irq_pile->num_entries = vectors; |
| 7825 | pf->irq_pile->search_hint = 0; |
| 7826 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7827 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7828 | (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] | 7829 | |
| 7830 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7831 | } |
| 7832 | |
| 7833 | /** |
| 7834 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 7835 | * @pf: board private structure |
| 7836 | * |
| 7837 | * This sets up the handler for MSIX 0, which is used to manage the |
| 7838 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 7839 | * when in MSI or Legacy interrupt mode. |
| 7840 | **/ |
| 7841 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 7842 | { |
| 7843 | struct i40e_hw *hw = &pf->hw; |
| 7844 | int err = 0; |
| 7845 | |
| 7846 | /* Only request the irq if this is the first time through, and |
| 7847 | * not when we're rebuilding after a Reset |
| 7848 | */ |
| 7849 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7850 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7851 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7852 | if (err) { |
| 7853 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7854 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7855 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7856 | return -EFAULT; |
| 7857 | } |
| 7858 | } |
| 7859 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 7860 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7861 | |
| 7862 | /* associate no queues to the misc vector */ |
| 7863 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 7864 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 7865 | |
| 7866 | i40e_flush(hw); |
| 7867 | |
| 7868 | i40e_irq_dynamic_enable_icr0(pf); |
| 7869 | |
| 7870 | return err; |
| 7871 | } |
| 7872 | |
| 7873 | /** |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7874 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 7875 | * @vsi: vsi structure |
| 7876 | * @seed: RSS hash seed |
| 7877 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7878 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 7879 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7880 | { |
| 7881 | struct i40e_aqc_get_set_rss_key_data rss_key; |
| 7882 | struct i40e_pf *pf = vsi->back; |
| 7883 | struct i40e_hw *hw = &pf->hw; |
| 7884 | bool pf_lut = false; |
| 7885 | u8 *rss_lut; |
| 7886 | int ret, i; |
| 7887 | |
| 7888 | memset(&rss_key, 0, sizeof(rss_key)); |
| 7889 | memcpy(&rss_key, seed, sizeof(rss_key)); |
| 7890 | |
| 7891 | rss_lut = kzalloc(pf->rss_table_size, GFP_KERNEL); |
| 7892 | if (!rss_lut) |
| 7893 | return -ENOMEM; |
| 7894 | |
| 7895 | /* Populate the LUT with max no. of queues in round robin fashion */ |
| 7896 | for (i = 0; i < vsi->rss_table_size; i++) |
| 7897 | rss_lut[i] = i % vsi->rss_size; |
| 7898 | |
| 7899 | ret = i40e_aq_set_rss_key(hw, vsi->id, &rss_key); |
| 7900 | if (ret) { |
| 7901 | dev_info(&pf->pdev->dev, |
| 7902 | "Cannot set RSS key, err %s aq_err %s\n", |
| 7903 | i40e_stat_str(&pf->hw, ret), |
| 7904 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai | 126b63d | 2015-08-24 13:26:53 -0700 | [diff] [blame] | 7905 | goto config_rss_aq_out; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7906 | } |
| 7907 | |
| 7908 | if (vsi->type == I40E_VSI_MAIN) |
| 7909 | pf_lut = true; |
| 7910 | |
| 7911 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, rss_lut, |
| 7912 | vsi->rss_table_size); |
| 7913 | if (ret) |
| 7914 | dev_info(&pf->pdev->dev, |
| 7915 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 7916 | i40e_stat_str(&pf->hw, ret), |
| 7917 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 7918 | |
Anjali Singhai | 126b63d | 2015-08-24 13:26:53 -0700 | [diff] [blame] | 7919 | config_rss_aq_out: |
| 7920 | kfree(rss_lut); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7921 | return ret; |
| 7922 | } |
| 7923 | |
| 7924 | /** |
| 7925 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 7926 | * @vsi: VSI structure |
| 7927 | **/ |
| 7928 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 7929 | { |
| 7930 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 7931 | struct i40e_pf *pf = vsi->back; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7932 | u8 *lut; |
| 7933 | int ret; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7934 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7935 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) |
| 7936 | return 0; |
| 7937 | |
| 7938 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 7939 | if (!lut) |
| 7940 | return -ENOMEM; |
| 7941 | |
| 7942 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7943 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 7944 | vsi->rss_size = min_t(int, pf->alloc_rss_size, vsi->num_queue_pairs); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7945 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 7946 | kfree(lut); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7947 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7948 | return ret; |
| 7949 | } |
| 7950 | |
| 7951 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 7952 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 7953 | * @vsi: Pointer to vsi structure |
| 7954 | * @seed: Buffter to store the hash keys |
| 7955 | * @lut: Buffer to store the lookup table entries |
| 7956 | * @lut_size: Size of buffer to store the lookup table entries |
| 7957 | * |
| 7958 | * Return 0 on success, negative on failure |
| 7959 | */ |
| 7960 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 7961 | u8 *lut, u16 lut_size) |
| 7962 | { |
| 7963 | struct i40e_pf *pf = vsi->back; |
| 7964 | struct i40e_hw *hw = &pf->hw; |
| 7965 | int ret = 0; |
| 7966 | |
| 7967 | if (seed) { |
| 7968 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 7969 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 7970 | if (ret) { |
| 7971 | dev_info(&pf->pdev->dev, |
| 7972 | "Cannot get RSS key, err %s aq_err %s\n", |
| 7973 | i40e_stat_str(&pf->hw, ret), |
| 7974 | i40e_aq_str(&pf->hw, |
| 7975 | pf->hw.aq.asq_last_status)); |
| 7976 | return ret; |
| 7977 | } |
| 7978 | } |
| 7979 | |
| 7980 | if (lut) { |
| 7981 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 7982 | |
| 7983 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 7984 | if (ret) { |
| 7985 | dev_info(&pf->pdev->dev, |
| 7986 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 7987 | i40e_stat_str(&pf->hw, ret), |
| 7988 | i40e_aq_str(&pf->hw, |
| 7989 | pf->hw.aq.asq_last_status)); |
| 7990 | return ret; |
| 7991 | } |
| 7992 | } |
| 7993 | |
| 7994 | return ret; |
| 7995 | } |
| 7996 | |
| 7997 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 7998 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7999 | * @vsi: Pointer to vsi structure |
| 8000 | * @seed: RSS hash seed |
| 8001 | * @lut: Lookup table |
| 8002 | * @lut_size: Lookup table size |
| 8003 | * |
| 8004 | * Returns 0 on success, negative on failure |
| 8005 | **/ |
| 8006 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8007 | const u8 *lut, u16 lut_size) |
| 8008 | { |
| 8009 | struct i40e_pf *pf = vsi->back; |
| 8010 | struct i40e_hw *hw = &pf->hw; |
| 8011 | u8 i; |
| 8012 | |
| 8013 | /* Fill out hash function seed */ |
| 8014 | if (seed) { |
| 8015 | u32 *seed_dw = (u32 *)seed; |
| 8016 | |
| 8017 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 8018 | wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]); |
| 8019 | } |
| 8020 | |
| 8021 | if (lut) { |
| 8022 | u32 *lut_dw = (u32 *)lut; |
| 8023 | |
| 8024 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8025 | return -EINVAL; |
| 8026 | |
| 8027 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8028 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8029 | } |
| 8030 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8031 | |
| 8032 | return 0; |
| 8033 | } |
| 8034 | |
| 8035 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8036 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8037 | * @vsi: Pointer to VSI structure |
| 8038 | * @seed: Buffer to store the keys |
| 8039 | * @lut: Buffer to store the lookup table entries |
| 8040 | * @lut_size: Size of buffer to store the lookup table entries |
| 8041 | * |
| 8042 | * Returns 0 on success, negative on failure |
| 8043 | */ |
| 8044 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8045 | u8 *lut, u16 lut_size) |
| 8046 | { |
| 8047 | struct i40e_pf *pf = vsi->back; |
| 8048 | struct i40e_hw *hw = &pf->hw; |
| 8049 | u16 i; |
| 8050 | |
| 8051 | if (seed) { |
| 8052 | u32 *seed_dw = (u32 *)seed; |
| 8053 | |
| 8054 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 8055 | seed_dw[i] = rd32(hw, I40E_PFQF_HKEY(i)); |
| 8056 | } |
| 8057 | if (lut) { |
| 8058 | u32 *lut_dw = (u32 *)lut; |
| 8059 | |
| 8060 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8061 | return -EINVAL; |
| 8062 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8063 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8064 | } |
| 8065 | |
| 8066 | return 0; |
| 8067 | } |
| 8068 | |
| 8069 | /** |
| 8070 | * i40e_config_rss - Configure RSS keys and lut |
| 8071 | * @vsi: Pointer to VSI structure |
| 8072 | * @seed: RSS hash seed |
| 8073 | * @lut: Lookup table |
| 8074 | * @lut_size: Lookup table size |
| 8075 | * |
| 8076 | * Returns 0 on success, negative on failure |
| 8077 | */ |
| 8078 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8079 | { |
| 8080 | struct i40e_pf *pf = vsi->back; |
| 8081 | |
| 8082 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8083 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8084 | else |
| 8085 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8086 | } |
| 8087 | |
| 8088 | /** |
| 8089 | * i40e_get_rss - Get RSS keys and lut |
| 8090 | * @vsi: Pointer to VSI structure |
| 8091 | * @seed: Buffer to store the keys |
| 8092 | * @lut: Buffer to store the lookup table entries |
| 8093 | * lut_size: Size of buffer to store the lookup table entries |
| 8094 | * |
| 8095 | * Returns 0 on success, negative on failure |
| 8096 | */ |
| 8097 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8098 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8099 | struct i40e_pf *pf = vsi->back; |
| 8100 | |
| 8101 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8102 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8103 | else |
| 8104 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8105 | } |
| 8106 | |
| 8107 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8108 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8109 | * @pf: Pointer to board private structure |
| 8110 | * @lut: Lookup table |
| 8111 | * @rss_table_size: Lookup table size |
| 8112 | * @rss_size: Range of queue number for hashing |
| 8113 | */ |
| 8114 | static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8115 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8116 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8117 | u16 i; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8118 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8119 | for (i = 0; i < rss_table_size; i++) |
| 8120 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8121 | } |
| 8122 | |
| 8123 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8124 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8125 | * @pf: board private structure |
| 8126 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8127 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8128 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8129 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8130 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8131 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8132 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8133 | u32 reg_val; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8134 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8135 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8136 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8137 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
| 8138 | hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) | |
| 8139 | ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8140 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8141 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8142 | wr32(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8143 | wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
| 8144 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8145 | /* Determine the RSS table size based on the hardware capabilities */ |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8146 | reg_val = rd32(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8147 | reg_val = (pf->rss_table_size == 512) ? |
| 8148 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8149 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8150 | wr32(hw, I40E_PFQF_CTL_0, reg_val); |
| 8151 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8152 | /* Determine the RSS size of the VSI */ |
| 8153 | if (!vsi->rss_size) |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8154 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8155 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8156 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8157 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8158 | if (!lut) |
| 8159 | return -ENOMEM; |
| 8160 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8161 | /* Use user configured lut if there is one, otherwise use default */ |
| 8162 | if (vsi->rss_lut_user) |
| 8163 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8164 | else |
| 8165 | 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] | 8166 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8167 | /* Use user configured hash key if there is one, otherwise |
| 8168 | * use default. |
| 8169 | */ |
| 8170 | if (vsi->rss_hkey_user) |
| 8171 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8172 | else |
| 8173 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8174 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8175 | kfree(lut); |
| 8176 | |
| 8177 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8178 | } |
| 8179 | |
| 8180 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8181 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8182 | * @pf: board private structure |
| 8183 | * @queue_count: the requested queue count for rss. |
| 8184 | * |
| 8185 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8186 | * count which may be different from the requested queue count. |
| 8187 | **/ |
| 8188 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8189 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8190 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8191 | int new_rss_size; |
| 8192 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8193 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8194 | return 0; |
| 8195 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8196 | 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] | 8197 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8198 | if (queue_count != vsi->num_queue_pairs) { |
| 8199 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8200 | i40e_prep_for_reset(pf); |
| 8201 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8202 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8203 | |
| 8204 | i40e_reset_and_rebuild(pf, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8205 | |
| 8206 | /* Discard the user configured hash keys and lut, if less |
| 8207 | * queues are enabled. |
| 8208 | */ |
| 8209 | if (queue_count < vsi->rss_size) { |
| 8210 | i40e_clear_rss_config_user(vsi); |
| 8211 | dev_dbg(&pf->pdev->dev, |
| 8212 | "discard user configured hash keys and lut\n"); |
| 8213 | } |
| 8214 | |
| 8215 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8216 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8217 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8218 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8219 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8220 | } |
Helin Zhang | e36b0b1 | 2015-10-26 19:44:36 -0400 | [diff] [blame] | 8221 | dev_info(&pf->pdev->dev, "RSS count/HW max RSS count: %d/%d\n", |
| 8222 | pf->alloc_rss_size, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8223 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8224 | } |
| 8225 | |
| 8226 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8227 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 8228 | * @pf: board private structure |
| 8229 | **/ |
| 8230 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 8231 | { |
| 8232 | i40e_status status; |
| 8233 | bool min_valid, max_valid; |
| 8234 | u32 max_bw, min_bw; |
| 8235 | |
| 8236 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8237 | &min_valid, &max_valid); |
| 8238 | |
| 8239 | if (!status) { |
| 8240 | if (min_valid) |
| 8241 | pf->npar_min_bw = min_bw; |
| 8242 | if (max_valid) |
| 8243 | pf->npar_max_bw = max_bw; |
| 8244 | } |
| 8245 | |
| 8246 | return status; |
| 8247 | } |
| 8248 | |
| 8249 | /** |
| 8250 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 8251 | * @pf: board private structure |
| 8252 | **/ |
| 8253 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 8254 | { |
| 8255 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8256 | i40e_status status; |
| 8257 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8258 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8259 | 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] | 8260 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8261 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 8262 | |
| 8263 | /* Set the new bandwidths */ |
| 8264 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8265 | |
| 8266 | return status; |
| 8267 | } |
| 8268 | |
| 8269 | /** |
| 8270 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 8271 | * @pf: board private structure |
| 8272 | **/ |
| 8273 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 8274 | { |
| 8275 | /* Commit temporary BW setting to permanent NVM image */ |
| 8276 | enum i40e_admin_queue_err last_aq_status; |
| 8277 | i40e_status ret; |
| 8278 | u16 nvm_word; |
| 8279 | |
| 8280 | if (pf->hw.partition_id != 1) { |
| 8281 | dev_info(&pf->pdev->dev, |
| 8282 | "Commit BW only works on partition 1! This is partition %d", |
| 8283 | pf->hw.partition_id); |
| 8284 | ret = I40E_NOT_SUPPORTED; |
| 8285 | goto bw_commit_out; |
| 8286 | } |
| 8287 | |
| 8288 | /* Acquire NVM for read access */ |
| 8289 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8290 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8291 | if (ret) { |
| 8292 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8293 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8294 | i40e_stat_str(&pf->hw, ret), |
| 8295 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8296 | goto bw_commit_out; |
| 8297 | } |
| 8298 | |
| 8299 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8300 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8301 | I40E_SR_NVM_CONTROL_WORD, |
| 8302 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8303 | false, NULL); |
| 8304 | /* Save off last admin queue command status before releasing |
| 8305 | * the NVM |
| 8306 | */ |
| 8307 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8308 | i40e_release_nvm(&pf->hw); |
| 8309 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8310 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8311 | i40e_stat_str(&pf->hw, ret), |
| 8312 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8313 | goto bw_commit_out; |
| 8314 | } |
| 8315 | |
| 8316 | /* Wait a bit for NVM release to complete */ |
| 8317 | msleep(50); |
| 8318 | |
| 8319 | /* Acquire NVM for write access */ |
| 8320 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8321 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8322 | if (ret) { |
| 8323 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8324 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8325 | i40e_stat_str(&pf->hw, ret), |
| 8326 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8327 | goto bw_commit_out; |
| 8328 | } |
| 8329 | /* Write it back out unchanged to initiate update NVM, |
| 8330 | * which will force a write of the shadow (alt) RAM to |
| 8331 | * the NVM - thus storing the bandwidth values permanently. |
| 8332 | */ |
| 8333 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8334 | I40E_SR_NVM_CONTROL_WORD, |
| 8335 | 0x10, sizeof(nvm_word), |
| 8336 | &nvm_word, true, NULL); |
| 8337 | /* Save off last admin queue command status before releasing |
| 8338 | * the NVM |
| 8339 | */ |
| 8340 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8341 | i40e_release_nvm(&pf->hw); |
| 8342 | if (ret) |
| 8343 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8344 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8345 | i40e_stat_str(&pf->hw, ret), |
| 8346 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8347 | bw_commit_out: |
| 8348 | |
| 8349 | return ret; |
| 8350 | } |
| 8351 | |
| 8352 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8353 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8354 | * @pf: board private structure to initialize |
| 8355 | * |
| 8356 | * i40e_sw_init initializes the Adapter private data structure. |
| 8357 | * Fields are initialized based on PCI device information and |
| 8358 | * OS network device settings (MTU size). |
| 8359 | **/ |
| 8360 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8361 | { |
| 8362 | int err = 0; |
| 8363 | int size; |
| 8364 | |
| 8365 | pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, |
| 8366 | (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); |
Shannon Nelson | 2759997 | 2013-11-16 10:00:43 +0000 | [diff] [blame] | 8367 | pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8368 | if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { |
| 8369 | if (I40E_DEBUG_USER & debug) |
| 8370 | pf->hw.debug_mask = debug; |
| 8371 | pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), |
| 8372 | I40E_DEFAULT_MSG_ENABLE); |
| 8373 | } |
| 8374 | |
| 8375 | /* Set default capability flags */ |
| 8376 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8377 | I40E_FLAG_MSI_ENABLED | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 8378 | I40E_FLAG_LINK_POLLING_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8379 | I40E_FLAG_MSIX_ENABLED; |
| 8380 | |
| 8381 | if (iommu_present(&pci_bus_type)) |
| 8382 | pf->flags |= I40E_FLAG_RX_PS_ENABLED; |
| 8383 | else |
| 8384 | pf->flags |= I40E_FLAG_RX_1BUF_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8385 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8386 | /* Set default ITR */ |
| 8387 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8388 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8389 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8390 | /* Depending on PF configurations, it is possible that the RSS |
| 8391 | * maximum might end up larger than the available queues |
| 8392 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8393 | 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] | 8394 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8395 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8396 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8397 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8398 | if (pf->hw.func_caps.rss) { |
| 8399 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8400 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8401 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8402 | } |
| 8403 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8404 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8405 | 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] | 8406 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8407 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8408 | if (i40e_get_npar_bw_setting(pf)) |
| 8409 | dev_warn(&pf->pdev->dev, |
| 8410 | "Could not get NPAR bw settings\n"); |
| 8411 | else |
| 8412 | dev_info(&pf->pdev->dev, |
| 8413 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 8414 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8415 | } |
| 8416 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8417 | /* FW/NVM is not yet fixed in this regard */ |
| 8418 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8419 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8420 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8421 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8422 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8423 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8424 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8425 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8426 | else |
| 8427 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8428 | pf->fdir_pf_filter_count = |
| 8429 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8430 | pf->hw.fdir_shared_filter_count = |
| 8431 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8432 | } |
| 8433 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8434 | if (((pf->hw.mac.type == I40E_MAC_X710) || |
| 8435 | (pf->hw.mac.type == I40E_MAC_XL710)) && |
| 8436 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) || |
| 8437 | (pf->hw.aq.fw_maj_ver < 4))) |
| 8438 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
| 8439 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8440 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8441 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8442 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 8443 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8444 | } |
| 8445 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8446 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 8447 | i40e_init_pf_fcoe(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8448 | |
| 8449 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8450 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 8451 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8452 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 8453 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 8454 | pf->num_req_vfs = min_t(int, |
| 8455 | pf->hw.func_caps.num_vfs, |
| 8456 | I40E_MAX_VF_COUNT); |
| 8457 | } |
| 8458 | #endif /* CONFIG_PCI_IOV */ |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8459 | if (pf->hw.mac.type == I40E_MAC_X722) { |
| 8460 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE | |
| 8461 | I40E_FLAG_128_QP_RSS_CAPABLE | |
| 8462 | I40E_FLAG_HW_ATR_EVICT_CAPABLE | |
| 8463 | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE | |
| 8464 | I40E_FLAG_WB_ON_ITR_CAPABLE | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8465 | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
Catherine Sullivan | f8db54cc | 2015-12-22 14:25:14 -0800 | [diff] [blame] | 8466 | I40E_FLAG_100M_SGMII_CAPABLE | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8467 | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8468 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8469 | pf->eeprom_version = 0xDEAD; |
| 8470 | pf->lan_veb = I40E_NO_VEB; |
| 8471 | pf->lan_vsi = I40E_NO_VSI; |
| 8472 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 8473 | /* By default FW has this off for performance reasons */ |
| 8474 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 8475 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8476 | /* set up queue assignment tracking */ |
| 8477 | size = sizeof(struct i40e_lump_tracking) |
| 8478 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 8479 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 8480 | if (!pf->qp_pile) { |
| 8481 | err = -ENOMEM; |
| 8482 | goto sw_init_done; |
| 8483 | } |
| 8484 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 8485 | pf->qp_pile->search_hint = 0; |
| 8486 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 8487 | pf->tx_timeout_recovery_level = 1; |
| 8488 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8489 | mutex_init(&pf->switch_mutex); |
| 8490 | |
Greg Rose | c668a12 | 2015-02-26 16:10:39 +0000 | [diff] [blame] | 8491 | /* If NPAR is enabled nudge the Tx scheduler */ |
| 8492 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) |
| 8493 | i40e_set_npar_bw_setting(pf); |
| 8494 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8495 | sw_init_done: |
| 8496 | return err; |
| 8497 | } |
| 8498 | |
| 8499 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8500 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 8501 | * @pf: board private structure to initialize |
| 8502 | * @features: the feature set that the stack is suggesting |
| 8503 | * |
| 8504 | * returns a bool to indicate if reset needs to happen |
| 8505 | **/ |
| 8506 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 8507 | { |
| 8508 | bool need_reset = false; |
| 8509 | |
| 8510 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 8511 | * the state changed, we need to reset. |
| 8512 | */ |
| 8513 | if (features & NETIF_F_NTUPLE) { |
| 8514 | /* Enable filters and mark for reset */ |
| 8515 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 8516 | need_reset = true; |
| 8517 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
| 8518 | } else { |
| 8519 | /* turn off filters, mark for reset and clear SW filter list */ |
| 8520 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8521 | need_reset = true; |
| 8522 | i40e_fdir_filter_exit(pf); |
| 8523 | } |
| 8524 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8525 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 8526 | /* reset fd counters */ |
| 8527 | pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0; |
| 8528 | pf->fdir_pf_active_filters = 0; |
| 8529 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 8530 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 8531 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8532 | /* if ATR was auto disabled it can be re-enabled. */ |
| 8533 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 8534 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 8535 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8536 | } |
| 8537 | return need_reset; |
| 8538 | } |
| 8539 | |
| 8540 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8541 | * i40e_set_features - set the netdev feature flags |
| 8542 | * @netdev: ptr to the netdev being adjusted |
| 8543 | * @features: the feature set that the stack is suggesting |
| 8544 | **/ |
| 8545 | static int i40e_set_features(struct net_device *netdev, |
| 8546 | netdev_features_t features) |
| 8547 | { |
| 8548 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8549 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8550 | struct i40e_pf *pf = vsi->back; |
| 8551 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8552 | |
| 8553 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8554 | i40e_vlan_stripping_enable(vsi); |
| 8555 | else |
| 8556 | i40e_vlan_stripping_disable(vsi); |
| 8557 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8558 | need_reset = i40e_set_ntuple(pf, features); |
| 8559 | |
| 8560 | if (need_reset) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8561 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8562 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8563 | return 0; |
| 8564 | } |
| 8565 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8566 | #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8567 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8568 | * 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] | 8569 | * @pf: board private structure |
| 8570 | * @port: The UDP port to look up |
| 8571 | * |
| 8572 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 8573 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8574 | 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] | 8575 | { |
| 8576 | u8 i; |
| 8577 | |
| 8578 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8579 | if (pf->udp_ports[i].index == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8580 | return i; |
| 8581 | } |
| 8582 | |
| 8583 | return i; |
| 8584 | } |
| 8585 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8586 | #endif |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8587 | |
| 8588 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8589 | /** |
| 8590 | * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up |
| 8591 | * @netdev: This physical port's netdev |
| 8592 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 8593 | * @port: New UDP port number that VXLAN started listening to |
| 8594 | **/ |
| 8595 | static void i40e_add_vxlan_port(struct net_device *netdev, |
| 8596 | sa_family_t sa_family, __be16 port) |
| 8597 | { |
| 8598 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8599 | struct i40e_vsi *vsi = np->vsi; |
| 8600 | struct i40e_pf *pf = vsi->back; |
| 8601 | u8 next_idx; |
| 8602 | u8 idx; |
| 8603 | |
| 8604 | if (sa_family == AF_INET6) |
| 8605 | return; |
| 8606 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8607 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8608 | |
| 8609 | /* Check if port already exists */ |
| 8610 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8611 | netdev_info(netdev, "vxlan port %d already offloaded\n", |
| 8612 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8613 | return; |
| 8614 | } |
| 8615 | |
| 8616 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8617 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8618 | |
| 8619 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8620 | netdev_info(netdev, "maximum number of vxlan UDP ports reached, not adding port %d\n", |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8621 | ntohs(port)); |
| 8622 | return; |
| 8623 | } |
| 8624 | |
| 8625 | /* New port: add it and mark its index in the bitmap */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8626 | pf->udp_ports[next_idx].index = port; |
| 8627 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 8628 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8629 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8630 | } |
| 8631 | |
| 8632 | /** |
| 8633 | * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away |
| 8634 | * @netdev: This physical port's netdev |
| 8635 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 8636 | * @port: UDP port number that VXLAN stopped listening to |
| 8637 | **/ |
| 8638 | static void i40e_del_vxlan_port(struct net_device *netdev, |
| 8639 | sa_family_t sa_family, __be16 port) |
| 8640 | { |
| 8641 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8642 | struct i40e_vsi *vsi = np->vsi; |
| 8643 | struct i40e_pf *pf = vsi->back; |
| 8644 | u8 idx; |
| 8645 | |
| 8646 | if (sa_family == AF_INET6) |
| 8647 | return; |
| 8648 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8649 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8650 | |
| 8651 | /* Check if port already exists */ |
| 8652 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8653 | /* if port exists, set it to 0 (mark for deletion) |
| 8654 | * and make it pending |
| 8655 | */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8656 | pf->udp_ports[idx].index = 0; |
| 8657 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
| 8658 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8659 | } else { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8660 | netdev_warn(netdev, "vxlan port %d was not found, not deleting\n", |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8661 | ntohs(port)); |
| 8662 | } |
| 8663 | } |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8664 | #endif |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8665 | |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8666 | #if IS_ENABLED(CONFIG_GENEVE) |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8667 | /** |
| 8668 | * i40e_add_geneve_port - Get notifications about GENEVE ports that come up |
| 8669 | * @netdev: This physical port's netdev |
| 8670 | * @sa_family: Socket Family that GENEVE is notifying us about |
| 8671 | * @port: New UDP port number that GENEVE started listening to |
| 8672 | **/ |
| 8673 | static void i40e_add_geneve_port(struct net_device *netdev, |
| 8674 | sa_family_t sa_family, __be16 port) |
| 8675 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8676 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8677 | struct i40e_vsi *vsi = np->vsi; |
| 8678 | struct i40e_pf *pf = vsi->back; |
| 8679 | u8 next_idx; |
| 8680 | u8 idx; |
| 8681 | |
| 8682 | if (sa_family == AF_INET6) |
| 8683 | return; |
| 8684 | |
| 8685 | idx = i40e_get_udp_port_idx(pf, port); |
| 8686 | |
| 8687 | /* Check if port already exists */ |
| 8688 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8689 | netdev_info(netdev, "udp port %d already offloaded\n", |
| 8690 | ntohs(port)); |
| 8691 | return; |
| 8692 | } |
| 8693 | |
| 8694 | /* Now check if there is space to add the new port */ |
| 8695 | next_idx = i40e_get_udp_port_idx(pf, 0); |
| 8696 | |
| 8697 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8698 | netdev_info(netdev, "maximum number of UDP ports reached, not adding port %d\n", |
| 8699 | ntohs(port)); |
| 8700 | return; |
| 8701 | } |
| 8702 | |
| 8703 | /* New port: add it and mark its index in the bitmap */ |
| 8704 | pf->udp_ports[next_idx].index = port; |
| 8705 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 8706 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8707 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8708 | |
| 8709 | dev_info(&pf->pdev->dev, "adding geneve port %d\n", ntohs(port)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8710 | } |
| 8711 | |
| 8712 | /** |
| 8713 | * i40e_del_geneve_port - Get notifications about GENEVE ports that go away |
| 8714 | * @netdev: This physical port's netdev |
| 8715 | * @sa_family: Socket Family that GENEVE is notifying us about |
| 8716 | * @port: UDP port number that GENEVE stopped listening to |
| 8717 | **/ |
| 8718 | static void i40e_del_geneve_port(struct net_device *netdev, |
| 8719 | sa_family_t sa_family, __be16 port) |
| 8720 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8721 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8722 | struct i40e_vsi *vsi = np->vsi; |
| 8723 | struct i40e_pf *pf = vsi->back; |
| 8724 | u8 idx; |
| 8725 | |
| 8726 | if (sa_family == AF_INET6) |
| 8727 | return; |
| 8728 | |
| 8729 | idx = i40e_get_udp_port_idx(pf, port); |
| 8730 | |
| 8731 | /* Check if port already exists */ |
| 8732 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8733 | /* if port exists, set it to 0 (mark for deletion) |
| 8734 | * and make it pending |
| 8735 | */ |
| 8736 | pf->udp_ports[idx].index = 0; |
| 8737 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
| 8738 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8739 | |
| 8740 | dev_info(&pf->pdev->dev, "deleting geneve port %d\n", |
| 8741 | ntohs(port)); |
| 8742 | } else { |
| 8743 | netdev_warn(netdev, "geneve port %d was not found, not deleting\n", |
| 8744 | ntohs(port)); |
| 8745 | } |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8746 | } |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8747 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8748 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8749 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 8750 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8751 | { |
| 8752 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8753 | struct i40e_pf *pf = np->vsi->back; |
| 8754 | struct i40e_hw *hw = &pf->hw; |
| 8755 | |
| 8756 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 8757 | return -EOPNOTSUPP; |
| 8758 | |
| 8759 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 8760 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 8761 | |
| 8762 | return 0; |
| 8763 | } |
| 8764 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 8765 | /** |
| 8766 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 8767 | * @ndm: the input from the stack |
| 8768 | * @tb: pointer to array of nladdr (unused) |
| 8769 | * @dev: the net device pointer |
| 8770 | * @addr: the MAC address entry being added |
| 8771 | * @flags: instructions from stack about fdb operation |
| 8772 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8773 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 8774 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8775 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8776 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8777 | { |
| 8778 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8779 | struct i40e_pf *pf = np->vsi->back; |
| 8780 | int err = 0; |
| 8781 | |
| 8782 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 8783 | return -EOPNOTSUPP; |
| 8784 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 8785 | if (vid) { |
| 8786 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 8787 | return -EINVAL; |
| 8788 | } |
| 8789 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8790 | /* Hardware does not support aging addresses so if a |
| 8791 | * ndm_state is given only allow permanent addresses |
| 8792 | */ |
| 8793 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 8794 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 8795 | return -EINVAL; |
| 8796 | } |
| 8797 | |
| 8798 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 8799 | err = dev_uc_add_excl(dev, addr); |
| 8800 | else if (is_multicast_ether_addr(addr)) |
| 8801 | err = dev_mc_add_excl(dev, addr); |
| 8802 | else |
| 8803 | err = -EINVAL; |
| 8804 | |
| 8805 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 8806 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 8807 | err = 0; |
| 8808 | |
| 8809 | return err; |
| 8810 | } |
| 8811 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8812 | /** |
| 8813 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 8814 | * @dev: the netdev being configured |
| 8815 | * @nlh: RTNL message |
| 8816 | * |
| 8817 | * Inserts a new hardware bridge if not already created and |
| 8818 | * enables the bridging mode requested (VEB or VEPA). If the |
| 8819 | * hardware bridge has already been inserted and the request |
| 8820 | * is to change the mode then that requires a PF reset to |
| 8821 | * allow rebuild of the components with required hardware |
| 8822 | * bridge mode enabled. |
| 8823 | **/ |
| 8824 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 8825 | struct nlmsghdr *nlh, |
| 8826 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8827 | { |
| 8828 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8829 | struct i40e_vsi *vsi = np->vsi; |
| 8830 | struct i40e_pf *pf = vsi->back; |
| 8831 | struct i40e_veb *veb = NULL; |
| 8832 | struct nlattr *attr, *br_spec; |
| 8833 | int i, rem; |
| 8834 | |
| 8835 | /* Only for PF VSI for now */ |
| 8836 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8837 | return -EOPNOTSUPP; |
| 8838 | |
| 8839 | /* Find the HW bridge for PF VSI */ |
| 8840 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8841 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8842 | veb = pf->veb[i]; |
| 8843 | } |
| 8844 | |
| 8845 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 8846 | |
| 8847 | nla_for_each_nested(attr, br_spec, rem) { |
| 8848 | __u16 mode; |
| 8849 | |
| 8850 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 8851 | continue; |
| 8852 | |
| 8853 | mode = nla_get_u16(attr); |
| 8854 | if ((mode != BRIDGE_MODE_VEPA) && |
| 8855 | (mode != BRIDGE_MODE_VEB)) |
| 8856 | return -EINVAL; |
| 8857 | |
| 8858 | /* Insert a new HW bridge */ |
| 8859 | if (!veb) { |
| 8860 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 8861 | vsi->tc_config.enabled_tc); |
| 8862 | if (veb) { |
| 8863 | veb->bridge_mode = mode; |
| 8864 | i40e_config_bridge_mode(veb); |
| 8865 | } else { |
| 8866 | /* No Bridge HW offload available */ |
| 8867 | return -ENOENT; |
| 8868 | } |
| 8869 | break; |
| 8870 | } else if (mode != veb->bridge_mode) { |
| 8871 | /* Existing HW bridge but different mode needs reset */ |
| 8872 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 8873 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 8874 | if (mode == BRIDGE_MODE_VEB) |
| 8875 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 8876 | else |
| 8877 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 8878 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8879 | break; |
| 8880 | } |
| 8881 | } |
| 8882 | |
| 8883 | return 0; |
| 8884 | } |
| 8885 | |
| 8886 | /** |
| 8887 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 8888 | * @skb: skb buff |
| 8889 | * @pid: process id |
| 8890 | * @seq: RTNL message seq # |
| 8891 | * @dev: the netdev being configured |
| 8892 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 8893 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8894 | * |
| 8895 | * Return the mode in which the hardware bridge is operating in |
| 8896 | * i.e VEB or VEPA. |
| 8897 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8898 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 8899 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 8900 | u32 __always_unused filter_mask, |
| 8901 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8902 | { |
| 8903 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8904 | struct i40e_vsi *vsi = np->vsi; |
| 8905 | struct i40e_pf *pf = vsi->back; |
| 8906 | struct i40e_veb *veb = NULL; |
| 8907 | int i; |
| 8908 | |
| 8909 | /* Only for PF VSI for now */ |
| 8910 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8911 | return -EOPNOTSUPP; |
| 8912 | |
| 8913 | /* Find the HW bridge for the PF VSI */ |
| 8914 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8915 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8916 | veb = pf->veb[i]; |
| 8917 | } |
| 8918 | |
| 8919 | if (!veb) |
| 8920 | return 0; |
| 8921 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 8922 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 8923 | nlflags, 0, 0, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8924 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8925 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8926 | /* Hardware supports L4 tunnel length of 128B (=2^7) which includes |
| 8927 | * inner mac plus all inner ethertypes. |
| 8928 | */ |
| 8929 | #define I40E_MAX_TUNNEL_HDR_LEN 128 |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8930 | /** |
| 8931 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 8932 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 8933 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8934 | * @features: Offload features that the stack believes apply |
| 8935 | **/ |
| 8936 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 8937 | struct net_device *dev, |
| 8938 | netdev_features_t features) |
| 8939 | { |
| 8940 | if (skb->encapsulation && |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8941 | ((skb_inner_network_header(skb) - skb_transport_header(skb)) > |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8942 | I40E_MAX_TUNNEL_HDR_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 8943 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8944 | |
| 8945 | return features; |
| 8946 | } |
| 8947 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 8948 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8949 | .ndo_open = i40e_open, |
| 8950 | .ndo_stop = i40e_close, |
| 8951 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 8952 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 8953 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 8954 | .ndo_validate_addr = eth_validate_addr, |
| 8955 | .ndo_set_mac_address = i40e_set_mac, |
| 8956 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 8957 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8958 | .ndo_tx_timeout = i40e_tx_timeout, |
| 8959 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 8960 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 8961 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8962 | .ndo_poll_controller = i40e_netpoll, |
| 8963 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8964 | .ndo_setup_tc = __i40e_setup_tc, |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8965 | #ifdef I40E_FCOE |
| 8966 | .ndo_fcoe_enable = i40e_fcoe_enable, |
| 8967 | .ndo_fcoe_disable = i40e_fcoe_disable, |
| 8968 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8969 | .ndo_set_features = i40e_set_features, |
| 8970 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 8971 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 8972 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8973 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 8974 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 8975 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8976 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8977 | .ndo_add_vxlan_port = i40e_add_vxlan_port, |
| 8978 | .ndo_del_vxlan_port = i40e_del_vxlan_port, |
| 8979 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8980 | #if IS_ENABLED(CONFIG_GENEVE) |
| 8981 | .ndo_add_geneve_port = i40e_add_geneve_port, |
| 8982 | .ndo_del_geneve_port = i40e_del_geneve_port, |
| 8983 | #endif |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8984 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8985 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8986 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8987 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 8988 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8989 | }; |
| 8990 | |
| 8991 | /** |
| 8992 | * i40e_config_netdev - Setup the netdev flags |
| 8993 | * @vsi: the VSI being configured |
| 8994 | * |
| 8995 | * Returns 0 on success, negative value on failure |
| 8996 | **/ |
| 8997 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 8998 | { |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 8999 | u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9000 | struct i40e_pf *pf = vsi->back; |
| 9001 | struct i40e_hw *hw = &pf->hw; |
| 9002 | struct i40e_netdev_priv *np; |
| 9003 | struct net_device *netdev; |
| 9004 | u8 mac_addr[ETH_ALEN]; |
| 9005 | int etherdev_size; |
| 9006 | |
| 9007 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9008 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9009 | if (!netdev) |
| 9010 | return -ENOMEM; |
| 9011 | |
| 9012 | vsi->netdev = netdev; |
| 9013 | np = netdev_priv(netdev); |
| 9014 | np->vsi = vsi; |
| 9015 | |
Jesse Brandeburg | 5afdaaa | 2015-12-10 11:38:50 -0800 | [diff] [blame] | 9016 | netdev->hw_enc_features |= NETIF_F_IP_CSUM | |
| 9017 | NETIF_F_GSO_UDP_TUNNEL | |
| 9018 | NETIF_F_GSO_GRE | |
| 9019 | NETIF_F_TSO | |
| 9020 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9021 | |
| 9022 | netdev->features = NETIF_F_SG | |
| 9023 | NETIF_F_IP_CSUM | |
Tom Herbert | 53692b1 | 2015-12-14 11:19:41 -0800 | [diff] [blame] | 9024 | NETIF_F_SCTP_CRC | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9025 | NETIF_F_HIGHDMA | |
| 9026 | NETIF_F_GSO_UDP_TUNNEL | |
Jesse Brandeburg | fec31ff | 2015-10-01 18:25:42 -0700 | [diff] [blame] | 9027 | NETIF_F_GSO_GRE | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9028 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9029 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9030 | NETIF_F_HW_VLAN_CTAG_FILTER | |
| 9031 | NETIF_F_IPV6_CSUM | |
| 9032 | NETIF_F_TSO | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 9033 | NETIF_F_TSO_ECN | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9034 | NETIF_F_TSO6 | |
| 9035 | NETIF_F_RXCSUM | |
| 9036 | NETIF_F_RXHASH | |
| 9037 | 0; |
| 9038 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9039 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 9040 | netdev->features |= NETIF_F_NTUPLE; |
| 9041 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9042 | /* copy netdev features into list of user selectable features */ |
| 9043 | netdev->hw_features |= netdev->features; |
| 9044 | |
| 9045 | if (vsi->type == I40E_VSI_MAIN) { |
| 9046 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9047 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9048 | /* The following steps are necessary to prevent reception |
| 9049 | * of tagged packets - some older NVM configurations load a |
| 9050 | * default a MAC-VLAN filter that accepts any tagged packet |
| 9051 | * which must be replaced by a normal filter. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 9052 | */ |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9053 | if (!i40e_rm_default_mac_filter(vsi, mac_addr)) { |
| 9054 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9055 | i40e_add_filter(vsi, mac_addr, |
| 9056 | I40E_VLAN_ANY, false, true); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9057 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9058 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9059 | } else { |
| 9060 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 9061 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 9062 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9063 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9064 | |
| 9065 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9066 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9067 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9068 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9069 | |
| 9070 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 9071 | i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9072 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9073 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9074 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9075 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9076 | /* vlan gets same features (except vlan offload) |
| 9077 | * after any tweaks for specific VSI types |
| 9078 | */ |
| 9079 | netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX | |
| 9080 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9081 | NETIF_F_HW_VLAN_CTAG_FILTER); |
| 9082 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9083 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9084 | /* Setup netdev TC information */ |
| 9085 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9086 | |
| 9087 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9088 | netdev->watchdog_timeo = 5 * HZ; |
| 9089 | i40e_set_ethtool_ops(netdev); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9090 | #ifdef I40E_FCOE |
| 9091 | i40e_fcoe_config_netdev(netdev, vsi); |
| 9092 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9093 | |
| 9094 | return 0; |
| 9095 | } |
| 9096 | |
| 9097 | /** |
| 9098 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9099 | * @vsi: the VSI being removed |
| 9100 | * |
| 9101 | * Returns 0 on success, negative value on failure |
| 9102 | **/ |
| 9103 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9104 | { |
| 9105 | /* remove default VSI is not allowed */ |
| 9106 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9107 | return; |
| 9108 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9109 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9110 | } |
| 9111 | |
| 9112 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9113 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9114 | * @vsi: the VSI being queried |
| 9115 | * |
| 9116 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9117 | **/ |
| 9118 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9119 | { |
| 9120 | struct i40e_veb *veb; |
| 9121 | struct i40e_pf *pf = vsi->back; |
| 9122 | |
| 9123 | /* Uplink is not a bridge so default to VEB */ |
| 9124 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9125 | return 1; |
| 9126 | |
| 9127 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9128 | if (!veb) { |
| 9129 | dev_info(&pf->pdev->dev, |
| 9130 | "There is no veb associated with the bridge\n"); |
| 9131 | return -ENOENT; |
| 9132 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9133 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9134 | /* Uplink is a bridge in VEPA mode */ |
| 9135 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9136 | return 0; |
| 9137 | } else { |
| 9138 | /* Uplink is a bridge in VEB mode */ |
| 9139 | return 1; |
| 9140 | } |
| 9141 | |
| 9142 | /* VEPA is now default bridge, so return 0 */ |
| 9143 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9144 | } |
| 9145 | |
| 9146 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9147 | * i40e_add_vsi - Add a VSI to the switch |
| 9148 | * @vsi: the VSI being configured |
| 9149 | * |
| 9150 | * This initializes a VSI context depending on the VSI type to be added and |
| 9151 | * passes it down to the add_vsi aq command. |
| 9152 | **/ |
| 9153 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9154 | { |
| 9155 | int ret = -ENODEV; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9156 | u8 laa_macaddr[ETH_ALEN]; |
| 9157 | bool found_laa_mac_filter = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9158 | struct i40e_pf *pf = vsi->back; |
| 9159 | struct i40e_hw *hw = &pf->hw; |
| 9160 | struct i40e_vsi_context ctxt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9161 | struct i40e_mac_filter *f, *ftmp; |
| 9162 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9163 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9164 | int f_count = 0; |
| 9165 | |
| 9166 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9167 | switch (vsi->type) { |
| 9168 | case I40E_VSI_MAIN: |
| 9169 | /* The PF's main VSI is already setup as part of the |
| 9170 | * device initialization, so we'll not bother with |
| 9171 | * the add_vsi call, but we will retrieve the current |
| 9172 | * VSI context. |
| 9173 | */ |
| 9174 | ctxt.seid = pf->main_vsi_seid; |
| 9175 | ctxt.pf_num = pf->hw.pf_id; |
| 9176 | ctxt.vf_num = 0; |
| 9177 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9178 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9179 | if (ret) { |
| 9180 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9181 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9182 | i40e_stat_str(&pf->hw, ret), |
| 9183 | i40e_aq_str(&pf->hw, |
| 9184 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9185 | return -ENOENT; |
| 9186 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9187 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9188 | vsi->info.valid_sections = 0; |
| 9189 | |
| 9190 | vsi->seid = ctxt.seid; |
| 9191 | vsi->id = ctxt.vsi_number; |
| 9192 | |
| 9193 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9194 | |
| 9195 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9196 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9197 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9198 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9199 | ctxt.seid = pf->main_vsi_seid; |
| 9200 | ctxt.pf_num = pf->hw.pf_id; |
| 9201 | ctxt.vf_num = 0; |
| 9202 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9203 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9204 | if (ret) { |
| 9205 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9206 | "update vsi failed, err %s aq_err %s\n", |
| 9207 | i40e_stat_str(&pf->hw, ret), |
| 9208 | i40e_aq_str(&pf->hw, |
| 9209 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9210 | ret = -ENOENT; |
| 9211 | goto err; |
| 9212 | } |
| 9213 | /* update the local VSI info queue map */ |
| 9214 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9215 | vsi->info.valid_sections = 0; |
| 9216 | } else { |
| 9217 | /* Default/Main VSI is only enabled for TC0 |
| 9218 | * reconfigure it to enable all TCs that are |
| 9219 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9220 | * For MFP case the iSCSI PF would use this |
| 9221 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9222 | */ |
| 9223 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9224 | if (ret) { |
| 9225 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9226 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9227 | enabled_tc, |
| 9228 | i40e_stat_str(&pf->hw, ret), |
| 9229 | i40e_aq_str(&pf->hw, |
| 9230 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9231 | ret = -ENOENT; |
| 9232 | } |
| 9233 | } |
| 9234 | break; |
| 9235 | |
| 9236 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9237 | ctxt.pf_num = hw->pf_id; |
| 9238 | ctxt.vf_num = 0; |
| 9239 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9240 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9241 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9242 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9243 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9244 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9245 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9246 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9247 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9248 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9249 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9250 | break; |
| 9251 | |
| 9252 | case I40E_VSI_VMDQ2: |
| 9253 | ctxt.pf_num = hw->pf_id; |
| 9254 | ctxt.vf_num = 0; |
| 9255 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9256 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9257 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9258 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9259 | /* This VSI is connected to VEB so the switch_id |
| 9260 | * should be set to zero by default. |
| 9261 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9262 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9263 | ctxt.info.valid_sections |= |
| 9264 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9265 | ctxt.info.switch_id = |
| 9266 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9267 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9268 | |
| 9269 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9270 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9271 | break; |
| 9272 | |
| 9273 | case I40E_VSI_SRIOV: |
| 9274 | ctxt.pf_num = hw->pf_id; |
| 9275 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9276 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9277 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9278 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9279 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9280 | /* This VSI is connected to VEB so the switch_id |
| 9281 | * should be set to zero by default. |
| 9282 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9283 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9284 | ctxt.info.valid_sections |= |
| 9285 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9286 | ctxt.info.switch_id = |
| 9287 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9288 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9289 | |
| 9290 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9291 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9292 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9293 | ctxt.info.valid_sections |= |
| 9294 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9295 | ctxt.info.sec_flags |= |
| 9296 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9297 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9298 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9299 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9300 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9301 | break; |
| 9302 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9303 | #ifdef I40E_FCOE |
| 9304 | case I40E_VSI_FCOE: |
| 9305 | ret = i40e_fcoe_vsi_init(vsi, &ctxt); |
| 9306 | if (ret) { |
| 9307 | dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n"); |
| 9308 | return ret; |
| 9309 | } |
| 9310 | break; |
| 9311 | |
| 9312 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9313 | default: |
| 9314 | return -ENODEV; |
| 9315 | } |
| 9316 | |
| 9317 | if (vsi->type != I40E_VSI_MAIN) { |
| 9318 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9319 | if (ret) { |
| 9320 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9321 | "add vsi failed, err %s aq_err %s\n", |
| 9322 | i40e_stat_str(&pf->hw, ret), |
| 9323 | i40e_aq_str(&pf->hw, |
| 9324 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9325 | ret = -ENOENT; |
| 9326 | goto err; |
| 9327 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9328 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9329 | vsi->info.valid_sections = 0; |
| 9330 | vsi->seid = ctxt.seid; |
| 9331 | vsi->id = ctxt.vsi_number; |
| 9332 | } |
| 9333 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9334 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9335 | /* If macvlan filters already exist, force them to get loaded */ |
| 9336 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 9337 | f->changed = true; |
| 9338 | f_count++; |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9339 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9340 | /* Expected to have only one MAC filter entry for LAA in list */ |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9341 | if (f->is_laa && vsi->type == I40E_VSI_MAIN) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9342 | ether_addr_copy(laa_macaddr, f->macaddr); |
| 9343 | found_laa_mac_filter = true; |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9344 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9345 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9346 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9347 | |
| 9348 | if (found_laa_mac_filter) { |
| 9349 | struct i40e_aqc_remove_macvlan_element_data element; |
| 9350 | |
| 9351 | memset(&element, 0, sizeof(element)); |
| 9352 | ether_addr_copy(element.mac_addr, laa_macaddr); |
| 9353 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 9354 | ret = i40e_aq_remove_macvlan(hw, vsi->seid, |
| 9355 | &element, 1, NULL); |
| 9356 | if (ret) { |
| 9357 | /* some older FW has a different default */ |
| 9358 | element.flags |= |
| 9359 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
| 9360 | i40e_aq_remove_macvlan(hw, vsi->seid, |
| 9361 | &element, 1, NULL); |
| 9362 | } |
| 9363 | |
| 9364 | i40e_aq_mac_address_write(hw, |
| 9365 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 9366 | laa_macaddr, NULL); |
| 9367 | } |
| 9368 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9369 | if (f_count) { |
| 9370 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 9371 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 9372 | } |
| 9373 | |
| 9374 | /* Update VSI BW information */ |
| 9375 | ret = i40e_vsi_get_bw_info(vsi); |
| 9376 | if (ret) { |
| 9377 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9378 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 9379 | i40e_stat_str(&pf->hw, ret), |
| 9380 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9381 | /* VSI is already added so not tearing that up */ |
| 9382 | ret = 0; |
| 9383 | } |
| 9384 | |
| 9385 | err: |
| 9386 | return ret; |
| 9387 | } |
| 9388 | |
| 9389 | /** |
| 9390 | * i40e_vsi_release - Delete a VSI and free its resources |
| 9391 | * @vsi: the VSI being removed |
| 9392 | * |
| 9393 | * Returns 0 on success or < 0 on error |
| 9394 | **/ |
| 9395 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 9396 | { |
| 9397 | struct i40e_mac_filter *f, *ftmp; |
| 9398 | struct i40e_veb *veb = NULL; |
| 9399 | struct i40e_pf *pf; |
| 9400 | u16 uplink_seid; |
| 9401 | int i, n; |
| 9402 | |
| 9403 | pf = vsi->back; |
| 9404 | |
| 9405 | /* release of a VEB-owner or last VSI is not allowed */ |
| 9406 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 9407 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 9408 | vsi->seid, vsi->uplink_seid); |
| 9409 | return -ENODEV; |
| 9410 | } |
| 9411 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 9412 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 9413 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 9414 | return -ENODEV; |
| 9415 | } |
| 9416 | |
| 9417 | uplink_seid = vsi->uplink_seid; |
| 9418 | if (vsi->type != I40E_VSI_SRIOV) { |
| 9419 | if (vsi->netdev_registered) { |
| 9420 | vsi->netdev_registered = false; |
| 9421 | if (vsi->netdev) { |
| 9422 | /* results in a call to i40e_close() */ |
| 9423 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9424 | } |
| 9425 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 9426 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9427 | } |
| 9428 | i40e_vsi_disable_irq(vsi); |
| 9429 | } |
| 9430 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9431 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9432 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
| 9433 | i40e_del_filter(vsi, f->macaddr, f->vlan, |
| 9434 | f->is_vf, f->is_netdev); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9435 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9436 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 9437 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9438 | |
| 9439 | i40e_vsi_delete(vsi); |
| 9440 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 9441 | if (vsi->netdev) { |
| 9442 | free_netdev(vsi->netdev); |
| 9443 | vsi->netdev = NULL; |
| 9444 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9445 | i40e_vsi_clear_rings(vsi); |
| 9446 | i40e_vsi_clear(vsi); |
| 9447 | |
| 9448 | /* If this was the last thing on the VEB, except for the |
| 9449 | * controlling VSI, remove the VEB, which puts the controlling |
| 9450 | * VSI onto the next level down in the switch. |
| 9451 | * |
| 9452 | * Well, okay, there's one more exception here: don't remove |
| 9453 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 9454 | * from up the network stack. |
| 9455 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9456 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9457 | if (pf->vsi[i] && |
| 9458 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 9459 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9460 | n++; /* count the VSIs */ |
| 9461 | } |
| 9462 | } |
| 9463 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9464 | if (!pf->veb[i]) |
| 9465 | continue; |
| 9466 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 9467 | n++; /* count the VEBs */ |
| 9468 | if (pf->veb[i]->seid == uplink_seid) |
| 9469 | veb = pf->veb[i]; |
| 9470 | } |
| 9471 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 9472 | i40e_veb_release(veb); |
| 9473 | |
| 9474 | return 0; |
| 9475 | } |
| 9476 | |
| 9477 | /** |
| 9478 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 9479 | * @vsi: ptr to the VSI |
| 9480 | * |
| 9481 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 9482 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 9483 | * newly allocated VSI. |
| 9484 | * |
| 9485 | * Returns 0 on success or negative on failure |
| 9486 | **/ |
| 9487 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 9488 | { |
| 9489 | int ret = -ENOENT; |
| 9490 | struct i40e_pf *pf = vsi->back; |
| 9491 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9492 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9493 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 9494 | vsi->seid); |
| 9495 | return -EEXIST; |
| 9496 | } |
| 9497 | |
| 9498 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 9499 | 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] | 9500 | vsi->seid, vsi->base_vector); |
| 9501 | return -EEXIST; |
| 9502 | } |
| 9503 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9504 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9505 | if (ret) { |
| 9506 | dev_info(&pf->pdev->dev, |
| 9507 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 9508 | vsi->num_q_vectors, vsi->seid, ret); |
| 9509 | vsi->num_q_vectors = 0; |
| 9510 | goto vector_setup_out; |
| 9511 | } |
| 9512 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 9513 | /* In Legacy mode, we do not have to get any other vector since we |
| 9514 | * piggyback on the misc/ICR0 for queue interrupts. |
| 9515 | */ |
| 9516 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9517 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9518 | if (vsi->num_q_vectors) |
| 9519 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 9520 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9521 | if (vsi->base_vector < 0) { |
| 9522 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9523 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 9524 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9525 | i40e_vsi_free_q_vectors(vsi); |
| 9526 | ret = -ENOENT; |
| 9527 | goto vector_setup_out; |
| 9528 | } |
| 9529 | |
| 9530 | vector_setup_out: |
| 9531 | return ret; |
| 9532 | } |
| 9533 | |
| 9534 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9535 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 9536 | * @vsi: pointer to the vsi. |
| 9537 | * |
| 9538 | * This re-allocates a vsi's queue resources. |
| 9539 | * |
| 9540 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 9541 | * on success, otherwise returns NULL on failure. |
| 9542 | **/ |
| 9543 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 9544 | { |
| 9545 | struct i40e_pf *pf = vsi->back; |
| 9546 | u8 enabled_tc; |
| 9547 | int ret; |
| 9548 | |
| 9549 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9550 | i40e_vsi_clear_rings(vsi); |
| 9551 | |
| 9552 | i40e_vsi_free_arrays(vsi, false); |
| 9553 | i40e_set_num_rings_in_vsi(vsi); |
| 9554 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 9555 | if (ret) |
| 9556 | goto err_vsi; |
| 9557 | |
| 9558 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 9559 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9560 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9561 | "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] | 9562 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9563 | goto err_vsi; |
| 9564 | } |
| 9565 | vsi->base_queue = ret; |
| 9566 | |
| 9567 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 9568 | * layout configurations. |
| 9569 | */ |
| 9570 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9571 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9572 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9573 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 9574 | |
| 9575 | /* assign it some queues */ |
| 9576 | ret = i40e_alloc_rings(vsi); |
| 9577 | if (ret) |
| 9578 | goto err_rings; |
| 9579 | |
| 9580 | /* map all of the rings to the q_vectors */ |
| 9581 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9582 | return vsi; |
| 9583 | |
| 9584 | err_rings: |
| 9585 | i40e_vsi_free_q_vectors(vsi); |
| 9586 | if (vsi->netdev_registered) { |
| 9587 | vsi->netdev_registered = false; |
| 9588 | unregister_netdev(vsi->netdev); |
| 9589 | free_netdev(vsi->netdev); |
| 9590 | vsi->netdev = NULL; |
| 9591 | } |
| 9592 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9593 | err_vsi: |
| 9594 | i40e_vsi_clear(vsi); |
| 9595 | return NULL; |
| 9596 | } |
| 9597 | |
| 9598 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9599 | * i40e_macaddr_init - explicitly write the mac address filters. |
| 9600 | * |
| 9601 | * @vsi: pointer to the vsi. |
| 9602 | * @macaddr: the MAC address |
| 9603 | * |
| 9604 | * This is needed when the macaddr has been obtained by other |
| 9605 | * means than the default, e.g., from Open Firmware or IDPROM. |
| 9606 | * Returns 0 on success, negative on failure |
| 9607 | **/ |
| 9608 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) |
| 9609 | { |
| 9610 | int ret; |
| 9611 | struct i40e_aqc_add_macvlan_element_data element; |
| 9612 | |
| 9613 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 9614 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 9615 | macaddr, NULL); |
| 9616 | if (ret) { |
| 9617 | dev_info(&vsi->back->pdev->dev, |
| 9618 | "Addr change for VSI failed: %d\n", ret); |
| 9619 | return -EADDRNOTAVAIL; |
| 9620 | } |
| 9621 | |
| 9622 | memset(&element, 0, sizeof(element)); |
| 9623 | ether_addr_copy(element.mac_addr, macaddr); |
| 9624 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 9625 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); |
| 9626 | if (ret) { |
| 9627 | dev_info(&vsi->back->pdev->dev, |
| 9628 | "add filter failed err %s aq_err %s\n", |
| 9629 | i40e_stat_str(&vsi->back->hw, ret), |
| 9630 | i40e_aq_str(&vsi->back->hw, |
| 9631 | vsi->back->hw.aq.asq_last_status)); |
| 9632 | } |
| 9633 | return ret; |
| 9634 | } |
| 9635 | |
| 9636 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9637 | * i40e_vsi_setup - Set up a VSI by a given type |
| 9638 | * @pf: board private structure |
| 9639 | * @type: VSI type |
| 9640 | * @uplink_seid: the switch element to link to |
| 9641 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 9642 | * |
| 9643 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 9644 | * to the identified VEB. |
| 9645 | * |
| 9646 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 9647 | * success, otherwise returns NULL on failure. |
| 9648 | **/ |
| 9649 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 9650 | u16 uplink_seid, u32 param1) |
| 9651 | { |
| 9652 | struct i40e_vsi *vsi = NULL; |
| 9653 | struct i40e_veb *veb = NULL; |
| 9654 | int ret, i; |
| 9655 | int v_idx; |
| 9656 | |
| 9657 | /* The requested uplink_seid must be either |
| 9658 | * - the PF's port seid |
| 9659 | * no VEB is needed because this is the PF |
| 9660 | * or this is a Flow Director special case VSI |
| 9661 | * - seid of an existing VEB |
| 9662 | * - seid of a VSI that owns an existing VEB |
| 9663 | * - seid of a VSI that doesn't own a VEB |
| 9664 | * a new VEB is created and the VSI becomes the owner |
| 9665 | * - seid of the PF VSI, which is what creates the first VEB |
| 9666 | * this is a special case of the previous |
| 9667 | * |
| 9668 | * Find which uplink_seid we were given and create a new VEB if needed |
| 9669 | */ |
| 9670 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9671 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 9672 | veb = pf->veb[i]; |
| 9673 | break; |
| 9674 | } |
| 9675 | } |
| 9676 | |
| 9677 | if (!veb && uplink_seid != pf->mac_seid) { |
| 9678 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9679 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9680 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 9681 | vsi = pf->vsi[i]; |
| 9682 | break; |
| 9683 | } |
| 9684 | } |
| 9685 | if (!vsi) { |
| 9686 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 9687 | uplink_seid); |
| 9688 | return NULL; |
| 9689 | } |
| 9690 | |
| 9691 | if (vsi->uplink_seid == pf->mac_seid) |
| 9692 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 9693 | vsi->tc_config.enabled_tc); |
| 9694 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 9695 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9696 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9697 | if (veb) { |
| 9698 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 9699 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 9700 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9701 | return NULL; |
| 9702 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 9703 | /* We come up by default in VEPA mode if SRIOV is not |
| 9704 | * already enabled, in which case we can't force VEPA |
| 9705 | * mode. |
| 9706 | */ |
| 9707 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 9708 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 9709 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9710 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9711 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9712 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9713 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9714 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9715 | veb = pf->veb[i]; |
| 9716 | } |
| 9717 | if (!veb) { |
| 9718 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 9719 | return NULL; |
| 9720 | } |
| 9721 | |
| 9722 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 9723 | uplink_seid = veb->seid; |
| 9724 | } |
| 9725 | |
| 9726 | /* get vsi sw struct */ |
| 9727 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 9728 | if (v_idx < 0) |
| 9729 | goto err_alloc; |
| 9730 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9731 | if (!vsi) |
| 9732 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9733 | vsi->type = type; |
| 9734 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 9735 | |
| 9736 | if (type == I40E_VSI_MAIN) |
| 9737 | pf->lan_vsi = v_idx; |
| 9738 | else if (type == I40E_VSI_SRIOV) |
| 9739 | vsi->vf_id = param1; |
| 9740 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9741 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 9742 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9743 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9744 | dev_info(&pf->pdev->dev, |
| 9745 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 9746 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9747 | goto err_vsi; |
| 9748 | } |
| 9749 | vsi->base_queue = ret; |
| 9750 | |
| 9751 | /* get a VSI from the hardware */ |
| 9752 | vsi->uplink_seid = uplink_seid; |
| 9753 | ret = i40e_add_vsi(vsi); |
| 9754 | if (ret) |
| 9755 | goto err_vsi; |
| 9756 | |
| 9757 | switch (vsi->type) { |
| 9758 | /* setup the netdev if needed */ |
| 9759 | case I40E_VSI_MAIN: |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9760 | /* Apply relevant filters if a platform-specific mac |
| 9761 | * address was selected. |
| 9762 | */ |
| 9763 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 9764 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 9765 | if (ret) { |
| 9766 | dev_warn(&pf->pdev->dev, |
| 9767 | "could not set up macaddr; err %d\n", |
| 9768 | ret); |
| 9769 | } |
| 9770 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9771 | case I40E_VSI_VMDQ2: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9772 | case I40E_VSI_FCOE: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9773 | ret = i40e_config_netdev(vsi); |
| 9774 | if (ret) |
| 9775 | goto err_netdev; |
| 9776 | ret = register_netdev(vsi->netdev); |
| 9777 | if (ret) |
| 9778 | goto err_netdev; |
| 9779 | vsi->netdev_registered = true; |
| 9780 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9781 | #ifdef CONFIG_I40E_DCB |
| 9782 | /* Setup DCB netlink interface */ |
| 9783 | i40e_dcbnl_setup(vsi); |
| 9784 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9785 | /* fall through */ |
| 9786 | |
| 9787 | case I40E_VSI_FDIR: |
| 9788 | /* set up vectors and rings if needed */ |
| 9789 | ret = i40e_vsi_setup_vectors(vsi); |
| 9790 | if (ret) |
| 9791 | goto err_msix; |
| 9792 | |
| 9793 | ret = i40e_alloc_rings(vsi); |
| 9794 | if (ret) |
| 9795 | goto err_rings; |
| 9796 | |
| 9797 | /* map all of the rings to the q_vectors */ |
| 9798 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9799 | |
| 9800 | i40e_vsi_reset_stats(vsi); |
| 9801 | break; |
| 9802 | |
| 9803 | default: |
| 9804 | /* no netdev or rings for the other VSI types */ |
| 9805 | break; |
| 9806 | } |
| 9807 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9808 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
| 9809 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 9810 | ret = i40e_vsi_config_rss(vsi); |
| 9811 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9812 | return vsi; |
| 9813 | |
| 9814 | err_rings: |
| 9815 | i40e_vsi_free_q_vectors(vsi); |
| 9816 | err_msix: |
| 9817 | if (vsi->netdev_registered) { |
| 9818 | vsi->netdev_registered = false; |
| 9819 | unregister_netdev(vsi->netdev); |
| 9820 | free_netdev(vsi->netdev); |
| 9821 | vsi->netdev = NULL; |
| 9822 | } |
| 9823 | err_netdev: |
| 9824 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9825 | err_vsi: |
| 9826 | i40e_vsi_clear(vsi); |
| 9827 | err_alloc: |
| 9828 | return NULL; |
| 9829 | } |
| 9830 | |
| 9831 | /** |
| 9832 | * i40e_veb_get_bw_info - Query VEB BW information |
| 9833 | * @veb: the veb to query |
| 9834 | * |
| 9835 | * Query the Tx scheduler BW configuration data for given VEB |
| 9836 | **/ |
| 9837 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 9838 | { |
| 9839 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 9840 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 9841 | struct i40e_pf *pf = veb->pf; |
| 9842 | struct i40e_hw *hw = &pf->hw; |
| 9843 | u32 tc_bw_max; |
| 9844 | int ret = 0; |
| 9845 | int i; |
| 9846 | |
| 9847 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 9848 | &bw_data, NULL); |
| 9849 | if (ret) { |
| 9850 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9851 | "query veb bw config failed, err %s aq_err %s\n", |
| 9852 | i40e_stat_str(&pf->hw, ret), |
| 9853 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9854 | goto out; |
| 9855 | } |
| 9856 | |
| 9857 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 9858 | &ets_data, NULL); |
| 9859 | if (ret) { |
| 9860 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9861 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 9862 | i40e_stat_str(&pf->hw, ret), |
| 9863 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9864 | goto out; |
| 9865 | } |
| 9866 | |
| 9867 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 9868 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 9869 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 9870 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9871 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 9872 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 9873 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 9874 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 9875 | veb->bw_tc_limit_credits[i] = |
| 9876 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 9877 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 9878 | } |
| 9879 | |
| 9880 | out: |
| 9881 | return ret; |
| 9882 | } |
| 9883 | |
| 9884 | /** |
| 9885 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 9886 | * @pf: board private structure |
| 9887 | * |
| 9888 | * On error: returns error code (negative) |
| 9889 | * On success: returns vsi index in PF (positive) |
| 9890 | **/ |
| 9891 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 9892 | { |
| 9893 | int ret = -ENOENT; |
| 9894 | struct i40e_veb *veb; |
| 9895 | int i; |
| 9896 | |
| 9897 | /* Need to protect the allocation of switch elements at the PF level */ |
| 9898 | mutex_lock(&pf->switch_mutex); |
| 9899 | |
| 9900 | /* VEB list may be fragmented if VEB creation/destruction has |
| 9901 | * been happening. We can afford to do a quick scan to look |
| 9902 | * for any free slots in the list. |
| 9903 | * |
| 9904 | * find next empty veb slot, looping back around if necessary |
| 9905 | */ |
| 9906 | i = 0; |
| 9907 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 9908 | i++; |
| 9909 | if (i >= I40E_MAX_VEB) { |
| 9910 | ret = -ENOMEM; |
| 9911 | goto err_alloc_veb; /* out of VEB slots! */ |
| 9912 | } |
| 9913 | |
| 9914 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 9915 | if (!veb) { |
| 9916 | ret = -ENOMEM; |
| 9917 | goto err_alloc_veb; |
| 9918 | } |
| 9919 | veb->pf = pf; |
| 9920 | veb->idx = i; |
| 9921 | veb->enabled_tc = 1; |
| 9922 | |
| 9923 | pf->veb[i] = veb; |
| 9924 | ret = i; |
| 9925 | err_alloc_veb: |
| 9926 | mutex_unlock(&pf->switch_mutex); |
| 9927 | return ret; |
| 9928 | } |
| 9929 | |
| 9930 | /** |
| 9931 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 9932 | * @branch: where to start deleting |
| 9933 | * |
| 9934 | * This uses recursion to find the tips of the branch to be |
| 9935 | * removed, deleting until we get back to and can delete this VEB. |
| 9936 | **/ |
| 9937 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 9938 | { |
| 9939 | struct i40e_pf *pf = branch->pf; |
| 9940 | u16 branch_seid = branch->seid; |
| 9941 | u16 veb_idx = branch->idx; |
| 9942 | int i; |
| 9943 | |
| 9944 | /* release any VEBs on this VEB - RECURSION */ |
| 9945 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9946 | if (!pf->veb[i]) |
| 9947 | continue; |
| 9948 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 9949 | i40e_switch_branch_release(pf->veb[i]); |
| 9950 | } |
| 9951 | |
| 9952 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 9953 | * |
| 9954 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 9955 | * the VEB itself, so don't use (*branch) after this loop. |
| 9956 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9957 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9958 | if (!pf->vsi[i]) |
| 9959 | continue; |
| 9960 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 9961 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9962 | i40e_vsi_release(pf->vsi[i]); |
| 9963 | } |
| 9964 | } |
| 9965 | |
| 9966 | /* There's one corner case where the VEB might not have been |
| 9967 | * removed, so double check it here and remove it if needed. |
| 9968 | * This case happens if the veb was created from the debugfs |
| 9969 | * commands and no VSIs were added to it. |
| 9970 | */ |
| 9971 | if (pf->veb[veb_idx]) |
| 9972 | i40e_veb_release(pf->veb[veb_idx]); |
| 9973 | } |
| 9974 | |
| 9975 | /** |
| 9976 | * i40e_veb_clear - remove veb struct |
| 9977 | * @veb: the veb to remove |
| 9978 | **/ |
| 9979 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 9980 | { |
| 9981 | if (!veb) |
| 9982 | return; |
| 9983 | |
| 9984 | if (veb->pf) { |
| 9985 | struct i40e_pf *pf = veb->pf; |
| 9986 | |
| 9987 | mutex_lock(&pf->switch_mutex); |
| 9988 | if (pf->veb[veb->idx] == veb) |
| 9989 | pf->veb[veb->idx] = NULL; |
| 9990 | mutex_unlock(&pf->switch_mutex); |
| 9991 | } |
| 9992 | |
| 9993 | kfree(veb); |
| 9994 | } |
| 9995 | |
| 9996 | /** |
| 9997 | * i40e_veb_release - Delete a VEB and free its resources |
| 9998 | * @veb: the VEB being removed |
| 9999 | **/ |
| 10000 | void i40e_veb_release(struct i40e_veb *veb) |
| 10001 | { |
| 10002 | struct i40e_vsi *vsi = NULL; |
| 10003 | struct i40e_pf *pf; |
| 10004 | int i, n = 0; |
| 10005 | |
| 10006 | pf = veb->pf; |
| 10007 | |
| 10008 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10009 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10010 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 10011 | n++; |
| 10012 | vsi = pf->vsi[i]; |
| 10013 | } |
| 10014 | } |
| 10015 | if (n != 1) { |
| 10016 | dev_info(&pf->pdev->dev, |
| 10017 | "can't remove VEB %d with %d VSIs left\n", |
| 10018 | veb->seid, n); |
| 10019 | return; |
| 10020 | } |
| 10021 | |
| 10022 | /* move the remaining VSI to uplink veb */ |
| 10023 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10024 | if (veb->uplink_seid) { |
| 10025 | vsi->uplink_seid = veb->uplink_seid; |
| 10026 | if (veb->uplink_seid == pf->mac_seid) |
| 10027 | vsi->veb_idx = I40E_NO_VEB; |
| 10028 | else |
| 10029 | vsi->veb_idx = veb->veb_idx; |
| 10030 | } else { |
| 10031 | /* floating VEB */ |
| 10032 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10033 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10034 | } |
| 10035 | |
| 10036 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10037 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10038 | } |
| 10039 | |
| 10040 | /** |
| 10041 | * i40e_add_veb - create the VEB in the switch |
| 10042 | * @veb: the VEB to be instantiated |
| 10043 | * @vsi: the controlling VSI |
| 10044 | **/ |
| 10045 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10046 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10047 | struct i40e_pf *pf = veb->pf; |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 10048 | bool is_default = veb->pf->cur_promisc; |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 10049 | bool is_cloud = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10050 | int ret; |
| 10051 | |
| 10052 | /* get a VEB from the hardware */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10053 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 10054 | veb->enabled_tc, is_default, |
| 10055 | is_cloud, &veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10056 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10057 | dev_info(&pf->pdev->dev, |
| 10058 | "couldn't add VEB, err %s aq_err %s\n", |
| 10059 | i40e_stat_str(&pf->hw, ret), |
| 10060 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10061 | return -EPERM; |
| 10062 | } |
| 10063 | |
| 10064 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10065 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10066 | &veb->stats_idx, NULL, NULL, NULL); |
| 10067 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10068 | dev_info(&pf->pdev->dev, |
| 10069 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10070 | i40e_stat_str(&pf->hw, ret), |
| 10071 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10072 | return -EPERM; |
| 10073 | } |
| 10074 | ret = i40e_veb_get_bw_info(veb); |
| 10075 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10076 | dev_info(&pf->pdev->dev, |
| 10077 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10078 | i40e_stat_str(&pf->hw, ret), |
| 10079 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10080 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10081 | return -ENOENT; |
| 10082 | } |
| 10083 | |
| 10084 | vsi->uplink_seid = veb->seid; |
| 10085 | vsi->veb_idx = veb->idx; |
| 10086 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10087 | |
| 10088 | return 0; |
| 10089 | } |
| 10090 | |
| 10091 | /** |
| 10092 | * i40e_veb_setup - Set up a VEB |
| 10093 | * @pf: board private structure |
| 10094 | * @flags: VEB setup flags |
| 10095 | * @uplink_seid: the switch element to link to |
| 10096 | * @vsi_seid: the initial VSI seid |
| 10097 | * @enabled_tc: Enabled TC bit-map |
| 10098 | * |
| 10099 | * This allocates the sw VEB structure and links it into the switch |
| 10100 | * It is possible and legal for this to be a duplicate of an already |
| 10101 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10102 | * to be zero, in order to create a floating VEB. |
| 10103 | * |
| 10104 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10105 | * success, otherwise returns NULL on failure. |
| 10106 | **/ |
| 10107 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10108 | u16 uplink_seid, u16 vsi_seid, |
| 10109 | u8 enabled_tc) |
| 10110 | { |
| 10111 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10112 | int vsi_idx, veb_idx; |
| 10113 | int ret; |
| 10114 | |
| 10115 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10116 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10117 | (uplink_seid + vsi_seid != 0)) { |
| 10118 | dev_info(&pf->pdev->dev, |
| 10119 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10120 | uplink_seid, vsi_seid); |
| 10121 | return NULL; |
| 10122 | } |
| 10123 | |
| 10124 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10125 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10126 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10127 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10128 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10129 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10130 | vsi_seid); |
| 10131 | return NULL; |
| 10132 | } |
| 10133 | |
| 10134 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10135 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10136 | if (pf->veb[veb_idx] && |
| 10137 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10138 | uplink_veb = pf->veb[veb_idx]; |
| 10139 | break; |
| 10140 | } |
| 10141 | } |
| 10142 | if (!uplink_veb) { |
| 10143 | dev_info(&pf->pdev->dev, |
| 10144 | "uplink seid %d not found\n", uplink_seid); |
| 10145 | return NULL; |
| 10146 | } |
| 10147 | } |
| 10148 | |
| 10149 | /* get veb sw struct */ |
| 10150 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10151 | if (veb_idx < 0) |
| 10152 | goto err_alloc; |
| 10153 | veb = pf->veb[veb_idx]; |
| 10154 | veb->flags = flags; |
| 10155 | veb->uplink_seid = uplink_seid; |
| 10156 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10157 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10158 | |
| 10159 | /* create the VEB in the switch */ |
| 10160 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10161 | if (ret) |
| 10162 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10163 | if (vsi_idx == pf->lan_vsi) |
| 10164 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10165 | |
| 10166 | return veb; |
| 10167 | |
| 10168 | err_veb: |
| 10169 | i40e_veb_clear(veb); |
| 10170 | err_alloc: |
| 10171 | return NULL; |
| 10172 | } |
| 10173 | |
| 10174 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10175 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10176 | * @pf: board private structure |
| 10177 | * @ele: element we are building info from |
| 10178 | * @num_reported: total number of elements |
| 10179 | * @printconfig: should we print the contents |
| 10180 | * |
| 10181 | * helper function to assist in extracting a few useful SEID values. |
| 10182 | **/ |
| 10183 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10184 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10185 | u16 num_reported, bool printconfig) |
| 10186 | { |
| 10187 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10188 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10189 | u8 element_type = ele->element_type; |
| 10190 | u16 seid = le16_to_cpu(ele->seid); |
| 10191 | |
| 10192 | if (printconfig) |
| 10193 | dev_info(&pf->pdev->dev, |
| 10194 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10195 | element_type, seid, uplink_seid, downlink_seid); |
| 10196 | |
| 10197 | switch (element_type) { |
| 10198 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10199 | pf->mac_seid = seid; |
| 10200 | break; |
| 10201 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10202 | /* Main VEB? */ |
| 10203 | if (uplink_seid != pf->mac_seid) |
| 10204 | break; |
| 10205 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10206 | int v; |
| 10207 | |
| 10208 | /* find existing or else empty VEB */ |
| 10209 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10210 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10211 | pf->lan_veb = v; |
| 10212 | break; |
| 10213 | } |
| 10214 | } |
| 10215 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10216 | v = i40e_veb_mem_alloc(pf); |
| 10217 | if (v < 0) |
| 10218 | break; |
| 10219 | pf->lan_veb = v; |
| 10220 | } |
| 10221 | } |
| 10222 | |
| 10223 | pf->veb[pf->lan_veb]->seid = seid; |
| 10224 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10225 | pf->veb[pf->lan_veb]->pf = pf; |
| 10226 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10227 | break; |
| 10228 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10229 | if (num_reported != 1) |
| 10230 | break; |
| 10231 | /* This is immediately after a reset so we can assume this is |
| 10232 | * the PF's VSI |
| 10233 | */ |
| 10234 | pf->mac_seid = uplink_seid; |
| 10235 | pf->pf_seid = downlink_seid; |
| 10236 | pf->main_vsi_seid = seid; |
| 10237 | if (printconfig) |
| 10238 | dev_info(&pf->pdev->dev, |
| 10239 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10240 | pf->pf_seid, pf->main_vsi_seid); |
| 10241 | break; |
| 10242 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10243 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10244 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10245 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10246 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10247 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10248 | /* ignore these for now */ |
| 10249 | break; |
| 10250 | default: |
| 10251 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10252 | element_type, seid); |
| 10253 | break; |
| 10254 | } |
| 10255 | } |
| 10256 | |
| 10257 | /** |
| 10258 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10259 | * @pf: board private structure |
| 10260 | * @printconfig: should we print the contents |
| 10261 | * |
| 10262 | * Get the current switch configuration from the device and |
| 10263 | * extract a few useful SEID values. |
| 10264 | **/ |
| 10265 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10266 | { |
| 10267 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10268 | u16 next_seid = 0; |
| 10269 | int ret = 0; |
| 10270 | u8 *aq_buf; |
| 10271 | int i; |
| 10272 | |
| 10273 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10274 | if (!aq_buf) |
| 10275 | return -ENOMEM; |
| 10276 | |
| 10277 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10278 | do { |
| 10279 | u16 num_reported, num_total; |
| 10280 | |
| 10281 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10282 | I40E_AQ_LARGE_BUF, |
| 10283 | &next_seid, NULL); |
| 10284 | if (ret) { |
| 10285 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10286 | "get switch config failed err %s aq_err %s\n", |
| 10287 | i40e_stat_str(&pf->hw, ret), |
| 10288 | i40e_aq_str(&pf->hw, |
| 10289 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10290 | kfree(aq_buf); |
| 10291 | return -ENOENT; |
| 10292 | } |
| 10293 | |
| 10294 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10295 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10296 | |
| 10297 | if (printconfig) |
| 10298 | dev_info(&pf->pdev->dev, |
| 10299 | "header: %d reported %d total\n", |
| 10300 | num_reported, num_total); |
| 10301 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10302 | for (i = 0; i < num_reported; i++) { |
| 10303 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10304 | &sw_config->element[i]; |
| 10305 | |
| 10306 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10307 | printconfig); |
| 10308 | } |
| 10309 | } while (next_seid != 0); |
| 10310 | |
| 10311 | kfree(aq_buf); |
| 10312 | return ret; |
| 10313 | } |
| 10314 | |
| 10315 | /** |
| 10316 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10317 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10318 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10319 | * |
| 10320 | * Returns 0 on success, negative value on failure |
| 10321 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10322 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10323 | { |
| 10324 | int ret; |
| 10325 | |
| 10326 | /* find out what's out there already */ |
| 10327 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10328 | if (ret) { |
| 10329 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10330 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10331 | i40e_stat_str(&pf->hw, ret), |
| 10332 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10333 | return ret; |
| 10334 | } |
| 10335 | i40e_pf_reset_stats(pf); |
| 10336 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10337 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10338 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10339 | struct i40e_vsi *vsi = NULL; |
| 10340 | u16 uplink_seid; |
| 10341 | |
| 10342 | /* Set up the PF VSI associated with the PF's main VSI |
| 10343 | * that is already in the HW switch |
| 10344 | */ |
| 10345 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10346 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10347 | else |
| 10348 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10349 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10350 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10351 | else if (reinit) |
| 10352 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10353 | if (!vsi) { |
| 10354 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10355 | i40e_fdir_teardown(pf); |
| 10356 | return -EAGAIN; |
| 10357 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10358 | } else { |
| 10359 | /* force a reset of TC and queue layout configurations */ |
| 10360 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10361 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10362 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10363 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10364 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10365 | } |
| 10366 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 10367 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10368 | i40e_fdir_sb_setup(pf); |
| 10369 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10370 | /* Setup static PF queue filter control settings */ |
| 10371 | ret = i40e_setup_pf_filter_control(pf); |
| 10372 | if (ret) { |
| 10373 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 10374 | ret); |
| 10375 | /* Failure here should not stop continuing other steps */ |
| 10376 | } |
| 10377 | |
| 10378 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 10379 | * the hash |
| 10380 | */ |
| 10381 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 10382 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10383 | |
| 10384 | /* fill in link information and enable LSE reporting */ |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 10385 | i40e_update_link_info(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10386 | i40e_link_event(pf); |
| 10387 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10388 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10389 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 10390 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10391 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10392 | i40e_ptp_init(pf); |
| 10393 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10394 | return ret; |
| 10395 | } |
| 10396 | |
| 10397 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10398 | * i40e_determine_queue_usage - Work out queue distribution |
| 10399 | * @pf: board private structure |
| 10400 | **/ |
| 10401 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 10402 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10403 | int queues_left; |
| 10404 | |
| 10405 | pf->num_lan_qps = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10406 | #ifdef I40E_FCOE |
| 10407 | pf->num_fcoe_qps = 0; |
| 10408 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10409 | |
| 10410 | /* Find the max queues to be put into basic use. We'll always be |
| 10411 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 10412 | * big RSS set. |
| 10413 | */ |
| 10414 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 10415 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10416 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10417 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10418 | /* one qp for PF, no queues for anything else */ |
| 10419 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10420 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10421 | |
| 10422 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10423 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10424 | #ifdef I40E_FCOE |
| 10425 | I40E_FLAG_FCOE_ENABLED | |
| 10426 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10427 | I40E_FLAG_FD_SB_ENABLED | |
| 10428 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10429 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10430 | I40E_FLAG_SRIOV_ENABLED | |
| 10431 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10432 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 10433 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 10434 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10435 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10436 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10437 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10438 | queues_left -= pf->num_lan_qps; |
| 10439 | |
| 10440 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10441 | #ifdef I40E_FCOE |
| 10442 | I40E_FLAG_FCOE_ENABLED | |
| 10443 | #endif |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10444 | I40E_FLAG_FD_SB_ENABLED | |
| 10445 | I40E_FLAG_FD_ATR_ENABLED | |
| 10446 | I40E_FLAG_DCB_ENABLED | |
| 10447 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10448 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10449 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10450 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10451 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10452 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10453 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 10454 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 10455 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 10456 | num_online_cpus()); |
| 10457 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 10458 | pf->hw.func_caps.num_tx_qp); |
| 10459 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10460 | queues_left -= pf->num_lan_qps; |
| 10461 | } |
| 10462 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10463 | #ifdef I40E_FCOE |
| 10464 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 10465 | if (I40E_DEFAULT_FCOE <= queues_left) { |
| 10466 | pf->num_fcoe_qps = I40E_DEFAULT_FCOE; |
| 10467 | } else if (I40E_MINIMUM_FCOE <= queues_left) { |
| 10468 | pf->num_fcoe_qps = I40E_MINIMUM_FCOE; |
| 10469 | } else { |
| 10470 | pf->num_fcoe_qps = 0; |
| 10471 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 10472 | dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n"); |
| 10473 | } |
| 10474 | |
| 10475 | queues_left -= pf->num_fcoe_qps; |
| 10476 | } |
| 10477 | |
| 10478 | #endif |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10479 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10480 | if (queues_left > 1) { |
| 10481 | queues_left -= 1; /* save 1 queue for FD */ |
| 10482 | } else { |
| 10483 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 10484 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 10485 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10486 | } |
| 10487 | |
| 10488 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10489 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10490 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 10491 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10492 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 10493 | } |
| 10494 | |
| 10495 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 10496 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 10497 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 10498 | (queues_left / pf->num_vmdq_qps)); |
| 10499 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 10500 | } |
| 10501 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10502 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10503 | dev_dbg(&pf->pdev->dev, |
| 10504 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 10505 | pf->hw.func_caps.num_tx_qp, |
| 10506 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10507 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 10508 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 10509 | queues_left); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10510 | #ifdef I40E_FCOE |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10511 | 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] | 10512 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10513 | } |
| 10514 | |
| 10515 | /** |
| 10516 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 10517 | * @pf: PF to be setup |
| 10518 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10519 | * 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] | 10520 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 10521 | * based filter sizes required for them. It also enables Flow director, |
| 10522 | * ethertype and macvlan type filter settings for the pf. |
| 10523 | * |
| 10524 | * Returns 0 on success, negative on failure |
| 10525 | **/ |
| 10526 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 10527 | { |
| 10528 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 10529 | |
| 10530 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 10531 | |
| 10532 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10533 | 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] | 10534 | settings->enable_fdir = true; |
| 10535 | |
| 10536 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 10537 | settings->enable_ethtype = true; |
| 10538 | settings->enable_macvlan = true; |
| 10539 | |
| 10540 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 10541 | return -ENOENT; |
| 10542 | |
| 10543 | return 0; |
| 10544 | } |
| 10545 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10546 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10547 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10548 | static void i40e_print_features(struct i40e_pf *pf) |
| 10549 | { |
| 10550 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10551 | char *buf; |
| 10552 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10553 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10554 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 10555 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10556 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10557 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10558 | 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] | 10559 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10560 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10561 | #endif |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10562 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d RX: %s", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10563 | pf->hw.func_caps.num_vsis, |
| 10564 | pf->vsi[pf->lan_vsi]->num_queue_pairs, |
| 10565 | pf->flags & I40E_FLAG_RX_PS_ENABLED ? "PS" : "1BUF"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10566 | |
| 10567 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10568 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10569 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10570 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10571 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10572 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 10573 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10574 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10575 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10576 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Jesse Brandeburg | ce6fcb3 | 2015-08-28 17:55:59 -0400 | [diff] [blame] | 10577 | #if IS_ENABLED(CONFIG_VXLAN) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10578 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Jesse Brandeburg | ce6fcb3 | 2015-08-28 17:55:59 -0400 | [diff] [blame] | 10579 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10580 | #if IS_ENABLED(CONFIG_GENEVE) |
| 10581 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
| 10582 | #endif |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10583 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10584 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10585 | #ifdef I40E_FCOE |
| 10586 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10587 | i += snprintf(&buf[i], REMAIN(i), " FCOE"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10588 | #endif |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10589 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10590 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10591 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10592 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10593 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10594 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 10595 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10596 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10597 | } |
| 10598 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10599 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10600 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
| 10601 | * |
| 10602 | * @pdev: PCI device information struct |
| 10603 | * @pf: board private structure |
| 10604 | * |
| 10605 | * Look up the MAC address in Open Firmware on systems that support it, |
| 10606 | * and use IDPROM on SPARC if no OF address is found. On return, the |
| 10607 | * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value |
| 10608 | * has been selected. |
| 10609 | **/ |
| 10610 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 10611 | { |
| 10612 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 10613 | const unsigned char *addr; |
| 10614 | u8 *mac_addr = pf->hw.mac.addr; |
| 10615 | |
| 10616 | pf->flags &= ~I40E_FLAG_PF_MAC; |
| 10617 | addr = of_get_mac_address(dp); |
| 10618 | if (addr) { |
| 10619 | ether_addr_copy(mac_addr, addr); |
| 10620 | pf->flags |= I40E_FLAG_PF_MAC; |
| 10621 | #ifdef CONFIG_SPARC |
| 10622 | } else { |
| 10623 | ether_addr_copy(mac_addr, idprom->id_ethaddr); |
| 10624 | pf->flags |= I40E_FLAG_PF_MAC; |
| 10625 | #endif /* CONFIG_SPARC */ |
| 10626 | } |
| 10627 | } |
| 10628 | |
| 10629 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10630 | * i40e_probe - Device initialization routine |
| 10631 | * @pdev: PCI device information struct |
| 10632 | * @ent: entry in i40e_pci_tbl |
| 10633 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10634 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 10635 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10636 | * and a hardware reset occur. |
| 10637 | * |
| 10638 | * Returns 0 on success, negative on failure |
| 10639 | **/ |
| 10640 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 10641 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 10642 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10643 | struct i40e_pf *pf; |
| 10644 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10645 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10646 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10647 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 10648 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10649 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10650 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10651 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10652 | |
| 10653 | err = pci_enable_device_mem(pdev); |
| 10654 | if (err) |
| 10655 | return err; |
| 10656 | |
| 10657 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10658 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10659 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 10660 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10661 | if (err) { |
| 10662 | dev_err(&pdev->dev, |
| 10663 | "DMA configuration failed: 0x%x\n", err); |
| 10664 | goto err_dma; |
| 10665 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10666 | } |
| 10667 | |
| 10668 | /* set up pci connections */ |
| 10669 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 10670 | IORESOURCE_MEM), i40e_driver_name); |
| 10671 | if (err) { |
| 10672 | dev_info(&pdev->dev, |
| 10673 | "pci_request_selected_regions failed %d\n", err); |
| 10674 | goto err_pci_reg; |
| 10675 | } |
| 10676 | |
| 10677 | pci_enable_pcie_error_reporting(pdev); |
| 10678 | pci_set_master(pdev); |
| 10679 | |
| 10680 | /* Now that we have a PCI connection, we need to do the |
| 10681 | * low level device setup. This is primarily setting up |
| 10682 | * the Admin Queue structures and then querying for the |
| 10683 | * device's current profile information. |
| 10684 | */ |
| 10685 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 10686 | if (!pf) { |
| 10687 | err = -ENOMEM; |
| 10688 | goto err_pf_alloc; |
| 10689 | } |
| 10690 | pf->next_vsi = 0; |
| 10691 | pf->pdev = pdev; |
| 10692 | set_bit(__I40E_DOWN, &pf->state); |
| 10693 | |
| 10694 | hw = &pf->hw; |
| 10695 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10696 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10697 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 10698 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10699 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10700 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10701 | if (!hw->hw_addr) { |
| 10702 | err = -EIO; |
| 10703 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 10704 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10705 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10706 | goto err_ioremap; |
| 10707 | } |
| 10708 | hw->vendor_id = pdev->vendor; |
| 10709 | hw->device_id = pdev->device; |
| 10710 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 10711 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 10712 | hw->subsystem_device_id = pdev->subsystem_device; |
| 10713 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 10714 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10715 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10716 | |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 10717 | if (debug != -1) { |
| 10718 | pf->msg_enable = pf->hw.debug_mask; |
| 10719 | pf->msg_enable = debug; |
| 10720 | } |
| 10721 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10722 | /* do a special CORER for clearing PXE mode once at init */ |
| 10723 | if (hw->revision_id == 0 && |
| 10724 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 10725 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 10726 | i40e_flush(hw); |
| 10727 | msleep(200); |
| 10728 | pf->corer_count++; |
| 10729 | |
| 10730 | i40e_clear_pxe_mode(hw); |
| 10731 | } |
| 10732 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10733 | /* 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] | 10734 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10735 | err = i40e_pf_reset(hw); |
| 10736 | if (err) { |
| 10737 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 10738 | goto err_pf_reset; |
| 10739 | } |
| 10740 | pf->pfr_count++; |
| 10741 | |
| 10742 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 10743 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 10744 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10745 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10746 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10747 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 10748 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10749 | "%s-%s:misc", |
| 10750 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10751 | |
| 10752 | err = i40e_init_shared_code(hw); |
| 10753 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 10754 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 10755 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10756 | goto err_pf_reset; |
| 10757 | } |
| 10758 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10759 | /* set up a default setting for link flow control */ |
| 10760 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 10761 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 10762 | /* set up the locks for the AQ, do this only once in probe |
| 10763 | * and destroy them only once in remove |
| 10764 | */ |
| 10765 | mutex_init(&hw->aq.asq_mutex); |
| 10766 | mutex_init(&hw->aq.arq_mutex); |
| 10767 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10768 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 10769 | if (err) { |
| 10770 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 10771 | dev_info(&pdev->dev, |
| 10772 | "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"); |
| 10773 | else |
| 10774 | dev_info(&pdev->dev, |
| 10775 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 10776 | |
| 10777 | goto err_pf_reset; |
| 10778 | } |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10779 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10780 | /* provide nvm, fw, api versions */ |
| 10781 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 10782 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 10783 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 10784 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10785 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10786 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 10787 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10788 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10789 | "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"); |
| 10790 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 10791 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10792 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10793 | "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] | 10794 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 10795 | i40e_verify_eeprom(pf); |
| 10796 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 10797 | /* Rev 0 hardware was never productized */ |
| 10798 | if (hw->revision_id < 1) |
| 10799 | 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"); |
| 10800 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 10801 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10802 | err = i40e_get_capabilities(pf); |
| 10803 | if (err) |
| 10804 | goto err_adminq_setup; |
| 10805 | |
| 10806 | err = i40e_sw_init(pf); |
| 10807 | if (err) { |
| 10808 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 10809 | goto err_sw_init; |
| 10810 | } |
| 10811 | |
| 10812 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 10813 | hw->func_caps.num_rx_qp, |
| 10814 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 10815 | if (err) { |
| 10816 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 10817 | goto err_init_lan_hmc; |
| 10818 | } |
| 10819 | |
| 10820 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 10821 | if (err) { |
| 10822 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 10823 | err = -ENOENT; |
| 10824 | goto err_configure_lan_hmc; |
| 10825 | } |
| 10826 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10827 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 10828 | * Ignore error return codes because if it was already disabled via |
| 10829 | * hardware settings this will fail |
| 10830 | */ |
| 10831 | if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 10832 | (pf->hw.aq.fw_maj_ver < 4)) { |
| 10833 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 10834 | i40e_aq_stop_lldp(hw, true, NULL); |
| 10835 | } |
| 10836 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10837 | i40e_get_mac_addr(hw, hw->mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10838 | /* allow a platform config to override the HW addr */ |
| 10839 | i40e_get_platform_mac_addr(pdev, pf); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 10840 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10841 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 10842 | err = -EIO; |
| 10843 | goto err_mac_addr; |
| 10844 | } |
| 10845 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 10846 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10847 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 10848 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 10849 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10850 | #ifdef I40E_FCOE |
| 10851 | err = i40e_get_san_mac_addr(hw, hw->mac.san_addr); |
| 10852 | if (err) |
| 10853 | dev_info(&pdev->dev, |
| 10854 | "(non-fatal) SAN MAC retrieval failed: %d\n", err); |
| 10855 | if (!is_valid_ether_addr(hw->mac.san_addr)) { |
| 10856 | dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n", |
| 10857 | hw->mac.san_addr); |
| 10858 | ether_addr_copy(hw->mac.san_addr, hw->mac.addr); |
| 10859 | } |
| 10860 | dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr); |
| 10861 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10862 | |
| 10863 | pci_set_drvdata(pdev, pf); |
| 10864 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10865 | #ifdef CONFIG_I40E_DCB |
| 10866 | err = i40e_init_pf_dcb(pf); |
| 10867 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 10868 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10869 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 10870 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10871 | } |
| 10872 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10873 | |
| 10874 | /* set up periodic task facility */ |
| 10875 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 10876 | pf->service_timer_period = HZ; |
| 10877 | |
| 10878 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 10879 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 10880 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10881 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10882 | /* NVM bit on means WoL disabled for the port */ |
| 10883 | 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] | 10884 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10885 | pf->wol_en = false; |
| 10886 | else |
| 10887 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 10888 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 10889 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10890 | /* set up the main switch operations */ |
| 10891 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 10892 | err = i40e_init_interrupt_scheme(pf); |
| 10893 | if (err) |
| 10894 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10895 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10896 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 10897 | * to us; HW supports far more and we share the remaining pool with |
| 10898 | * the other PFs. We allocate space for more than the guarantee with |
| 10899 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10900 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10901 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 10902 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 10903 | else |
| 10904 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 10905 | |
| 10906 | /* 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] | 10907 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 10908 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 10909 | if (!pf->vsi) { |
| 10910 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10911 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 10912 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10913 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 10914 | #ifdef CONFIG_PCI_IOV |
| 10915 | /* prep for VF support */ |
| 10916 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10917 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 10918 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 10919 | if (pci_num_vf(pdev)) |
| 10920 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 10921 | } |
| 10922 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10923 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10924 | if (err) { |
| 10925 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 10926 | goto err_vsis; |
| 10927 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10928 | |
| 10929 | /* Make sure flow control is set according to current settings */ |
| 10930 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 10931 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 10932 | dev_dbg(&pf->pdev->dev, |
| 10933 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 10934 | i40e_stat_str(hw, err), |
| 10935 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 10936 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 10937 | dev_dbg(&pf->pdev->dev, |
| 10938 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 10939 | i40e_stat_str(hw, err), |
| 10940 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 10941 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 10942 | dev_dbg(&pf->pdev->dev, |
| 10943 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 10944 | i40e_stat_str(hw, err), |
| 10945 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 10946 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10947 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10948 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10949 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 10950 | i40e_vsi_open(pf->vsi[i]); |
| 10951 | break; |
| 10952 | } |
| 10953 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10954 | |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 10955 | /* driver is only interested in link up/down and module qualification |
| 10956 | * reports from firmware |
| 10957 | */ |
| 10958 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
| 10959 | I40E_AQ_EVENT_LINK_UPDOWN | |
| 10960 | I40E_AQ_EVENT_MODULE_QUAL_FAIL, NULL); |
| 10961 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10962 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 10963 | i40e_stat_str(&pf->hw, err), |
| 10964 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 10965 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10966 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 10967 | * of TSO, so that we avoid the MDD being fired and causing |
| 10968 | * a reset in the case of small MSS+TSO. |
| 10969 | */ |
| 10970 | val = rd32(hw, I40E_REG_MSS); |
| 10971 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 10972 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 10973 | val |= I40E_64BYTE_MSS; |
| 10974 | wr32(hw, I40E_REG_MSS, val); |
| 10975 | } |
| 10976 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 10977 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 10978 | msleep(75); |
| 10979 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 10980 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10981 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 10982 | i40e_stat_str(&pf->hw, err), |
| 10983 | i40e_aq_str(&pf->hw, |
| 10984 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 10985 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10986 | /* The main driver is (mostly) up and happy. We need to set this state |
| 10987 | * before setting up the misc vector or we get a race and the vector |
| 10988 | * ends up disabled forever. |
| 10989 | */ |
| 10990 | clear_bit(__I40E_DOWN, &pf->state); |
| 10991 | |
| 10992 | /* In case of MSIX we are going to setup the misc vector right here |
| 10993 | * to handle admin queue events etc. In case of legacy and MSI |
| 10994 | * the misc functionality and queue processing is combined in |
| 10995 | * the same vector and that gets setup at open. |
| 10996 | */ |
| 10997 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 10998 | err = i40e_setup_misc_vector(pf); |
| 10999 | if (err) { |
| 11000 | dev_info(&pdev->dev, |
| 11001 | "setup of misc vector failed: %d\n", err); |
| 11002 | goto err_vsis; |
| 11003 | } |
| 11004 | } |
| 11005 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11006 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11007 | /* prep for VF support */ |
| 11008 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11009 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11010 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11011 | /* disable link interrupts for VFs */ |
| 11012 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11013 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11014 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11015 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11016 | |
| 11017 | if (pci_num_vf(pdev)) { |
| 11018 | dev_info(&pdev->dev, |
| 11019 | "Active VFs found, allocating resources.\n"); |
| 11020 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11021 | if (err) |
| 11022 | dev_info(&pdev->dev, |
| 11023 | "Error %d allocating resources for existing VFs\n", |
| 11024 | err); |
| 11025 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11026 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11027 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11028 | |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11029 | pfs_found++; |
| 11030 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11031 | i40e_dbg_pf_init(pf); |
| 11032 | |
| 11033 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11034 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11035 | |
| 11036 | /* since everything's happy, start the service_task timer */ |
| 11037 | mod_timer(&pf->service_timer, |
| 11038 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11039 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11040 | #ifdef I40E_FCOE |
| 11041 | /* create FCoE interface */ |
| 11042 | i40e_fcoe_vsi_setup(pf); |
| 11043 | |
| 11044 | #endif |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11045 | #define PCI_SPEED_SIZE 8 |
| 11046 | #define PCI_WIDTH_SIZE 8 |
| 11047 | /* Devices on the IOSF bus do not have this information |
| 11048 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11049 | * checking them. |
| 11050 | */ |
| 11051 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { |
| 11052 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11053 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11054 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11055 | /* Get the negotiated link width and speed from PCI config |
| 11056 | * space |
| 11057 | */ |
| 11058 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11059 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11060 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11061 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11062 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11063 | switch (hw->bus.speed) { |
| 11064 | case i40e_bus_speed_8000: |
| 11065 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11066 | case i40e_bus_speed_5000: |
| 11067 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11068 | case i40e_bus_speed_2500: |
| 11069 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11070 | default: |
| 11071 | break; |
| 11072 | } |
| 11073 | switch (hw->bus.width) { |
| 11074 | case i40e_bus_width_pcie_x8: |
| 11075 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11076 | case i40e_bus_width_pcie_x4: |
| 11077 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11078 | case i40e_bus_width_pcie_x2: |
| 11079 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11080 | case i40e_bus_width_pcie_x1: |
| 11081 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11082 | default: |
| 11083 | break; |
| 11084 | } |
| 11085 | |
| 11086 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11087 | speed, width); |
| 11088 | |
| 11089 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11090 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11091 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11092 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11093 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11094 | } |
| 11095 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11096 | /* get the requested speeds from the fw */ |
| 11097 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11098 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11099 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11100 | i40e_stat_str(&pf->hw, err), |
| 11101 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11102 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11103 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11104 | /* get the supported phy types from the fw */ |
| 11105 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11106 | if (err) |
| 11107 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11108 | i40e_stat_str(&pf->hw, err), |
| 11109 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 11110 | pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type); |
| 11111 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11112 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11113 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11114 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11115 | * PF/VF VSIs. |
| 11116 | * The FW can still send Flow control frames if enabled. |
| 11117 | */ |
| 11118 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11119 | pf->main_vsi_seid); |
| 11120 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11121 | /* print a string summarizing features */ |
| 11122 | i40e_print_features(pf); |
| 11123 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11124 | return 0; |
| 11125 | |
| 11126 | /* Unwind what we've done if something failed in the setup */ |
| 11127 | err_vsis: |
| 11128 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11129 | i40e_clear_interrupt_scheme(pf); |
| 11130 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11131 | err_switch_setup: |
| 11132 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11133 | del_timer_sync(&pf->service_timer); |
| 11134 | err_mac_addr: |
| 11135 | err_configure_lan_hmc: |
| 11136 | (void)i40e_shutdown_lan_hmc(hw); |
| 11137 | err_init_lan_hmc: |
| 11138 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11139 | err_sw_init: |
| 11140 | err_adminq_setup: |
| 11141 | (void)i40e_shutdown_adminq(hw); |
| 11142 | err_pf_reset: |
| 11143 | iounmap(hw->hw_addr); |
| 11144 | err_ioremap: |
| 11145 | kfree(pf); |
| 11146 | err_pf_alloc: |
| 11147 | pci_disable_pcie_error_reporting(pdev); |
| 11148 | pci_release_selected_regions(pdev, |
| 11149 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 11150 | err_pci_reg: |
| 11151 | err_dma: |
| 11152 | pci_disable_device(pdev); |
| 11153 | return err; |
| 11154 | } |
| 11155 | |
| 11156 | /** |
| 11157 | * i40e_remove - Device removal routine |
| 11158 | * @pdev: PCI device information struct |
| 11159 | * |
| 11160 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11161 | * that is should release a PCI device. This could be caused by a |
| 11162 | * Hot-Plug event, or because the driver is going to be removed from |
| 11163 | * memory. |
| 11164 | **/ |
| 11165 | static void i40e_remove(struct pci_dev *pdev) |
| 11166 | { |
| 11167 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11168 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11169 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11170 | int i; |
| 11171 | |
| 11172 | i40e_dbg_pf_exit(pf); |
| 11173 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11174 | i40e_ptp_stop(pf); |
| 11175 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11176 | /* Disable RSS in hw */ |
| 11177 | wr32(hw, I40E_PFQF_HENA(0), 0); |
| 11178 | wr32(hw, I40E_PFQF_HENA(1), 0); |
| 11179 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11180 | /* no more scheduling of any task */ |
| 11181 | set_bit(__I40E_DOWN, &pf->state); |
| 11182 | del_timer_sync(&pf->service_timer); |
| 11183 | cancel_work_sync(&pf->service_task); |
| 11184 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11185 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11186 | i40e_free_vfs(pf); |
| 11187 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11188 | } |
| 11189 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11190 | i40e_fdir_teardown(pf); |
| 11191 | |
| 11192 | /* If there is a switch structure or any orphans, remove them. |
| 11193 | * This will leave only the PF's VSI remaining. |
| 11194 | */ |
| 11195 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11196 | if (!pf->veb[i]) |
| 11197 | continue; |
| 11198 | |
| 11199 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11200 | pf->veb[i]->uplink_seid == 0) |
| 11201 | i40e_switch_branch_release(pf->veb[i]); |
| 11202 | } |
| 11203 | |
| 11204 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11205 | * adminq and hmc. |
| 11206 | */ |
| 11207 | if (pf->vsi[pf->lan_vsi]) |
| 11208 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11209 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11210 | /* shutdown and destroy the HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11211 | if (pf->hw.hmc.hmc_obj) { |
| 11212 | ret_code = i40e_shutdown_lan_hmc(&pf->hw); |
| 11213 | if (ret_code) |
| 11214 | dev_warn(&pdev->dev, |
| 11215 | "Failed to destroy the HMC resources: %d\n", |
| 11216 | ret_code); |
| 11217 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11218 | |
| 11219 | /* shutdown the adminq */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11220 | ret_code = i40e_shutdown_adminq(&pf->hw); |
| 11221 | if (ret_code) |
| 11222 | dev_warn(&pdev->dev, |
| 11223 | "Failed to destroy the Admin Queue resources: %d\n", |
| 11224 | ret_code); |
| 11225 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11226 | /* destroy the locks only once, here */ |
| 11227 | mutex_destroy(&hw->aq.arq_mutex); |
| 11228 | mutex_destroy(&hw->aq.asq_mutex); |
| 11229 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11230 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11231 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11232 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11233 | if (pf->vsi[i]) { |
| 11234 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11235 | i40e_vsi_clear(pf->vsi[i]); |
| 11236 | pf->vsi[i] = NULL; |
| 11237 | } |
| 11238 | } |
| 11239 | |
| 11240 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11241 | kfree(pf->veb[i]); |
| 11242 | pf->veb[i] = NULL; |
| 11243 | } |
| 11244 | |
| 11245 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11246 | kfree(pf->vsi); |
| 11247 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11248 | iounmap(pf->hw.hw_addr); |
| 11249 | kfree(pf); |
| 11250 | pci_release_selected_regions(pdev, |
| 11251 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 11252 | |
| 11253 | pci_disable_pcie_error_reporting(pdev); |
| 11254 | pci_disable_device(pdev); |
| 11255 | } |
| 11256 | |
| 11257 | /** |
| 11258 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11259 | * @pdev: PCI device information struct |
| 11260 | * |
| 11261 | * Called to warn that something happened and the error handling steps |
| 11262 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11263 | * remediation. |
| 11264 | **/ |
| 11265 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11266 | enum pci_channel_state error) |
| 11267 | { |
| 11268 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11269 | |
| 11270 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11271 | |
| 11272 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11273 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11274 | rtnl_lock(); |
| 11275 | i40e_prep_for_reset(pf); |
| 11276 | rtnl_unlock(); |
| 11277 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11278 | |
| 11279 | /* Request a slot reset */ |
| 11280 | return PCI_ERS_RESULT_NEED_RESET; |
| 11281 | } |
| 11282 | |
| 11283 | /** |
| 11284 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11285 | * @pdev: PCI device information struct |
| 11286 | * |
| 11287 | * Called to find if the driver can work with the device now that |
| 11288 | * the pci slot has been reset. If a basic connection seems good |
| 11289 | * (registers are readable and have sane content) then return a |
| 11290 | * happy little PCI_ERS_RESULT_xxx. |
| 11291 | **/ |
| 11292 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11293 | { |
| 11294 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11295 | pci_ers_result_t result; |
| 11296 | int err; |
| 11297 | u32 reg; |
| 11298 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11299 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11300 | if (pci_enable_device_mem(pdev)) { |
| 11301 | dev_info(&pdev->dev, |
| 11302 | "Cannot re-enable PCI device after reset.\n"); |
| 11303 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11304 | } else { |
| 11305 | pci_set_master(pdev); |
| 11306 | pci_restore_state(pdev); |
| 11307 | pci_save_state(pdev); |
| 11308 | pci_wake_from_d3(pdev, false); |
| 11309 | |
| 11310 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11311 | if (reg == 0) |
| 11312 | result = PCI_ERS_RESULT_RECOVERED; |
| 11313 | else |
| 11314 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11315 | } |
| 11316 | |
| 11317 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11318 | if (err) { |
| 11319 | dev_info(&pdev->dev, |
| 11320 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11321 | err); |
| 11322 | /* non-fatal, continue */ |
| 11323 | } |
| 11324 | |
| 11325 | return result; |
| 11326 | } |
| 11327 | |
| 11328 | /** |
| 11329 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11330 | * @pdev: PCI device information struct |
| 11331 | * |
| 11332 | * Called to allow the driver to bring things back up after PCI error |
| 11333 | * and/or reset recovery has finished. |
| 11334 | **/ |
| 11335 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11336 | { |
| 11337 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11338 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11339 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11340 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 11341 | return; |
| 11342 | |
| 11343 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11344 | i40e_handle_reset_warning(pf); |
Vasily Averin | 4c4935a | 2015-07-08 15:04:26 +0300 | [diff] [blame] | 11345 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11346 | } |
| 11347 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11348 | /** |
| 11349 | * i40e_shutdown - PCI callback for shutting down |
| 11350 | * @pdev: PCI device information struct |
| 11351 | **/ |
| 11352 | static void i40e_shutdown(struct pci_dev *pdev) |
| 11353 | { |
| 11354 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11355 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11356 | |
| 11357 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11358 | set_bit(__I40E_DOWN, &pf->state); |
| 11359 | rtnl_lock(); |
| 11360 | i40e_prep_for_reset(pf); |
| 11361 | rtnl_unlock(); |
| 11362 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11363 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11364 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11365 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11366 | del_timer_sync(&pf->service_timer); |
| 11367 | cancel_work_sync(&pf->service_task); |
| 11368 | i40e_fdir_teardown(pf); |
| 11369 | |
| 11370 | rtnl_lock(); |
| 11371 | i40e_prep_for_reset(pf); |
| 11372 | rtnl_unlock(); |
| 11373 | |
| 11374 | wr32(hw, I40E_PFPM_APM, |
| 11375 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11376 | wr32(hw, I40E_PFPM_WUFC, |
| 11377 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11378 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 11379 | i40e_clear_interrupt_scheme(pf); |
| 11380 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11381 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11382 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11383 | pci_set_power_state(pdev, PCI_D3hot); |
| 11384 | } |
| 11385 | } |
| 11386 | |
| 11387 | #ifdef CONFIG_PM |
| 11388 | /** |
| 11389 | * i40e_suspend - PCI callback for moving to D3 |
| 11390 | * @pdev: PCI device information struct |
| 11391 | **/ |
| 11392 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11393 | { |
| 11394 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11395 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11396 | |
| 11397 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11398 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 11399 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11400 | rtnl_lock(); |
| 11401 | i40e_prep_for_reset(pf); |
| 11402 | rtnl_unlock(); |
| 11403 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11404 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11405 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11406 | |
| 11407 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11408 | pci_set_power_state(pdev, PCI_D3hot); |
| 11409 | |
| 11410 | return 0; |
| 11411 | } |
| 11412 | |
| 11413 | /** |
| 11414 | * i40e_resume - PCI callback for waking up from D3 |
| 11415 | * @pdev: PCI device information struct |
| 11416 | **/ |
| 11417 | static int i40e_resume(struct pci_dev *pdev) |
| 11418 | { |
| 11419 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11420 | u32 err; |
| 11421 | |
| 11422 | pci_set_power_state(pdev, PCI_D0); |
| 11423 | pci_restore_state(pdev); |
| 11424 | /* pci_restore_state() clears dev->state_saves, so |
| 11425 | * call pci_save_state() again to restore it. |
| 11426 | */ |
| 11427 | pci_save_state(pdev); |
| 11428 | |
| 11429 | err = pci_enable_device_mem(pdev); |
| 11430 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11431 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11432 | return err; |
| 11433 | } |
| 11434 | pci_set_master(pdev); |
| 11435 | |
| 11436 | /* no wakeup events while running */ |
| 11437 | pci_wake_from_d3(pdev, false); |
| 11438 | |
| 11439 | /* handling the reset will rebuild the device state */ |
| 11440 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11441 | clear_bit(__I40E_DOWN, &pf->state); |
| 11442 | rtnl_lock(); |
| 11443 | i40e_reset_and_rebuild(pf, false); |
| 11444 | rtnl_unlock(); |
| 11445 | } |
| 11446 | |
| 11447 | return 0; |
| 11448 | } |
| 11449 | |
| 11450 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11451 | static const struct pci_error_handlers i40e_err_handler = { |
| 11452 | .error_detected = i40e_pci_error_detected, |
| 11453 | .slot_reset = i40e_pci_error_slot_reset, |
| 11454 | .resume = i40e_pci_error_resume, |
| 11455 | }; |
| 11456 | |
| 11457 | static struct pci_driver i40e_driver = { |
| 11458 | .name = i40e_driver_name, |
| 11459 | .id_table = i40e_pci_tbl, |
| 11460 | .probe = i40e_probe, |
| 11461 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11462 | #ifdef CONFIG_PM |
| 11463 | .suspend = i40e_suspend, |
| 11464 | .resume = i40e_resume, |
| 11465 | #endif |
| 11466 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11467 | .err_handler = &i40e_err_handler, |
| 11468 | .sriov_configure = i40e_pci_sriov_configure, |
| 11469 | }; |
| 11470 | |
| 11471 | /** |
| 11472 | * i40e_init_module - Driver registration routine |
| 11473 | * |
| 11474 | * i40e_init_module is the first routine called when the driver is |
| 11475 | * loaded. All it does is register with the PCI subsystem. |
| 11476 | **/ |
| 11477 | static int __init i40e_init_module(void) |
| 11478 | { |
| 11479 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 11480 | i40e_driver_string, i40e_driver_version_str); |
| 11481 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 11482 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11483 | /* we will see if single thread per module is enough for now, |
| 11484 | * it can't be any worse than using the system workqueue which |
| 11485 | * was already single threaded |
| 11486 | */ |
| 11487 | i40e_wq = create_singlethread_workqueue(i40e_driver_name); |
| 11488 | if (!i40e_wq) { |
| 11489 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 11490 | return -ENOMEM; |
| 11491 | } |
| 11492 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11493 | i40e_dbg_init(); |
| 11494 | return pci_register_driver(&i40e_driver); |
| 11495 | } |
| 11496 | module_init(i40e_init_module); |
| 11497 | |
| 11498 | /** |
| 11499 | * i40e_exit_module - Driver exit cleanup routine |
| 11500 | * |
| 11501 | * i40e_exit_module is called just before the driver is removed |
| 11502 | * from memory. |
| 11503 | **/ |
| 11504 | static void __exit i40e_exit_module(void) |
| 11505 | { |
| 11506 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11507 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11508 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11509 | } |
| 11510 | module_exit(i40e_exit_module); |