Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2016 Intel Corporation. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 27 | #include <linux/etherdevice.h> |
| 28 | #include <linux/of_net.h> |
| 29 | #include <linux/pci.h> |
| 30 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 31 | /* Local includes */ |
| 32 | #include "i40e.h" |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 33 | #include "i40e_diag.h" |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 34 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 35 | #include <net/vxlan.h> |
| 36 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 37 | #if IS_ENABLED(CONFIG_GENEVE) |
| 38 | #include <net/geneve.h> |
| 39 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 40 | |
| 41 | const char i40e_driver_name[] = "i40e"; |
| 42 | static const char i40e_driver_string[] = |
| 43 | "Intel(R) Ethernet Connection XL710 Network Driver"; |
| 44 | |
| 45 | #define DRV_KERN "-k" |
| 46 | |
Catherine Sullivan | e8e724d | 2014-07-10 07:58:26 +0000 | [diff] [blame] | 47 | #define DRV_VERSION_MAJOR 1 |
Catherine Sullivan | 50f26a5 | 2016-03-10 14:59:51 -0800 | [diff] [blame] | 48 | #define DRV_VERSION_MINOR 5 |
| 49 | #define DRV_VERSION_BUILD 1 |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 50 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 51 | __stringify(DRV_VERSION_MINOR) "." \ |
| 52 | __stringify(DRV_VERSION_BUILD) DRV_KERN |
| 53 | const char i40e_driver_version_str[] = DRV_VERSION; |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 54 | static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation."; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 55 | |
| 56 | /* a bit of forward declarations */ |
| 57 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); |
| 58 | static void i40e_handle_reset_warning(struct i40e_pf *pf); |
| 59 | static int i40e_add_vsi(struct i40e_vsi *vsi); |
| 60 | 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] | 61 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 62 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
| 63 | static void i40e_determine_queue_usage(struct i40e_pf *pf); |
| 64 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 65 | static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 66 | u16 rss_table_size, u16 rss_size); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 67 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 68 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 69 | |
| 70 | /* i40e_pci_tbl - PCI Device ID Table |
| 71 | * |
| 72 | * Last entry must be all 0s |
| 73 | * |
| 74 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 75 | * Class, Class Mask, private data (not used) } |
| 76 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 77 | static const struct pci_device_id i40e_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 78 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 79 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 80 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, |
| 81 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 82 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, |
| 83 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, |
| 84 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 85 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0}, |
Shannon Nelson | bc5166b9 | 2015-08-26 15:14:10 -0400 | [diff] [blame] | 86 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0}, |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 87 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
Anjali Singhai Jain | 35dae51 | 2015-12-22 14:25:03 -0800 | [diff] [blame] | 88 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0}, |
| 89 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame] | 90 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0}, |
| 91 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0}, |
| 92 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0}, |
Shannon Nelson | 48a3b51 | 2015-07-23 16:54:39 -0400 | [diff] [blame] | 93 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
| 94 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 95 | /* required last entry */ |
| 96 | {0, } |
| 97 | }; |
| 98 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 99 | |
| 100 | #define I40E_MAX_VF_COUNT 128 |
| 101 | static int debug = -1; |
| 102 | module_param(debug, int, 0); |
| 103 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 104 | |
| 105 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 106 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 107 | MODULE_LICENSE("GPL"); |
| 108 | MODULE_VERSION(DRV_VERSION); |
| 109 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 110 | static struct workqueue_struct *i40e_wq; |
| 111 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 112 | /** |
| 113 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 114 | * @hw: pointer to the HW structure |
| 115 | * @mem: ptr to mem struct to fill out |
| 116 | * @size: size of memory requested |
| 117 | * @alignment: what to align the allocation to |
| 118 | **/ |
| 119 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 120 | u64 size, u32 alignment) |
| 121 | { |
| 122 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 123 | |
| 124 | mem->size = ALIGN(size, alignment); |
| 125 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 126 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 127 | if (!mem->va) |
| 128 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 129 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 130 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /** |
| 134 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 135 | * @hw: pointer to the HW structure |
| 136 | * @mem: ptr to mem struct to free |
| 137 | **/ |
| 138 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 139 | { |
| 140 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 141 | |
| 142 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 143 | mem->va = NULL; |
| 144 | mem->pa = 0; |
| 145 | mem->size = 0; |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 152 | * @hw: pointer to the HW structure |
| 153 | * @mem: ptr to mem struct to fill out |
| 154 | * @size: size of memory requested |
| 155 | **/ |
| 156 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 157 | u32 size) |
| 158 | { |
| 159 | mem->size = size; |
| 160 | mem->va = kzalloc(size, GFP_KERNEL); |
| 161 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 162 | if (!mem->va) |
| 163 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 164 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 165 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | /** |
| 169 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 170 | * @hw: pointer to the HW structure |
| 171 | * @mem: ptr to mem struct to free |
| 172 | **/ |
| 173 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 174 | { |
| 175 | /* it's ok to kfree a NULL pointer */ |
| 176 | kfree(mem->va); |
| 177 | mem->va = NULL; |
| 178 | mem->size = 0; |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * i40e_get_lump - find a lump of free generic resource |
| 185 | * @pf: board private structure |
| 186 | * @pile: the pile of resource to search |
| 187 | * @needed: the number of items needed |
| 188 | * @id: an owner id to stick on the items assigned |
| 189 | * |
| 190 | * Returns the base item index of the lump, or negative for error |
| 191 | * |
| 192 | * The search_hint trick and lack of advanced fit-finding only work |
| 193 | * because we're highly likely to have all the same size lump requests. |
| 194 | * Linear search time and any fragmentation should be minimal. |
| 195 | **/ |
| 196 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 197 | u16 needed, u16 id) |
| 198 | { |
| 199 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 200 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 201 | |
| 202 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 203 | dev_info(&pf->pdev->dev, |
| 204 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 205 | pile, needed, id); |
| 206 | return -EINVAL; |
| 207 | } |
| 208 | |
| 209 | /* start the linear search with an imperfect hint */ |
| 210 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 211 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 212 | /* skip already allocated entries */ |
| 213 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 214 | i++; |
| 215 | continue; |
| 216 | } |
| 217 | |
| 218 | /* do we have enough in this lump? */ |
| 219 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 220 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 221 | break; |
| 222 | } |
| 223 | |
| 224 | if (j == needed) { |
| 225 | /* there was enough, so assign it to the requestor */ |
| 226 | for (j = 0; j < needed; j++) |
| 227 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 228 | ret = i; |
| 229 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 230 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 231 | } |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 232 | |
| 233 | /* not enough, so skip over it and continue looking */ |
| 234 | i += j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | return ret; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * i40e_put_lump - return a lump of generic resource |
| 242 | * @pile: the pile of resource to search |
| 243 | * @index: the base item index |
| 244 | * @id: the owner id of the items assigned |
| 245 | * |
| 246 | * Returns the count of items in the lump |
| 247 | **/ |
| 248 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 249 | { |
| 250 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 251 | int count = 0; |
| 252 | int i; |
| 253 | |
| 254 | if (!pile || index >= pile->num_entries) |
| 255 | return -EINVAL; |
| 256 | |
| 257 | for (i = index; |
| 258 | i < pile->num_entries && pile->list[i] == valid_id; |
| 259 | i++) { |
| 260 | pile->list[i] = 0; |
| 261 | count++; |
| 262 | } |
| 263 | |
| 264 | if (count && index < pile->search_hint) |
| 265 | pile->search_hint = index; |
| 266 | |
| 267 | return count; |
| 268 | } |
| 269 | |
| 270 | /** |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 271 | * i40e_find_vsi_from_id - searches for the vsi with the given id |
| 272 | * @pf - the pf structure to search for the vsi |
| 273 | * @id - id of the vsi it is searching for |
| 274 | **/ |
| 275 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) |
| 276 | { |
| 277 | int i; |
| 278 | |
| 279 | for (i = 0; i < pf->num_alloc_vsi; i++) |
| 280 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) |
| 281 | return pf->vsi[i]; |
| 282 | |
| 283 | return NULL; |
| 284 | } |
| 285 | |
| 286 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 287 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 288 | * @pf: board private structure |
| 289 | * |
| 290 | * If not already scheduled, this puts the task into the work queue |
| 291 | **/ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 292 | void i40e_service_event_schedule(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 293 | { |
| 294 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 295 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && |
| 296 | !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 297 | queue_work(i40e_wq, &pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /** |
| 301 | * i40e_tx_timeout - Respond to a Tx Hang |
| 302 | * @netdev: network interface device structure |
| 303 | * |
| 304 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 305 | * device is munged, not just the one netdev port, so go for the full |
| 306 | * reset. |
| 307 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 308 | #ifdef I40E_FCOE |
| 309 | void i40e_tx_timeout(struct net_device *netdev) |
| 310 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 311 | static void i40e_tx_timeout(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 312 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 313 | { |
| 314 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 315 | struct i40e_vsi *vsi = np->vsi; |
| 316 | struct i40e_pf *pf = vsi->back; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 317 | struct i40e_ring *tx_ring = NULL; |
| 318 | unsigned int i, hung_queue = 0; |
| 319 | u32 head, val; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 320 | |
| 321 | pf->tx_timeout_count++; |
| 322 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 323 | /* find the stopped queue the same way the stack does */ |
| 324 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 325 | struct netdev_queue *q; |
| 326 | unsigned long trans_start; |
| 327 | |
| 328 | q = netdev_get_tx_queue(netdev, i); |
| 329 | trans_start = q->trans_start ? : netdev->trans_start; |
| 330 | if (netif_xmit_stopped(q) && |
| 331 | time_after(jiffies, |
| 332 | (trans_start + netdev->watchdog_timeo))) { |
| 333 | hung_queue = i; |
| 334 | break; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | if (i == netdev->num_tx_queues) { |
| 339 | netdev_info(netdev, "tx_timeout: no netdev hung queue found\n"); |
| 340 | } else { |
| 341 | /* now that we have an index, find the tx_ring struct */ |
| 342 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 343 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 344 | if (hung_queue == |
| 345 | vsi->tx_rings[i]->queue_index) { |
| 346 | tx_ring = vsi->tx_rings[i]; |
| 347 | break; |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 353 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 354 | pf->tx_timeout_recovery_level = 1; /* reset after some time */ |
| 355 | else if (time_before(jiffies, |
| 356 | (pf->tx_timeout_last_recovery + netdev->watchdog_timeo))) |
| 357 | return; /* don't do any new action before the next timeout */ |
| 358 | |
| 359 | if (tx_ring) { |
| 360 | head = i40e_get_head(tx_ring); |
| 361 | /* Read interrupt register */ |
| 362 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 363 | val = rd32(&pf->hw, |
| 364 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 365 | tx_ring->vsi->base_vector - 1)); |
| 366 | else |
| 367 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 368 | |
| 369 | netdev_info(netdev, "tx_timeout: VSI_seid: %d, Q %d, NTC: 0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x, INT: 0x%x\n", |
| 370 | vsi->seid, hung_queue, tx_ring->next_to_clean, |
| 371 | head, tx_ring->next_to_use, |
| 372 | readl(tx_ring->tail), val); |
| 373 | } |
| 374 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 375 | pf->tx_timeout_last_recovery = jiffies; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 376 | netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n", |
| 377 | pf->tx_timeout_recovery_level, hung_queue); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 378 | |
| 379 | switch (pf->tx_timeout_recovery_level) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 380 | case 1: |
| 381 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 382 | break; |
| 383 | case 2: |
| 384 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 385 | break; |
| 386 | case 3: |
| 387 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 388 | break; |
| 389 | default: |
| 390 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 391 | break; |
| 392 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 393 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 394 | i40e_service_event_schedule(pf); |
| 395 | pf->tx_timeout_recovery_level++; |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * i40e_release_rx_desc - Store the new tail and head values |
| 400 | * @rx_ring: ring to bump |
| 401 | * @val: new head index |
| 402 | **/ |
| 403 | static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val) |
| 404 | { |
| 405 | rx_ring->next_to_use = val; |
| 406 | |
| 407 | /* Force memory writes to complete before letting h/w |
| 408 | * know there are new descriptors to fetch. (Only |
| 409 | * applicable for weak-ordered memory model archs, |
| 410 | * such as IA-64). |
| 411 | */ |
| 412 | wmb(); |
| 413 | writel(val, rx_ring->tail); |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 418 | * @vsi: the VSI we care about |
| 419 | * |
| 420 | * Returns the address of the device statistics structure. |
| 421 | * The statistics are actually updated from the service task. |
| 422 | **/ |
| 423 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 424 | { |
| 425 | return &vsi->net_stats; |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 430 | * @netdev: network interface device structure |
| 431 | * |
| 432 | * Returns the address of the device statistics structure. |
| 433 | * The statistics are actually updated from the service task. |
| 434 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 435 | #ifdef I40E_FCOE |
| 436 | struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 437 | struct net_device *netdev, |
| 438 | struct rtnl_link_stats64 *stats) |
| 439 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 440 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 441 | struct net_device *netdev, |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 442 | struct rtnl_link_stats64 *stats) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 443 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 444 | { |
| 445 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 446 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 447 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 448 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 449 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 450 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 451 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 452 | return stats; |
| 453 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 454 | if (!vsi->tx_rings) |
| 455 | return stats; |
| 456 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 457 | rcu_read_lock(); |
| 458 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 459 | u64 bytes, packets; |
| 460 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 461 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 462 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 463 | if (!tx_ring) |
| 464 | continue; |
| 465 | |
| 466 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 467 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 468 | packets = tx_ring->stats.packets; |
| 469 | bytes = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 470 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 471 | |
| 472 | stats->tx_packets += packets; |
| 473 | stats->tx_bytes += bytes; |
| 474 | rx_ring = &tx_ring[1]; |
| 475 | |
| 476 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 477 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 478 | packets = rx_ring->stats.packets; |
| 479 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 480 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 481 | |
| 482 | stats->rx_packets += packets; |
| 483 | stats->rx_bytes += bytes; |
| 484 | } |
| 485 | rcu_read_unlock(); |
| 486 | |
Akeem G Abodunrin | a5282f4 | 2014-05-10 04:49:03 +0000 | [diff] [blame] | 487 | /* following stats updated by i40e_watchdog_subtask() */ |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 488 | stats->multicast = vsi_stats->multicast; |
| 489 | stats->tx_errors = vsi_stats->tx_errors; |
| 490 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 491 | stats->rx_errors = vsi_stats->rx_errors; |
Jesse Brandeburg | d8201e2 | 2015-07-23 16:54:35 -0400 | [diff] [blame] | 492 | stats->rx_dropped = vsi_stats->rx_dropped; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 493 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 494 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
| 495 | |
| 496 | return stats; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | /** |
| 500 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 501 | * @vsi: the VSI to have its stats reset |
| 502 | **/ |
| 503 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 504 | { |
| 505 | struct rtnl_link_stats64 *ns; |
| 506 | int i; |
| 507 | |
| 508 | if (!vsi) |
| 509 | return; |
| 510 | |
| 511 | ns = i40e_get_vsi_stats_struct(vsi); |
| 512 | memset(ns, 0, sizeof(*ns)); |
| 513 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 514 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 515 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 516 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 517 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 518 | memset(&vsi->rx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 519 | sizeof(vsi->rx_rings[i]->stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 520 | memset(&vsi->rx_rings[i]->rx_stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 521 | sizeof(vsi->rx_rings[i]->rx_stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 522 | memset(&vsi->tx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 523 | sizeof(vsi->tx_rings[i]->stats)); |
| 524 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 525 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 526 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 527 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 528 | vsi->stat_offsets_loaded = false; |
| 529 | } |
| 530 | |
| 531 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 532 | * 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] | 533 | * @pf: the PF to be reset |
| 534 | **/ |
| 535 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 536 | { |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 537 | int i; |
| 538 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 539 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 540 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 541 | pf->stat_offsets_loaded = false; |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 542 | |
| 543 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 544 | if (pf->veb[i]) { |
| 545 | memset(&pf->veb[i]->stats, 0, |
| 546 | sizeof(pf->veb[i]->stats)); |
| 547 | memset(&pf->veb[i]->stats_offsets, 0, |
| 548 | sizeof(pf->veb[i]->stats_offsets)); |
| 549 | pf->veb[i]->stat_offsets_loaded = false; |
| 550 | } |
| 551 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /** |
| 555 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 556 | * @hw: ptr to the hardware info |
| 557 | * @hireg: the high 32 bit reg to read |
| 558 | * @loreg: the low 32 bit reg to read |
| 559 | * @offset_loaded: has the initial offset been loaded yet |
| 560 | * @offset: ptr to current offset value |
| 561 | * @stat: ptr to the stat |
| 562 | * |
| 563 | * Since the device stats are not reset at PFReset, they likely will not |
| 564 | * be zeroed when the driver starts. We'll save the first values read |
| 565 | * and use them as offsets to be subtracted from the raw values in order |
| 566 | * to report stats that count from zero. In the process, we also manage |
| 567 | * the potential roll-over. |
| 568 | **/ |
| 569 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 570 | bool offset_loaded, u64 *offset, u64 *stat) |
| 571 | { |
| 572 | u64 new_data; |
| 573 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 574 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 575 | new_data = rd32(hw, loreg); |
| 576 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 577 | } else { |
| 578 | new_data = rd64(hw, loreg); |
| 579 | } |
| 580 | if (!offset_loaded) |
| 581 | *offset = new_data; |
| 582 | if (likely(new_data >= *offset)) |
| 583 | *stat = new_data - *offset; |
| 584 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 585 | *stat = (new_data + BIT_ULL(48)) - *offset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 586 | *stat &= 0xFFFFFFFFFFFFULL; |
| 587 | } |
| 588 | |
| 589 | /** |
| 590 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 591 | * @hw: ptr to the hardware info |
| 592 | * @reg: the hw reg to read |
| 593 | * @offset_loaded: has the initial offset been loaded yet |
| 594 | * @offset: ptr to current offset value |
| 595 | * @stat: ptr to the stat |
| 596 | **/ |
| 597 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 598 | bool offset_loaded, u64 *offset, u64 *stat) |
| 599 | { |
| 600 | u32 new_data; |
| 601 | |
| 602 | new_data = rd32(hw, reg); |
| 603 | if (!offset_loaded) |
| 604 | *offset = new_data; |
| 605 | if (likely(new_data >= *offset)) |
| 606 | *stat = (u32)(new_data - *offset); |
| 607 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 608 | *stat = (u32)((new_data + BIT_ULL(32)) - *offset); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /** |
| 612 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 613 | * @vsi: the VSI to be updated |
| 614 | **/ |
| 615 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 616 | { |
| 617 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 618 | struct i40e_pf *pf = vsi->back; |
| 619 | struct i40e_hw *hw = &pf->hw; |
| 620 | struct i40e_eth_stats *oes; |
| 621 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 622 | |
| 623 | es = &vsi->eth_stats; |
| 624 | oes = &vsi->eth_stats_offsets; |
| 625 | |
| 626 | /* Gather up the stats that the hw collects */ |
| 627 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 628 | vsi->stat_offsets_loaded, |
| 629 | &oes->tx_errors, &es->tx_errors); |
| 630 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 631 | vsi->stat_offsets_loaded, |
| 632 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 633 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 634 | vsi->stat_offsets_loaded, |
| 635 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 636 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 637 | vsi->stat_offsets_loaded, |
| 638 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 639 | |
| 640 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 641 | I40E_GLV_GORCL(stat_idx), |
| 642 | vsi->stat_offsets_loaded, |
| 643 | &oes->rx_bytes, &es->rx_bytes); |
| 644 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 645 | I40E_GLV_UPRCL(stat_idx), |
| 646 | vsi->stat_offsets_loaded, |
| 647 | &oes->rx_unicast, &es->rx_unicast); |
| 648 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 649 | I40E_GLV_MPRCL(stat_idx), |
| 650 | vsi->stat_offsets_loaded, |
| 651 | &oes->rx_multicast, &es->rx_multicast); |
| 652 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 653 | I40E_GLV_BPRCL(stat_idx), |
| 654 | vsi->stat_offsets_loaded, |
| 655 | &oes->rx_broadcast, &es->rx_broadcast); |
| 656 | |
| 657 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 658 | I40E_GLV_GOTCL(stat_idx), |
| 659 | vsi->stat_offsets_loaded, |
| 660 | &oes->tx_bytes, &es->tx_bytes); |
| 661 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 662 | I40E_GLV_UPTCL(stat_idx), |
| 663 | vsi->stat_offsets_loaded, |
| 664 | &oes->tx_unicast, &es->tx_unicast); |
| 665 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 666 | I40E_GLV_MPTCL(stat_idx), |
| 667 | vsi->stat_offsets_loaded, |
| 668 | &oes->tx_multicast, &es->tx_multicast); |
| 669 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 670 | I40E_GLV_BPTCL(stat_idx), |
| 671 | vsi->stat_offsets_loaded, |
| 672 | &oes->tx_broadcast, &es->tx_broadcast); |
| 673 | vsi->stat_offsets_loaded = true; |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * i40e_update_veb_stats - Update Switch component statistics |
| 678 | * @veb: the VEB being updated |
| 679 | **/ |
| 680 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 681 | { |
| 682 | struct i40e_pf *pf = veb->pf; |
| 683 | struct i40e_hw *hw = &pf->hw; |
| 684 | struct i40e_eth_stats *oes; |
| 685 | struct i40e_eth_stats *es; /* device's eth stats */ |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 686 | struct i40e_veb_tc_stats *veb_oes; |
| 687 | struct i40e_veb_tc_stats *veb_es; |
| 688 | int i, idx = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 689 | |
| 690 | idx = veb->stats_idx; |
| 691 | es = &veb->stats; |
| 692 | oes = &veb->stats_offsets; |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 693 | veb_es = &veb->tc_stats; |
| 694 | veb_oes = &veb->tc_stats_offsets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 695 | |
| 696 | /* Gather up the stats that the hw collects */ |
| 697 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 698 | veb->stat_offsets_loaded, |
| 699 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 700 | if (hw->revision_id > 0) |
| 701 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 702 | veb->stat_offsets_loaded, |
| 703 | &oes->rx_unknown_protocol, |
| 704 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 705 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 706 | veb->stat_offsets_loaded, |
| 707 | &oes->rx_bytes, &es->rx_bytes); |
| 708 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 709 | veb->stat_offsets_loaded, |
| 710 | &oes->rx_unicast, &es->rx_unicast); |
| 711 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 712 | veb->stat_offsets_loaded, |
| 713 | &oes->rx_multicast, &es->rx_multicast); |
| 714 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 715 | veb->stat_offsets_loaded, |
| 716 | &oes->rx_broadcast, &es->rx_broadcast); |
| 717 | |
| 718 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 719 | veb->stat_offsets_loaded, |
| 720 | &oes->tx_bytes, &es->tx_bytes); |
| 721 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 722 | veb->stat_offsets_loaded, |
| 723 | &oes->tx_unicast, &es->tx_unicast); |
| 724 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 725 | veb->stat_offsets_loaded, |
| 726 | &oes->tx_multicast, &es->tx_multicast); |
| 727 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 728 | veb->stat_offsets_loaded, |
| 729 | &oes->tx_broadcast, &es->tx_broadcast); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 730 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 731 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), |
| 732 | I40E_GLVEBTC_RPCL(i, idx), |
| 733 | veb->stat_offsets_loaded, |
| 734 | &veb_oes->tc_rx_packets[i], |
| 735 | &veb_es->tc_rx_packets[i]); |
| 736 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), |
| 737 | I40E_GLVEBTC_RBCL(i, idx), |
| 738 | veb->stat_offsets_loaded, |
| 739 | &veb_oes->tc_rx_bytes[i], |
| 740 | &veb_es->tc_rx_bytes[i]); |
| 741 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), |
| 742 | I40E_GLVEBTC_TPCL(i, idx), |
| 743 | veb->stat_offsets_loaded, |
| 744 | &veb_oes->tc_tx_packets[i], |
| 745 | &veb_es->tc_tx_packets[i]); |
| 746 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), |
| 747 | I40E_GLVEBTC_TBCL(i, idx), |
| 748 | veb->stat_offsets_loaded, |
| 749 | &veb_oes->tc_tx_bytes[i], |
| 750 | &veb_es->tc_tx_bytes[i]); |
| 751 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 752 | veb->stat_offsets_loaded = true; |
| 753 | } |
| 754 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 755 | #ifdef I40E_FCOE |
| 756 | /** |
| 757 | * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters. |
| 758 | * @vsi: the VSI that is capable of doing FCoE |
| 759 | **/ |
| 760 | static void i40e_update_fcoe_stats(struct i40e_vsi *vsi) |
| 761 | { |
| 762 | struct i40e_pf *pf = vsi->back; |
| 763 | struct i40e_hw *hw = &pf->hw; |
| 764 | struct i40e_fcoe_stats *ofs; |
| 765 | struct i40e_fcoe_stats *fs; /* device's eth stats */ |
| 766 | int idx; |
| 767 | |
| 768 | if (vsi->type != I40E_VSI_FCOE) |
| 769 | return; |
| 770 | |
Kiran Patil | 4147e2c | 2016-01-15 14:33:14 -0800 | [diff] [blame] | 771 | idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 772 | fs = &vsi->fcoe_stats; |
| 773 | ofs = &vsi->fcoe_stats_offsets; |
| 774 | |
| 775 | i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx), |
| 776 | vsi->fcoe_stat_offsets_loaded, |
| 777 | &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets); |
| 778 | i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx), |
| 779 | vsi->fcoe_stat_offsets_loaded, |
| 780 | &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords); |
| 781 | i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx), |
| 782 | vsi->fcoe_stat_offsets_loaded, |
| 783 | &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped); |
| 784 | i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx), |
| 785 | vsi->fcoe_stat_offsets_loaded, |
| 786 | &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets); |
| 787 | i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx), |
| 788 | vsi->fcoe_stat_offsets_loaded, |
| 789 | &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords); |
| 790 | i40e_stat_update32(hw, I40E_GL_FCOECRC(idx), |
| 791 | vsi->fcoe_stat_offsets_loaded, |
| 792 | &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc); |
| 793 | i40e_stat_update32(hw, I40E_GL_FCOELAST(idx), |
| 794 | vsi->fcoe_stat_offsets_loaded, |
| 795 | &ofs->fcoe_last_error, &fs->fcoe_last_error); |
| 796 | i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx), |
| 797 | vsi->fcoe_stat_offsets_loaded, |
| 798 | &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count); |
| 799 | |
| 800 | vsi->fcoe_stat_offsets_loaded = true; |
| 801 | } |
| 802 | |
| 803 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 804 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 805 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 806 | * @vsi: the VSI to be updated |
| 807 | * |
| 808 | * There are a few instances where we store the same stat in a |
| 809 | * couple of different structs. This is partly because we have |
| 810 | * the netdev stats that need to be filled out, which is slightly |
| 811 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 812 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 813 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 814 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 815 | { |
| 816 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 817 | struct rtnl_link_stats64 *ons; |
| 818 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 819 | struct i40e_eth_stats *oes; |
| 820 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 821 | u32 tx_restart, tx_busy; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 822 | u64 tx_lost_interrupt; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 823 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 824 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 825 | u64 bytes, packets; |
| 826 | unsigned int start; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 827 | u64 tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 828 | u64 tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 829 | u64 rx_p, rx_b; |
| 830 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 831 | u16 q; |
| 832 | |
| 833 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 834 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 835 | return; |
| 836 | |
| 837 | ns = i40e_get_vsi_stats_struct(vsi); |
| 838 | ons = &vsi->net_stats_offsets; |
| 839 | es = &vsi->eth_stats; |
| 840 | oes = &vsi->eth_stats_offsets; |
| 841 | |
| 842 | /* Gather up the netdev and vsi stats that the driver collects |
| 843 | * on the fly during packet processing |
| 844 | */ |
| 845 | rx_b = rx_p = 0; |
| 846 | tx_b = tx_p = 0; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 847 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 848 | tx_lost_interrupt = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 849 | rx_page = 0; |
| 850 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 851 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 852 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 853 | /* locate Tx ring */ |
| 854 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 855 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 856 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 857 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 858 | packets = p->stats.packets; |
| 859 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 860 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 861 | tx_b += bytes; |
| 862 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 863 | tx_restart += p->tx_stats.restart_queue; |
| 864 | tx_busy += p->tx_stats.tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 865 | tx_linearize += p->tx_stats.tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 866 | tx_force_wb += p->tx_stats.tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 867 | tx_lost_interrupt += p->tx_stats.tx_lost_interrupt; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 868 | |
| 869 | /* Rx queue is part of the same block as Tx queue */ |
| 870 | p = &p[1]; |
| 871 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 872 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 873 | packets = p->stats.packets; |
| 874 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 875 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 876 | rx_b += bytes; |
| 877 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 878 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 879 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 880 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 881 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 882 | vsi->tx_restart = tx_restart; |
| 883 | vsi->tx_busy = tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 884 | vsi->tx_linearize = tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 885 | vsi->tx_force_wb = tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 886 | vsi->tx_lost_interrupt = tx_lost_interrupt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 887 | vsi->rx_page_failed = rx_page; |
| 888 | vsi->rx_buf_failed = rx_buf; |
| 889 | |
| 890 | ns->rx_packets = rx_p; |
| 891 | ns->rx_bytes = rx_b; |
| 892 | ns->tx_packets = tx_p; |
| 893 | ns->tx_bytes = tx_b; |
| 894 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 895 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 896 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 897 | ons->tx_errors = oes->tx_errors; |
| 898 | ns->tx_errors = es->tx_errors; |
| 899 | ons->multicast = oes->rx_multicast; |
| 900 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 901 | ons->rx_dropped = oes->rx_discards; |
| 902 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 903 | ons->tx_dropped = oes->tx_discards; |
| 904 | ns->tx_dropped = es->tx_discards; |
| 905 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 906 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 907 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 908 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 909 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 910 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 911 | } |
| 912 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 913 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 914 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 915 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 916 | * @pf: the PF to be updated |
| 917 | **/ |
| 918 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 919 | { |
| 920 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 921 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 922 | struct i40e_hw *hw = &pf->hw; |
| 923 | u32 val; |
| 924 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 925 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 926 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 927 | I40E_GLPRT_GORCL(hw->port), |
| 928 | pf->stat_offsets_loaded, |
| 929 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 930 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 931 | I40E_GLPRT_GOTCL(hw->port), |
| 932 | pf->stat_offsets_loaded, |
| 933 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 934 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 935 | pf->stat_offsets_loaded, |
| 936 | &osd->eth.rx_discards, |
| 937 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 938 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 939 | I40E_GLPRT_UPRCL(hw->port), |
| 940 | pf->stat_offsets_loaded, |
| 941 | &osd->eth.rx_unicast, |
| 942 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 943 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 944 | I40E_GLPRT_MPRCL(hw->port), |
| 945 | pf->stat_offsets_loaded, |
| 946 | &osd->eth.rx_multicast, |
| 947 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 948 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 949 | I40E_GLPRT_BPRCL(hw->port), |
| 950 | pf->stat_offsets_loaded, |
| 951 | &osd->eth.rx_broadcast, |
| 952 | &nsd->eth.rx_broadcast); |
| 953 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 954 | I40E_GLPRT_UPTCL(hw->port), |
| 955 | pf->stat_offsets_loaded, |
| 956 | &osd->eth.tx_unicast, |
| 957 | &nsd->eth.tx_unicast); |
| 958 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 959 | I40E_GLPRT_MPTCL(hw->port), |
| 960 | pf->stat_offsets_loaded, |
| 961 | &osd->eth.tx_multicast, |
| 962 | &nsd->eth.tx_multicast); |
| 963 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 964 | I40E_GLPRT_BPTCL(hw->port), |
| 965 | pf->stat_offsets_loaded, |
| 966 | &osd->eth.tx_broadcast, |
| 967 | &nsd->eth.tx_broadcast); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 968 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 969 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 970 | pf->stat_offsets_loaded, |
| 971 | &osd->tx_dropped_link_down, |
| 972 | &nsd->tx_dropped_link_down); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 973 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 974 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 975 | pf->stat_offsets_loaded, |
| 976 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 977 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 978 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 979 | pf->stat_offsets_loaded, |
| 980 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 981 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 982 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 983 | pf->stat_offsets_loaded, |
| 984 | &osd->mac_local_faults, |
| 985 | &nsd->mac_local_faults); |
| 986 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 987 | pf->stat_offsets_loaded, |
| 988 | &osd->mac_remote_faults, |
| 989 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 990 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 991 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 992 | pf->stat_offsets_loaded, |
| 993 | &osd->rx_length_errors, |
| 994 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 995 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 996 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 997 | pf->stat_offsets_loaded, |
| 998 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 999 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 1000 | pf->stat_offsets_loaded, |
| 1001 | &osd->link_xon_tx, &nsd->link_xon_tx); |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 1002 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 1003 | pf->stat_offsets_loaded, |
| 1004 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1005 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 1006 | pf->stat_offsets_loaded, |
| 1007 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1008 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1009 | for (i = 0; i < 8; i++) { |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 1010 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 1011 | pf->stat_offsets_loaded, |
| 1012 | &osd->priority_xoff_rx[i], |
| 1013 | &nsd->priority_xoff_rx[i]); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1014 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1015 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1016 | &osd->priority_xon_rx[i], |
| 1017 | &nsd->priority_xon_rx[i]); |
| 1018 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1019 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1020 | &osd->priority_xon_tx[i], |
| 1021 | &nsd->priority_xon_tx[i]); |
| 1022 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1023 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1024 | &osd->priority_xoff_tx[i], |
| 1025 | &nsd->priority_xoff_tx[i]); |
| 1026 | i40e_stat_update32(hw, |
| 1027 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1028 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1029 | &osd->priority_xon_2_xoff[i], |
| 1030 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1033 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 1034 | I40E_GLPRT_PRC64L(hw->port), |
| 1035 | pf->stat_offsets_loaded, |
| 1036 | &osd->rx_size_64, &nsd->rx_size_64); |
| 1037 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 1038 | I40E_GLPRT_PRC127L(hw->port), |
| 1039 | pf->stat_offsets_loaded, |
| 1040 | &osd->rx_size_127, &nsd->rx_size_127); |
| 1041 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 1042 | I40E_GLPRT_PRC255L(hw->port), |
| 1043 | pf->stat_offsets_loaded, |
| 1044 | &osd->rx_size_255, &nsd->rx_size_255); |
| 1045 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 1046 | I40E_GLPRT_PRC511L(hw->port), |
| 1047 | pf->stat_offsets_loaded, |
| 1048 | &osd->rx_size_511, &nsd->rx_size_511); |
| 1049 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 1050 | I40E_GLPRT_PRC1023L(hw->port), |
| 1051 | pf->stat_offsets_loaded, |
| 1052 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 1053 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 1054 | I40E_GLPRT_PRC1522L(hw->port), |
| 1055 | pf->stat_offsets_loaded, |
| 1056 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 1057 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 1058 | I40E_GLPRT_PRC9522L(hw->port), |
| 1059 | pf->stat_offsets_loaded, |
| 1060 | &osd->rx_size_big, &nsd->rx_size_big); |
| 1061 | |
| 1062 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 1063 | I40E_GLPRT_PTC64L(hw->port), |
| 1064 | pf->stat_offsets_loaded, |
| 1065 | &osd->tx_size_64, &nsd->tx_size_64); |
| 1066 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 1067 | I40E_GLPRT_PTC127L(hw->port), |
| 1068 | pf->stat_offsets_loaded, |
| 1069 | &osd->tx_size_127, &nsd->tx_size_127); |
| 1070 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 1071 | I40E_GLPRT_PTC255L(hw->port), |
| 1072 | pf->stat_offsets_loaded, |
| 1073 | &osd->tx_size_255, &nsd->tx_size_255); |
| 1074 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 1075 | I40E_GLPRT_PTC511L(hw->port), |
| 1076 | pf->stat_offsets_loaded, |
| 1077 | &osd->tx_size_511, &nsd->tx_size_511); |
| 1078 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 1079 | I40E_GLPRT_PTC1023L(hw->port), |
| 1080 | pf->stat_offsets_loaded, |
| 1081 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 1082 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 1083 | I40E_GLPRT_PTC1522L(hw->port), |
| 1084 | pf->stat_offsets_loaded, |
| 1085 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1086 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1087 | I40E_GLPRT_PTC9522L(hw->port), |
| 1088 | pf->stat_offsets_loaded, |
| 1089 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1090 | |
| 1091 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1092 | pf->stat_offsets_loaded, |
| 1093 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1094 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1095 | pf->stat_offsets_loaded, |
| 1096 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1097 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1098 | pf->stat_offsets_loaded, |
| 1099 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1100 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1101 | pf->stat_offsets_loaded, |
| 1102 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1103 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1104 | /* FDIR stats */ |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1105 | i40e_stat_update32(hw, |
| 1106 | 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] | 1107 | pf->stat_offsets_loaded, |
| 1108 | &osd->fd_atr_match, &nsd->fd_atr_match); |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1109 | i40e_stat_update32(hw, |
| 1110 | 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] | 1111 | pf->stat_offsets_loaded, |
| 1112 | &osd->fd_sb_match, &nsd->fd_sb_match); |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 1113 | i40e_stat_update32(hw, |
| 1114 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), |
| 1115 | pf->stat_offsets_loaded, |
| 1116 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1117 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1118 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1119 | nsd->tx_lpi_status = |
| 1120 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1121 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1122 | nsd->rx_lpi_status = |
| 1123 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1124 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1125 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1126 | pf->stat_offsets_loaded, |
| 1127 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1128 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1129 | pf->stat_offsets_loaded, |
| 1130 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1131 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1132 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
| 1133 | !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) |
| 1134 | nsd->fd_sb_status = true; |
| 1135 | else |
| 1136 | nsd->fd_sb_status = false; |
| 1137 | |
| 1138 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
| 1139 | !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 1140 | nsd->fd_atr_status = true; |
| 1141 | else |
| 1142 | nsd->fd_atr_status = false; |
| 1143 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1144 | pf->stat_offsets_loaded = true; |
| 1145 | } |
| 1146 | |
| 1147 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1148 | * i40e_update_stats - Update the various statistics counters. |
| 1149 | * @vsi: the VSI to be updated |
| 1150 | * |
| 1151 | * Update the various stats for this VSI and its related entities. |
| 1152 | **/ |
| 1153 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1154 | { |
| 1155 | struct i40e_pf *pf = vsi->back; |
| 1156 | |
| 1157 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1158 | i40e_update_pf_stats(pf); |
| 1159 | |
| 1160 | i40e_update_vsi_stats(vsi); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1161 | #ifdef I40E_FCOE |
| 1162 | i40e_update_fcoe_stats(vsi); |
| 1163 | #endif |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1167 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1168 | * @vsi: the VSI to be searched |
| 1169 | * @macaddr: the MAC address |
| 1170 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1171 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1172 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1173 | * |
| 1174 | * Returns ptr to the filter object or NULL |
| 1175 | **/ |
| 1176 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
| 1177 | u8 *macaddr, s16 vlan, |
| 1178 | bool is_vf, bool is_netdev) |
| 1179 | { |
| 1180 | struct i40e_mac_filter *f; |
| 1181 | |
| 1182 | if (!vsi || !macaddr) |
| 1183 | return NULL; |
| 1184 | |
| 1185 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1186 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1187 | (vlan == f->vlan) && |
| 1188 | (!is_vf || f->is_vf) && |
| 1189 | (!is_netdev || f->is_netdev)) |
| 1190 | return f; |
| 1191 | } |
| 1192 | return NULL; |
| 1193 | } |
| 1194 | |
| 1195 | /** |
| 1196 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1197 | * @vsi: the VSI to be searched |
| 1198 | * @macaddr: the MAC address we are searching for |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1199 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1200 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1201 | * |
| 1202 | * Returns the first filter with the provided MAC address or NULL if |
| 1203 | * MAC address was not found |
| 1204 | **/ |
| 1205 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr, |
| 1206 | bool is_vf, bool is_netdev) |
| 1207 | { |
| 1208 | struct i40e_mac_filter *f; |
| 1209 | |
| 1210 | if (!vsi || !macaddr) |
| 1211 | return NULL; |
| 1212 | |
| 1213 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1214 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1215 | (!is_vf || f->is_vf) && |
| 1216 | (!is_netdev || f->is_netdev)) |
| 1217 | return f; |
| 1218 | } |
| 1219 | return NULL; |
| 1220 | } |
| 1221 | |
| 1222 | /** |
| 1223 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1224 | * @vsi: the VSI to be searched |
| 1225 | * |
| 1226 | * Returns true if VSI is in vlan mode or false otherwise |
| 1227 | **/ |
| 1228 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1229 | { |
| 1230 | struct i40e_mac_filter *f; |
| 1231 | |
| 1232 | /* Only -1 for all the filters denotes not in vlan mode |
| 1233 | * so we have to go through all the list in order to make sure |
| 1234 | */ |
| 1235 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Greg Rose | d9b68f8 | 2015-07-23 16:54:31 -0400 | [diff] [blame] | 1236 | if (f->vlan >= 0 || vsi->info.pvid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1237 | return true; |
| 1238 | } |
| 1239 | |
| 1240 | return false; |
| 1241 | } |
| 1242 | |
| 1243 | /** |
| 1244 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1245 | * @vsi: the VSI to be searched |
| 1246 | * @macaddr: the mac address to be filtered |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1247 | * @is_vf: true if it is a VF |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1248 | * @is_netdev: true if it is a netdev |
| 1249 | * |
| 1250 | * Goes through all the macvlan filters and adds a |
| 1251 | * macvlan filter for each unique vlan that already exists |
| 1252 | * |
| 1253 | * Returns first filter found on success, else NULL |
| 1254 | **/ |
| 1255 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1256 | bool is_vf, bool is_netdev) |
| 1257 | { |
| 1258 | struct i40e_mac_filter *f; |
| 1259 | |
| 1260 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Mitch Williams | ecbb44e | 2015-07-10 19:35:56 -0400 | [diff] [blame] | 1261 | if (vsi->info.pvid) |
| 1262 | f->vlan = le16_to_cpu(vsi->info.pvid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1263 | if (!i40e_find_filter(vsi, macaddr, f->vlan, |
| 1264 | is_vf, is_netdev)) { |
| 1265 | if (!i40e_add_filter(vsi, macaddr, f->vlan, |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 1266 | is_vf, is_netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1267 | return NULL; |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | return list_first_entry_or_null(&vsi->mac_filter_list, |
| 1272 | struct i40e_mac_filter, list); |
| 1273 | } |
| 1274 | |
| 1275 | /** |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1276 | * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS |
| 1277 | * @vsi: the VSI to be searched |
| 1278 | * @macaddr: the mac address to be removed |
| 1279 | * @is_vf: true if it is a VF |
| 1280 | * @is_netdev: true if it is a netdev |
| 1281 | * |
| 1282 | * Removes a given MAC address from a VSI, regardless of VLAN |
| 1283 | * |
| 1284 | * Returns 0 for success, or error |
| 1285 | **/ |
| 1286 | int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1287 | bool is_vf, bool is_netdev) |
| 1288 | { |
| 1289 | struct i40e_mac_filter *f = NULL; |
| 1290 | int changed = 0; |
| 1291 | |
| 1292 | WARN(!spin_is_locked(&vsi->mac_filter_list_lock), |
| 1293 | "Missing mac_filter_list_lock\n"); |
| 1294 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1295 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1296 | (is_vf == f->is_vf) && |
| 1297 | (is_netdev == f->is_netdev)) { |
| 1298 | f->counter--; |
| 1299 | f->changed = true; |
| 1300 | changed = 1; |
| 1301 | } |
| 1302 | } |
| 1303 | if (changed) { |
| 1304 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1305 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1306 | return 0; |
| 1307 | } |
| 1308 | return -ENOENT; |
| 1309 | } |
| 1310 | |
| 1311 | /** |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1312 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM |
| 1313 | * @vsi: the PF Main VSI - inappropriate for any other VSI |
| 1314 | * @macaddr: the MAC address |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1315 | * |
| 1316 | * Some older firmware configurations set up a default promiscuous VLAN |
| 1317 | * filter that needs to be removed. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1318 | **/ |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1319 | 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] | 1320 | { |
| 1321 | struct i40e_aqc_remove_macvlan_element_data element; |
| 1322 | struct i40e_pf *pf = vsi->back; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1323 | i40e_status ret; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1324 | |
| 1325 | /* Only appropriate for the PF main VSI */ |
| 1326 | if (vsi->type != I40E_VSI_MAIN) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1327 | return -EINVAL; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1328 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1329 | memset(&element, 0, sizeof(element)); |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1330 | ether_addr_copy(element.mac_addr, macaddr); |
| 1331 | element.vlan_tag = 0; |
| 1332 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | |
| 1333 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1334 | ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1335 | if (ret) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1336 | return -ENOENT; |
| 1337 | |
| 1338 | return 0; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1342 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1343 | * @vsi: the VSI to be searched |
| 1344 | * @macaddr: the MAC address |
| 1345 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1346 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1347 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1348 | * |
| 1349 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1350 | * |
| 1351 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1352 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1353 | **/ |
| 1354 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
| 1355 | u8 *macaddr, s16 vlan, |
| 1356 | bool is_vf, bool is_netdev) |
| 1357 | { |
| 1358 | struct i40e_mac_filter *f; |
| 1359 | |
| 1360 | if (!vsi || !macaddr) |
| 1361 | return NULL; |
| 1362 | |
| 1363 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1364 | if (!f) { |
| 1365 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1366 | if (!f) |
| 1367 | goto add_filter_out; |
| 1368 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1369 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1370 | f->vlan = vlan; |
| 1371 | f->changed = true; |
| 1372 | |
| 1373 | INIT_LIST_HEAD(&f->list); |
Kiran Patil | 04d5a21 | 2015-12-09 15:50:23 -0800 | [diff] [blame] | 1374 | list_add_tail(&f->list, &vsi->mac_filter_list); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | /* increment counter and add a new flag if needed */ |
| 1378 | if (is_vf) { |
| 1379 | if (!f->is_vf) { |
| 1380 | f->is_vf = true; |
| 1381 | f->counter++; |
| 1382 | } |
| 1383 | } else if (is_netdev) { |
| 1384 | if (!f->is_netdev) { |
| 1385 | f->is_netdev = true; |
| 1386 | f->counter++; |
| 1387 | } |
| 1388 | } else { |
| 1389 | f->counter++; |
| 1390 | } |
| 1391 | |
| 1392 | /* changed tells sync_filters_subtask to |
| 1393 | * push the filter down to the firmware |
| 1394 | */ |
| 1395 | if (f->changed) { |
| 1396 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1397 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1398 | } |
| 1399 | |
| 1400 | add_filter_out: |
| 1401 | return f; |
| 1402 | } |
| 1403 | |
| 1404 | /** |
| 1405 | * i40e_del_filter - Remove a mac/vlan filter from the VSI |
| 1406 | * @vsi: the VSI to be searched |
| 1407 | * @macaddr: the MAC address |
| 1408 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1409 | * @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] | 1410 | * @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] | 1411 | * |
| 1412 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1413 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1414 | **/ |
| 1415 | void i40e_del_filter(struct i40e_vsi *vsi, |
| 1416 | u8 *macaddr, s16 vlan, |
| 1417 | bool is_vf, bool is_netdev) |
| 1418 | { |
| 1419 | struct i40e_mac_filter *f; |
| 1420 | |
| 1421 | if (!vsi || !macaddr) |
| 1422 | return; |
| 1423 | |
| 1424 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1425 | if (!f || f->counter == 0) |
| 1426 | return; |
| 1427 | |
| 1428 | if (is_vf) { |
| 1429 | if (f->is_vf) { |
| 1430 | f->is_vf = false; |
| 1431 | f->counter--; |
| 1432 | } |
| 1433 | } else if (is_netdev) { |
| 1434 | if (f->is_netdev) { |
| 1435 | f->is_netdev = false; |
| 1436 | f->counter--; |
| 1437 | } |
| 1438 | } else { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1439 | /* 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] | 1440 | int min_f = 0; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1441 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1442 | min_f += (f->is_vf ? 1 : 0); |
| 1443 | min_f += (f->is_netdev ? 1 : 0); |
| 1444 | |
| 1445 | if (f->counter > min_f) |
| 1446 | f->counter--; |
| 1447 | } |
| 1448 | |
| 1449 | /* counter == 0 tells sync_filters_subtask to |
| 1450 | * remove the filter from the firmware's list |
| 1451 | */ |
| 1452 | if (f->counter == 0) { |
| 1453 | f->changed = true; |
| 1454 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1455 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | /** |
| 1460 | * i40e_set_mac - NDO callback to set mac address |
| 1461 | * @netdev: network interface device structure |
| 1462 | * @p: pointer to an address structure |
| 1463 | * |
| 1464 | * Returns 0 on success, negative on failure |
| 1465 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1466 | #ifdef I40E_FCOE |
| 1467 | int i40e_set_mac(struct net_device *netdev, void *p) |
| 1468 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1469 | static int i40e_set_mac(struct net_device *netdev, void *p) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1470 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1471 | { |
| 1472 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1473 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1474 | struct i40e_pf *pf = vsi->back; |
| 1475 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1476 | struct sockaddr *addr = p; |
| 1477 | struct i40e_mac_filter *f; |
| 1478 | |
| 1479 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1480 | return -EADDRNOTAVAIL; |
| 1481 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1482 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1483 | netdev_info(netdev, "already using mac address %pM\n", |
| 1484 | addr->sa_data); |
| 1485 | return 0; |
| 1486 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1487 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1488 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1489 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1490 | return -EADDRNOTAVAIL; |
| 1491 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1492 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1493 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1494 | hw->mac.addr); |
| 1495 | else |
| 1496 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1497 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1498 | if (vsi->type == I40E_VSI_MAIN) { |
| 1499 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1500 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1501 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1502 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1503 | addr->sa_data, NULL); |
| 1504 | if (ret) { |
| 1505 | netdev_info(netdev, |
| 1506 | "Addr change for Main VSI failed: %d\n", |
| 1507 | ret); |
| 1508 | return -EADDRNOTAVAIL; |
| 1509 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1512 | if (ether_addr_equal(netdev->dev_addr, hw->mac.addr)) { |
| 1513 | struct i40e_aqc_remove_macvlan_element_data element; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1514 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1515 | memset(&element, 0, sizeof(element)); |
| 1516 | ether_addr_copy(element.mac_addr, netdev->dev_addr); |
| 1517 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1518 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1519 | } else { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1520 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1521 | i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 1522 | false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1523 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1526 | if (ether_addr_equal(addr->sa_data, hw->mac.addr)) { |
| 1527 | struct i40e_aqc_add_macvlan_element_data element; |
| 1528 | |
| 1529 | memset(&element, 0, sizeof(element)); |
| 1530 | ether_addr_copy(element.mac_addr, hw->mac.addr); |
| 1531 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 1532 | i40e_aq_add_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1533 | } else { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1534 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1535 | f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, |
| 1536 | false, false); |
| 1537 | if (f) |
| 1538 | f->is_laa = true; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1539 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1542 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1543 | |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1544 | /* schedule our worker thread which will take care of |
| 1545 | * applying the new filter changes |
| 1546 | */ |
| 1547 | i40e_service_event_schedule(vsi->back); |
| 1548 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | /** |
| 1552 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1553 | * @vsi: the VSI being setup |
| 1554 | * @ctxt: VSI context structure |
| 1555 | * @enabled_tc: Enabled TCs bitmap |
| 1556 | * @is_add: True if called before Add VSI |
| 1557 | * |
| 1558 | * Setup VSI queue mapping for enabled traffic classes. |
| 1559 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1560 | #ifdef I40E_FCOE |
| 1561 | void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1562 | struct i40e_vsi_context *ctxt, |
| 1563 | u8 enabled_tc, |
| 1564 | bool is_add) |
| 1565 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1566 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1567 | struct i40e_vsi_context *ctxt, |
| 1568 | u8 enabled_tc, |
| 1569 | bool is_add) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1570 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1571 | { |
| 1572 | struct i40e_pf *pf = vsi->back; |
| 1573 | u16 sections = 0; |
| 1574 | u8 netdev_tc = 0; |
| 1575 | u16 numtc = 0; |
| 1576 | u16 qcount; |
| 1577 | u8 offset; |
| 1578 | u16 qmap; |
| 1579 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1580 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1581 | |
| 1582 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1583 | offset = 0; |
| 1584 | |
| 1585 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1586 | /* Find numtc from enabled TC bitmap */ |
| 1587 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1588 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1589 | numtc++; |
| 1590 | } |
| 1591 | if (!numtc) { |
| 1592 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1593 | numtc = 1; |
| 1594 | } |
| 1595 | } else { |
| 1596 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1597 | numtc = 1; |
| 1598 | } |
| 1599 | |
| 1600 | vsi->tc_config.numtc = numtc; |
| 1601 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1602 | /* Number of queues per enabled TC */ |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1603 | /* In MFP case we can have a much lower count of MSIx |
| 1604 | * vectors available and so we need to lower the used |
| 1605 | * q count. |
| 1606 | */ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1607 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 1608 | qcount = min_t(int, vsi->alloc_queue_pairs, pf->num_lan_msix); |
| 1609 | else |
| 1610 | qcount = vsi->alloc_queue_pairs; |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1611 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1612 | 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] | 1613 | |
| 1614 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1615 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1616 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1617 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1618 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1619 | int pow, num_qps; |
| 1620 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1621 | switch (vsi->type) { |
| 1622 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1623 | qcount = min_t(int, pf->alloc_rss_size, |
| 1624 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1625 | break; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1626 | #ifdef I40E_FCOE |
| 1627 | case I40E_VSI_FCOE: |
| 1628 | qcount = num_tc_qps; |
| 1629 | break; |
| 1630 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1631 | case I40E_VSI_FDIR: |
| 1632 | case I40E_VSI_SRIOV: |
| 1633 | case I40E_VSI_VMDQ2: |
| 1634 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1635 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1636 | WARN_ON(i != 0); |
| 1637 | break; |
| 1638 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1639 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1640 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1641 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1642 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1643 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1644 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1645 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1646 | pow++; |
| 1647 | num_qps >>= 1; |
| 1648 | } |
| 1649 | |
| 1650 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1651 | qmap = |
| 1652 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1653 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1654 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1655 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1656 | } else { |
| 1657 | /* TC is not enabled so set the offset to |
| 1658 | * default queue and allocate one queue |
| 1659 | * for the given TC. |
| 1660 | */ |
| 1661 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1662 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1663 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1664 | |
| 1665 | qmap = 0; |
| 1666 | } |
| 1667 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1668 | } |
| 1669 | |
| 1670 | /* Set actual Tx/Rx queue pairs */ |
| 1671 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1672 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1673 | if (vsi->req_queue_pairs > 0) |
| 1674 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1675 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1676 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1677 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1678 | |
| 1679 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1680 | if (is_add) { |
| 1681 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1682 | |
| 1683 | ctxt->info.up_enable_bits = enabled_tc; |
| 1684 | } |
| 1685 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1686 | ctxt->info.mapping_flags |= |
| 1687 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1688 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1689 | ctxt->info.queue_mapping[i] = |
| 1690 | cpu_to_le16(vsi->base_queue + i); |
| 1691 | } else { |
| 1692 | ctxt->info.mapping_flags |= |
| 1693 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1694 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1695 | } |
| 1696 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1697 | } |
| 1698 | |
| 1699 | /** |
| 1700 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1701 | * @netdev: network interface device structure |
| 1702 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1703 | #ifdef I40E_FCOE |
| 1704 | void i40e_set_rx_mode(struct net_device *netdev) |
| 1705 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1706 | static void i40e_set_rx_mode(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1707 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1708 | { |
| 1709 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1710 | struct i40e_mac_filter *f, *ftmp; |
| 1711 | struct i40e_vsi *vsi = np->vsi; |
| 1712 | struct netdev_hw_addr *uca; |
| 1713 | struct netdev_hw_addr *mca; |
| 1714 | struct netdev_hw_addr *ha; |
| 1715 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1716 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1717 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1718 | /* add addr if not already in the filter list */ |
| 1719 | netdev_for_each_uc_addr(uca, netdev) { |
| 1720 | if (!i40e_find_mac(vsi, uca->addr, false, true)) { |
| 1721 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1722 | i40e_put_mac_in_vlan(vsi, uca->addr, |
| 1723 | false, true); |
| 1724 | else |
| 1725 | i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY, |
| 1726 | false, true); |
| 1727 | } |
| 1728 | } |
| 1729 | |
| 1730 | netdev_for_each_mc_addr(mca, netdev) { |
| 1731 | if (!i40e_find_mac(vsi, mca->addr, false, true)) { |
| 1732 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1733 | i40e_put_mac_in_vlan(vsi, mca->addr, |
| 1734 | false, true); |
| 1735 | else |
| 1736 | i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY, |
| 1737 | false, true); |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | /* remove filter if not in netdev list */ |
| 1742 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1743 | |
| 1744 | if (!f->is_netdev) |
| 1745 | continue; |
| 1746 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1747 | netdev_for_each_mc_addr(mca, netdev) |
| 1748 | if (ether_addr_equal(mca->addr, f->macaddr)) |
| 1749 | goto bottom_of_search_loop; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1750 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1751 | netdev_for_each_uc_addr(uca, netdev) |
| 1752 | if (ether_addr_equal(uca->addr, f->macaddr)) |
| 1753 | goto bottom_of_search_loop; |
| 1754 | |
| 1755 | for_each_dev_addr(netdev, ha) |
| 1756 | if (ether_addr_equal(ha->addr, f->macaddr)) |
| 1757 | goto bottom_of_search_loop; |
| 1758 | |
| 1759 | /* f->macaddr wasn't found in uc, mc, or ha list so delete it */ |
| 1760 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true); |
| 1761 | |
| 1762 | bottom_of_search_loop: |
| 1763 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1764 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1765 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1766 | |
| 1767 | /* check for other flag changes */ |
| 1768 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1769 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1770 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1771 | } |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1772 | |
| 1773 | /* schedule our worker thread which will take care of |
| 1774 | * applying the new filter changes |
| 1775 | */ |
| 1776 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | /** |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1780 | * i40e_mac_filter_entry_clone - Clones a MAC filter entry |
| 1781 | * @src: source MAC filter entry to be clones |
| 1782 | * |
| 1783 | * Returns the pointer to newly cloned MAC filter entry or NULL |
| 1784 | * in case of error |
| 1785 | **/ |
| 1786 | static struct i40e_mac_filter *i40e_mac_filter_entry_clone( |
| 1787 | struct i40e_mac_filter *src) |
| 1788 | { |
| 1789 | struct i40e_mac_filter *f; |
| 1790 | |
| 1791 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1792 | if (!f) |
| 1793 | return NULL; |
| 1794 | *f = *src; |
| 1795 | |
| 1796 | INIT_LIST_HEAD(&f->list); |
| 1797 | |
| 1798 | return f; |
| 1799 | } |
| 1800 | |
| 1801 | /** |
| 1802 | * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries |
| 1803 | * @vsi: pointer to vsi struct |
| 1804 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1805 | * those entries needs to be undone. |
| 1806 | * |
| 1807 | * MAC filter entries from list were slated to be removed from device. |
| 1808 | **/ |
| 1809 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1810 | struct list_head *from) |
| 1811 | { |
| 1812 | struct i40e_mac_filter *f, *ftmp; |
| 1813 | |
| 1814 | list_for_each_entry_safe(f, ftmp, from, list) { |
| 1815 | f->changed = true; |
| 1816 | /* Move the element back into MAC filter list*/ |
| 1817 | list_move_tail(&f->list, &vsi->mac_filter_list); |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | /** |
| 1822 | * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries |
| 1823 | * @vsi: pointer to vsi struct |
| 1824 | * |
| 1825 | * MAC filter entries from list were slated to be added from device. |
| 1826 | **/ |
| 1827 | static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi) |
| 1828 | { |
| 1829 | struct i40e_mac_filter *f, *ftmp; |
| 1830 | |
| 1831 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1832 | if (!f->changed && f->counter) |
| 1833 | f->changed = true; |
| 1834 | } |
| 1835 | } |
| 1836 | |
| 1837 | /** |
| 1838 | * i40e_cleanup_add_list - Deletes the element from add list and release |
| 1839 | * memory |
| 1840 | * @add_list: Pointer to list which contains MAC filter entries |
| 1841 | **/ |
| 1842 | static void i40e_cleanup_add_list(struct list_head *add_list) |
| 1843 | { |
| 1844 | struct i40e_mac_filter *f, *ftmp; |
| 1845 | |
| 1846 | list_for_each_entry_safe(f, ftmp, add_list, list) { |
| 1847 | list_del(&f->list); |
| 1848 | kfree(f); |
| 1849 | } |
| 1850 | } |
| 1851 | |
| 1852 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1853 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1854 | * @vsi: ptr to the VSI |
| 1855 | * |
| 1856 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1857 | * |
| 1858 | * Returns 0 or error value |
| 1859 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 1860 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1861 | { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1862 | struct list_head tmp_del_list, tmp_add_list; |
| 1863 | struct i40e_mac_filter *f, *ftmp, *fclone; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1864 | bool promisc_forced_on = false; |
| 1865 | bool add_happened = false; |
| 1866 | int filter_list_len = 0; |
| 1867 | u32 changed_flags = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1868 | i40e_status aq_ret = 0; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1869 | bool err_cond = false; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1870 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1871 | struct i40e_pf *pf; |
| 1872 | int num_add = 0; |
| 1873 | int num_del = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1874 | int aq_err = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1875 | u16 cmd_flags; |
| 1876 | |
| 1877 | /* empty array typed pointers, kcalloc later */ |
| 1878 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1879 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1880 | |
| 1881 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1882 | usleep_range(1000, 2000); |
| 1883 | pf = vsi->back; |
| 1884 | |
| 1885 | if (vsi->netdev) { |
| 1886 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1887 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1888 | } |
| 1889 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1890 | INIT_LIST_HEAD(&tmp_del_list); |
| 1891 | INIT_LIST_HEAD(&tmp_add_list); |
| 1892 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1893 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1894 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1895 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1896 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1897 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1898 | if (!f->changed) |
| 1899 | continue; |
| 1900 | |
| 1901 | if (f->counter != 0) |
| 1902 | continue; |
| 1903 | f->changed = false; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1904 | |
| 1905 | /* Move the element into temporary del_list */ |
| 1906 | list_move_tail(&f->list, &tmp_del_list); |
| 1907 | } |
| 1908 | |
| 1909 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1910 | if (!f->changed) |
| 1911 | continue; |
| 1912 | |
| 1913 | if (f->counter == 0) |
| 1914 | continue; |
| 1915 | f->changed = false; |
| 1916 | |
| 1917 | /* Clone MAC filter entry and add into temporary list */ |
| 1918 | fclone = i40e_mac_filter_entry_clone(f); |
| 1919 | if (!fclone) { |
| 1920 | err_cond = true; |
| 1921 | break; |
| 1922 | } |
| 1923 | list_add_tail(&fclone->list, &tmp_add_list); |
| 1924 | } |
| 1925 | |
| 1926 | /* if failed to clone MAC filter entry - undo */ |
| 1927 | if (err_cond) { |
| 1928 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 1929 | i40e_undo_add_filter_entries(vsi); |
| 1930 | } |
| 1931 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 1932 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1933 | if (err_cond) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1934 | i40e_cleanup_add_list(&tmp_add_list); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1935 | retval = -ENOMEM; |
| 1936 | goto out; |
| 1937 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | /* Now process 'del_list' outside the lock */ |
| 1941 | if (!list_empty(&tmp_del_list)) { |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1942 | int del_list_size; |
| 1943 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1944 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 1945 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1946 | del_list_size = filter_list_len * |
| 1947 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Jesse Brandeburg | 38c3cec | 2016-01-04 10:33:05 -0800 | [diff] [blame] | 1948 | del_list = kzalloc(del_list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1949 | if (!del_list) { |
| 1950 | i40e_cleanup_add_list(&tmp_add_list); |
| 1951 | |
| 1952 | /* Undo VSI's MAC filter entry element updates */ |
| 1953 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1954 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 1955 | i40e_undo_add_filter_entries(vsi); |
| 1956 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1957 | retval = -ENOMEM; |
| 1958 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1962 | cmd_flags = 0; |
| 1963 | |
| 1964 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1965 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1966 | del_list[num_del].vlan_tag = |
| 1967 | cpu_to_le16((u16)(f->vlan == |
| 1968 | I40E_VLAN_ANY ? 0 : f->vlan)); |
| 1969 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1970 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1971 | del_list[num_del].flags = cmd_flags; |
| 1972 | num_del++; |
| 1973 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1974 | /* flush a full buffer */ |
| 1975 | if (num_del == filter_list_len) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1976 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, |
| 1977 | vsi->seid, |
| 1978 | del_list, |
| 1979 | num_del, |
| 1980 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1981 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1982 | num_del = 0; |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1983 | memset(del_list, 0, del_list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1984 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1985 | if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) { |
| 1986 | retval = -EIO; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1987 | dev_err(&pf->pdev->dev, |
| 1988 | "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] | 1989 | i40e_stat_str(&pf->hw, aq_ret), |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1990 | i40e_aq_str(&pf->hw, aq_err)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1991 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1992 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1993 | /* Release memory for MAC filter entries which were |
| 1994 | * synced up with HW. |
| 1995 | */ |
| 1996 | list_del(&f->list); |
| 1997 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1998 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1999 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2000 | if (num_del) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2001 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, |
| 2002 | del_list, num_del, |
| 2003 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2004 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2005 | num_del = 0; |
| 2006 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2007 | if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2008 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2009 | "ignoring delete macvlan error, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2010 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2011 | i40e_aq_str(&pf->hw, aq_err)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | kfree(del_list); |
| 2015 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | if (!list_empty(&tmp_add_list)) { |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2019 | int add_list_size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2020 | |
| 2021 | /* do all the adds now */ |
| 2022 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 2023 | sizeof(struct i40e_aqc_add_macvlan_element_data), |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2024 | add_list_size = filter_list_len * |
| 2025 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Jesse Brandeburg | 38c3cec | 2016-01-04 10:33:05 -0800 | [diff] [blame] | 2026 | add_list = kzalloc(add_list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2027 | if (!add_list) { |
| 2028 | /* Purge element from temporary lists */ |
| 2029 | i40e_cleanup_add_list(&tmp_add_list); |
| 2030 | |
| 2031 | /* Undo add filter entries from VSI MAC filter list */ |
| 2032 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2033 | i40e_undo_add_filter_entries(vsi); |
| 2034 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2035 | retval = -ENOMEM; |
| 2036 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2037 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2038 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2039 | list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2040 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2041 | add_happened = true; |
| 2042 | cmd_flags = 0; |
| 2043 | |
| 2044 | /* add to add array */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2045 | ether_addr_copy(add_list[num_add].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2046 | add_list[num_add].vlan_tag = |
| 2047 | cpu_to_le16( |
| 2048 | (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan)); |
| 2049 | add_list[num_add].queue_number = 0; |
| 2050 | |
| 2051 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2052 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2053 | num_add++; |
| 2054 | |
| 2055 | /* flush a full buffer */ |
| 2056 | if (num_add == filter_list_len) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2057 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 2058 | add_list, num_add, |
| 2059 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2060 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2061 | num_add = 0; |
| 2062 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2063 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2064 | break; |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2065 | memset(add_list, 0, add_list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2066 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2067 | /* Entries from tmp_add_list were cloned from MAC |
| 2068 | * filter list, hence clean those cloned entries |
| 2069 | */ |
| 2070 | list_del(&f->list); |
| 2071 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2072 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2073 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2074 | if (num_add) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2075 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 2076 | add_list, num_add, NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2077 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2078 | num_add = 0; |
| 2079 | } |
| 2080 | kfree(add_list); |
| 2081 | add_list = NULL; |
| 2082 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2083 | if (add_happened && aq_ret && aq_err != I40E_AQ_RC_EINVAL) { |
| 2084 | retval = i40e_aq_rc_to_posix(aq_ret, aq_err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2085 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2086 | "add filter failed, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2087 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2088 | i40e_aq_str(&pf->hw, aq_err)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2089 | if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) && |
| 2090 | !test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2091 | &vsi->state)) { |
| 2092 | promisc_forced_on = true; |
| 2093 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2094 | &vsi->state); |
| 2095 | dev_info(&pf->pdev->dev, "promiscuous mode forced on\n"); |
| 2096 | } |
| 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | /* check for changes in promiscuous modes */ |
| 2101 | if (changed_flags & IFF_ALLMULTI) { |
| 2102 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2103 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2104 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2105 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2106 | vsi->seid, |
| 2107 | cur_multipromisc, |
| 2108 | NULL); |
| 2109 | if (aq_ret) { |
| 2110 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2111 | pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2112 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2113 | "set multi promisc failed, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2114 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2115 | i40e_aq_str(&pf->hw, |
| 2116 | pf->hw.aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2117 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2118 | } |
| 2119 | if ((changed_flags & IFF_PROMISC) || promisc_forced_on) { |
| 2120 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2121 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2122 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 2123 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2124 | &vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2125 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2126 | (pf->lan_veb != I40E_NO_VEB) && |
| 2127 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2128 | /* set defport ON for Main VSI instead of true promisc |
| 2129 | * this way we will get all unicast/multicast and VLAN |
| 2130 | * promisc behavior but will not get VF or VMDq traffic |
| 2131 | * replicated on the Main VSI. |
| 2132 | */ |
| 2133 | if (pf->cur_promisc != cur_promisc) { |
| 2134 | pf->cur_promisc = cur_promisc; |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2135 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2136 | } |
| 2137 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2138 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2139 | &vsi->back->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2140 | vsi->seid, |
| 2141 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2142 | if (aq_ret) { |
| 2143 | retval = |
| 2144 | i40e_aq_rc_to_posix(aq_ret, |
| 2145 | pf->hw.aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2146 | dev_info(&pf->pdev->dev, |
| 2147 | "set unicast promisc failed, err %d, aq_err %d\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2148 | aq_ret, pf->hw.aq.asq_last_status); |
| 2149 | } |
| 2150 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2151 | &vsi->back->hw, |
| 2152 | vsi->seid, |
| 2153 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2154 | if (aq_ret) { |
| 2155 | retval = |
| 2156 | i40e_aq_rc_to_posix(aq_ret, |
| 2157 | pf->hw.aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2158 | dev_info(&pf->pdev->dev, |
| 2159 | "set multicast promisc failed, err %d, aq_err %d\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2160 | aq_ret, pf->hw.aq.asq_last_status); |
| 2161 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2162 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2163 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2164 | vsi->seid, |
| 2165 | cur_promisc, NULL); |
| 2166 | if (aq_ret) { |
| 2167 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2168 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2169 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2170 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2171 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2172 | i40e_aq_str(&pf->hw, |
| 2173 | pf->hw.aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2174 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2175 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2176 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2177 | /* if something went wrong then set the changed flag so we try again */ |
| 2178 | if (retval) |
| 2179 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2180 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2181 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2182 | return retval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | /** |
| 2186 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2187 | * @pf: board private structure |
| 2188 | **/ |
| 2189 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2190 | { |
| 2191 | int v; |
| 2192 | |
| 2193 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2194 | return; |
| 2195 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2196 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2197 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2198 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2199 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2200 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2201 | |
| 2202 | if (ret) { |
| 2203 | /* come back and try again later */ |
| 2204 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2205 | break; |
| 2206 | } |
| 2207 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | /** |
| 2212 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2213 | * @netdev: network interface device structure |
| 2214 | * @new_mtu: new value for maximum frame size |
| 2215 | * |
| 2216 | * Returns 0 on success, negative on failure |
| 2217 | **/ |
| 2218 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2219 | { |
| 2220 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 61a46a4 | 2014-04-23 04:50:05 +0000 | [diff] [blame] | 2221 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2222 | struct i40e_vsi *vsi = np->vsi; |
| 2223 | |
| 2224 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 2225 | if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) |
| 2226 | return -EINVAL; |
| 2227 | |
| 2228 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2229 | netdev->mtu, new_mtu); |
| 2230 | netdev->mtu = new_mtu; |
| 2231 | if (netif_running(netdev)) |
| 2232 | i40e_vsi_reinit_locked(vsi); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 2233 | i40e_notify_client_of_l2_param_changes(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2234 | return 0; |
| 2235 | } |
| 2236 | |
| 2237 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2238 | * i40e_ioctl - Access the hwtstamp interface |
| 2239 | * @netdev: network interface device structure |
| 2240 | * @ifr: interface request data |
| 2241 | * @cmd: ioctl command |
| 2242 | **/ |
| 2243 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2244 | { |
| 2245 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2246 | struct i40e_pf *pf = np->vsi->back; |
| 2247 | |
| 2248 | switch (cmd) { |
| 2249 | case SIOCGHWTSTAMP: |
| 2250 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2251 | case SIOCSHWTSTAMP: |
| 2252 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2253 | default: |
| 2254 | return -EOPNOTSUPP; |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2259 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2260 | * @vsi: the vsi being adjusted |
| 2261 | **/ |
| 2262 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2263 | { |
| 2264 | struct i40e_vsi_context ctxt; |
| 2265 | i40e_status ret; |
| 2266 | |
| 2267 | if ((vsi->info.valid_sections & |
| 2268 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2269 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2270 | return; /* already enabled */ |
| 2271 | |
| 2272 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2273 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2274 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2275 | |
| 2276 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2277 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2278 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2279 | if (ret) { |
| 2280 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2281 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2282 | i40e_stat_str(&vsi->back->hw, ret), |
| 2283 | i40e_aq_str(&vsi->back->hw, |
| 2284 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | /** |
| 2289 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2290 | * @vsi: the vsi being adjusted |
| 2291 | **/ |
| 2292 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2293 | { |
| 2294 | struct i40e_vsi_context ctxt; |
| 2295 | i40e_status ret; |
| 2296 | |
| 2297 | if ((vsi->info.valid_sections & |
| 2298 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2299 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2300 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2301 | return; /* already disabled */ |
| 2302 | |
| 2303 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2304 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2305 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2306 | |
| 2307 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2308 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2309 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2310 | if (ret) { |
| 2311 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2312 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2313 | i40e_stat_str(&vsi->back->hw, ret), |
| 2314 | i40e_aq_str(&vsi->back->hw, |
| 2315 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2316 | } |
| 2317 | } |
| 2318 | |
| 2319 | /** |
| 2320 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2321 | * @netdev: network interface to be adjusted |
| 2322 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2323 | **/ |
| 2324 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2325 | { |
| 2326 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2327 | struct i40e_vsi *vsi = np->vsi; |
| 2328 | |
| 2329 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2330 | i40e_vlan_stripping_enable(vsi); |
| 2331 | else |
| 2332 | i40e_vlan_stripping_disable(vsi); |
| 2333 | } |
| 2334 | |
| 2335 | /** |
| 2336 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 2337 | * @vsi: the vsi being configured |
| 2338 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 2339 | **/ |
| 2340 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2341 | { |
| 2342 | struct i40e_mac_filter *f, *add_f; |
| 2343 | bool is_netdev, is_vf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2344 | |
| 2345 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2346 | is_netdev = !!(vsi->netdev); |
| 2347 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2348 | /* Locked once because all functions invoked below iterates list*/ |
| 2349 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2350 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2351 | if (is_netdev) { |
| 2352 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid, |
| 2353 | is_vf, is_netdev); |
| 2354 | if (!add_f) { |
| 2355 | dev_info(&vsi->back->pdev->dev, |
| 2356 | "Could not add vlan filter %d for %pM\n", |
| 2357 | vid, vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2358 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2359 | return -ENOMEM; |
| 2360 | } |
| 2361 | } |
| 2362 | |
| 2363 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2364 | add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2365 | if (!add_f) { |
| 2366 | dev_info(&vsi->back->pdev->dev, |
| 2367 | "Could not add vlan filter %d for %pM\n", |
| 2368 | vid, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2369 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2370 | return -ENOMEM; |
| 2371 | } |
| 2372 | } |
| 2373 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2374 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 2375 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 2376 | * with 0, so we now accept untagged and specified tagged traffic |
| 2377 | * (and not any taged and untagged) |
| 2378 | */ |
| 2379 | if (vid > 0) { |
| 2380 | if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 2381 | I40E_VLAN_ANY, |
| 2382 | is_vf, is_netdev)) { |
| 2383 | i40e_del_filter(vsi, vsi->netdev->dev_addr, |
| 2384 | I40E_VLAN_ANY, is_vf, is_netdev); |
| 2385 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0, |
| 2386 | is_vf, is_netdev); |
| 2387 | if (!add_f) { |
| 2388 | dev_info(&vsi->back->pdev->dev, |
| 2389 | "Could not add filter 0 for %pM\n", |
| 2390 | vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2391 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2392 | return -ENOMEM; |
| 2393 | } |
| 2394 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2395 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2396 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2397 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
| 2398 | if (vid > 0 && !vsi->info.pvid) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2399 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2400 | if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2401 | is_vf, is_netdev)) |
| 2402 | continue; |
| 2403 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2404 | is_vf, is_netdev); |
| 2405 | add_f = i40e_add_filter(vsi, f->macaddr, |
| 2406 | 0, is_vf, is_netdev); |
| 2407 | if (!add_f) { |
| 2408 | dev_info(&vsi->back->pdev->dev, |
| 2409 | "Could not add filter 0 for %pM\n", |
| 2410 | f->macaddr); |
| 2411 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2412 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2413 | } |
| 2414 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2417 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2418 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2419 | /* schedule our worker thread which will take care of |
| 2420 | * applying the new filter changes |
| 2421 | */ |
| 2422 | i40e_service_event_schedule(vsi->back); |
| 2423 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | /** |
| 2427 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 2428 | * @vsi: the vsi being configured |
| 2429 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2430 | * |
| 2431 | * Return: 0 on success or negative otherwise |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2432 | **/ |
| 2433 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2434 | { |
| 2435 | struct net_device *netdev = vsi->netdev; |
| 2436 | struct i40e_mac_filter *f, *add_f; |
| 2437 | bool is_vf, is_netdev; |
| 2438 | int filter_count = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2439 | |
| 2440 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2441 | is_netdev = !!(netdev); |
| 2442 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2443 | /* Locked once because all functions invoked below iterates list */ |
| 2444 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2445 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2446 | if (is_netdev) |
| 2447 | i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev); |
| 2448 | |
| 2449 | list_for_each_entry(f, &vsi->mac_filter_list, list) |
| 2450 | i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2451 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2452 | /* go through all the filters for this VSI and if there is only |
| 2453 | * vid == 0 it means there are no other filters, so vid 0 must |
| 2454 | * be replaced with -1. This signifies that we should from now |
| 2455 | * on accept any traffic (with any tag present, or untagged) |
| 2456 | */ |
| 2457 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2458 | if (is_netdev) { |
| 2459 | if (f->vlan && |
| 2460 | ether_addr_equal(netdev->dev_addr, f->macaddr)) |
| 2461 | filter_count++; |
| 2462 | } |
| 2463 | |
| 2464 | if (f->vlan) |
| 2465 | filter_count++; |
| 2466 | } |
| 2467 | |
| 2468 | if (!filter_count && is_netdev) { |
| 2469 | i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev); |
| 2470 | f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 2471 | is_vf, is_netdev); |
| 2472 | if (!f) { |
| 2473 | dev_info(&vsi->back->pdev->dev, |
| 2474 | "Could not add filter %d for %pM\n", |
| 2475 | I40E_VLAN_ANY, netdev->dev_addr); |
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 | if (!filter_count) { |
| 2482 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2483 | i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev); |
| 2484 | add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2485 | is_vf, is_netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2486 | if (!add_f) { |
| 2487 | dev_info(&vsi->back->pdev->dev, |
| 2488 | "Could not add filter %d for %pM\n", |
| 2489 | I40E_VLAN_ANY, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2490 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2491 | return -ENOMEM; |
| 2492 | } |
| 2493 | } |
| 2494 | } |
| 2495 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2496 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2497 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2498 | /* schedule our worker thread which will take care of |
| 2499 | * applying the new filter changes |
| 2500 | */ |
| 2501 | i40e_service_event_schedule(vsi->back); |
| 2502 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | /** |
| 2506 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2507 | * @netdev: network interface to be adjusted |
| 2508 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2509 | * |
| 2510 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2511 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2512 | #ifdef I40E_FCOE |
| 2513 | int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2514 | __always_unused __be16 proto, u16 vid) |
| 2515 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2516 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2517 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2518 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2519 | { |
| 2520 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2521 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2522 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2523 | |
| 2524 | if (vid > 4095) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2525 | return -EINVAL; |
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 | netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid); |
| 2528 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2529 | /* If the network stack called us with vid = 0 then |
| 2530 | * it is asking to receive priority tagged packets with |
| 2531 | * vlan id 0. Our HW receives them by default when configured |
| 2532 | * to receive untagged packets so there is no need to add an |
| 2533 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2534 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2535 | if (vid) |
| 2536 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2537 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2538 | if (!ret && (vid < VLAN_N_VID)) |
| 2539 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2540 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2541 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | /** |
| 2545 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2546 | * @netdev: network interface to be adjusted |
| 2547 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2548 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2549 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2550 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2551 | #ifdef I40E_FCOE |
| 2552 | int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2553 | __always_unused __be16 proto, u16 vid) |
| 2554 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2555 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2556 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2557 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2558 | { |
| 2559 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2560 | struct i40e_vsi *vsi = np->vsi; |
| 2561 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2562 | netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid); |
| 2563 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2564 | /* return code is ignored as there is nothing a user |
| 2565 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2566 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2567 | */ |
| 2568 | i40e_vsi_kill_vlan(vsi, vid); |
| 2569 | |
| 2570 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2571 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2572 | return 0; |
| 2573 | } |
| 2574 | |
| 2575 | /** |
| 2576 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2577 | * @vsi: the vsi being brought back up |
| 2578 | **/ |
| 2579 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2580 | { |
| 2581 | u16 vid; |
| 2582 | |
| 2583 | if (!vsi->netdev) |
| 2584 | return; |
| 2585 | |
| 2586 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2587 | |
| 2588 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2589 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2590 | vid); |
| 2591 | } |
| 2592 | |
| 2593 | /** |
| 2594 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2595 | * @vsi: the vsi being adjusted |
| 2596 | * @vid: the vlan id to set as a PVID |
| 2597 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2598 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2599 | { |
| 2600 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2601 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2602 | |
| 2603 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2604 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2605 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2606 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2607 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2608 | |
| 2609 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2610 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2611 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2612 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2613 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2614 | "add pvid failed, err %s aq_err %s\n", |
| 2615 | i40e_stat_str(&vsi->back->hw, ret), |
| 2616 | i40e_aq_str(&vsi->back->hw, |
| 2617 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2618 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2619 | } |
| 2620 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2621 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | /** |
| 2625 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2626 | * @vsi: the vsi being adjusted |
| 2627 | * |
| 2628 | * Just use the vlan_rx_register() service to put it back to normal |
| 2629 | **/ |
| 2630 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2631 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2632 | i40e_vlan_stripping_disable(vsi); |
| 2633 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2634 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | /** |
| 2638 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2639 | * @vsi: ptr to the VSI |
| 2640 | * |
| 2641 | * If this function returns with an error, then it's possible one or |
| 2642 | * more of the rings is populated (while the rest are not). It is the |
| 2643 | * callers duty to clean those orphaned rings. |
| 2644 | * |
| 2645 | * Return 0 on success, negative on failure |
| 2646 | **/ |
| 2647 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2648 | { |
| 2649 | int i, err = 0; |
| 2650 | |
| 2651 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2652 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2653 | |
| 2654 | return err; |
| 2655 | } |
| 2656 | |
| 2657 | /** |
| 2658 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2659 | * @vsi: ptr to the VSI |
| 2660 | * |
| 2661 | * Free VSI's transmit software resources |
| 2662 | **/ |
| 2663 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2664 | { |
| 2665 | int i; |
| 2666 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2667 | if (!vsi->tx_rings) |
| 2668 | return; |
| 2669 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2670 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2671 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2672 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | /** |
| 2676 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2677 | * @vsi: ptr to the VSI |
| 2678 | * |
| 2679 | * If this function returns with an error, then it's possible one or |
| 2680 | * more of the rings is populated (while the rest are not). It is the |
| 2681 | * callers duty to clean those orphaned rings. |
| 2682 | * |
| 2683 | * Return 0 on success, negative on failure |
| 2684 | **/ |
| 2685 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2686 | { |
| 2687 | int i, err = 0; |
| 2688 | |
| 2689 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2690 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2691 | #ifdef I40E_FCOE |
| 2692 | i40e_fcoe_setup_ddp_resources(vsi); |
| 2693 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2694 | return err; |
| 2695 | } |
| 2696 | |
| 2697 | /** |
| 2698 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2699 | * @vsi: ptr to the VSI |
| 2700 | * |
| 2701 | * Free all receive software resources |
| 2702 | **/ |
| 2703 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2704 | { |
| 2705 | int i; |
| 2706 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2707 | if (!vsi->rx_rings) |
| 2708 | return; |
| 2709 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2710 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2711 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2712 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2713 | #ifdef I40E_FCOE |
| 2714 | i40e_fcoe_free_ddp_resources(vsi); |
| 2715 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2719 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2720 | * @ring: The Tx ring to configure |
| 2721 | * |
| 2722 | * This enables/disables XPS for a given Tx descriptor ring |
| 2723 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2724 | **/ |
| 2725 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2726 | { |
| 2727 | struct i40e_vsi *vsi = ring->vsi; |
| 2728 | cpumask_var_t mask; |
| 2729 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2730 | if (!ring->q_vector || !ring->netdev) |
| 2731 | return; |
| 2732 | |
| 2733 | /* Single TC mode enable XPS */ |
| 2734 | if (vsi->tc_config.numtc <= 1) { |
| 2735 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2736 | netif_set_xps_queue(ring->netdev, |
| 2737 | &ring->q_vector->affinity_mask, |
| 2738 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2739 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2740 | /* Disable XPS to allow selection based on TC */ |
| 2741 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2742 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2743 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2744 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2745 | |
| 2746 | /* schedule our worker thread which will take care of |
| 2747 | * applying the new filter changes |
| 2748 | */ |
| 2749 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2753 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2754 | * @ring: The Tx ring to configure |
| 2755 | * |
| 2756 | * Configure the Tx descriptor ring in the HMC context. |
| 2757 | **/ |
| 2758 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2759 | { |
| 2760 | struct i40e_vsi *vsi = ring->vsi; |
| 2761 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2762 | struct i40e_hw *hw = &vsi->back->hw; |
| 2763 | struct i40e_hmc_obj_txq tx_ctx; |
| 2764 | i40e_status err = 0; |
| 2765 | u32 qtx_ctl = 0; |
| 2766 | |
| 2767 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2768 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2769 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2770 | ring->atr_count = 0; |
| 2771 | } else { |
| 2772 | ring->atr_sample_rate = 0; |
| 2773 | } |
| 2774 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2775 | /* configure XPS */ |
| 2776 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2777 | |
| 2778 | /* clear the context structure first */ |
| 2779 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2780 | |
| 2781 | tx_ctx.new_context = 1; |
| 2782 | tx_ctx.base = (ring->dma / 128); |
| 2783 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2784 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2785 | I40E_FLAG_FD_ATR_ENABLED)); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2786 | #ifdef I40E_FCOE |
| 2787 | tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2788 | #endif |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2789 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2790 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2791 | if (vsi->type != I40E_VSI_FDIR) |
| 2792 | tx_ctx.head_wb_ena = 1; |
| 2793 | tx_ctx.head_wb_addr = ring->dma + |
| 2794 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2795 | |
| 2796 | /* As part of VSI creation/update, FW allocates certain |
| 2797 | * Tx arbitration queue sets for each TC enabled for |
| 2798 | * the VSI. The FW returns the handles to these queue |
| 2799 | * sets as part of the response buffer to Add VSI, |
| 2800 | * Update VSI, etc. AQ commands. It is expected that |
| 2801 | * these queue set handles be associated with the Tx |
| 2802 | * queues by the driver as part of the TX queue context |
| 2803 | * initialization. This has to be done regardless of |
| 2804 | * DCB as by default everything is mapped to TC0. |
| 2805 | */ |
| 2806 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2807 | tx_ctx.rdylist_act = 0; |
| 2808 | |
| 2809 | /* clear the context in the HMC */ |
| 2810 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2811 | if (err) { |
| 2812 | dev_info(&vsi->back->pdev->dev, |
| 2813 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2814 | ring->queue_index, pf_q, err); |
| 2815 | return -ENOMEM; |
| 2816 | } |
| 2817 | |
| 2818 | /* set the context in the HMC */ |
| 2819 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2820 | if (err) { |
| 2821 | dev_info(&vsi->back->pdev->dev, |
| 2822 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2823 | ring->queue_index, pf_q, err); |
| 2824 | return -ENOMEM; |
| 2825 | } |
| 2826 | |
| 2827 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2828 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2829 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2830 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2831 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2832 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2833 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2834 | } |
| 2835 | |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2836 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2837 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2838 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2839 | i40e_flush(hw); |
| 2840 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2841 | /* cache tail off for easier writes later */ |
| 2842 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2843 | |
| 2844 | return 0; |
| 2845 | } |
| 2846 | |
| 2847 | /** |
| 2848 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2849 | * @ring: The Rx ring to configure |
| 2850 | * |
| 2851 | * Configure the Rx descriptor ring in the HMC context. |
| 2852 | **/ |
| 2853 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2854 | { |
| 2855 | struct i40e_vsi *vsi = ring->vsi; |
| 2856 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2857 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2858 | struct i40e_hw *hw = &vsi->back->hw; |
| 2859 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2860 | i40e_status err = 0; |
| 2861 | |
| 2862 | ring->state = 0; |
| 2863 | |
| 2864 | /* clear the context structure first */ |
| 2865 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2866 | |
| 2867 | ring->rx_buf_len = vsi->rx_buf_len; |
| 2868 | ring->rx_hdr_len = vsi->rx_hdr_len; |
| 2869 | |
| 2870 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
| 2871 | rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT; |
| 2872 | |
| 2873 | rx_ctx.base = (ring->dma / 128); |
| 2874 | rx_ctx.qlen = ring->count; |
| 2875 | |
| 2876 | if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) { |
| 2877 | set_ring_16byte_desc_enabled(ring); |
| 2878 | rx_ctx.dsize = 0; |
| 2879 | } else { |
| 2880 | rx_ctx.dsize = 1; |
| 2881 | } |
| 2882 | |
| 2883 | rx_ctx.dtype = vsi->dtype; |
| 2884 | if (vsi->dtype) { |
| 2885 | set_ring_ps_enabled(ring); |
| 2886 | rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 | |
| 2887 | I40E_RX_SPLIT_IP | |
| 2888 | I40E_RX_SPLIT_TCP_UDP | |
| 2889 | I40E_RX_SPLIT_SCTP; |
| 2890 | } else { |
| 2891 | rx_ctx.hsplit_0 = 0; |
| 2892 | } |
| 2893 | |
| 2894 | rx_ctx.rxmax = min_t(u16, vsi->max_frame, |
| 2895 | (chain_len * ring->rx_buf_len)); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 2896 | if (hw->revision_id == 0) |
| 2897 | rx_ctx.lrxqthresh = 0; |
| 2898 | else |
| 2899 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2900 | rx_ctx.crcstrip = 1; |
| 2901 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 2902 | /* this controls whether VLAN is stripped from inner headers */ |
| 2903 | rx_ctx.showiv = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2904 | #ifdef I40E_FCOE |
| 2905 | rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2906 | #endif |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 2907 | /* set the prefena field to 1 because the manual says to */ |
| 2908 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2909 | |
| 2910 | /* clear the context in the HMC */ |
| 2911 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 2912 | if (err) { |
| 2913 | dev_info(&vsi->back->pdev->dev, |
| 2914 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2915 | ring->queue_index, pf_q, err); |
| 2916 | return -ENOMEM; |
| 2917 | } |
| 2918 | |
| 2919 | /* set the context in the HMC */ |
| 2920 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 2921 | if (err) { |
| 2922 | dev_info(&vsi->back->pdev->dev, |
| 2923 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2924 | ring->queue_index, pf_q, err); |
| 2925 | return -ENOMEM; |
| 2926 | } |
| 2927 | |
| 2928 | /* cache tail for quicker writes, and clear the reg before use */ |
| 2929 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 2930 | writel(0, ring->tail); |
| 2931 | |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 2932 | if (ring_is_ps_enabled(ring)) { |
| 2933 | i40e_alloc_rx_headers(ring); |
| 2934 | i40e_alloc_rx_buffers_ps(ring, I40E_DESC_UNUSED(ring)); |
| 2935 | } else { |
| 2936 | i40e_alloc_rx_buffers_1buf(ring, I40E_DESC_UNUSED(ring)); |
| 2937 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2938 | |
| 2939 | return 0; |
| 2940 | } |
| 2941 | |
| 2942 | /** |
| 2943 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 2944 | * @vsi: VSI structure describing this set of rings and resources |
| 2945 | * |
| 2946 | * Configure the Tx VSI for operation. |
| 2947 | **/ |
| 2948 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 2949 | { |
| 2950 | int err = 0; |
| 2951 | u16 i; |
| 2952 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2953 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 2954 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2955 | |
| 2956 | return err; |
| 2957 | } |
| 2958 | |
| 2959 | /** |
| 2960 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 2961 | * @vsi: the VSI being configured |
| 2962 | * |
| 2963 | * Configure the Rx VSI for operation. |
| 2964 | **/ |
| 2965 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 2966 | { |
| 2967 | int err = 0; |
| 2968 | u16 i; |
| 2969 | |
| 2970 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 2971 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 2972 | + ETH_FCS_LEN + VLAN_HLEN; |
| 2973 | else |
| 2974 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 2975 | |
| 2976 | /* figure out correct receive buffer length */ |
| 2977 | switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED | |
| 2978 | I40E_FLAG_RX_PS_ENABLED)) { |
| 2979 | case I40E_FLAG_RX_1BUF_ENABLED: |
| 2980 | vsi->rx_hdr_len = 0; |
| 2981 | vsi->rx_buf_len = vsi->max_frame; |
| 2982 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 2983 | break; |
| 2984 | case I40E_FLAG_RX_PS_ENABLED: |
| 2985 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2986 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2987 | vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT; |
| 2988 | break; |
| 2989 | default: |
| 2990 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2991 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2992 | vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS; |
| 2993 | break; |
| 2994 | } |
| 2995 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2996 | #ifdef I40E_FCOE |
| 2997 | /* setup rx buffer for FCoE */ |
| 2998 | if ((vsi->type == I40E_VSI_FCOE) && |
| 2999 | (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) { |
| 3000 | vsi->rx_hdr_len = 0; |
| 3001 | vsi->rx_buf_len = I40E_RXBUFFER_3072; |
| 3002 | vsi->max_frame = I40E_RXBUFFER_3072; |
| 3003 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 3004 | } |
| 3005 | |
| 3006 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3007 | /* round up for the chip's needs */ |
| 3008 | vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3009 | BIT_ULL(I40E_RXQ_CTX_HBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3010 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3011 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3012 | |
| 3013 | /* set up individual rings */ |
| 3014 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3015 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3016 | |
| 3017 | return err; |
| 3018 | } |
| 3019 | |
| 3020 | /** |
| 3021 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3022 | * @vsi: ptr to the VSI |
| 3023 | **/ |
| 3024 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3025 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3026 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3027 | u16 qoffset, qcount; |
| 3028 | int i, n; |
| 3029 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3030 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3031 | /* Reset the TC information */ |
| 3032 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3033 | rx_ring = vsi->rx_rings[i]; |
| 3034 | tx_ring = vsi->tx_rings[i]; |
| 3035 | rx_ring->dcb_tc = 0; |
| 3036 | tx_ring->dcb_tc = 0; |
| 3037 | } |
| 3038 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3039 | |
| 3040 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3041 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3042 | continue; |
| 3043 | |
| 3044 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3045 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3046 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3047 | rx_ring = vsi->rx_rings[i]; |
| 3048 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3049 | rx_ring->dcb_tc = n; |
| 3050 | tx_ring->dcb_tc = n; |
| 3051 | } |
| 3052 | } |
| 3053 | } |
| 3054 | |
| 3055 | /** |
| 3056 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3057 | * @vsi: ptr to the VSI |
| 3058 | **/ |
| 3059 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3060 | { |
| 3061 | if (vsi->netdev) |
| 3062 | i40e_set_rx_mode(vsi->netdev); |
| 3063 | } |
| 3064 | |
| 3065 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3066 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3067 | * @vsi: Pointer to the targeted VSI |
| 3068 | * |
| 3069 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3070 | * filters were saved. |
| 3071 | **/ |
| 3072 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3073 | { |
| 3074 | struct i40e_fdir_filter *filter; |
| 3075 | struct i40e_pf *pf = vsi->back; |
| 3076 | struct hlist_node *node; |
| 3077 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3078 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3079 | return; |
| 3080 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3081 | hlist_for_each_entry_safe(filter, node, |
| 3082 | &pf->fdir_filter_list, fdir_node) { |
| 3083 | i40e_add_del_fdir(vsi, filter, true); |
| 3084 | } |
| 3085 | } |
| 3086 | |
| 3087 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3088 | * i40e_vsi_configure - Set up the VSI for action |
| 3089 | * @vsi: the VSI being configured |
| 3090 | **/ |
| 3091 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3092 | { |
| 3093 | int err; |
| 3094 | |
| 3095 | i40e_set_vsi_rx_mode(vsi); |
| 3096 | i40e_restore_vlan(vsi); |
| 3097 | i40e_vsi_config_dcb_rings(vsi); |
| 3098 | err = i40e_vsi_configure_tx(vsi); |
| 3099 | if (!err) |
| 3100 | err = i40e_vsi_configure_rx(vsi); |
| 3101 | |
| 3102 | return err; |
| 3103 | } |
| 3104 | |
| 3105 | /** |
| 3106 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3107 | * @vsi: the VSI being configured |
| 3108 | **/ |
| 3109 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3110 | { |
| 3111 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3112 | struct i40e_hw *hw = &pf->hw; |
| 3113 | u16 vector; |
| 3114 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3115 | u32 qp; |
| 3116 | |
| 3117 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3118 | * and PFINT_LNKLSTn registers, e.g.: |
| 3119 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3120 | */ |
| 3121 | qp = vsi->base_queue; |
| 3122 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3123 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3124 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3125 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3126 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3127 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3128 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3129 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3130 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3131 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3132 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3133 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3134 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3135 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
| 3136 | INTRL_USEC_TO_REG(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3137 | |
| 3138 | /* Linked list for the queuepairs assigned to this vector */ |
| 3139 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3140 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3141 | u32 val; |
| 3142 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3143 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3144 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3145 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3146 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 3147 | (I40E_QUEUE_TYPE_TX |
| 3148 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 3149 | |
| 3150 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3151 | |
| 3152 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3153 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3154 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3155 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 3156 | (I40E_QUEUE_TYPE_RX |
| 3157 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3158 | |
| 3159 | /* Terminate the linked list */ |
| 3160 | if (q == (q_vector->num_ringpairs - 1)) |
| 3161 | val |= (I40E_QUEUE_END_OF_LIST |
| 3162 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3163 | |
| 3164 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3165 | qp++; |
| 3166 | } |
| 3167 | } |
| 3168 | |
| 3169 | i40e_flush(hw); |
| 3170 | } |
| 3171 | |
| 3172 | /** |
| 3173 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3174 | * @hw: ptr to the hardware info |
| 3175 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3176 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3177 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3178 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3179 | u32 val; |
| 3180 | |
| 3181 | /* clear things first */ |
| 3182 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3183 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3184 | |
| 3185 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3186 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3187 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3188 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3189 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3190 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3191 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3192 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3193 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3194 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3195 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3196 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3197 | if (pf->flags & I40E_FLAG_PTP) |
| 3198 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3199 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3200 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3201 | |
| 3202 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3203 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3204 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3205 | |
| 3206 | /* OTHER_ITR_IDX = 0 */ |
| 3207 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3208 | } |
| 3209 | |
| 3210 | /** |
| 3211 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3212 | * @vsi: the VSI being configured |
| 3213 | **/ |
| 3214 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3215 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3216 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3217 | struct i40e_pf *pf = vsi->back; |
| 3218 | struct i40e_hw *hw = &pf->hw; |
| 3219 | u32 val; |
| 3220 | |
| 3221 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3222 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3223 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3224 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3225 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3226 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3227 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3228 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3229 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3230 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3231 | |
| 3232 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3233 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3234 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3235 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3236 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3237 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3238 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3239 | |
| 3240 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3241 | |
| 3242 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3243 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3244 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3245 | |
| 3246 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3247 | i40e_flush(hw); |
| 3248 | } |
| 3249 | |
| 3250 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3251 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3252 | * @pf: board private structure |
| 3253 | **/ |
| 3254 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3255 | { |
| 3256 | struct i40e_hw *hw = &pf->hw; |
| 3257 | |
| 3258 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3259 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3260 | i40e_flush(hw); |
| 3261 | } |
| 3262 | |
| 3263 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3264 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3265 | * @pf: board private structure |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3266 | * @clearpba: true when all pending interrupt events should be cleared |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3267 | **/ |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3268 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3269 | { |
| 3270 | struct i40e_hw *hw = &pf->hw; |
| 3271 | u32 val; |
| 3272 | |
| 3273 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3274 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3275 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3276 | |
| 3277 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3278 | i40e_flush(hw); |
| 3279 | } |
| 3280 | |
| 3281 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3282 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3283 | * @irq: interrupt number |
| 3284 | * @data: pointer to a q_vector |
| 3285 | **/ |
| 3286 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3287 | { |
| 3288 | struct i40e_q_vector *q_vector = data; |
| 3289 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3290 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3291 | return IRQ_HANDLED; |
| 3292 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3293 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3294 | |
| 3295 | return IRQ_HANDLED; |
| 3296 | } |
| 3297 | |
| 3298 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3299 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3300 | * @vsi: the VSI being configured |
| 3301 | * @basename: name for the vector |
| 3302 | * |
| 3303 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3304 | **/ |
| 3305 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3306 | { |
| 3307 | int q_vectors = vsi->num_q_vectors; |
| 3308 | struct i40e_pf *pf = vsi->back; |
| 3309 | int base = vsi->base_vector; |
| 3310 | int rx_int_idx = 0; |
| 3311 | int tx_int_idx = 0; |
| 3312 | int vector, err; |
| 3313 | |
| 3314 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3315 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3316 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3317 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3318 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3319 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3320 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3321 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3322 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3323 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3324 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3325 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3326 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3327 | } else { |
| 3328 | /* skip this unused q_vector */ |
| 3329 | continue; |
| 3330 | } |
| 3331 | err = request_irq(pf->msix_entries[base + vector].vector, |
| 3332 | vsi->irq_handler, |
| 3333 | 0, |
| 3334 | q_vector->name, |
| 3335 | q_vector); |
| 3336 | if (err) { |
| 3337 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3338 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3339 | goto free_queue_irqs; |
| 3340 | } |
| 3341 | /* assign the mask for this irq */ |
| 3342 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3343 | &q_vector->affinity_mask); |
| 3344 | } |
| 3345 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3346 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3347 | return 0; |
| 3348 | |
| 3349 | free_queue_irqs: |
| 3350 | while (vector) { |
| 3351 | vector--; |
| 3352 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3353 | NULL); |
| 3354 | free_irq(pf->msix_entries[base + vector].vector, |
| 3355 | &(vsi->q_vectors[vector])); |
| 3356 | } |
| 3357 | return err; |
| 3358 | } |
| 3359 | |
| 3360 | /** |
| 3361 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3362 | * @vsi: the VSI being un-configured |
| 3363 | **/ |
| 3364 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3365 | { |
| 3366 | struct i40e_pf *pf = vsi->back; |
| 3367 | struct i40e_hw *hw = &pf->hw; |
| 3368 | int base = vsi->base_vector; |
| 3369 | int i; |
| 3370 | |
| 3371 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3372 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3373 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3377 | for (i = vsi->base_vector; |
| 3378 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3379 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3380 | |
| 3381 | i40e_flush(hw); |
| 3382 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3383 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3384 | } else { |
| 3385 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3386 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3387 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3388 | i40e_flush(hw); |
| 3389 | synchronize_irq(pf->pdev->irq); |
| 3390 | } |
| 3391 | } |
| 3392 | |
| 3393 | /** |
| 3394 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3395 | * @vsi: the VSI being configured |
| 3396 | **/ |
| 3397 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3398 | { |
| 3399 | struct i40e_pf *pf = vsi->back; |
| 3400 | int i; |
| 3401 | |
| 3402 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3403 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3404 | i40e_irq_dynamic_enable(vsi, i); |
| 3405 | } else { |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3406 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3407 | } |
| 3408 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3409 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3410 | return 0; |
| 3411 | } |
| 3412 | |
| 3413 | /** |
| 3414 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3415 | * @pf: board private structure |
| 3416 | **/ |
| 3417 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3418 | { |
| 3419 | /* Disable ICR 0 */ |
| 3420 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3421 | i40e_flush(&pf->hw); |
| 3422 | } |
| 3423 | |
| 3424 | /** |
| 3425 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3426 | * @irq: interrupt number |
| 3427 | * @data: pointer to a q_vector |
| 3428 | * |
| 3429 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3430 | * with both queue and non-queue interrupts. This is also used in |
| 3431 | * MSIX mode to handle the non-queue interrupts. |
| 3432 | **/ |
| 3433 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3434 | { |
| 3435 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3436 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3437 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3438 | u32 icr0, icr0_remaining; |
| 3439 | u32 val, ena_mask; |
| 3440 | |
| 3441 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3442 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3443 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3444 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3445 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3446 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3447 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3448 | /* if interrupt but no bits showing, must be SWINT */ |
| 3449 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3450 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3451 | pf->sw_int_count++; |
| 3452 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3453 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 3454 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
| 3455 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3456 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3457 | dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
| 3458 | } |
| 3459 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3460 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3461 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3462 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3463 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3464 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3465 | /* We do not have a way to disarm Queue causes while leaving |
| 3466 | * interrupt enabled for all other causes, ideally |
| 3467 | * interrupt should be disabled while we are in NAPI but |
| 3468 | * this is not a performance path and napi_schedule() |
| 3469 | * can deal with rescheduling. |
| 3470 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3471 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3472 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3473 | } |
| 3474 | |
| 3475 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3476 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3477 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3478 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3482 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3483 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3484 | } |
| 3485 | |
| 3486 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3487 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3488 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3489 | } |
| 3490 | |
| 3491 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3492 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3493 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3494 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3495 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3496 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3497 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3498 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3499 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3500 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3501 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3502 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3503 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3504 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3505 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3506 | } |
| 3507 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3508 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3509 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3510 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3511 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3512 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3513 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3514 | } |
| 3515 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3516 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3517 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3518 | |
| 3519 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3520 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3521 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3522 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3523 | } |
| 3524 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3525 | /* If a critical error is pending we have no choice but to reset the |
| 3526 | * device. |
| 3527 | * Report and mask out any remaining unexpected interrupts. |
| 3528 | */ |
| 3529 | icr0_remaining = icr0 & ena_mask; |
| 3530 | if (icr0_remaining) { |
| 3531 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3532 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3533 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3534 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3535 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3536 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3537 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3538 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3539 | } |
| 3540 | ena_mask &= ~icr0_remaining; |
| 3541 | } |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3542 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3543 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3544 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3545 | /* re-enable interrupt causes */ |
| 3546 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3547 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3548 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3549 | i40e_irq_dynamic_enable_icr0(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3550 | } |
| 3551 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3552 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3556 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3557 | * @tx_ring: tx ring to clean |
| 3558 | * @budget: how many cleans we're allowed |
| 3559 | * |
| 3560 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3561 | **/ |
| 3562 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3563 | { |
| 3564 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3565 | u16 i = tx_ring->next_to_clean; |
| 3566 | struct i40e_tx_buffer *tx_buf; |
| 3567 | struct i40e_tx_desc *tx_desc; |
| 3568 | |
| 3569 | tx_buf = &tx_ring->tx_bi[i]; |
| 3570 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3571 | i -= tx_ring->count; |
| 3572 | |
| 3573 | do { |
| 3574 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3575 | |
| 3576 | /* if next_to_watch is not set then there is no work pending */ |
| 3577 | if (!eop_desc) |
| 3578 | break; |
| 3579 | |
| 3580 | /* prevent any other reads prior to eop_desc */ |
| 3581 | read_barrier_depends(); |
| 3582 | |
| 3583 | /* if the descriptor isn't done, no work yet to do */ |
| 3584 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3585 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3586 | break; |
| 3587 | |
| 3588 | /* clear next_to_watch to prevent false hangs */ |
| 3589 | tx_buf->next_to_watch = NULL; |
| 3590 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3591 | tx_desc->buffer_addr = 0; |
| 3592 | tx_desc->cmd_type_offset_bsz = 0; |
| 3593 | /* move past filter desc */ |
| 3594 | tx_buf++; |
| 3595 | tx_desc++; |
| 3596 | i++; |
| 3597 | if (unlikely(!i)) { |
| 3598 | i -= tx_ring->count; |
| 3599 | tx_buf = tx_ring->tx_bi; |
| 3600 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3601 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3602 | /* unmap skb header data */ |
| 3603 | dma_unmap_single(tx_ring->dev, |
| 3604 | dma_unmap_addr(tx_buf, dma), |
| 3605 | dma_unmap_len(tx_buf, len), |
| 3606 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3607 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3608 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3609 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3610 | tx_buf->raw_buf = NULL; |
| 3611 | tx_buf->tx_flags = 0; |
| 3612 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3613 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3614 | tx_desc->buffer_addr = 0; |
| 3615 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3616 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3617 | /* 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] | 3618 | tx_buf++; |
| 3619 | tx_desc++; |
| 3620 | i++; |
| 3621 | if (unlikely(!i)) { |
| 3622 | i -= tx_ring->count; |
| 3623 | tx_buf = tx_ring->tx_bi; |
| 3624 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3625 | } |
| 3626 | |
| 3627 | /* update budget accounting */ |
| 3628 | budget--; |
| 3629 | } while (likely(budget)); |
| 3630 | |
| 3631 | i += tx_ring->count; |
| 3632 | tx_ring->next_to_clean = i; |
| 3633 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3634 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3635 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3636 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3637 | return budget > 0; |
| 3638 | } |
| 3639 | |
| 3640 | /** |
| 3641 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3642 | * @irq: interrupt number |
| 3643 | * @data: pointer to a q_vector |
| 3644 | **/ |
| 3645 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3646 | { |
| 3647 | struct i40e_q_vector *q_vector = data; |
| 3648 | struct i40e_vsi *vsi; |
| 3649 | |
| 3650 | if (!q_vector->tx.ring) |
| 3651 | return IRQ_HANDLED; |
| 3652 | |
| 3653 | vsi = q_vector->tx.ring->vsi; |
| 3654 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3655 | |
| 3656 | return IRQ_HANDLED; |
| 3657 | } |
| 3658 | |
| 3659 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3660 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3661 | * @vsi: the VSI being configured |
| 3662 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3663 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3664 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3665 | 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] | 3666 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3667 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3668 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3669 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3670 | |
| 3671 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3672 | tx_ring->next = q_vector->tx.ring; |
| 3673 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3674 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3675 | |
| 3676 | rx_ring->q_vector = q_vector; |
| 3677 | rx_ring->next = q_vector->rx.ring; |
| 3678 | q_vector->rx.ring = rx_ring; |
| 3679 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3680 | } |
| 3681 | |
| 3682 | /** |
| 3683 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3684 | * @vsi: the VSI being configured |
| 3685 | * |
| 3686 | * This function maps descriptor rings to the queue-specific vectors |
| 3687 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3688 | * one vector per queue pair, but on a constrained vector budget, we |
| 3689 | * group the queue pairs as "efficiently" as possible. |
| 3690 | **/ |
| 3691 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3692 | { |
| 3693 | int qp_remaining = vsi->num_queue_pairs; |
| 3694 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3695 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3696 | int v_start = 0; |
| 3697 | int qp_idx = 0; |
| 3698 | |
| 3699 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3700 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3701 | * It is also important to go through all the vectors available to be |
| 3702 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3703 | * are cleared. This is especially important when decreasing the |
| 3704 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3705 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3706 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3707 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3708 | |
| 3709 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3710 | |
| 3711 | q_vector->num_ringpairs = num_ringpairs; |
| 3712 | |
| 3713 | q_vector->rx.count = 0; |
| 3714 | q_vector->tx.count = 0; |
| 3715 | q_vector->rx.ring = NULL; |
| 3716 | q_vector->tx.ring = NULL; |
| 3717 | |
| 3718 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3719 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3720 | qp_idx++; |
| 3721 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3722 | } |
| 3723 | } |
| 3724 | } |
| 3725 | |
| 3726 | /** |
| 3727 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3728 | * @vsi: the VSI being configured |
| 3729 | * @basename: name for the vector |
| 3730 | **/ |
| 3731 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3732 | { |
| 3733 | struct i40e_pf *pf = vsi->back; |
| 3734 | int err; |
| 3735 | |
| 3736 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3737 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3738 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3739 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3740 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3741 | else |
| 3742 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3743 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3744 | |
| 3745 | if (err) |
| 3746 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3747 | |
| 3748 | return err; |
| 3749 | } |
| 3750 | |
| 3751 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3752 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3753 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3754 | * @netdev: network interface device structure |
| 3755 | * |
| 3756 | * This is used by netconsole to send skbs without having to re-enable |
| 3757 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3758 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3759 | #ifdef I40E_FCOE |
| 3760 | void i40e_netpoll(struct net_device *netdev) |
| 3761 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3762 | static void i40e_netpoll(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3763 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3764 | { |
| 3765 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3766 | struct i40e_vsi *vsi = np->vsi; |
| 3767 | struct i40e_pf *pf = vsi->back; |
| 3768 | int i; |
| 3769 | |
| 3770 | /* if interface is down do nothing */ |
| 3771 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3772 | return; |
| 3773 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3774 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3775 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3776 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3777 | } else { |
| 3778 | i40e_intr(pf->pdev->irq, netdev); |
| 3779 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3780 | } |
| 3781 | #endif |
| 3782 | |
| 3783 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3784 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3785 | * @pf: the PF being configured |
| 3786 | * @pf_q: the PF queue |
| 3787 | * @enable: enable or disable state of the queue |
| 3788 | * |
| 3789 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3790 | * enabled or disabled state. |
| 3791 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3792 | * multiple retries; else will return 0 in case of success. |
| 3793 | **/ |
| 3794 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3795 | { |
| 3796 | int i; |
| 3797 | u32 tx_reg; |
| 3798 | |
| 3799 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3800 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3801 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3802 | break; |
| 3803 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3804 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3805 | } |
| 3806 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3807 | return -ETIMEDOUT; |
| 3808 | |
| 3809 | return 0; |
| 3810 | } |
| 3811 | |
| 3812 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3813 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3814 | * @vsi: the VSI being configured |
| 3815 | * @enable: start or stop the rings |
| 3816 | **/ |
| 3817 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3818 | { |
| 3819 | struct i40e_pf *pf = vsi->back; |
| 3820 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3821 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3822 | u32 tx_reg; |
| 3823 | |
| 3824 | pf_q = vsi->base_queue; |
| 3825 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3826 | |
| 3827 | /* warn the TX unit of coming changes */ |
| 3828 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3829 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3830 | usleep_range(10, 20); |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3831 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3832 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3833 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3834 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3835 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3836 | break; |
| 3837 | usleep_range(1000, 2000); |
| 3838 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3839 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3840 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3841 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3842 | |
| 3843 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3844 | if (enable) { |
| 3845 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3846 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3847 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3848 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3849 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3850 | |
| 3851 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 3852 | /* No waiting for the Tx queue to disable */ |
| 3853 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3854 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3855 | |
| 3856 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3857 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 3858 | if (ret) { |
| 3859 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3860 | "VSI seid %d Tx ring %d %sable timeout\n", |
| 3861 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3862 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3863 | } |
| 3864 | } |
| 3865 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3866 | if (hw->revision_id == 0) |
| 3867 | mdelay(50); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3868 | return ret; |
| 3869 | } |
| 3870 | |
| 3871 | /** |
| 3872 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 3873 | * @pf: the PF being configured |
| 3874 | * @pf_q: the PF queue |
| 3875 | * @enable: enable or disable state of the queue |
| 3876 | * |
| 3877 | * This routine will wait for the given Rx queue of the PF to reach the |
| 3878 | * enabled or disabled state. |
| 3879 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3880 | * multiple retries; else will return 0 in case of success. |
| 3881 | **/ |
| 3882 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3883 | { |
| 3884 | int i; |
| 3885 | u32 rx_reg; |
| 3886 | |
| 3887 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3888 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 3889 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3890 | break; |
| 3891 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3892 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3893 | } |
| 3894 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3895 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3896 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3897 | return 0; |
| 3898 | } |
| 3899 | |
| 3900 | /** |
| 3901 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 3902 | * @vsi: the VSI being configured |
| 3903 | * @enable: start or stop the rings |
| 3904 | **/ |
| 3905 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 3906 | { |
| 3907 | struct i40e_pf *pf = vsi->back; |
| 3908 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3909 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3910 | u32 rx_reg; |
| 3911 | |
| 3912 | pf_q = vsi->base_queue; |
| 3913 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3914 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3915 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3916 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3917 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3918 | break; |
| 3919 | usleep_range(1000, 2000); |
| 3920 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3921 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3922 | /* Skip if the queue is already in the requested state */ |
| 3923 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3924 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3925 | |
| 3926 | /* turn on/off the queue */ |
| 3927 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3928 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3929 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3930 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3931 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 3932 | /* No waiting for the Tx queue to disable */ |
| 3933 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3934 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3935 | |
| 3936 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3937 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 3938 | if (ret) { |
| 3939 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3940 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 3941 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3942 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3943 | } |
| 3944 | } |
| 3945 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3946 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3947 | } |
| 3948 | |
| 3949 | /** |
| 3950 | * i40e_vsi_control_rings - Start or stop a VSI's rings |
| 3951 | * @vsi: the VSI being configured |
| 3952 | * @enable: start or stop the rings |
| 3953 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 3954 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3955 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3956 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3957 | |
| 3958 | /* do rx first for enable and last for disable */ |
| 3959 | if (request) { |
| 3960 | ret = i40e_vsi_control_rx(vsi, request); |
| 3961 | if (ret) |
| 3962 | return ret; |
| 3963 | ret = i40e_vsi_control_tx(vsi, request); |
| 3964 | } else { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3965 | /* Ignore return value, we need to shutdown whatever we can */ |
| 3966 | i40e_vsi_control_tx(vsi, request); |
| 3967 | i40e_vsi_control_rx(vsi, request); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3968 | } |
| 3969 | |
| 3970 | return ret; |
| 3971 | } |
| 3972 | |
| 3973 | /** |
| 3974 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 3975 | * @vsi: the VSI being configured |
| 3976 | **/ |
| 3977 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 3978 | { |
| 3979 | struct i40e_pf *pf = vsi->back; |
| 3980 | struct i40e_hw *hw = &pf->hw; |
| 3981 | int base = vsi->base_vector; |
| 3982 | u32 val, qp; |
| 3983 | int i; |
| 3984 | |
| 3985 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3986 | if (!vsi->q_vectors) |
| 3987 | return; |
| 3988 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3989 | if (!vsi->irqs_ready) |
| 3990 | return; |
| 3991 | |
| 3992 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3993 | for (i = 0; i < vsi->num_q_vectors; i++) { |
| 3994 | u16 vector = i + base; |
| 3995 | |
| 3996 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 3997 | if (!vsi->q_vectors[i] || |
| 3998 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3999 | continue; |
| 4000 | |
| 4001 | /* clear the affinity_mask in the IRQ descriptor */ |
| 4002 | irq_set_affinity_hint(pf->msix_entries[vector].vector, |
| 4003 | NULL); |
| 4004 | free_irq(pf->msix_entries[vector].vector, |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4005 | vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4006 | |
| 4007 | /* Tear down the interrupt queue link list |
| 4008 | * |
| 4009 | * We know that they come in pairs and always |
| 4010 | * the Rx first, then the Tx. To clear the |
| 4011 | * link list, stick the EOL value into the |
| 4012 | * next_q field of the registers. |
| 4013 | */ |
| 4014 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4015 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4016 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4017 | val |= I40E_QUEUE_END_OF_LIST |
| 4018 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4019 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4020 | |
| 4021 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4022 | u32 next; |
| 4023 | |
| 4024 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4025 | |
| 4026 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4027 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4028 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4029 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4030 | |
| 4031 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4032 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4033 | |
| 4034 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4035 | |
| 4036 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4037 | |
| 4038 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4039 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4040 | |
| 4041 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4042 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4043 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4044 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4045 | |
| 4046 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4047 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4048 | |
| 4049 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4050 | qp = next; |
| 4051 | } |
| 4052 | } |
| 4053 | } else { |
| 4054 | free_irq(pf->pdev->irq, pf); |
| 4055 | |
| 4056 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4057 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4058 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4059 | val |= I40E_QUEUE_END_OF_LIST |
| 4060 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4061 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4062 | |
| 4063 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4064 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4065 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4066 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4067 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4068 | |
| 4069 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4070 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4071 | |
| 4072 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4073 | |
| 4074 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4075 | |
| 4076 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4077 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4078 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4079 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4080 | |
| 4081 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4082 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4083 | |
| 4084 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4085 | } |
| 4086 | } |
| 4087 | |
| 4088 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4089 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4090 | * @vsi: the VSI being configured |
| 4091 | * @v_idx: Index of vector to be freed |
| 4092 | * |
| 4093 | * This function frees the memory allocated to the q_vector. In addition if |
| 4094 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4095 | * to freeing the q_vector. |
| 4096 | **/ |
| 4097 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4098 | { |
| 4099 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4100 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4101 | |
| 4102 | if (!q_vector) |
| 4103 | return; |
| 4104 | |
| 4105 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4106 | i40e_for_each_ring(ring, q_vector->tx) |
| 4107 | ring->q_vector = NULL; |
| 4108 | |
| 4109 | i40e_for_each_ring(ring, q_vector->rx) |
| 4110 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4111 | |
| 4112 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4113 | if (vsi->netdev) |
| 4114 | netif_napi_del(&q_vector->napi); |
| 4115 | |
| 4116 | vsi->q_vectors[v_idx] = NULL; |
| 4117 | |
| 4118 | kfree_rcu(q_vector, rcu); |
| 4119 | } |
| 4120 | |
| 4121 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4122 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4123 | * @vsi: the VSI being un-configured |
| 4124 | * |
| 4125 | * This frees the memory allocated to the q_vectors and |
| 4126 | * deletes references to the NAPI struct. |
| 4127 | **/ |
| 4128 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4129 | { |
| 4130 | int v_idx; |
| 4131 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4132 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4133 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4134 | } |
| 4135 | |
| 4136 | /** |
| 4137 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4138 | * @pf: board private structure |
| 4139 | **/ |
| 4140 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4141 | { |
| 4142 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4143 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4144 | pci_disable_msix(pf->pdev); |
| 4145 | kfree(pf->msix_entries); |
| 4146 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4147 | kfree(pf->irq_pile); |
| 4148 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4149 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4150 | pci_disable_msi(pf->pdev); |
| 4151 | } |
| 4152 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4153 | } |
| 4154 | |
| 4155 | /** |
| 4156 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4157 | * @pf: board private structure |
| 4158 | * |
| 4159 | * We go through and clear interrupt specific resources and reset the structure |
| 4160 | * to pre-load conditions |
| 4161 | **/ |
| 4162 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4163 | { |
| 4164 | int i; |
| 4165 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4166 | i40e_stop_misc_vector(pf); |
Shannon Nelson | 6927839 | 2016-03-10 14:59:43 -0800 | [diff] [blame] | 4167 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4168 | synchronize_irq(pf->msix_entries[0].vector); |
| 4169 | free_irq(pf->msix_entries[0].vector, pf); |
| 4170 | } |
| 4171 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4172 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4173 | I40E_IWARP_IRQ_PILE_ID); |
| 4174 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4175 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4176 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4177 | if (pf->vsi[i]) |
| 4178 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4179 | i40e_reset_interrupt_capability(pf); |
| 4180 | } |
| 4181 | |
| 4182 | /** |
| 4183 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4184 | * @vsi: the VSI being configured |
| 4185 | **/ |
| 4186 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4187 | { |
| 4188 | int q_idx; |
| 4189 | |
| 4190 | if (!vsi->netdev) |
| 4191 | return; |
| 4192 | |
| 4193 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4194 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4195 | } |
| 4196 | |
| 4197 | /** |
| 4198 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4199 | * @vsi: the VSI being configured |
| 4200 | **/ |
| 4201 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4202 | { |
| 4203 | int q_idx; |
| 4204 | |
| 4205 | if (!vsi->netdev) |
| 4206 | return; |
| 4207 | |
| 4208 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4209 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4210 | } |
| 4211 | |
| 4212 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4213 | * i40e_vsi_close - Shut down a VSI |
| 4214 | * @vsi: the vsi to be quelled |
| 4215 | **/ |
| 4216 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4217 | { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4218 | bool reset = false; |
| 4219 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4220 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4221 | i40e_down(vsi); |
| 4222 | i40e_vsi_free_irq(vsi); |
| 4223 | i40e_vsi_free_tx_resources(vsi); |
| 4224 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4225 | vsi->current_netdev_flags = 0; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4226 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4227 | reset = true; |
| 4228 | i40e_notify_client_of_netdev_close(vsi, reset); |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4232 | * i40e_quiesce_vsi - Pause a given VSI |
| 4233 | * @vsi: the VSI being paused |
| 4234 | **/ |
| 4235 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4236 | { |
| 4237 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4238 | return; |
| 4239 | |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4240 | /* No need to disable FCoE VSI when Tx suspended */ |
| 4241 | if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) && |
| 4242 | vsi->type == I40E_VSI_FCOE) { |
| 4243 | dev_dbg(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4244 | "VSI seid %d skipping FCoE VSI disable\n", vsi->seid); |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4245 | return; |
| 4246 | } |
| 4247 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4248 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4249 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4250 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4251 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4252 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | /** |
| 4256 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4257 | * @vsi: the VSI being resumed |
| 4258 | **/ |
| 4259 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4260 | { |
| 4261 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 4262 | return; |
| 4263 | |
| 4264 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4265 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4266 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4267 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4268 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | /** |
| 4272 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4273 | * @pf: the PF |
| 4274 | **/ |
| 4275 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4276 | { |
| 4277 | int v; |
| 4278 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4279 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4280 | if (pf->vsi[v]) |
| 4281 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4282 | } |
| 4283 | } |
| 4284 | |
| 4285 | /** |
| 4286 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4287 | * @pf: the PF |
| 4288 | **/ |
| 4289 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4290 | { |
| 4291 | int v; |
| 4292 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4293 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4294 | if (pf->vsi[v]) |
| 4295 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4296 | } |
| 4297 | } |
| 4298 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4299 | #ifdef CONFIG_I40E_DCB |
| 4300 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4301 | * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4302 | * @vsi: the VSI being configured |
| 4303 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4304 | * This function waits for the given VSI's queues to be disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4305 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4306 | static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4307 | { |
| 4308 | struct i40e_pf *pf = vsi->back; |
| 4309 | int i, pf_q, ret; |
| 4310 | |
| 4311 | pf_q = vsi->base_queue; |
| 4312 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4313 | /* Check and wait for the disable status of the queue */ |
| 4314 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4315 | if (ret) { |
| 4316 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4317 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4318 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4319 | return ret; |
| 4320 | } |
| 4321 | } |
| 4322 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4323 | pf_q = vsi->base_queue; |
| 4324 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4325 | /* Check and wait for the disable status of the queue */ |
| 4326 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4327 | if (ret) { |
| 4328 | dev_info(&pf->pdev->dev, |
| 4329 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4330 | vsi->seid, pf_q); |
| 4331 | return ret; |
| 4332 | } |
| 4333 | } |
| 4334 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4335 | return 0; |
| 4336 | } |
| 4337 | |
| 4338 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4339 | * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4340 | * @pf: the PF |
| 4341 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4342 | * This function waits for the queues to be in disabled state for all the |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4343 | * VSIs that are managed by this PF. |
| 4344 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4345 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4346 | { |
| 4347 | int v, ret = 0; |
| 4348 | |
| 4349 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4350 | /* No need to wait for FCoE VSI queues */ |
| 4351 | if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4352 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4353 | if (ret) |
| 4354 | break; |
| 4355 | } |
| 4356 | } |
| 4357 | |
| 4358 | return ret; |
| 4359 | } |
| 4360 | |
| 4361 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4362 | |
| 4363 | /** |
| 4364 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4365 | * @q_idx: TX queue number |
| 4366 | * @vsi: Pointer to VSI struct |
| 4367 | * |
| 4368 | * This function checks specified queue for given VSI. Detects hung condition. |
| 4369 | * Sets hung bit since it is two step process. Before next run of service task |
| 4370 | * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not, |
| 4371 | * hung condition remain unchanged and during subsequent run, this function |
| 4372 | * issues SW interrupt to recover from hung condition. |
| 4373 | **/ |
| 4374 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4375 | { |
| 4376 | struct i40e_ring *tx_ring = NULL; |
| 4377 | struct i40e_pf *pf; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4378 | u32 head, val, tx_pending_hw; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4379 | int i; |
| 4380 | |
| 4381 | pf = vsi->back; |
| 4382 | |
| 4383 | /* now that we have an index, find the tx_ring struct */ |
| 4384 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4385 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4386 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4387 | tx_ring = vsi->tx_rings[i]; |
| 4388 | break; |
| 4389 | } |
| 4390 | } |
| 4391 | } |
| 4392 | |
| 4393 | if (!tx_ring) |
| 4394 | return; |
| 4395 | |
| 4396 | /* Read interrupt register */ |
| 4397 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4398 | val = rd32(&pf->hw, |
| 4399 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4400 | tx_ring->vsi->base_vector - 1)); |
| 4401 | else |
| 4402 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4403 | |
| 4404 | head = i40e_get_head(tx_ring); |
| 4405 | |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4406 | tx_pending_hw = i40e_get_tx_pending(tx_ring, false); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4407 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4408 | /* HW is done executing descriptors, updated HEAD write back, |
| 4409 | * but SW hasn't processed those descriptors. If interrupt is |
| 4410 | * not generated from this point ON, it could result into |
| 4411 | * dev_watchdog detecting timeout on those netdev_queue, |
| 4412 | * hence proactively trigger SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4413 | */ |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4414 | if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4415 | /* NAPI Poll didn't run and clear since it was set */ |
| 4416 | if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4417 | &tx_ring->q_vector->hung_detected)) { |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4418 | netdev_info(vsi->netdev, "VSI_seid %d, Hung TX queue %d, tx_pending_hw: %d, NTC:0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x\n", |
| 4419 | vsi->seid, q_idx, tx_pending_hw, |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4420 | tx_ring->next_to_clean, head, |
| 4421 | tx_ring->next_to_use, |
| 4422 | readl(tx_ring->tail)); |
| 4423 | netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n", |
| 4424 | vsi->seid, q_idx, val); |
| 4425 | i40e_force_wb(vsi, tx_ring->q_vector); |
| 4426 | } else { |
| 4427 | /* First Chance - detected possible hung */ |
| 4428 | set_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4429 | &tx_ring->q_vector->hung_detected); |
| 4430 | } |
| 4431 | } |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4432 | |
| 4433 | /* This is the case where we have interrupts missing, |
| 4434 | * so the tx_pending in HW will most likely be 0, but we |
| 4435 | * will have tx_pending in SW since the WB happened but the |
| 4436 | * interrupt got lost. |
| 4437 | */ |
| 4438 | if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) && |
| 4439 | (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
| 4440 | if (napi_reschedule(&tx_ring->q_vector->napi)) |
| 4441 | tx_ring->tx_stats.tx_lost_interrupt++; |
| 4442 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4443 | } |
| 4444 | |
| 4445 | /** |
| 4446 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4447 | * @pf: pointer to PF struct |
| 4448 | * |
| 4449 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4450 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4451 | * SW interrupt. |
| 4452 | **/ |
| 4453 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4454 | { |
| 4455 | struct net_device *netdev; |
| 4456 | struct i40e_vsi *vsi; |
| 4457 | int i; |
| 4458 | |
| 4459 | /* Only for LAN VSI */ |
| 4460 | vsi = pf->vsi[pf->lan_vsi]; |
| 4461 | |
| 4462 | if (!vsi) |
| 4463 | return; |
| 4464 | |
| 4465 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
| 4466 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 4467 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4468 | return; |
| 4469 | |
| 4470 | /* Make sure type is MAIN VSI */ |
| 4471 | if (vsi->type != I40E_VSI_MAIN) |
| 4472 | return; |
| 4473 | |
| 4474 | netdev = vsi->netdev; |
| 4475 | if (!netdev) |
| 4476 | return; |
| 4477 | |
| 4478 | /* Bail out if netif_carrier is not OK */ |
| 4479 | if (!netif_carrier_ok(netdev)) |
| 4480 | return; |
| 4481 | |
| 4482 | /* Go thru' TX queues for netdev */ |
| 4483 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4484 | struct netdev_queue *q; |
| 4485 | |
| 4486 | q = netdev_get_tx_queue(netdev, i); |
| 4487 | if (q) |
| 4488 | i40e_detect_recover_hung_queue(i, vsi); |
| 4489 | } |
| 4490 | } |
| 4491 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4492 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4493 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4494 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4495 | * |
| 4496 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4497 | * and LAN TC. |
| 4498 | **/ |
| 4499 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4500 | { |
| 4501 | struct i40e_dcb_app_priority_table app; |
| 4502 | struct i40e_hw *hw = &pf->hw; |
| 4503 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4504 | u8 tc, i; |
| 4505 | /* Get the iSCSI APP TLV */ |
| 4506 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4507 | |
| 4508 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4509 | app = dcbcfg->app[i]; |
| 4510 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4511 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4512 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4513 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4514 | break; |
| 4515 | } |
| 4516 | } |
| 4517 | |
| 4518 | return enabled_tc; |
| 4519 | } |
| 4520 | |
| 4521 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4522 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4523 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4524 | * |
| 4525 | * Return the number of TCs from given DCBx configuration |
| 4526 | **/ |
| 4527 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4528 | { |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4529 | u8 num_tc = 0; |
| 4530 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4531 | |
| 4532 | /* Scan the ETS Config Priority Table to find |
| 4533 | * traffic class enabled for a given priority |
| 4534 | * and use the traffic class index to get the |
| 4535 | * number of traffic classes enabled |
| 4536 | */ |
| 4537 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4538 | if (dcbcfg->etscfg.prioritytable[i] > num_tc) |
| 4539 | num_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4540 | } |
| 4541 | |
| 4542 | /* Traffic class index starts from zero so |
| 4543 | * increment to return the actual count |
| 4544 | */ |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4545 | return num_tc + 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4546 | } |
| 4547 | |
| 4548 | /** |
| 4549 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4550 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4551 | * |
| 4552 | * Query the current DCB configuration and return the number of |
| 4553 | * traffic classes enabled from the given DCBX config |
| 4554 | **/ |
| 4555 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4556 | { |
| 4557 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4558 | u8 enabled_tc = 1; |
| 4559 | u8 i; |
| 4560 | |
| 4561 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4562 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4563 | |
| 4564 | return enabled_tc; |
| 4565 | } |
| 4566 | |
| 4567 | /** |
| 4568 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4569 | * @pf: PF being queried |
| 4570 | * |
| 4571 | * Return number of traffic classes enabled for the given PF |
| 4572 | **/ |
| 4573 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4574 | { |
| 4575 | struct i40e_hw *hw = &pf->hw; |
| 4576 | u8 i, enabled_tc; |
| 4577 | u8 num_tc = 0; |
| 4578 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4579 | |
| 4580 | /* If DCB is not enabled then always in single TC */ |
| 4581 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4582 | return 1; |
| 4583 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4584 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4585 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4586 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4587 | |
| 4588 | /* MFP mode return count of enabled TCs for this PF */ |
| 4589 | if (pf->hw.func_caps.iscsi) |
| 4590 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4591 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4592 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4593 | |
| 4594 | /* At least have TC0 */ |
| 4595 | enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 4596 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4597 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4598 | num_tc++; |
| 4599 | } |
| 4600 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | /** |
| 4604 | * i40e_pf_get_default_tc - Get bitmap for first enabled TC |
| 4605 | * @pf: PF being queried |
| 4606 | * |
| 4607 | * Return a bitmap for first enabled traffic class for this PF. |
| 4608 | **/ |
| 4609 | static u8 i40e_pf_get_default_tc(struct i40e_pf *pf) |
| 4610 | { |
| 4611 | u8 enabled_tc = pf->hw.func_caps.enabled_tcmap; |
| 4612 | u8 i = 0; |
| 4613 | |
| 4614 | if (!enabled_tc) |
| 4615 | return 0x1; /* TC0 */ |
| 4616 | |
| 4617 | /* Find the first enabled TC */ |
| 4618 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4619 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4620 | break; |
| 4621 | } |
| 4622 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4623 | return BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | /** |
| 4627 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4628 | * @pf: PF being queried |
| 4629 | * |
| 4630 | * Return a bitmap for enabled traffic classes for this PF. |
| 4631 | **/ |
| 4632 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4633 | { |
| 4634 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4635 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4636 | return i40e_pf_get_default_tc(pf); |
| 4637 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4638 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4639 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4640 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4641 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4642 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4643 | if (pf->hw.func_caps.iscsi) |
| 4644 | return i40e_get_iscsi_tc_map(pf); |
| 4645 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4646 | return i40e_pf_get_default_tc(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | /** |
| 4650 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4651 | * @vsi: the VSI being queried |
| 4652 | * |
| 4653 | * Returns 0 on success, negative value on failure |
| 4654 | **/ |
| 4655 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4656 | { |
| 4657 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4658 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4659 | struct i40e_pf *pf = vsi->back; |
| 4660 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4661 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4662 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4663 | int i; |
| 4664 | |
| 4665 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4666 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4667 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4668 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4669 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4670 | i40e_stat_str(&pf->hw, ret), |
| 4671 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4672 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4673 | } |
| 4674 | |
| 4675 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4676 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4677 | NULL); |
| 4678 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4679 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4680 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4681 | i40e_stat_str(&pf->hw, ret), |
| 4682 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4683 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4687 | dev_info(&pf->pdev->dev, |
| 4688 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4689 | bw_config.tc_valid_bits, |
| 4690 | bw_ets_config.tc_valid_bits); |
| 4691 | /* Still continuing */ |
| 4692 | } |
| 4693 | |
| 4694 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4695 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4696 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4697 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4698 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4699 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4700 | vsi->bw_ets_limit_credits[i] = |
| 4701 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4702 | /* 3 bits out of 4 for each TC */ |
| 4703 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4704 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4705 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4706 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4707 | } |
| 4708 | |
| 4709 | /** |
| 4710 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4711 | * @vsi: the VSI being configured |
| 4712 | * @enabled_tc: TC bitmap |
| 4713 | * @bw_credits: BW shared credits per TC |
| 4714 | * |
| 4715 | * Returns 0 on success, negative value on failure |
| 4716 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4717 | 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] | 4718 | u8 *bw_share) |
| 4719 | { |
| 4720 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4721 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4722 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4723 | |
| 4724 | bw_data.tc_valid_bits = enabled_tc; |
| 4725 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4726 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4727 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4728 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4729 | NULL); |
| 4730 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4731 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4732 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4733 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4734 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4738 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4739 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4740 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4741 | } |
| 4742 | |
| 4743 | /** |
| 4744 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4745 | * @vsi: the VSI being configured |
| 4746 | * @enabled_tc: TC map to be enabled |
| 4747 | * |
| 4748 | **/ |
| 4749 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4750 | { |
| 4751 | struct net_device *netdev = vsi->netdev; |
| 4752 | struct i40e_pf *pf = vsi->back; |
| 4753 | struct i40e_hw *hw = &pf->hw; |
| 4754 | u8 netdev_tc = 0; |
| 4755 | int i; |
| 4756 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4757 | |
| 4758 | if (!netdev) |
| 4759 | return; |
| 4760 | |
| 4761 | if (!enabled_tc) { |
| 4762 | netdev_reset_tc(netdev); |
| 4763 | return; |
| 4764 | } |
| 4765 | |
| 4766 | /* Set up actual enabled TCs on the VSI */ |
| 4767 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 4768 | return; |
| 4769 | |
| 4770 | /* set per TC queues for the VSI */ |
| 4771 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4772 | /* Only set TC queues for enabled tcs |
| 4773 | * |
| 4774 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 4775 | * enabled_tc bitmap would be 0x00001001; the driver |
| 4776 | * will set the numtc for netdev as 2 that will be |
| 4777 | * referenced by the netdev layer as TC 0 and 1. |
| 4778 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4779 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4780 | netdev_set_tc_queue(netdev, |
| 4781 | vsi->tc_config.tc_info[i].netdev_tc, |
| 4782 | vsi->tc_config.tc_info[i].qcount, |
| 4783 | vsi->tc_config.tc_info[i].qoffset); |
| 4784 | } |
| 4785 | |
| 4786 | /* Assign UP2TC map for the VSI */ |
| 4787 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4788 | /* Get the actual TC# for the UP */ |
| 4789 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4790 | /* Get the mapped netdev TC# for the UP */ |
| 4791 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 4792 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 4793 | } |
| 4794 | } |
| 4795 | |
| 4796 | /** |
| 4797 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 4798 | * @vsi: the VSI being configured |
| 4799 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 4800 | **/ |
| 4801 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 4802 | struct i40e_vsi_context *ctxt) |
| 4803 | { |
| 4804 | /* copy just the sections touched not the entire info |
| 4805 | * since not all sections are valid as returned by |
| 4806 | * update vsi params |
| 4807 | */ |
| 4808 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 4809 | memcpy(&vsi->info.queue_mapping, |
| 4810 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 4811 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 4812 | sizeof(vsi->info.tc_mapping)); |
| 4813 | } |
| 4814 | |
| 4815 | /** |
| 4816 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 4817 | * @vsi: VSI to be configured |
| 4818 | * @enabled_tc: TC bitmap |
| 4819 | * |
| 4820 | * This configures a particular VSI for TCs that are mapped to the |
| 4821 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 4822 | * VSIs to configure TC for a particular VSI. |
| 4823 | * |
| 4824 | * NOTE: |
| 4825 | * It is expected that the VSI queues have been quisced before calling |
| 4826 | * this function. |
| 4827 | **/ |
| 4828 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4829 | { |
| 4830 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 4831 | struct i40e_vsi_context ctxt; |
| 4832 | int ret = 0; |
| 4833 | int i; |
| 4834 | |
| 4835 | /* Check if enabled_tc is same as existing or new TCs */ |
| 4836 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 4837 | return ret; |
| 4838 | |
| 4839 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 4840 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4841 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4842 | bw_share[i] = 1; |
| 4843 | } |
| 4844 | |
| 4845 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 4846 | if (ret) { |
| 4847 | dev_info(&vsi->back->pdev->dev, |
| 4848 | "Failed configuring TC map %d for VSI %d\n", |
| 4849 | enabled_tc, vsi->seid); |
| 4850 | goto out; |
| 4851 | } |
| 4852 | |
| 4853 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 4854 | ctxt.seid = vsi->seid; |
| 4855 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 4856 | ctxt.vf_num = 0; |
| 4857 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 4858 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4859 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 4860 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4861 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 4862 | ctxt.info.valid_sections |= |
| 4863 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 4864 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 4865 | } |
| 4866 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4867 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 4868 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 4869 | if (ret) { |
| 4870 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4871 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 4872 | i40e_stat_str(&vsi->back->hw, ret), |
| 4873 | i40e_aq_str(&vsi->back->hw, |
| 4874 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4875 | goto out; |
| 4876 | } |
| 4877 | /* update the local VSI info with updated queue map */ |
| 4878 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 4879 | vsi->info.valid_sections = 0; |
| 4880 | |
| 4881 | /* Update current VSI BW information */ |
| 4882 | ret = i40e_vsi_get_bw_info(vsi); |
| 4883 | if (ret) { |
| 4884 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4885 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 4886 | i40e_stat_str(&vsi->back->hw, ret), |
| 4887 | i40e_aq_str(&vsi->back->hw, |
| 4888 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4889 | goto out; |
| 4890 | } |
| 4891 | |
| 4892 | /* Update the netdev TC setup */ |
| 4893 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 4894 | out: |
| 4895 | return ret; |
| 4896 | } |
| 4897 | |
| 4898 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4899 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 4900 | * @veb: given VEB |
| 4901 | * @enabled_tc: TC bitmap |
| 4902 | * |
| 4903 | * Configures given TC bitmap for VEB (switching) element |
| 4904 | **/ |
| 4905 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 4906 | { |
| 4907 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 4908 | struct i40e_pf *pf = veb->pf; |
| 4909 | int ret = 0; |
| 4910 | int i; |
| 4911 | |
| 4912 | /* No TCs or already enabled TCs just return */ |
| 4913 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 4914 | return ret; |
| 4915 | |
| 4916 | bw_data.tc_valid_bits = enabled_tc; |
| 4917 | /* bw_data.absolute_credits is not set (relative) */ |
| 4918 | |
| 4919 | /* Enable ETS TCs with equal BW Share for now */ |
| 4920 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4921 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4922 | bw_data.tc_bw_share_credits[i] = 1; |
| 4923 | } |
| 4924 | |
| 4925 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 4926 | &bw_data, NULL); |
| 4927 | if (ret) { |
| 4928 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4929 | "VEB bw config failed, err %s aq_err %s\n", |
| 4930 | i40e_stat_str(&pf->hw, ret), |
| 4931 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4932 | goto out; |
| 4933 | } |
| 4934 | |
| 4935 | /* Update the BW information */ |
| 4936 | ret = i40e_veb_get_bw_info(veb); |
| 4937 | if (ret) { |
| 4938 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4939 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 4940 | i40e_stat_str(&pf->hw, ret), |
| 4941 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | out: |
| 4945 | return ret; |
| 4946 | } |
| 4947 | |
| 4948 | #ifdef CONFIG_I40E_DCB |
| 4949 | /** |
| 4950 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 4951 | * @pf: PF struct |
| 4952 | * |
| 4953 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 4954 | * the caller would've quiesce all the VSIs before calling |
| 4955 | * this function |
| 4956 | **/ |
| 4957 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 4958 | { |
| 4959 | u8 tc_map = 0; |
| 4960 | int ret; |
| 4961 | u8 v; |
| 4962 | |
| 4963 | /* Enable the TCs available on PF to all VEBs */ |
| 4964 | tc_map = i40e_pf_get_tc_map(pf); |
| 4965 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 4966 | if (!pf->veb[v]) |
| 4967 | continue; |
| 4968 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 4969 | if (ret) { |
| 4970 | dev_info(&pf->pdev->dev, |
| 4971 | "Failed configuring TC for VEB seid=%d\n", |
| 4972 | pf->veb[v]->seid); |
| 4973 | /* Will try to configure as many components */ |
| 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4978 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4979 | if (!pf->vsi[v]) |
| 4980 | continue; |
| 4981 | |
| 4982 | /* - Enable all TCs for the LAN VSI |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4983 | #ifdef I40E_FCOE |
| 4984 | * - For FCoE VSI only enable the TC configured |
| 4985 | * as per the APP TLV |
| 4986 | #endif |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4987 | * - For all others keep them at TC0 for now |
| 4988 | */ |
| 4989 | if (v == pf->lan_vsi) |
| 4990 | tc_map = i40e_pf_get_tc_map(pf); |
| 4991 | else |
| 4992 | tc_map = i40e_pf_get_default_tc(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4993 | #ifdef I40E_FCOE |
| 4994 | if (pf->vsi[v]->type == I40E_VSI_FCOE) |
| 4995 | tc_map = i40e_get_fcoe_tc_map(pf); |
| 4996 | #endif /* #ifdef I40E_FCOE */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4997 | |
| 4998 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 4999 | if (ret) { |
| 5000 | dev_info(&pf->pdev->dev, |
| 5001 | "Failed configuring TC for VSI seid=%d\n", |
| 5002 | pf->vsi[v]->seid); |
| 5003 | /* Will try to configure as many components */ |
| 5004 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 5005 | /* Re-configure VSI vectors based on updated TC map */ |
| 5006 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5007 | if (pf->vsi[v]->netdev) |
| 5008 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 5009 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5010 | i40e_notify_client_of_l2_param_changes(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5011 | } |
| 5012 | } |
| 5013 | |
| 5014 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5015 | * i40e_resume_port_tx - Resume port Tx |
| 5016 | * @pf: PF struct |
| 5017 | * |
| 5018 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 5019 | * resume. |
| 5020 | **/ |
| 5021 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 5022 | { |
| 5023 | struct i40e_hw *hw = &pf->hw; |
| 5024 | int ret; |
| 5025 | |
| 5026 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 5027 | if (ret) { |
| 5028 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5029 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 5030 | i40e_stat_str(&pf->hw, ret), |
| 5031 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5032 | /* Schedule PF reset to recover */ |
| 5033 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5034 | i40e_service_event_schedule(pf); |
| 5035 | } |
| 5036 | |
| 5037 | return ret; |
| 5038 | } |
| 5039 | |
| 5040 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5041 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 5042 | * @pf: PF being configured |
| 5043 | * |
| 5044 | * Query the current DCB configuration and cache it |
| 5045 | * in the hardware structure |
| 5046 | **/ |
| 5047 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 5048 | { |
| 5049 | struct i40e_hw *hw = &pf->hw; |
| 5050 | int err = 0; |
| 5051 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5052 | /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */ |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 5053 | if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5054 | goto out; |
| 5055 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5056 | /* Get the initial DCB configuration */ |
| 5057 | err = i40e_init_dcb(hw); |
| 5058 | if (!err) { |
| 5059 | /* Device/Function is not DCBX capable */ |
| 5060 | if ((!hw->func_caps.dcb) || |
| 5061 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5062 | dev_info(&pf->pdev->dev, |
| 5063 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 5064 | |
| 5065 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 5066 | goto out; |
| 5067 | |
| 5068 | } else { |
| 5069 | /* When status is not DISABLED then DCBX in FW */ |
| 5070 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5071 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5072 | |
| 5073 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
| 5074 | /* Enable DCB tagging only when more than one TC */ |
| 5075 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5076 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5077 | dev_dbg(&pf->pdev->dev, |
| 5078 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5079 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5080 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5081 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5082 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5083 | i40e_stat_str(&pf->hw, err), |
| 5084 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5085 | } |
| 5086 | |
| 5087 | out: |
| 5088 | return err; |
| 5089 | } |
| 5090 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5091 | #define SPEED_SIZE 14 |
| 5092 | #define FC_SIZE 8 |
| 5093 | /** |
| 5094 | * i40e_print_link_message - print link up or down |
| 5095 | * @vsi: the VSI for which link needs a message |
| 5096 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5097 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5098 | { |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5099 | char *speed = "Unknown"; |
| 5100 | char *fc = "Unknown"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5101 | |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5102 | if (vsi->current_isup == isup) |
| 5103 | return; |
| 5104 | vsi->current_isup = isup; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5105 | if (!isup) { |
| 5106 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5107 | return; |
| 5108 | } |
| 5109 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5110 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5111 | * least 10GB |
| 5112 | */ |
| 5113 | if (vsi->back->hw.func_caps.npar_enable && |
| 5114 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5115 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5116 | netdev_warn(vsi->netdev, |
| 5117 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5118 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5119 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5120 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5121 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5122 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5123 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5124 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5125 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5126 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5127 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5128 | break; |
| 5129 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5130 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5131 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5132 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5133 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5134 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5135 | default: |
| 5136 | break; |
| 5137 | } |
| 5138 | |
| 5139 | switch (vsi->back->hw.fc.current_mode) { |
| 5140 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5141 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5142 | break; |
| 5143 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5144 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5145 | break; |
| 5146 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5147 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5148 | break; |
| 5149 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5150 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5151 | break; |
| 5152 | } |
| 5153 | |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5154 | 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] | 5155 | speed, fc); |
| 5156 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5157 | |
| 5158 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5159 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5160 | * @vsi: the VSI being configured |
| 5161 | **/ |
| 5162 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5163 | { |
| 5164 | struct i40e_pf *pf = vsi->back; |
| 5165 | int err; |
| 5166 | |
| 5167 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5168 | i40e_vsi_configure_msix(vsi); |
| 5169 | else |
| 5170 | i40e_configure_msi_and_legacy(vsi); |
| 5171 | |
| 5172 | /* start rings */ |
| 5173 | err = i40e_vsi_control_rings(vsi, true); |
| 5174 | if (err) |
| 5175 | return err; |
| 5176 | |
| 5177 | clear_bit(__I40E_DOWN, &vsi->state); |
| 5178 | i40e_napi_enable_all(vsi); |
| 5179 | i40e_vsi_enable_irq(vsi); |
| 5180 | |
| 5181 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5182 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5183 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5184 | netif_tx_start_all_queues(vsi->netdev); |
| 5185 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5186 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5187 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5188 | /* need to check for qualified module here*/ |
| 5189 | if ((pf->hw.phy.link_info.link_info & |
| 5190 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5191 | (!(pf->hw.phy.link_info.an_info & |
| 5192 | I40E_AQ_QUALIFIED_MODULE))) |
| 5193 | netdev_err(vsi->netdev, |
| 5194 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5195 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5196 | |
| 5197 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5198 | if (vsi->type == I40E_VSI_FDIR) { |
| 5199 | /* reset fd counters */ |
| 5200 | pf->fd_add_err = pf->fd_atr_cnt = 0; |
| 5201 | if (pf->fd_tcp_rule > 0) { |
| 5202 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5203 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5204 | 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] | 5205 | pf->fd_tcp_rule = 0; |
| 5206 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5207 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5208 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5209 | |
| 5210 | /* On the next run of the service_task, notify any clients of the new |
| 5211 | * opened netdev |
| 5212 | */ |
| 5213 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5214 | i40e_service_event_schedule(pf); |
| 5215 | |
| 5216 | return 0; |
| 5217 | } |
| 5218 | |
| 5219 | /** |
| 5220 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5221 | * @vsi: the VSI being configured |
| 5222 | * |
| 5223 | * Rebuild the ring structs after some configuration |
| 5224 | * has changed, e.g. MTU size. |
| 5225 | **/ |
| 5226 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5227 | { |
| 5228 | struct i40e_pf *pf = vsi->back; |
| 5229 | |
| 5230 | WARN_ON(in_interrupt()); |
| 5231 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5232 | usleep_range(1000, 2000); |
| 5233 | i40e_down(vsi); |
| 5234 | |
| 5235 | /* Give a VF some time to respond to the reset. The |
| 5236 | * two second wait is based upon the watchdog cycle in |
| 5237 | * the VF driver. |
| 5238 | */ |
| 5239 | if (vsi->type == I40E_VSI_SRIOV) |
| 5240 | msleep(2000); |
| 5241 | i40e_up(vsi); |
| 5242 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 5243 | } |
| 5244 | |
| 5245 | /** |
| 5246 | * i40e_up - Bring the connection back up after being down |
| 5247 | * @vsi: the VSI being configured |
| 5248 | **/ |
| 5249 | int i40e_up(struct i40e_vsi *vsi) |
| 5250 | { |
| 5251 | int err; |
| 5252 | |
| 5253 | err = i40e_vsi_configure(vsi); |
| 5254 | if (!err) |
| 5255 | err = i40e_up_complete(vsi); |
| 5256 | |
| 5257 | return err; |
| 5258 | } |
| 5259 | |
| 5260 | /** |
| 5261 | * i40e_down - Shutdown the connection processing |
| 5262 | * @vsi: the VSI being stopped |
| 5263 | **/ |
| 5264 | void i40e_down(struct i40e_vsi *vsi) |
| 5265 | { |
| 5266 | int i; |
| 5267 | |
| 5268 | /* It is assumed that the caller of this function |
| 5269 | * sets the vsi->state __I40E_DOWN bit. |
| 5270 | */ |
| 5271 | if (vsi->netdev) { |
| 5272 | netif_carrier_off(vsi->netdev); |
| 5273 | netif_tx_disable(vsi->netdev); |
| 5274 | } |
| 5275 | i40e_vsi_disable_irq(vsi); |
| 5276 | i40e_vsi_control_rings(vsi, false); |
| 5277 | i40e_napi_disable_all(vsi); |
| 5278 | |
| 5279 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5280 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 5281 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5282 | } |
| 5283 | } |
| 5284 | |
| 5285 | /** |
| 5286 | * i40e_setup_tc - configure multiple traffic classes |
| 5287 | * @netdev: net device to configure |
| 5288 | * @tc: number of traffic classes to enable |
| 5289 | **/ |
| 5290 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5291 | { |
| 5292 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5293 | struct i40e_vsi *vsi = np->vsi; |
| 5294 | struct i40e_pf *pf = vsi->back; |
| 5295 | u8 enabled_tc = 0; |
| 5296 | int ret = -EINVAL; |
| 5297 | int i; |
| 5298 | |
| 5299 | /* Check if DCB enabled to continue */ |
| 5300 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5301 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5302 | goto exit; |
| 5303 | } |
| 5304 | |
| 5305 | /* Check if MFP enabled */ |
| 5306 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5307 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5308 | goto exit; |
| 5309 | } |
| 5310 | |
| 5311 | /* Check whether tc count is within enabled limit */ |
| 5312 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5313 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5314 | goto exit; |
| 5315 | } |
| 5316 | |
| 5317 | /* Generate TC map for number of tc requested */ |
| 5318 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5319 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5320 | |
| 5321 | /* Requesting same TC configuration as already enabled */ |
| 5322 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5323 | return 0; |
| 5324 | |
| 5325 | /* Quiesce VSI queues */ |
| 5326 | i40e_quiesce_vsi(vsi); |
| 5327 | |
| 5328 | /* Configure VSI for enabled TCs */ |
| 5329 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5330 | if (ret) { |
| 5331 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5332 | vsi->seid); |
| 5333 | goto exit; |
| 5334 | } |
| 5335 | |
| 5336 | /* Unquiesce VSI */ |
| 5337 | i40e_unquiesce_vsi(vsi); |
| 5338 | |
| 5339 | exit: |
| 5340 | return ret; |
| 5341 | } |
| 5342 | |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5343 | #ifdef I40E_FCOE |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5344 | int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5345 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5346 | #else |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5347 | static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5348 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5349 | #endif |
| 5350 | { |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5351 | if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5352 | return -EINVAL; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5353 | return i40e_setup_tc(netdev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5354 | } |
| 5355 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5356 | /** |
| 5357 | * i40e_open - Called when a network interface is made active |
| 5358 | * @netdev: network interface device structure |
| 5359 | * |
| 5360 | * The open entry point is called when a network interface is made |
| 5361 | * active by the system (IFF_UP). At this point all resources needed |
| 5362 | * for transmit and receive operations are allocated, the interrupt |
| 5363 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5364 | * enabled, and the stack is notified that the interface is ready. |
| 5365 | * |
| 5366 | * Returns 0 on success, negative value on failure |
| 5367 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5368 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5369 | { |
| 5370 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5371 | struct i40e_vsi *vsi = np->vsi; |
| 5372 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5373 | int err; |
| 5374 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5375 | /* disallow open during test or if eeprom is broken */ |
| 5376 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 5377 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5378 | return -EBUSY; |
| 5379 | |
| 5380 | netif_carrier_off(netdev); |
| 5381 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5382 | err = i40e_vsi_open(vsi); |
| 5383 | if (err) |
| 5384 | return err; |
| 5385 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5386 | /* configure global TSO hardware offload settings */ |
| 5387 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5388 | TCP_FLAG_FIN) >> 16); |
| 5389 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5390 | TCP_FLAG_FIN | |
| 5391 | TCP_FLAG_CWR) >> 16); |
| 5392 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5393 | |
Singhai, Anjali | 6633d38 | 2015-12-03 23:49:31 -0800 | [diff] [blame] | 5394 | #ifdef CONFIG_I40E_VXLAN |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5395 | vxlan_get_rx_port(netdev); |
| 5396 | #endif |
Singhai, Anjali | cd86660 | 2015-12-14 12:21:21 -0800 | [diff] [blame] | 5397 | #ifdef CONFIG_I40E_GENEVE |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 5398 | if (pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE) |
| 5399 | geneve_get_rx_port(netdev); |
Singhai, Anjali | cd86660 | 2015-12-14 12:21:21 -0800 | [diff] [blame] | 5400 | #endif |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5401 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5402 | i40e_notify_client_of_netdev_open(vsi); |
| 5403 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5404 | return 0; |
| 5405 | } |
| 5406 | |
| 5407 | /** |
| 5408 | * i40e_vsi_open - |
| 5409 | * @vsi: the VSI to open |
| 5410 | * |
| 5411 | * Finish initialization of the VSI. |
| 5412 | * |
| 5413 | * Returns 0 on success, negative value on failure |
| 5414 | **/ |
| 5415 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5416 | { |
| 5417 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5418 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5419 | int err; |
| 5420 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5421 | /* allocate descriptors */ |
| 5422 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5423 | if (err) |
| 5424 | goto err_setup_tx; |
| 5425 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5426 | if (err) |
| 5427 | goto err_setup_rx; |
| 5428 | |
| 5429 | err = i40e_vsi_configure(vsi); |
| 5430 | if (err) |
| 5431 | goto err_setup_rx; |
| 5432 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5433 | if (vsi->netdev) { |
| 5434 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5435 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5436 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5437 | if (err) |
| 5438 | goto err_setup_rx; |
| 5439 | |
| 5440 | /* Notify the stack of the actual queue counts. */ |
| 5441 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5442 | vsi->num_queue_pairs); |
| 5443 | if (err) |
| 5444 | goto err_set_queues; |
| 5445 | |
| 5446 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5447 | vsi->num_queue_pairs); |
| 5448 | if (err) |
| 5449 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5450 | |
| 5451 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5452 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5453 | dev_driver_string(&pf->pdev->dev), |
| 5454 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5455 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5456 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5457 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5458 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5459 | goto err_setup_rx; |
| 5460 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5461 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5462 | err = i40e_up_complete(vsi); |
| 5463 | if (err) |
| 5464 | goto err_up_complete; |
| 5465 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5466 | return 0; |
| 5467 | |
| 5468 | err_up_complete: |
| 5469 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5470 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5471 | i40e_vsi_free_irq(vsi); |
| 5472 | err_setup_rx: |
| 5473 | i40e_vsi_free_rx_resources(vsi); |
| 5474 | err_setup_tx: |
| 5475 | i40e_vsi_free_tx_resources(vsi); |
| 5476 | if (vsi == pf->vsi[pf->lan_vsi]) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5477 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5478 | |
| 5479 | return err; |
| 5480 | } |
| 5481 | |
| 5482 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5483 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5484 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5485 | * |
| 5486 | * This function destroys the hlist where all the Flow Director |
| 5487 | * filters were saved. |
| 5488 | **/ |
| 5489 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5490 | { |
| 5491 | struct i40e_fdir_filter *filter; |
| 5492 | struct hlist_node *node2; |
| 5493 | |
| 5494 | hlist_for_each_entry_safe(filter, node2, |
| 5495 | &pf->fdir_filter_list, fdir_node) { |
| 5496 | hlist_del(&filter->fdir_node); |
| 5497 | kfree(filter); |
| 5498 | } |
| 5499 | pf->fdir_pf_active_filters = 0; |
| 5500 | } |
| 5501 | |
| 5502 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5503 | * i40e_close - Disables a network interface |
| 5504 | * @netdev: network interface device structure |
| 5505 | * |
| 5506 | * The close entry point is called when an interface is de-activated |
| 5507 | * by the OS. The hardware is still under the driver's control, but |
| 5508 | * this netdev interface is disabled. |
| 5509 | * |
| 5510 | * Returns 0, this is not allowed to fail |
| 5511 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5512 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5513 | { |
| 5514 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5515 | struct i40e_vsi *vsi = np->vsi; |
| 5516 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5517 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5518 | |
| 5519 | return 0; |
| 5520 | } |
| 5521 | |
| 5522 | /** |
| 5523 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5524 | * @pf: board private structure |
| 5525 | * @reset_flags: which reset is requested |
| 5526 | * |
| 5527 | * The essential difference in resets is that the PF Reset |
| 5528 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5529 | * firmware, and doesn't bother the other PFs on the chip. |
| 5530 | **/ |
| 5531 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5532 | { |
| 5533 | u32 val; |
| 5534 | |
| 5535 | WARN_ON(in_interrupt()); |
| 5536 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5537 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5538 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5539 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5540 | |
| 5541 | /* Request a Global Reset |
| 5542 | * |
| 5543 | * This will start the chip's countdown to the actual full |
| 5544 | * chip reset event, and a warning interrupt to be sent |
| 5545 | * to all PFs, including the requestor. Our handler |
| 5546 | * for the warning interrupt will deal with the shutdown |
| 5547 | * and recovery of the switch setup. |
| 5548 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5549 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5550 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5551 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5552 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5553 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5554 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5555 | |
| 5556 | /* Request a Core Reset |
| 5557 | * |
| 5558 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5559 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5560 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5561 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5562 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5563 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5564 | i40e_flush(&pf->hw); |
| 5565 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5566 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5567 | |
| 5568 | /* Request a PF Reset |
| 5569 | * |
| 5570 | * Resets only the PF-specific registers |
| 5571 | * |
| 5572 | * This goes directly to the tear-down and rebuild of |
| 5573 | * the switch, since we need to do all the recovery as |
| 5574 | * for the Core Reset. |
| 5575 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5576 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5577 | i40e_handle_reset_warning(pf); |
| 5578 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5579 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5580 | int v; |
| 5581 | |
| 5582 | /* Find the VSI(s) that requested a re-init */ |
| 5583 | dev_info(&pf->pdev->dev, |
| 5584 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5585 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5586 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5587 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5588 | if (vsi != NULL && |
| 5589 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5590 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5591 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5592 | } |
| 5593 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5594 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5595 | int v; |
| 5596 | |
| 5597 | /* Find the VSI(s) that needs to be brought down */ |
| 5598 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5599 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5600 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5601 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5602 | if (vsi != NULL && |
| 5603 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5604 | set_bit(__I40E_DOWN, &vsi->state); |
| 5605 | i40e_down(vsi); |
| 5606 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5607 | } |
| 5608 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5609 | } else { |
| 5610 | dev_info(&pf->pdev->dev, |
| 5611 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5612 | } |
| 5613 | } |
| 5614 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5615 | #ifdef CONFIG_I40E_DCB |
| 5616 | /** |
| 5617 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5618 | * @pf: board private structure |
| 5619 | * @old_cfg: current DCB config |
| 5620 | * @new_cfg: new DCB config |
| 5621 | **/ |
| 5622 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5623 | struct i40e_dcbx_config *old_cfg, |
| 5624 | struct i40e_dcbx_config *new_cfg) |
| 5625 | { |
| 5626 | bool need_reconfig = false; |
| 5627 | |
| 5628 | /* Check if ETS configuration has changed */ |
| 5629 | if (memcmp(&new_cfg->etscfg, |
| 5630 | &old_cfg->etscfg, |
| 5631 | sizeof(new_cfg->etscfg))) { |
| 5632 | /* If Priority Table has changed reconfig is needed */ |
| 5633 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5634 | &old_cfg->etscfg.prioritytable, |
| 5635 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5636 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5637 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5638 | } |
| 5639 | |
| 5640 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5641 | &old_cfg->etscfg.tcbwtable, |
| 5642 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5643 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5644 | |
| 5645 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5646 | &old_cfg->etscfg.tsatable, |
| 5647 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5648 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5649 | } |
| 5650 | |
| 5651 | /* Check if PFC configuration has changed */ |
| 5652 | if (memcmp(&new_cfg->pfc, |
| 5653 | &old_cfg->pfc, |
| 5654 | sizeof(new_cfg->pfc))) { |
| 5655 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5656 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5657 | } |
| 5658 | |
| 5659 | /* Check if APP Table has changed */ |
| 5660 | if (memcmp(&new_cfg->app, |
| 5661 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5662 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5663 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5664 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5665 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5666 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5667 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5668 | return need_reconfig; |
| 5669 | } |
| 5670 | |
| 5671 | /** |
| 5672 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5673 | * @pf: board private structure |
| 5674 | * @e: event info posted on ARQ |
| 5675 | **/ |
| 5676 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5677 | struct i40e_arq_event_info *e) |
| 5678 | { |
| 5679 | struct i40e_aqc_lldp_get_mib *mib = |
| 5680 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5681 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5682 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5683 | bool need_reconfig = false; |
| 5684 | int ret = 0; |
| 5685 | u8 type; |
| 5686 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5687 | /* Not DCB capable or capability disabled */ |
| 5688 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
| 5689 | return ret; |
| 5690 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5691 | /* Ignore if event is not for Nearest Bridge */ |
| 5692 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5693 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5694 | 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] | 5695 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5696 | return ret; |
| 5697 | |
| 5698 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5699 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5700 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5701 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5702 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5703 | /* Update the remote cached instance and return */ |
| 5704 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5705 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5706 | &hw->remote_dcbx_config); |
| 5707 | goto exit; |
| 5708 | } |
| 5709 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5710 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5711 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5712 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5713 | /* Reset the old DCBx configuration data */ |
| 5714 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5715 | /* Get updated DCBX data from firmware */ |
| 5716 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5717 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5718 | dev_info(&pf->pdev->dev, |
| 5719 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 5720 | i40e_stat_str(&pf->hw, ret), |
| 5721 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5722 | goto exit; |
| 5723 | } |
| 5724 | |
| 5725 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5726 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5727 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5728 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5729 | goto exit; |
| 5730 | } |
| 5731 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5732 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5733 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5734 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5735 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5736 | |
| 5737 | if (!need_reconfig) |
| 5738 | goto exit; |
| 5739 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5740 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5741 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5742 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5743 | else |
| 5744 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5745 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5746 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5747 | /* Reconfiguration needed quiesce all VSIs */ |
| 5748 | i40e_pf_quiesce_all_vsi(pf); |
| 5749 | |
| 5750 | /* Changes in configuration update VEB/VSI */ |
| 5751 | i40e_dcb_reconfigure(pf); |
| 5752 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5753 | ret = i40e_resume_port_tx(pf); |
| 5754 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5755 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5756 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5757 | if (ret) |
| 5758 | goto exit; |
| 5759 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 5760 | /* Wait for the PF's queues to be disabled */ |
| 5761 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5762 | if (ret) { |
| 5763 | /* Schedule PF reset to recover */ |
| 5764 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5765 | i40e_service_event_schedule(pf); |
| 5766 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5767 | i40e_pf_unquiesce_all_vsi(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5768 | } |
| 5769 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5770 | exit: |
| 5771 | return ret; |
| 5772 | } |
| 5773 | #endif /* CONFIG_I40E_DCB */ |
| 5774 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5775 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5776 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 5777 | * @pf: board private structure |
| 5778 | * @reset_flags: which reset is requested |
| 5779 | * |
| 5780 | **/ |
| 5781 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 5782 | { |
| 5783 | rtnl_lock(); |
| 5784 | i40e_do_reset(pf, reset_flags); |
| 5785 | rtnl_unlock(); |
| 5786 | } |
| 5787 | |
| 5788 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5789 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 5790 | * @pf: board private structure |
| 5791 | * @e: event info posted on ARQ |
| 5792 | * |
| 5793 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 5794 | * and VF queues |
| 5795 | **/ |
| 5796 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 5797 | struct i40e_arq_event_info *e) |
| 5798 | { |
| 5799 | struct i40e_aqc_lan_overflow *data = |
| 5800 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 5801 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 5802 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 5803 | struct i40e_hw *hw = &pf->hw; |
| 5804 | struct i40e_vf *vf; |
| 5805 | u16 vf_id; |
| 5806 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5807 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 5808 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5809 | |
| 5810 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 5811 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 5812 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 5813 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 5814 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 5815 | vf_id -= hw->func_caps.vf_base_id; |
| 5816 | vf = &pf->vf[vf_id]; |
| 5817 | i40e_vc_notify_vf_reset(vf); |
| 5818 | /* Allow VF to process pending reset notification */ |
| 5819 | msleep(20); |
| 5820 | i40e_reset_vf(vf, false); |
| 5821 | } |
| 5822 | } |
| 5823 | |
| 5824 | /** |
| 5825 | * i40e_service_event_complete - Finish up the service event |
| 5826 | * @pf: board private structure |
| 5827 | **/ |
| 5828 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 5829 | { |
Shannon Nelson | b875f99 | 2015-10-21 19:47:03 -0400 | [diff] [blame] | 5830 | WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5831 | |
| 5832 | /* flush memory to make sure state is correct before next watchog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5833 | smp_mb__before_atomic(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5834 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 5835 | } |
| 5836 | |
| 5837 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5838 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 5839 | * @pf: board private structure |
| 5840 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5841 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5842 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5843 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5844 | |
| 5845 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5846 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 5847 | return fcnt_prog; |
| 5848 | } |
| 5849 | |
| 5850 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5851 | * 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] | 5852 | * @pf: board private structure |
| 5853 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5854 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5855 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5856 | u32 val, fcnt_prog; |
| 5857 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5858 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5859 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 5860 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 5861 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 5862 | return fcnt_prog; |
| 5863 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5864 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5865 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5866 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 5867 | * @pf: board private structure |
| 5868 | **/ |
| 5869 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 5870 | { |
| 5871 | u32 val, fcnt_prog; |
| 5872 | |
| 5873 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 5874 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 5875 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 5876 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 5877 | return fcnt_prog; |
| 5878 | } |
| 5879 | |
| 5880 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5881 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 5882 | * @pf: board private structure |
| 5883 | **/ |
| 5884 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 5885 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5886 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5887 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5888 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5889 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5890 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 5891 | return; |
| 5892 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5893 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 5894 | * to re-enable |
| 5895 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5896 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5897 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5898 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 5899 | (pf->fd_add_err == 0) || |
| 5900 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5901 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 5902 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 5903 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5904 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5905 | 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] | 5906 | } |
| 5907 | } |
| 5908 | /* Wait for some more space to be available to turn on ATR */ |
| 5909 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 5910 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 5911 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
| 5912 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5913 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5914 | 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] | 5915 | } |
| 5916 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5917 | |
| 5918 | /* if hw had a problem adding a filter, delete it */ |
| 5919 | if (pf->fd_inv > 0) { |
| 5920 | hlist_for_each_entry_safe(filter, node, |
| 5921 | &pf->fdir_filter_list, fdir_node) { |
| 5922 | if (filter->fd_id == pf->fd_inv) { |
| 5923 | hlist_del(&filter->fdir_node); |
| 5924 | kfree(filter); |
| 5925 | pf->fdir_pf_active_filters--; |
| 5926 | } |
| 5927 | } |
| 5928 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5929 | } |
| 5930 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5931 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5932 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5933 | /** |
| 5934 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 5935 | * @pf: board private structure |
| 5936 | **/ |
| 5937 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 5938 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5939 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5940 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5941 | bool disable_atr = false; |
| 5942 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5943 | int reg; |
| 5944 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 5945 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 5946 | return; |
| 5947 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5948 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 5949 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 5950 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5951 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5952 | /* If the flush is happening too quick and we have mostly SB rules we |
| 5953 | * should not re-enable ATR for some time. |
| 5954 | */ |
| 5955 | min_flush_time = pf->fd_flush_timestamp + |
| 5956 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 5957 | 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] | 5958 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5959 | if (!(time_after(jiffies, min_flush_time)) && |
| 5960 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 5961 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5962 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 5963 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5964 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5965 | |
| 5966 | pf->fd_flush_timestamp = jiffies; |
| 5967 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
| 5968 | /* flush all filters */ |
| 5969 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 5970 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 5971 | i40e_flush(&pf->hw); |
| 5972 | pf->fd_flush_cnt++; |
| 5973 | pf->fd_add_err = 0; |
| 5974 | do { |
| 5975 | /* Check FD flush status every 5-6msec */ |
| 5976 | usleep_range(5000, 6000); |
| 5977 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 5978 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 5979 | break; |
| 5980 | } while (flush_wait_retry--); |
| 5981 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 5982 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 5983 | } else { |
| 5984 | /* replay sideband filters */ |
| 5985 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
| 5986 | if (!disable_atr) |
| 5987 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 5988 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
| 5989 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5990 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 5991 | } |
| 5992 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5993 | } |
| 5994 | |
| 5995 | /** |
| 5996 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 5997 | * @pf: board private structure |
| 5998 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5999 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6000 | { |
| 6001 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 6002 | } |
| 6003 | |
| 6004 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 6005 | * being applied really fast; before we see the first |
| 6006 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 6007 | * reacting will make sure we don't cause flush too often. |
| 6008 | */ |
| 6009 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 6010 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6011 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6012 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 6013 | * @pf: board private structure |
| 6014 | **/ |
| 6015 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 6016 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6017 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6018 | /* if interface is down do nothing */ |
| 6019 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 6020 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6021 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 6022 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 6023 | return; |
| 6024 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6025 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6026 | i40e_fdir_flush_and_replay(pf); |
| 6027 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6028 | i40e_fdir_check_and_reenable(pf); |
| 6029 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6030 | } |
| 6031 | |
| 6032 | /** |
| 6033 | * i40e_vsi_link_event - notify VSI of a link event |
| 6034 | * @vsi: vsi to be notified |
| 6035 | * @link_up: link up or down |
| 6036 | **/ |
| 6037 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 6038 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 6039 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6040 | return; |
| 6041 | |
| 6042 | switch (vsi->type) { |
| 6043 | case I40E_VSI_MAIN: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6044 | #ifdef I40E_FCOE |
| 6045 | case I40E_VSI_FCOE: |
| 6046 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6047 | if (!vsi->netdev || !vsi->netdev_registered) |
| 6048 | break; |
| 6049 | |
| 6050 | if (link_up) { |
| 6051 | netif_carrier_on(vsi->netdev); |
| 6052 | netif_tx_wake_all_queues(vsi->netdev); |
| 6053 | } else { |
| 6054 | netif_carrier_off(vsi->netdev); |
| 6055 | netif_tx_stop_all_queues(vsi->netdev); |
| 6056 | } |
| 6057 | break; |
| 6058 | |
| 6059 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6060 | case I40E_VSI_VMDQ2: |
| 6061 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6062 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6063 | case I40E_VSI_MIRROR: |
| 6064 | default: |
| 6065 | /* there is no notification for other VSIs */ |
| 6066 | break; |
| 6067 | } |
| 6068 | } |
| 6069 | |
| 6070 | /** |
| 6071 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6072 | * @veb: veb to be notified |
| 6073 | * @link_up: link up or down |
| 6074 | **/ |
| 6075 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6076 | { |
| 6077 | struct i40e_pf *pf; |
| 6078 | int i; |
| 6079 | |
| 6080 | if (!veb || !veb->pf) |
| 6081 | return; |
| 6082 | pf = veb->pf; |
| 6083 | |
| 6084 | /* depth first... */ |
| 6085 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6086 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6087 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6088 | |
| 6089 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6090 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6091 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6092 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6093 | } |
| 6094 | |
| 6095 | /** |
| 6096 | * i40e_link_event - Update netif_carrier status |
| 6097 | * @pf: board private structure |
| 6098 | **/ |
| 6099 | static void i40e_link_event(struct i40e_pf *pf) |
| 6100 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6101 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6102 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6103 | i40e_status status; |
| 6104 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6105 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6106 | /* save off old link status information */ |
| 6107 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6108 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6109 | /* set this to force the get_link_status call to refresh state */ |
| 6110 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6111 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6112 | 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] | 6113 | |
| 6114 | status = i40e_get_link_status(&pf->hw, &new_link); |
| 6115 | if (status) { |
| 6116 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6117 | status); |
| 6118 | return; |
| 6119 | } |
| 6120 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6121 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6122 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6123 | |
| 6124 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6125 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6126 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 6127 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6128 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6129 | |
| 6130 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 6131 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6132 | |
| 6133 | /* Notify the base of the switch tree connected to |
| 6134 | * the link. Floating VEBs are not notified. |
| 6135 | */ |
| 6136 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6137 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6138 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6139 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6140 | |
| 6141 | if (pf->vf) |
| 6142 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6143 | |
| 6144 | if (pf->flags & I40E_FLAG_PTP) |
| 6145 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6146 | } |
| 6147 | |
| 6148 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6149 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6150 | * @pf: board private structure |
| 6151 | **/ |
| 6152 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6153 | { |
| 6154 | int i; |
| 6155 | |
| 6156 | /* if interface is down do nothing */ |
| 6157 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 6158 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6159 | return; |
| 6160 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6161 | /* make sure we don't do these things too often */ |
| 6162 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6163 | pf->service_timer_period))) |
| 6164 | return; |
| 6165 | pf->service_timer_previous = jiffies; |
| 6166 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6167 | if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) |
| 6168 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6169 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6170 | /* Update the stats for active netdevs so the network stack |
| 6171 | * can look at updated numbers whenever it cares to |
| 6172 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6173 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6174 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6175 | i40e_update_stats(pf->vsi[i]); |
| 6176 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6177 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6178 | /* Update the stats for the active switching components */ |
| 6179 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6180 | if (pf->veb[i]) |
| 6181 | i40e_update_veb_stats(pf->veb[i]); |
| 6182 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6183 | |
| 6184 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6185 | } |
| 6186 | |
| 6187 | /** |
| 6188 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6189 | * @pf: board private structure |
| 6190 | **/ |
| 6191 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6192 | { |
| 6193 | u32 reset_flags = 0; |
| 6194 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6195 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6196 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6197 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6198 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 6199 | } |
| 6200 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6201 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6202 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6203 | } |
| 6204 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6205 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6206 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 6207 | } |
| 6208 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6209 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6210 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 6211 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6212 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6213 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6214 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 6215 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6216 | |
| 6217 | /* If there's a recovery already waiting, it takes |
| 6218 | * precedence before starting a new reset sequence. |
| 6219 | */ |
| 6220 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 6221 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6222 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | /* If we're already down or resetting, just bail */ |
| 6226 | if (reset_flags && |
| 6227 | !test_bit(__I40E_DOWN, &pf->state) && |
| 6228 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6229 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6230 | |
| 6231 | unlock: |
| 6232 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6233 | } |
| 6234 | |
| 6235 | /** |
| 6236 | * i40e_handle_link_event - Handle link event |
| 6237 | * @pf: board private structure |
| 6238 | * @e: event info posted on ARQ |
| 6239 | **/ |
| 6240 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6241 | struct i40e_arq_event_info *e) |
| 6242 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6243 | struct i40e_aqc_get_link_status *status = |
| 6244 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6245 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6246 | /* Do a new status request to re-enable LSE reporting |
| 6247 | * and load new status information into the hw struct |
| 6248 | * This completely ignores any state information |
| 6249 | * in the ARQ event info, instead choosing to always |
| 6250 | * issue the AQ update link status command. |
| 6251 | */ |
| 6252 | i40e_link_event(pf); |
| 6253 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6254 | /* check for unqualified module, if link is down */ |
| 6255 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6256 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6257 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6258 | dev_err(&pf->pdev->dev, |
| 6259 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6260 | } |
| 6261 | |
| 6262 | /** |
| 6263 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6264 | * @pf: board private structure |
| 6265 | **/ |
| 6266 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6267 | { |
| 6268 | struct i40e_arq_event_info event; |
| 6269 | struct i40e_hw *hw = &pf->hw; |
| 6270 | u16 pending, i = 0; |
| 6271 | i40e_status ret; |
| 6272 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6273 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6274 | u32 val; |
| 6275 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6276 | /* Do not run clean AQ when PF reset fails */ |
| 6277 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 6278 | return; |
| 6279 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6280 | /* check for error indications */ |
| 6281 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6282 | oldval = val; |
| 6283 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6284 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6285 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6286 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6287 | } |
| 6288 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6289 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6290 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6291 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6292 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6293 | } |
| 6294 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6295 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6296 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6297 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6298 | } |
| 6299 | if (oldval != val) |
| 6300 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6301 | |
| 6302 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6303 | oldval = val; |
| 6304 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6305 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6306 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6307 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6308 | } |
| 6309 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6310 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6311 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6312 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6313 | } |
| 6314 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6315 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6316 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6317 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6318 | } |
| 6319 | if (oldval != val) |
| 6320 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6321 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6322 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6323 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6324 | if (!event.msg_buf) |
| 6325 | return; |
| 6326 | |
| 6327 | do { |
| 6328 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6329 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6330 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6331 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6332 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6333 | break; |
| 6334 | } |
| 6335 | |
| 6336 | opcode = le16_to_cpu(event.desc.opcode); |
| 6337 | switch (opcode) { |
| 6338 | |
| 6339 | case i40e_aqc_opc_get_link_status: |
| 6340 | i40e_handle_link_event(pf, &event); |
| 6341 | break; |
| 6342 | case i40e_aqc_opc_send_msg_to_pf: |
| 6343 | ret = i40e_vc_process_vf_msg(pf, |
| 6344 | le16_to_cpu(event.desc.retval), |
| 6345 | le32_to_cpu(event.desc.cookie_high), |
| 6346 | le32_to_cpu(event.desc.cookie_low), |
| 6347 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6348 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6349 | break; |
| 6350 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6351 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6352 | #ifdef CONFIG_I40E_DCB |
| 6353 | rtnl_lock(); |
| 6354 | ret = i40e_handle_lldp_event(pf, &event); |
| 6355 | rtnl_unlock(); |
| 6356 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6357 | break; |
| 6358 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6359 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6360 | i40e_handle_lan_overflow_event(pf, &event); |
| 6361 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6362 | case i40e_aqc_opc_send_msg_to_peer: |
| 6363 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6364 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6365 | case i40e_aqc_opc_nvm_erase: |
| 6366 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6367 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 6368 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 6369 | "ARQ NVM operation 0x%04x completed\n", |
| 6370 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6371 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6372 | default: |
| 6373 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 6374 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6375 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6376 | break; |
| 6377 | } |
| 6378 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 6379 | |
| 6380 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 6381 | /* re-enable Admin queue interrupt cause */ |
| 6382 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6383 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6384 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6385 | i40e_flush(hw); |
| 6386 | |
| 6387 | kfree(event.msg_buf); |
| 6388 | } |
| 6389 | |
| 6390 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6391 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6392 | * @pf: board private structure |
| 6393 | **/ |
| 6394 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6395 | { |
| 6396 | int err; |
| 6397 | |
| 6398 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6399 | if (err) { |
| 6400 | /* retry in case of garbage read */ |
| 6401 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6402 | if (err) { |
| 6403 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6404 | err); |
| 6405 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6406 | } |
| 6407 | } |
| 6408 | |
| 6409 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 6410 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 6411 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6412 | } |
| 6413 | } |
| 6414 | |
| 6415 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6416 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6417 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6418 | * |
| 6419 | * enable switch loop back or die - no point in a return value |
| 6420 | **/ |
| 6421 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6422 | { |
| 6423 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6424 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6425 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6426 | |
| 6427 | ctxt.seid = pf->main_vsi_seid; |
| 6428 | ctxt.pf_num = pf->hw.pf_id; |
| 6429 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6430 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6431 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6432 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6433 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6434 | i40e_stat_str(&pf->hw, ret), |
| 6435 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6436 | return; |
| 6437 | } |
| 6438 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6439 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6440 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6441 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6442 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6443 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6444 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6445 | "update vsi switch failed, err %s aq_err %s\n", |
| 6446 | i40e_stat_str(&pf->hw, ret), |
| 6447 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6448 | } |
| 6449 | } |
| 6450 | |
| 6451 | /** |
| 6452 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6453 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6454 | * |
| 6455 | * disable switch loop back or die - no point in a return value |
| 6456 | **/ |
| 6457 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6458 | { |
| 6459 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6460 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6461 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6462 | |
| 6463 | ctxt.seid = pf->main_vsi_seid; |
| 6464 | ctxt.pf_num = pf->hw.pf_id; |
| 6465 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6466 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6467 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6468 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6469 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6470 | i40e_stat_str(&pf->hw, ret), |
| 6471 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6472 | return; |
| 6473 | } |
| 6474 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6475 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6476 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6477 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6478 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6479 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6480 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6481 | "update vsi switch failed, err %s aq_err %s\n", |
| 6482 | i40e_stat_str(&pf->hw, ret), |
| 6483 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6484 | } |
| 6485 | } |
| 6486 | |
| 6487 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6488 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6489 | * @veb: pointer to the bridge instance |
| 6490 | * |
| 6491 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6492 | * specified HW bridge instance. It is expected this function is called |
| 6493 | * when a new HW bridge is instantiated. |
| 6494 | **/ |
| 6495 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6496 | { |
| 6497 | struct i40e_pf *pf = veb->pf; |
| 6498 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6499 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6500 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6501 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6502 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6503 | i40e_disable_pf_switch_lb(pf); |
| 6504 | else |
| 6505 | i40e_enable_pf_switch_lb(pf); |
| 6506 | } |
| 6507 | |
| 6508 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6509 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6510 | * @veb: pointer to the VEB instance |
| 6511 | * |
| 6512 | * This is a recursive function that first builds the attached VSIs then |
| 6513 | * recurses in to build the next layer of VEB. We track the connections |
| 6514 | * through our own index numbers because the seid's from the HW could |
| 6515 | * change across the reset. |
| 6516 | **/ |
| 6517 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6518 | { |
| 6519 | struct i40e_vsi *ctl_vsi = NULL; |
| 6520 | struct i40e_pf *pf = veb->pf; |
| 6521 | int v, veb_idx; |
| 6522 | int ret; |
| 6523 | |
| 6524 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6525 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6526 | if (pf->vsi[v] && |
| 6527 | pf->vsi[v]->veb_idx == veb->idx && |
| 6528 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6529 | ctl_vsi = pf->vsi[v]; |
| 6530 | break; |
| 6531 | } |
| 6532 | } |
| 6533 | if (!ctl_vsi) { |
| 6534 | dev_info(&pf->pdev->dev, |
| 6535 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6536 | ret = -ENOENT; |
| 6537 | goto end_reconstitute; |
| 6538 | } |
| 6539 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6540 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6541 | ret = i40e_add_vsi(ctl_vsi); |
| 6542 | if (ret) { |
| 6543 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6544 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6545 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6546 | goto end_reconstitute; |
| 6547 | } |
| 6548 | i40e_vsi_reset_stats(ctl_vsi); |
| 6549 | |
| 6550 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6551 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6552 | if (ret) |
| 6553 | goto end_reconstitute; |
| 6554 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6555 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6556 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6557 | else |
| 6558 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6559 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6560 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6561 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6562 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6563 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6564 | continue; |
| 6565 | |
| 6566 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6567 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6568 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6569 | vsi->uplink_seid = veb->seid; |
| 6570 | ret = i40e_add_vsi(vsi); |
| 6571 | if (ret) { |
| 6572 | dev_info(&pf->pdev->dev, |
| 6573 | "rebuild of vsi_idx %d failed: %d\n", |
| 6574 | v, ret); |
| 6575 | goto end_reconstitute; |
| 6576 | } |
| 6577 | i40e_vsi_reset_stats(vsi); |
| 6578 | } |
| 6579 | } |
| 6580 | |
| 6581 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6582 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6583 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6584 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6585 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6586 | if (ret) |
| 6587 | break; |
| 6588 | } |
| 6589 | } |
| 6590 | |
| 6591 | end_reconstitute: |
| 6592 | return ret; |
| 6593 | } |
| 6594 | |
| 6595 | /** |
| 6596 | * i40e_get_capabilities - get info about the HW |
| 6597 | * @pf: the PF struct |
| 6598 | **/ |
| 6599 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6600 | { |
| 6601 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6602 | u16 data_size; |
| 6603 | int buf_len; |
| 6604 | int err; |
| 6605 | |
| 6606 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6607 | do { |
| 6608 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6609 | if (!cap_buf) |
| 6610 | return -ENOMEM; |
| 6611 | |
| 6612 | /* this loads the data into the hw struct for us */ |
| 6613 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6614 | &data_size, |
| 6615 | i40e_aqc_opc_list_func_capabilities, |
| 6616 | NULL); |
| 6617 | /* data loaded, buffer no longer needed */ |
| 6618 | kfree(cap_buf); |
| 6619 | |
| 6620 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6621 | /* retry with a larger buffer */ |
| 6622 | buf_len = data_size; |
| 6623 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6624 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6625 | "capability discovery failed, err %s aq_err %s\n", |
| 6626 | i40e_stat_str(&pf->hw, err), |
| 6627 | i40e_aq_str(&pf->hw, |
| 6628 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6629 | return -ENODEV; |
| 6630 | } |
| 6631 | } while (err); |
| 6632 | |
| 6633 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6634 | dev_info(&pf->pdev->dev, |
| 6635 | "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", |
| 6636 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6637 | pf->hw.func_caps.num_msix_vectors, |
| 6638 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6639 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6640 | pf->hw.func_caps.fd_filters_best_effort, |
| 6641 | pf->hw.func_caps.num_tx_qp, |
| 6642 | pf->hw.func_caps.num_vsis); |
| 6643 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6644 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6645 | + pf->hw.func_caps.num_vfs) |
| 6646 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6647 | dev_info(&pf->pdev->dev, |
| 6648 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6649 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6650 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6651 | } |
| 6652 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6653 | return 0; |
| 6654 | } |
| 6655 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6656 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6657 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6658 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6659 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6660 | * @pf: board private structure |
| 6661 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6662 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6663 | { |
| 6664 | struct i40e_vsi *vsi; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6665 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6666 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6667 | /* quick workaround for an NVM issue that leaves a critical register |
| 6668 | * uninitialized |
| 6669 | */ |
| 6670 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6671 | static const u32 hkey[] = { |
| 6672 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6673 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6674 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6675 | 0x95b3a76d}; |
| 6676 | |
| 6677 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6678 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6679 | } |
| 6680 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6681 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6682 | return; |
| 6683 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6684 | /* find existing VSI and see if it needs configuring */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6685 | vsi = NULL; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6686 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6687 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6688 | vsi = pf->vsi[i]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6689 | break; |
| 6690 | } |
| 6691 | } |
| 6692 | |
| 6693 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6694 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6695 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6696 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6697 | if (!vsi) { |
| 6698 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6699 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6700 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6701 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6702 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6703 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6704 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6705 | } |
| 6706 | |
| 6707 | /** |
| 6708 | * i40e_fdir_teardown - release the Flow Director resources |
| 6709 | * @pf: board private structure |
| 6710 | **/ |
| 6711 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6712 | { |
| 6713 | int i; |
| 6714 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6715 | i40e_fdir_filter_exit(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6716 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6717 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 6718 | i40e_vsi_release(pf->vsi[i]); |
| 6719 | break; |
| 6720 | } |
| 6721 | } |
| 6722 | } |
| 6723 | |
| 6724 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6725 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6726 | * @pf: board private structure |
| 6727 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6728 | * 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] | 6729 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6730 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6731 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6732 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6733 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6734 | u32 v; |
| 6735 | |
| 6736 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6737 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6738 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 6739 | if (i40e_check_asq_alive(&pf->hw)) |
| 6740 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6741 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6742 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6743 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6744 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6745 | i40e_pf_quiesce_all_vsi(pf); |
| 6746 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6747 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6748 | if (pf->vsi[v]) |
| 6749 | pf->vsi[v]->seid = 0; |
| 6750 | } |
| 6751 | |
| 6752 | i40e_shutdown_adminq(&pf->hw); |
| 6753 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6754 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6755 | if (hw->hmc.hmc_obj) { |
| 6756 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6757 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6758 | dev_warn(&pf->pdev->dev, |
| 6759 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6760 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6761 | } |
| 6762 | |
| 6763 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6764 | * i40e_send_version - update firmware with driver version |
| 6765 | * @pf: PF struct |
| 6766 | */ |
| 6767 | static void i40e_send_version(struct i40e_pf *pf) |
| 6768 | { |
| 6769 | struct i40e_driver_version dv; |
| 6770 | |
| 6771 | dv.major_version = DRV_VERSION_MAJOR; |
| 6772 | dv.minor_version = DRV_VERSION_MINOR; |
| 6773 | dv.build_version = DRV_VERSION_BUILD; |
| 6774 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 6775 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6776 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 6777 | } |
| 6778 | |
| 6779 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 6780 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6781 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6782 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6783 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6784 | 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] | 6785 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6786 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6787 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6788 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6789 | u32 val; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6790 | u32 v; |
| 6791 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6792 | /* Now we wait for GRST to settle out. |
| 6793 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 6794 | * because the reset will make them disappear. |
| 6795 | */ |
| 6796 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6797 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6798 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6799 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 6800 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6801 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6802 | pf->pfr_count++; |
| 6803 | |
| 6804 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6805 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6806 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6807 | |
| 6808 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 6809 | ret = i40e_init_adminq(&pf->hw); |
| 6810 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6811 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 6812 | i40e_stat_str(&pf->hw, ret), |
| 6813 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6814 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6815 | } |
| 6816 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6817 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 6818 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6819 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6820 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 6821 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6822 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6823 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6824 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6825 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6826 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 6827 | hw->func_caps.num_rx_qp, |
| 6828 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 6829 | if (ret) { |
| 6830 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 6831 | goto end_core_reset; |
| 6832 | } |
| 6833 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 6834 | if (ret) { |
| 6835 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 6836 | goto end_core_reset; |
| 6837 | } |
| 6838 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6839 | #ifdef CONFIG_I40E_DCB |
| 6840 | ret = i40e_init_pf_dcb(pf); |
| 6841 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6842 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 6843 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 6844 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6845 | } |
| 6846 | #endif /* CONFIG_I40E_DCB */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6847 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 6848 | i40e_init_pf_fcoe(pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6849 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6850 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6851 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6852 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6853 | if (ret) |
| 6854 | goto end_core_reset; |
| 6855 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6856 | /* The driver only wants link up/down and module qualification |
| 6857 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6858 | */ |
| 6859 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6860 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
| 6861 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6862 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6863 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 6864 | i40e_stat_str(&pf->hw, ret), |
| 6865 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6866 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6867 | /* make sure our flow control settings are restored */ |
| 6868 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 6869 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 6870 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 6871 | i40e_stat_str(&pf->hw, ret), |
| 6872 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6873 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6874 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 6875 | * They are still in our local switch element arrays, so only |
| 6876 | * need to rebuild the switch model in the HW. |
| 6877 | * |
| 6878 | * If there were VEBs but the reconstitution failed, we'll try |
| 6879 | * try to recover minimal use by getting the basic PF VSI working. |
| 6880 | */ |
| 6881 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6882 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6883 | /* find the one VEB connected to the MAC, and find orphans */ |
| 6884 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6885 | if (!pf->veb[v]) |
| 6886 | continue; |
| 6887 | |
| 6888 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 6889 | pf->veb[v]->uplink_seid == 0) { |
| 6890 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 6891 | |
| 6892 | if (!ret) |
| 6893 | continue; |
| 6894 | |
| 6895 | /* If Main VEB failed, we're in deep doodoo, |
| 6896 | * so give up rebuilding the switch and set up |
| 6897 | * for minimal rebuild of PF VSI. |
| 6898 | * If orphan failed, we'll report the error |
| 6899 | * but try to keep going. |
| 6900 | */ |
| 6901 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 6902 | dev_info(&pf->pdev->dev, |
| 6903 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 6904 | ret); |
| 6905 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 6906 | = pf->mac_seid; |
| 6907 | break; |
| 6908 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 6909 | dev_info(&pf->pdev->dev, |
| 6910 | "rebuild of orphan VEB failed: %d\n", |
| 6911 | ret); |
| 6912 | } |
| 6913 | } |
| 6914 | } |
| 6915 | } |
| 6916 | |
| 6917 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 6918 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6919 | /* no VEB, so rebuild only the Main VSI */ |
| 6920 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 6921 | if (ret) { |
| 6922 | dev_info(&pf->pdev->dev, |
| 6923 | "rebuild of Main VSI failed: %d\n", ret); |
| 6924 | goto end_core_reset; |
| 6925 | } |
| 6926 | } |
| 6927 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6928 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 6929 | * of TSO, so that we avoid the MDD being fired and causing |
| 6930 | * a reset in the case of small MSS+TSO. |
| 6931 | */ |
| 6932 | #define I40E_REG_MSS 0x000E64DC |
| 6933 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 6934 | #define I40E_64BYTE_MSS 0x400000 |
| 6935 | val = rd32(hw, I40E_REG_MSS); |
| 6936 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 6937 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 6938 | val |= I40E_64BYTE_MSS; |
| 6939 | wr32(hw, I40E_REG_MSS, val); |
| 6940 | } |
| 6941 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 6942 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 6943 | msleep(75); |
| 6944 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 6945 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6946 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 6947 | i40e_stat_str(&pf->hw, ret), |
| 6948 | i40e_aq_str(&pf->hw, |
| 6949 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6950 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6951 | /* reinit the misc interrupt */ |
| 6952 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 6953 | ret = i40e_setup_misc_vector(pf); |
| 6954 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 6955 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 6956 | * transmitted. By doing so we stop a malicious VF from sending out |
| 6957 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 6958 | * PF/VF VSIs. |
| 6959 | * The FW can still send Flow control frames if enabled. |
| 6960 | */ |
| 6961 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 6962 | pf->main_vsi_seid); |
| 6963 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6964 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 6965 | i40e_pf_unquiesce_all_vsi(pf); |
| 6966 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 6967 | if (pf->num_alloc_vfs) { |
| 6968 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 6969 | i40e_reset_vf(&pf->vf[v], true); |
| 6970 | } |
| 6971 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6972 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6973 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6974 | |
| 6975 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6976 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 6977 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6978 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 6979 | } |
| 6980 | |
| 6981 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6982 | * 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] | 6983 | * @pf: board private structure |
| 6984 | * |
| 6985 | * Close up the VFs and other things in prep for a Core Reset, |
| 6986 | * then get ready to rebuild the world. |
| 6987 | **/ |
| 6988 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 6989 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6990 | i40e_prep_for_reset(pf); |
| 6991 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6992 | } |
| 6993 | |
| 6994 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6995 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6996 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6997 | * |
| 6998 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 6999 | **/ |
| 7000 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 7001 | { |
| 7002 | struct i40e_hw *hw = &pf->hw; |
| 7003 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7004 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7005 | struct i40e_vf *vf; |
| 7006 | u32 reg; |
| 7007 | int i; |
| 7008 | |
| 7009 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 7010 | return; |
| 7011 | |
| 7012 | /* find what triggered the MDD event */ |
| 7013 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 7014 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7015 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 7016 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7017 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7018 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7019 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7020 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7021 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 7022 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 7023 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7024 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7025 | 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] | 7026 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7027 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 7028 | mdd_detected = true; |
| 7029 | } |
| 7030 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 7031 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7032 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 7033 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7034 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7035 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7036 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 7037 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 7038 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7039 | if (netif_msg_rx_err(pf)) |
| 7040 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 7041 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7042 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 7043 | mdd_detected = true; |
| 7044 | } |
| 7045 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7046 | if (mdd_detected) { |
| 7047 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 7048 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 7049 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7050 | 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] | 7051 | pf_mdd_detected = true; |
| 7052 | } |
| 7053 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 7054 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 7055 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7056 | 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] | 7057 | pf_mdd_detected = true; |
| 7058 | } |
| 7059 | /* Queue belongs to the PF, initiate a reset */ |
| 7060 | if (pf_mdd_detected) { |
| 7061 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 7062 | i40e_service_event_schedule(pf); |
| 7063 | } |
| 7064 | } |
| 7065 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7066 | /* see if one of the VFs needs its hand slapped */ |
| 7067 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7068 | vf = &(pf->vf[i]); |
| 7069 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7070 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7071 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7072 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7073 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7074 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7075 | } |
| 7076 | |
| 7077 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7078 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7079 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7080 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7081 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7082 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7083 | } |
| 7084 | |
| 7085 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7086 | dev_info(&pf->pdev->dev, |
| 7087 | "Too many MDD events on VF %d, disabled\n", i); |
| 7088 | dev_info(&pf->pdev->dev, |
| 7089 | "Use PF Control I/F to re-enable the VF\n"); |
| 7090 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 7091 | } |
| 7092 | } |
| 7093 | |
| 7094 | /* re-enable mdd interrupt cause */ |
| 7095 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 7096 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7097 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7098 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7099 | i40e_flush(hw); |
| 7100 | } |
| 7101 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7102 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7103 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7104 | * @pf: board private structure |
| 7105 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7106 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7107 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7108 | #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7109 | struct i40e_hw *hw = &pf->hw; |
| 7110 | i40e_status ret; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7111 | __be16 port; |
| 7112 | int i; |
| 7113 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7114 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7115 | return; |
| 7116 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7117 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7118 | |
| 7119 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7120 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7121 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
| 7122 | port = pf->udp_ports[i].index; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7123 | if (port) |
| 7124 | ret = i40e_aq_add_udp_tunnel(hw, ntohs(port), |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7125 | pf->udp_ports[i].type, |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7126 | NULL, NULL); |
| 7127 | else |
| 7128 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7129 | |
| 7130 | if (ret) { |
Carolyn Wyborny | 730a8f8 | 2016-02-17 16:12:16 -0800 | [diff] [blame] | 7131 | dev_dbg(&pf->pdev->dev, |
| 7132 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 7133 | pf->udp_ports[i].type ? "vxlan" : "geneve", |
| 7134 | port ? "add" : "delete", |
| 7135 | ntohs(port), i, |
| 7136 | i40e_stat_str(&pf->hw, ret), |
| 7137 | i40e_aq_str(&pf->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7138 | pf->hw.aq.asq_last_status)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7139 | pf->udp_ports[i].index = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7140 | } |
| 7141 | } |
| 7142 | } |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7143 | #endif |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7144 | } |
| 7145 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7146 | /** |
| 7147 | * i40e_service_task - Run the driver's async subtasks |
| 7148 | * @work: pointer to work_struct containing our data |
| 7149 | **/ |
| 7150 | static void i40e_service_task(struct work_struct *work) |
| 7151 | { |
| 7152 | struct i40e_pf *pf = container_of(work, |
| 7153 | struct i40e_pf, |
| 7154 | service_task); |
| 7155 | unsigned long start_time = jiffies; |
| 7156 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7157 | /* don't bother with service tasks if a reset is in progress */ |
| 7158 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7159 | i40e_service_event_complete(pf); |
| 7160 | return; |
| 7161 | } |
| 7162 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7163 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 7164 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7165 | i40e_reset_subtask(pf); |
| 7166 | i40e_handle_mdd_event(pf); |
| 7167 | i40e_vc_process_vflr_event(pf); |
| 7168 | i40e_watchdog_subtask(pf); |
| 7169 | i40e_fdir_reinit_subtask(pf); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7170 | i40e_client_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7171 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7172 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7173 | i40e_clean_adminq_subtask(pf); |
| 7174 | |
| 7175 | i40e_service_event_complete(pf); |
| 7176 | |
| 7177 | /* If the tasks have taken longer than one timer cycle or there |
| 7178 | * is more work to be done, reschedule the service task now |
| 7179 | * rather than wait for the timer to tick again. |
| 7180 | */ |
| 7181 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 7182 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 7183 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 7184 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 7185 | i40e_service_event_schedule(pf); |
| 7186 | } |
| 7187 | |
| 7188 | /** |
| 7189 | * i40e_service_timer - timer callback |
| 7190 | * @data: pointer to PF struct |
| 7191 | **/ |
| 7192 | static void i40e_service_timer(unsigned long data) |
| 7193 | { |
| 7194 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7195 | |
| 7196 | mod_timer(&pf->service_timer, |
| 7197 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7198 | i40e_service_event_schedule(pf); |
| 7199 | } |
| 7200 | |
| 7201 | /** |
| 7202 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7203 | * @vsi: the VSI being configured |
| 7204 | **/ |
| 7205 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7206 | { |
| 7207 | struct i40e_pf *pf = vsi->back; |
| 7208 | |
| 7209 | switch (vsi->type) { |
| 7210 | case I40E_VSI_MAIN: |
| 7211 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7212 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7213 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7214 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7215 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7216 | else |
| 7217 | vsi->num_q_vectors = 1; |
| 7218 | |
| 7219 | break; |
| 7220 | |
| 7221 | case I40E_VSI_FDIR: |
| 7222 | vsi->alloc_queue_pairs = 1; |
| 7223 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7224 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7225 | vsi->num_q_vectors = 1; |
| 7226 | break; |
| 7227 | |
| 7228 | case I40E_VSI_VMDQ2: |
| 7229 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7230 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7231 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7232 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7233 | break; |
| 7234 | |
| 7235 | case I40E_VSI_SRIOV: |
| 7236 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7237 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7238 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7239 | break; |
| 7240 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7241 | #ifdef I40E_FCOE |
| 7242 | case I40E_VSI_FCOE: |
| 7243 | vsi->alloc_queue_pairs = pf->num_fcoe_qps; |
| 7244 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7245 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7246 | vsi->num_q_vectors = pf->num_fcoe_msix; |
| 7247 | break; |
| 7248 | |
| 7249 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7250 | default: |
| 7251 | WARN_ON(1); |
| 7252 | return -ENODATA; |
| 7253 | } |
| 7254 | |
| 7255 | return 0; |
| 7256 | } |
| 7257 | |
| 7258 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7259 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7260 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7261 | * @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] | 7262 | * |
| 7263 | * On error: returns error code (negative) |
| 7264 | * On success: returns 0 |
| 7265 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7266 | 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] | 7267 | { |
| 7268 | int size; |
| 7269 | int ret = 0; |
| 7270 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7271 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7272 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 7273 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7274 | if (!vsi->tx_rings) |
| 7275 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7276 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 7277 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7278 | if (alloc_qvectors) { |
| 7279 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7280 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7281 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7282 | if (!vsi->q_vectors) { |
| 7283 | ret = -ENOMEM; |
| 7284 | goto err_vectors; |
| 7285 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7286 | } |
| 7287 | return ret; |
| 7288 | |
| 7289 | err_vectors: |
| 7290 | kfree(vsi->tx_rings); |
| 7291 | return ret; |
| 7292 | } |
| 7293 | |
| 7294 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7295 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7296 | * @pf: board private structure |
| 7297 | * @type: type of VSI |
| 7298 | * |
| 7299 | * On error: returns error code (negative) |
| 7300 | * On success: returns vsi index in PF (positive) |
| 7301 | **/ |
| 7302 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7303 | { |
| 7304 | int ret = -ENODEV; |
| 7305 | struct i40e_vsi *vsi; |
| 7306 | int vsi_idx; |
| 7307 | int i; |
| 7308 | |
| 7309 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7310 | mutex_lock(&pf->switch_mutex); |
| 7311 | |
| 7312 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7313 | * been happening. We can afford to do a quick scan to look |
| 7314 | * for any free VSIs in the list. |
| 7315 | * |
| 7316 | * find next empty vsi slot, looping back around if necessary |
| 7317 | */ |
| 7318 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7319 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7320 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7321 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7322 | i = 0; |
| 7323 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7324 | i++; |
| 7325 | } |
| 7326 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7327 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7328 | vsi_idx = i; /* Found one! */ |
| 7329 | } else { |
| 7330 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7331 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7332 | } |
| 7333 | pf->next_vsi = ++i; |
| 7334 | |
| 7335 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7336 | if (!vsi) { |
| 7337 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7338 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7339 | } |
| 7340 | vsi->type = type; |
| 7341 | vsi->back = pf; |
| 7342 | set_bit(__I40E_DOWN, &vsi->state); |
| 7343 | vsi->flags = 0; |
| 7344 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7345 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7346 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7347 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7348 | vsi->netdev_registered = false; |
| 7349 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
| 7350 | INIT_LIST_HEAD(&vsi->mac_filter_list); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7351 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7352 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7353 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7354 | if (ret) |
| 7355 | goto err_rings; |
| 7356 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7357 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7358 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7359 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7360 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7361 | /* Setup default MSIX irq handler for VSI */ |
| 7362 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7363 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7364 | /* Initialize VSI lock */ |
| 7365 | spin_lock_init(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7366 | pf->vsi[vsi_idx] = vsi; |
| 7367 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7368 | goto unlock_pf; |
| 7369 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7370 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7371 | pf->next_vsi = i - 1; |
| 7372 | kfree(vsi); |
| 7373 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7374 | mutex_unlock(&pf->switch_mutex); |
| 7375 | return ret; |
| 7376 | } |
| 7377 | |
| 7378 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7379 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7380 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7381 | * @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] | 7382 | * |
| 7383 | * On error: returns error code (negative) |
| 7384 | * On success: returns 0 |
| 7385 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7386 | 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] | 7387 | { |
| 7388 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7389 | if (free_qvectors) { |
| 7390 | kfree(vsi->q_vectors); |
| 7391 | vsi->q_vectors = NULL; |
| 7392 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7393 | kfree(vsi->tx_rings); |
| 7394 | vsi->tx_rings = NULL; |
| 7395 | vsi->rx_rings = NULL; |
| 7396 | } |
| 7397 | |
| 7398 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7399 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7400 | * and lookup table |
| 7401 | * @vsi: Pointer to VSI structure |
| 7402 | */ |
| 7403 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7404 | { |
| 7405 | if (!vsi) |
| 7406 | return; |
| 7407 | |
| 7408 | kfree(vsi->rss_hkey_user); |
| 7409 | vsi->rss_hkey_user = NULL; |
| 7410 | |
| 7411 | kfree(vsi->rss_lut_user); |
| 7412 | vsi->rss_lut_user = NULL; |
| 7413 | } |
| 7414 | |
| 7415 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7416 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7417 | * @vsi: the VSI being un-configured |
| 7418 | **/ |
| 7419 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7420 | { |
| 7421 | struct i40e_pf *pf; |
| 7422 | |
| 7423 | if (!vsi) |
| 7424 | return 0; |
| 7425 | |
| 7426 | if (!vsi->back) |
| 7427 | goto free_vsi; |
| 7428 | pf = vsi->back; |
| 7429 | |
| 7430 | mutex_lock(&pf->switch_mutex); |
| 7431 | if (!pf->vsi[vsi->idx]) { |
| 7432 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7433 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7434 | goto unlock_vsi; |
| 7435 | } |
| 7436 | |
| 7437 | if (pf->vsi[vsi->idx] != vsi) { |
| 7438 | dev_err(&pf->pdev->dev, |
| 7439 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7440 | pf->vsi[vsi->idx]->idx, |
| 7441 | pf->vsi[vsi->idx], |
| 7442 | pf->vsi[vsi->idx]->type, |
| 7443 | vsi->idx, vsi, vsi->type); |
| 7444 | goto unlock_vsi; |
| 7445 | } |
| 7446 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7447 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7448 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7449 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7450 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7451 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7452 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7453 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7454 | pf->vsi[vsi->idx] = NULL; |
| 7455 | if (vsi->idx < pf->next_vsi) |
| 7456 | pf->next_vsi = vsi->idx; |
| 7457 | |
| 7458 | unlock_vsi: |
| 7459 | mutex_unlock(&pf->switch_mutex); |
| 7460 | free_vsi: |
| 7461 | kfree(vsi); |
| 7462 | |
| 7463 | return 0; |
| 7464 | } |
| 7465 | |
| 7466 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7467 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7468 | * @vsi: the VSI being cleaned |
| 7469 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7470 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7471 | { |
| 7472 | int i; |
| 7473 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7474 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7475 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7476 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7477 | vsi->tx_rings[i] = NULL; |
| 7478 | vsi->rx_rings[i] = NULL; |
| 7479 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7480 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7481 | } |
| 7482 | |
| 7483 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7484 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7485 | * @vsi: the VSI being configured |
| 7486 | **/ |
| 7487 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7488 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7489 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7490 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7491 | int i; |
| 7492 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7493 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7494 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7495 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7496 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7497 | if (!tx_ring) |
| 7498 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7499 | |
| 7500 | tx_ring->queue_index = i; |
| 7501 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7502 | tx_ring->ring_active = false; |
| 7503 | tx_ring->vsi = vsi; |
| 7504 | tx_ring->netdev = vsi->netdev; |
| 7505 | tx_ring->dev = &pf->pdev->dev; |
| 7506 | tx_ring->count = vsi->num_desc; |
| 7507 | tx_ring->size = 0; |
| 7508 | tx_ring->dcb_tc = 0; |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 7509 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 7510 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7511 | tx_ring->tx_itr_setting = pf->tx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7512 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7513 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7514 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7515 | rx_ring->queue_index = i; |
| 7516 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7517 | rx_ring->ring_active = false; |
| 7518 | rx_ring->vsi = vsi; |
| 7519 | rx_ring->netdev = vsi->netdev; |
| 7520 | rx_ring->dev = &pf->pdev->dev; |
| 7521 | rx_ring->count = vsi->num_desc; |
| 7522 | rx_ring->size = 0; |
| 7523 | rx_ring->dcb_tc = 0; |
| 7524 | if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) |
| 7525 | set_ring_16byte_desc_enabled(rx_ring); |
| 7526 | else |
| 7527 | clear_ring_16byte_desc_enabled(rx_ring); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7528 | rx_ring->rx_itr_setting = pf->rx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7529 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7530 | } |
| 7531 | |
| 7532 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7533 | |
| 7534 | err_out: |
| 7535 | i40e_vsi_clear_rings(vsi); |
| 7536 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7537 | } |
| 7538 | |
| 7539 | /** |
| 7540 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7541 | * @pf: board private structure |
| 7542 | * @vectors: the number of MSI-X vectors to request |
| 7543 | * |
| 7544 | * Returns the number of vectors reserved, or error |
| 7545 | **/ |
| 7546 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7547 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7548 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7549 | I40E_MIN_MSIX, vectors); |
| 7550 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7551 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7552 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7553 | vectors = 0; |
| 7554 | } |
| 7555 | |
| 7556 | return vectors; |
| 7557 | } |
| 7558 | |
| 7559 | /** |
| 7560 | * i40e_init_msix - Setup the MSIX capability |
| 7561 | * @pf: board private structure |
| 7562 | * |
| 7563 | * Work with the OS to set up the MSIX vectors needed. |
| 7564 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7565 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7566 | **/ |
| 7567 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7568 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7569 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7570 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7571 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7572 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7573 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7574 | |
| 7575 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7576 | return -ENODEV; |
| 7577 | |
| 7578 | /* The number of vectors we'll request will be comprised of: |
| 7579 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7580 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7581 | * - Queues being used for RSS. |
| 7582 | * We don't need as many as max_rss_size vectors. |
| 7583 | * use rss_size instead in the calculation since that |
| 7584 | * is governed by number of cpus in the system. |
| 7585 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7586 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7587 | * - The CPU count within the NUMA node if iWARP is enabled |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7588 | #ifdef I40E_FCOE |
| 7589 | * - The number of FCOE qps. |
| 7590 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7591 | * Once we count this up, try the request. |
| 7592 | * |
| 7593 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7594 | * and try again. If that still fails, we punt. |
| 7595 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7596 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7597 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7598 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7599 | /* reserve one vector for miscellaneous handler */ |
| 7600 | if (vectors_left) { |
| 7601 | v_budget++; |
| 7602 | vectors_left--; |
| 7603 | } |
| 7604 | |
| 7605 | /* reserve vectors for the main PF traffic queues */ |
| 7606 | pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left); |
| 7607 | vectors_left -= pf->num_lan_msix; |
| 7608 | v_budget += pf->num_lan_msix; |
| 7609 | |
| 7610 | /* reserve one vector for sideband flow director */ |
| 7611 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7612 | if (vectors_left) { |
| 7613 | v_budget++; |
| 7614 | vectors_left--; |
| 7615 | } else { |
| 7616 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7617 | } |
| 7618 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7619 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7620 | #ifdef I40E_FCOE |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7621 | /* can we reserve enough for FCoE? */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7622 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7623 | if (!vectors_left) |
| 7624 | pf->num_fcoe_msix = 0; |
| 7625 | else if (vectors_left >= pf->num_fcoe_qps) |
| 7626 | pf->num_fcoe_msix = pf->num_fcoe_qps; |
| 7627 | else |
| 7628 | pf->num_fcoe_msix = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7629 | v_budget += pf->num_fcoe_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7630 | vectors_left -= pf->num_fcoe_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7631 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7632 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7633 | #endif |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7634 | /* can we reserve enough for iWARP? */ |
| 7635 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7636 | if (!vectors_left) |
| 7637 | pf->num_iwarp_msix = 0; |
| 7638 | else if (vectors_left < pf->num_iwarp_msix) |
| 7639 | pf->num_iwarp_msix = 1; |
| 7640 | v_budget += pf->num_iwarp_msix; |
| 7641 | vectors_left -= pf->num_iwarp_msix; |
| 7642 | } |
| 7643 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7644 | /* any vectors left over go for VMDq support */ |
| 7645 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7646 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7647 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7648 | |
| 7649 | /* if we're short on vectors for what's desired, we limit |
| 7650 | * the queues per vmdq. If this is still more than are |
| 7651 | * available, the user will need to change the number of |
| 7652 | * queues/vectors used by the PF later with the ethtool |
| 7653 | * channels command |
| 7654 | */ |
| 7655 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7656 | pf->num_vmdq_qps = 1; |
| 7657 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
| 7658 | |
| 7659 | v_budget += vmdq_vecs; |
| 7660 | vectors_left -= vmdq_vecs; |
| 7661 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7662 | |
| 7663 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7664 | GFP_KERNEL); |
| 7665 | if (!pf->msix_entries) |
| 7666 | return -ENOMEM; |
| 7667 | |
| 7668 | for (i = 0; i < v_budget; i++) |
| 7669 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7670 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7671 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7672 | if (v_actual != v_budget) { |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7673 | /* If we have limited resources, we will start with no vectors |
| 7674 | * for the special features and then allocate vectors to some |
| 7675 | * of these features based on the policy and at the end disable |
| 7676 | * the features that did not get any vectors. |
| 7677 | */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7678 | iwarp_requested = pf->num_iwarp_msix; |
| 7679 | pf->num_iwarp_msix = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7680 | #ifdef I40E_FCOE |
| 7681 | pf->num_fcoe_qps = 0; |
| 7682 | pf->num_fcoe_msix = 0; |
| 7683 | #endif |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7684 | pf->num_vmdq_msix = 0; |
| 7685 | } |
| 7686 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7687 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7688 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7689 | kfree(pf->msix_entries); |
| 7690 | pf->msix_entries = NULL; |
| 7691 | return -ENODEV; |
| 7692 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7693 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7694 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7695 | pf->num_vmdq_vsis = 0; |
| 7696 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7697 | pf->num_lan_qps = 1; |
| 7698 | pf->num_lan_msix = 1; |
| 7699 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7700 | } else if (v_actual != v_budget) { |
| 7701 | int vec; |
| 7702 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7703 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7704 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7705 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7706 | /* Scale vector usage down */ |
| 7707 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7708 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7709 | pf->num_vmdq_qps = 1; |
| 7710 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7711 | |
| 7712 | /* partition out the remaining vectors */ |
| 7713 | switch (vec) { |
| 7714 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7715 | pf->num_lan_msix = 1; |
| 7716 | break; |
| 7717 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7718 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7719 | pf->num_lan_msix = 1; |
| 7720 | pf->num_iwarp_msix = 1; |
| 7721 | } else { |
| 7722 | pf->num_lan_msix = 2; |
| 7723 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7724 | #ifdef I40E_FCOE |
| 7725 | /* give one vector to FCoE */ |
| 7726 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7727 | pf->num_lan_msix = 1; |
| 7728 | pf->num_fcoe_msix = 1; |
| 7729 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7730 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7731 | break; |
| 7732 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7733 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7734 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 7735 | iwarp_requested); |
| 7736 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 7737 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7738 | } else { |
| 7739 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 7740 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7741 | } |
| 7742 | pf->num_lan_msix = min_t(int, |
| 7743 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 7744 | pf->num_lan_msix); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7745 | #ifdef I40E_FCOE |
| 7746 | /* give one vector to FCoE */ |
| 7747 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7748 | pf->num_fcoe_msix = 1; |
| 7749 | vec--; |
| 7750 | } |
| 7751 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7752 | break; |
| 7753 | } |
| 7754 | } |
| 7755 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7756 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7757 | (pf->num_vmdq_msix == 0)) { |
| 7758 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 7759 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 7760 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7761 | |
| 7762 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 7763 | (pf->num_iwarp_msix == 0)) { |
| 7764 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 7765 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 7766 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7767 | #ifdef I40E_FCOE |
| 7768 | |
| 7769 | if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { |
| 7770 | dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n"); |
| 7771 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 7772 | } |
| 7773 | #endif |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7774 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7775 | } |
| 7776 | |
| 7777 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7778 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7779 | * @vsi: the VSI being configured |
| 7780 | * @v_idx: index of the vector in the vsi struct |
| 7781 | * |
| 7782 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 7783 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7784 | 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] | 7785 | { |
| 7786 | struct i40e_q_vector *q_vector; |
| 7787 | |
| 7788 | /* allocate q_vector */ |
| 7789 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 7790 | if (!q_vector) |
| 7791 | return -ENOMEM; |
| 7792 | |
| 7793 | q_vector->vsi = vsi; |
| 7794 | q_vector->v_idx = v_idx; |
| 7795 | cpumask_set_cpu(v_idx, &q_vector->affinity_mask); |
| 7796 | if (vsi->netdev) |
| 7797 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 7798 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7799 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 7800 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 7801 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 7802 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7803 | /* tie q_vector and vsi together */ |
| 7804 | vsi->q_vectors[v_idx] = q_vector; |
| 7805 | |
| 7806 | return 0; |
| 7807 | } |
| 7808 | |
| 7809 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7810 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7811 | * @vsi: the VSI being configured |
| 7812 | * |
| 7813 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 7814 | * return -ENOMEM. |
| 7815 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7816 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7817 | { |
| 7818 | struct i40e_pf *pf = vsi->back; |
| 7819 | int v_idx, num_q_vectors; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7820 | int err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7821 | |
| 7822 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 7823 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7824 | num_q_vectors = vsi->num_q_vectors; |
| 7825 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 7826 | num_q_vectors = 1; |
| 7827 | else |
| 7828 | return -EINVAL; |
| 7829 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7830 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7831 | err = i40e_vsi_alloc_q_vector(vsi, v_idx); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7832 | if (err) |
| 7833 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7834 | } |
| 7835 | |
| 7836 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7837 | |
| 7838 | err_out: |
| 7839 | while (v_idx--) |
| 7840 | i40e_free_q_vector(vsi, v_idx); |
| 7841 | |
| 7842 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7843 | } |
| 7844 | |
| 7845 | /** |
| 7846 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 7847 | * @pf: board private structure to initialize |
| 7848 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7849 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7850 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7851 | int vectors = 0; |
| 7852 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7853 | |
| 7854 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7855 | vectors = i40e_init_msix(pf); |
| 7856 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7857 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7858 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7859 | #ifdef I40E_FCOE |
| 7860 | I40E_FLAG_FCOE_ENABLED | |
| 7861 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7862 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7863 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7864 | I40E_FLAG_SRIOV_ENABLED | |
| 7865 | I40E_FLAG_FD_SB_ENABLED | |
| 7866 | I40E_FLAG_FD_ATR_ENABLED | |
| 7867 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7868 | |
| 7869 | /* rework the queue expectations without MSIX */ |
| 7870 | i40e_determine_queue_usage(pf); |
| 7871 | } |
| 7872 | } |
| 7873 | |
| 7874 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 7875 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7876 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7877 | vectors = pci_enable_msi(pf->pdev); |
| 7878 | if (vectors < 0) { |
| 7879 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 7880 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7881 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 7882 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7883 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7884 | } |
| 7885 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 7886 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7887 | 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] | 7888 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7889 | /* set up vector assignment tracking */ |
| 7890 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 7891 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7892 | if (!pf->irq_pile) { |
| 7893 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 7894 | return -ENOMEM; |
| 7895 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7896 | pf->irq_pile->num_entries = vectors; |
| 7897 | pf->irq_pile->search_hint = 0; |
| 7898 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7899 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7900 | (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] | 7901 | |
| 7902 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7903 | } |
| 7904 | |
| 7905 | /** |
| 7906 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 7907 | * @pf: board private structure |
| 7908 | * |
| 7909 | * This sets up the handler for MSIX 0, which is used to manage the |
| 7910 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 7911 | * when in MSI or Legacy interrupt mode. |
| 7912 | **/ |
| 7913 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 7914 | { |
| 7915 | struct i40e_hw *hw = &pf->hw; |
| 7916 | int err = 0; |
| 7917 | |
| 7918 | /* Only request the irq if this is the first time through, and |
| 7919 | * not when we're rebuilding after a Reset |
| 7920 | */ |
| 7921 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7922 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7923 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7924 | if (err) { |
| 7925 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7926 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7927 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7928 | return -EFAULT; |
| 7929 | } |
| 7930 | } |
| 7931 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 7932 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7933 | |
| 7934 | /* associate no queues to the misc vector */ |
| 7935 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 7936 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 7937 | |
| 7938 | i40e_flush(hw); |
| 7939 | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 7940 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7941 | |
| 7942 | return err; |
| 7943 | } |
| 7944 | |
| 7945 | /** |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7946 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 7947 | * @vsi: vsi structure |
| 7948 | * @seed: RSS hash seed |
| 7949 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7950 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 7951 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7952 | { |
| 7953 | struct i40e_aqc_get_set_rss_key_data rss_key; |
| 7954 | struct i40e_pf *pf = vsi->back; |
| 7955 | struct i40e_hw *hw = &pf->hw; |
| 7956 | bool pf_lut = false; |
| 7957 | u8 *rss_lut; |
| 7958 | int ret, i; |
| 7959 | |
| 7960 | memset(&rss_key, 0, sizeof(rss_key)); |
| 7961 | memcpy(&rss_key, seed, sizeof(rss_key)); |
| 7962 | |
| 7963 | rss_lut = kzalloc(pf->rss_table_size, GFP_KERNEL); |
| 7964 | if (!rss_lut) |
| 7965 | return -ENOMEM; |
| 7966 | |
| 7967 | /* Populate the LUT with max no. of queues in round robin fashion */ |
| 7968 | for (i = 0; i < vsi->rss_table_size; i++) |
| 7969 | rss_lut[i] = i % vsi->rss_size; |
| 7970 | |
| 7971 | ret = i40e_aq_set_rss_key(hw, vsi->id, &rss_key); |
| 7972 | if (ret) { |
| 7973 | dev_info(&pf->pdev->dev, |
| 7974 | "Cannot set RSS key, err %s aq_err %s\n", |
| 7975 | i40e_stat_str(&pf->hw, ret), |
| 7976 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai | 126b63d | 2015-08-24 13:26:53 -0700 | [diff] [blame] | 7977 | goto config_rss_aq_out; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7978 | } |
| 7979 | |
| 7980 | if (vsi->type == I40E_VSI_MAIN) |
| 7981 | pf_lut = true; |
| 7982 | |
| 7983 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, rss_lut, |
| 7984 | vsi->rss_table_size); |
| 7985 | if (ret) |
| 7986 | dev_info(&pf->pdev->dev, |
| 7987 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 7988 | i40e_stat_str(&pf->hw, ret), |
| 7989 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 7990 | |
Anjali Singhai | 126b63d | 2015-08-24 13:26:53 -0700 | [diff] [blame] | 7991 | config_rss_aq_out: |
| 7992 | kfree(rss_lut); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7993 | return ret; |
| 7994 | } |
| 7995 | |
| 7996 | /** |
| 7997 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 7998 | * @vsi: VSI structure |
| 7999 | **/ |
| 8000 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 8001 | { |
| 8002 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 8003 | struct i40e_pf *pf = vsi->back; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8004 | u8 *lut; |
| 8005 | int ret; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8006 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8007 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) |
| 8008 | return 0; |
| 8009 | |
| 8010 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8011 | if (!lut) |
| 8012 | return -ENOMEM; |
| 8013 | |
| 8014 | 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] | 8015 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8016 | 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] | 8017 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 8018 | kfree(lut); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8019 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8020 | return ret; |
| 8021 | } |
| 8022 | |
| 8023 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8024 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 8025 | * @vsi: Pointer to vsi structure |
| 8026 | * @seed: Buffter to store the hash keys |
| 8027 | * @lut: Buffer to store the lookup table entries |
| 8028 | * @lut_size: Size of buffer to store the lookup table entries |
| 8029 | * |
| 8030 | * Return 0 on success, negative on failure |
| 8031 | */ |
| 8032 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8033 | u8 *lut, u16 lut_size) |
| 8034 | { |
| 8035 | struct i40e_pf *pf = vsi->back; |
| 8036 | struct i40e_hw *hw = &pf->hw; |
| 8037 | int ret = 0; |
| 8038 | |
| 8039 | if (seed) { |
| 8040 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 8041 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 8042 | if (ret) { |
| 8043 | dev_info(&pf->pdev->dev, |
| 8044 | "Cannot get RSS key, err %s aq_err %s\n", |
| 8045 | i40e_stat_str(&pf->hw, ret), |
| 8046 | i40e_aq_str(&pf->hw, |
| 8047 | pf->hw.aq.asq_last_status)); |
| 8048 | return ret; |
| 8049 | } |
| 8050 | } |
| 8051 | |
| 8052 | if (lut) { |
| 8053 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 8054 | |
| 8055 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8056 | if (ret) { |
| 8057 | dev_info(&pf->pdev->dev, |
| 8058 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 8059 | i40e_stat_str(&pf->hw, ret), |
| 8060 | i40e_aq_str(&pf->hw, |
| 8061 | pf->hw.aq.asq_last_status)); |
| 8062 | return ret; |
| 8063 | } |
| 8064 | } |
| 8065 | |
| 8066 | return ret; |
| 8067 | } |
| 8068 | |
| 8069 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8070 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 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 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8079 | const u8 *lut, u16 lut_size) |
| 8080 | { |
| 8081 | struct i40e_pf *pf = vsi->back; |
| 8082 | struct i40e_hw *hw = &pf->hw; |
| 8083 | u8 i; |
| 8084 | |
| 8085 | /* Fill out hash function seed */ |
| 8086 | if (seed) { |
| 8087 | u32 *seed_dw = (u32 *)seed; |
| 8088 | |
| 8089 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8090 | i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), seed_dw[i]); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8091 | } |
| 8092 | |
| 8093 | if (lut) { |
| 8094 | u32 *lut_dw = (u32 *)lut; |
| 8095 | |
| 8096 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8097 | return -EINVAL; |
| 8098 | |
| 8099 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8100 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8101 | } |
| 8102 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8103 | |
| 8104 | return 0; |
| 8105 | } |
| 8106 | |
| 8107 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8108 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8109 | * @vsi: Pointer to VSI structure |
| 8110 | * @seed: Buffer to store the keys |
| 8111 | * @lut: Buffer to store the lookup table entries |
| 8112 | * @lut_size: Size of buffer to store the lookup table entries |
| 8113 | * |
| 8114 | * Returns 0 on success, negative on failure |
| 8115 | */ |
| 8116 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8117 | u8 *lut, u16 lut_size) |
| 8118 | { |
| 8119 | struct i40e_pf *pf = vsi->back; |
| 8120 | struct i40e_hw *hw = &pf->hw; |
| 8121 | u16 i; |
| 8122 | |
| 8123 | if (seed) { |
| 8124 | u32 *seed_dw = (u32 *)seed; |
| 8125 | |
| 8126 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8127 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8128 | } |
| 8129 | if (lut) { |
| 8130 | u32 *lut_dw = (u32 *)lut; |
| 8131 | |
| 8132 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8133 | return -EINVAL; |
| 8134 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8135 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8136 | } |
| 8137 | |
| 8138 | return 0; |
| 8139 | } |
| 8140 | |
| 8141 | /** |
| 8142 | * i40e_config_rss - Configure RSS keys and lut |
| 8143 | * @vsi: Pointer to VSI structure |
| 8144 | * @seed: RSS hash seed |
| 8145 | * @lut: Lookup table |
| 8146 | * @lut_size: Lookup table size |
| 8147 | * |
| 8148 | * Returns 0 on success, negative on failure |
| 8149 | */ |
| 8150 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8151 | { |
| 8152 | struct i40e_pf *pf = vsi->back; |
| 8153 | |
| 8154 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8155 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8156 | else |
| 8157 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8158 | } |
| 8159 | |
| 8160 | /** |
| 8161 | * i40e_get_rss - Get RSS keys and lut |
| 8162 | * @vsi: Pointer to VSI structure |
| 8163 | * @seed: Buffer to store the keys |
| 8164 | * @lut: Buffer to store the lookup table entries |
| 8165 | * lut_size: Size of buffer to store the lookup table entries |
| 8166 | * |
| 8167 | * Returns 0 on success, negative on failure |
| 8168 | */ |
| 8169 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8170 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8171 | struct i40e_pf *pf = vsi->back; |
| 8172 | |
| 8173 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8174 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8175 | else |
| 8176 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8177 | } |
| 8178 | |
| 8179 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8180 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8181 | * @pf: Pointer to board private structure |
| 8182 | * @lut: Lookup table |
| 8183 | * @rss_table_size: Lookup table size |
| 8184 | * @rss_size: Range of queue number for hashing |
| 8185 | */ |
| 8186 | static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8187 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8188 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8189 | u16 i; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8190 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8191 | for (i = 0; i < rss_table_size; i++) |
| 8192 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8193 | } |
| 8194 | |
| 8195 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8196 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8197 | * @pf: board private structure |
| 8198 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8199 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8200 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8201 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8202 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8203 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8204 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8205 | u32 reg_val; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8206 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8207 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8208 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8209 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8210 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 8211 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8212 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8213 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8214 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8215 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8216 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8217 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8218 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8219 | reg_val = (pf->rss_table_size == 512) ? |
| 8220 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8221 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8222 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8223 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8224 | /* Determine the RSS size of the VSI */ |
| 8225 | if (!vsi->rss_size) |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8226 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8227 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8228 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8229 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8230 | if (!lut) |
| 8231 | return -ENOMEM; |
| 8232 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8233 | /* Use user configured lut if there is one, otherwise use default */ |
| 8234 | if (vsi->rss_lut_user) |
| 8235 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8236 | else |
| 8237 | 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] | 8238 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8239 | /* Use user configured hash key if there is one, otherwise |
| 8240 | * use default. |
| 8241 | */ |
| 8242 | if (vsi->rss_hkey_user) |
| 8243 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8244 | else |
| 8245 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8246 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8247 | kfree(lut); |
| 8248 | |
| 8249 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8250 | } |
| 8251 | |
| 8252 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8253 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8254 | * @pf: board private structure |
| 8255 | * @queue_count: the requested queue count for rss. |
| 8256 | * |
| 8257 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8258 | * count which may be different from the requested queue count. |
| 8259 | **/ |
| 8260 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8261 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8262 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8263 | int new_rss_size; |
| 8264 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8265 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8266 | return 0; |
| 8267 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8268 | 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] | 8269 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8270 | if (queue_count != vsi->num_queue_pairs) { |
| 8271 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8272 | i40e_prep_for_reset(pf); |
| 8273 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8274 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8275 | |
| 8276 | i40e_reset_and_rebuild(pf, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8277 | |
| 8278 | /* Discard the user configured hash keys and lut, if less |
| 8279 | * queues are enabled. |
| 8280 | */ |
| 8281 | if (queue_count < vsi->rss_size) { |
| 8282 | i40e_clear_rss_config_user(vsi); |
| 8283 | dev_dbg(&pf->pdev->dev, |
| 8284 | "discard user configured hash keys and lut\n"); |
| 8285 | } |
| 8286 | |
| 8287 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8288 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8289 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8290 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8291 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8292 | } |
Helin Zhang | e36b0b1 | 2015-10-26 19:44:36 -0400 | [diff] [blame] | 8293 | dev_info(&pf->pdev->dev, "RSS count/HW max RSS count: %d/%d\n", |
| 8294 | pf->alloc_rss_size, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8295 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8296 | } |
| 8297 | |
| 8298 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8299 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 8300 | * @pf: board private structure |
| 8301 | **/ |
| 8302 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 8303 | { |
| 8304 | i40e_status status; |
| 8305 | bool min_valid, max_valid; |
| 8306 | u32 max_bw, min_bw; |
| 8307 | |
| 8308 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8309 | &min_valid, &max_valid); |
| 8310 | |
| 8311 | if (!status) { |
| 8312 | if (min_valid) |
| 8313 | pf->npar_min_bw = min_bw; |
| 8314 | if (max_valid) |
| 8315 | pf->npar_max_bw = max_bw; |
| 8316 | } |
| 8317 | |
| 8318 | return status; |
| 8319 | } |
| 8320 | |
| 8321 | /** |
| 8322 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 8323 | * @pf: board private structure |
| 8324 | **/ |
| 8325 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 8326 | { |
| 8327 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8328 | i40e_status status; |
| 8329 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8330 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8331 | 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] | 8332 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8333 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 8334 | |
| 8335 | /* Set the new bandwidths */ |
| 8336 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8337 | |
| 8338 | return status; |
| 8339 | } |
| 8340 | |
| 8341 | /** |
| 8342 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 8343 | * @pf: board private structure |
| 8344 | **/ |
| 8345 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 8346 | { |
| 8347 | /* Commit temporary BW setting to permanent NVM image */ |
| 8348 | enum i40e_admin_queue_err last_aq_status; |
| 8349 | i40e_status ret; |
| 8350 | u16 nvm_word; |
| 8351 | |
| 8352 | if (pf->hw.partition_id != 1) { |
| 8353 | dev_info(&pf->pdev->dev, |
| 8354 | "Commit BW only works on partition 1! This is partition %d", |
| 8355 | pf->hw.partition_id); |
| 8356 | ret = I40E_NOT_SUPPORTED; |
| 8357 | goto bw_commit_out; |
| 8358 | } |
| 8359 | |
| 8360 | /* Acquire NVM for read access */ |
| 8361 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8362 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8363 | if (ret) { |
| 8364 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8365 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8366 | i40e_stat_str(&pf->hw, ret), |
| 8367 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8368 | goto bw_commit_out; |
| 8369 | } |
| 8370 | |
| 8371 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8372 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8373 | I40E_SR_NVM_CONTROL_WORD, |
| 8374 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8375 | false, NULL); |
| 8376 | /* Save off last admin queue command status before releasing |
| 8377 | * the NVM |
| 8378 | */ |
| 8379 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8380 | i40e_release_nvm(&pf->hw); |
| 8381 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8382 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8383 | i40e_stat_str(&pf->hw, ret), |
| 8384 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8385 | goto bw_commit_out; |
| 8386 | } |
| 8387 | |
| 8388 | /* Wait a bit for NVM release to complete */ |
| 8389 | msleep(50); |
| 8390 | |
| 8391 | /* Acquire NVM for write access */ |
| 8392 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8393 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8394 | if (ret) { |
| 8395 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8396 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8397 | i40e_stat_str(&pf->hw, ret), |
| 8398 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8399 | goto bw_commit_out; |
| 8400 | } |
| 8401 | /* Write it back out unchanged to initiate update NVM, |
| 8402 | * which will force a write of the shadow (alt) RAM to |
| 8403 | * the NVM - thus storing the bandwidth values permanently. |
| 8404 | */ |
| 8405 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8406 | I40E_SR_NVM_CONTROL_WORD, |
| 8407 | 0x10, sizeof(nvm_word), |
| 8408 | &nvm_word, true, NULL); |
| 8409 | /* Save off last admin queue command status before releasing |
| 8410 | * the NVM |
| 8411 | */ |
| 8412 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8413 | i40e_release_nvm(&pf->hw); |
| 8414 | if (ret) |
| 8415 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8416 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8417 | i40e_stat_str(&pf->hw, ret), |
| 8418 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8419 | bw_commit_out: |
| 8420 | |
| 8421 | return ret; |
| 8422 | } |
| 8423 | |
| 8424 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8425 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8426 | * @pf: board private structure to initialize |
| 8427 | * |
| 8428 | * i40e_sw_init initializes the Adapter private data structure. |
| 8429 | * Fields are initialized based on PCI device information and |
| 8430 | * OS network device settings (MTU size). |
| 8431 | **/ |
| 8432 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8433 | { |
| 8434 | int err = 0; |
| 8435 | int size; |
| 8436 | |
| 8437 | pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, |
| 8438 | (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); |
Shannon Nelson | 2759997 | 2013-11-16 10:00:43 +0000 | [diff] [blame] | 8439 | pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8440 | if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { |
| 8441 | if (I40E_DEBUG_USER & debug) |
| 8442 | pf->hw.debug_mask = debug; |
| 8443 | pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), |
| 8444 | I40E_DEFAULT_MSG_ENABLE); |
| 8445 | } |
| 8446 | |
| 8447 | /* Set default capability flags */ |
| 8448 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8449 | I40E_FLAG_MSI_ENABLED | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 8450 | I40E_FLAG_LINK_POLLING_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8451 | I40E_FLAG_MSIX_ENABLED; |
| 8452 | |
| 8453 | if (iommu_present(&pci_bus_type)) |
| 8454 | pf->flags |= I40E_FLAG_RX_PS_ENABLED; |
| 8455 | else |
| 8456 | pf->flags |= I40E_FLAG_RX_1BUF_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8457 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8458 | /* Set default ITR */ |
| 8459 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8460 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8461 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8462 | /* Depending on PF configurations, it is possible that the RSS |
| 8463 | * maximum might end up larger than the available queues |
| 8464 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8465 | 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] | 8466 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8467 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8468 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8469 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8470 | if (pf->hw.func_caps.rss) { |
| 8471 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8472 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8473 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8474 | } |
| 8475 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8476 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8477 | 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] | 8478 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8479 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8480 | if (i40e_get_npar_bw_setting(pf)) |
| 8481 | dev_warn(&pf->pdev->dev, |
| 8482 | "Could not get NPAR bw settings\n"); |
| 8483 | else |
| 8484 | dev_info(&pf->pdev->dev, |
| 8485 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 8486 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8487 | } |
| 8488 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8489 | /* FW/NVM is not yet fixed in this regard */ |
| 8490 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8491 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8492 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8493 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8494 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8495 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8496 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8497 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8498 | else |
| 8499 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8500 | pf->fdir_pf_filter_count = |
| 8501 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8502 | pf->hw.fdir_shared_filter_count = |
| 8503 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8504 | } |
| 8505 | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8506 | if (i40e_is_mac_710(&pf->hw) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8507 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) || |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8508 | (pf->hw.aq.fw_maj_ver < 4))) { |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8509 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8510 | /* No DCB support for FW < v4.33 */ |
| 8511 | pf->flags |= I40E_FLAG_NO_DCB_SUPPORT; |
| 8512 | } |
| 8513 | |
| 8514 | /* Disable FW LLDP if FW < v4.3 */ |
| 8515 | if (i40e_is_mac_710(&pf->hw) && |
| 8516 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 8517 | (pf->hw.aq.fw_maj_ver < 4))) |
| 8518 | pf->flags |= I40E_FLAG_STOP_FW_LLDP; |
| 8519 | |
| 8520 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
| 8521 | if (i40e_is_mac_710(&pf->hw) && |
| 8522 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 8523 | (pf->hw.aq.fw_maj_ver >= 5))) |
| 8524 | pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8525 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8526 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8527 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8528 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 8529 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8530 | } |
| 8531 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8532 | if (pf->hw.func_caps.iwarp) { |
| 8533 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 8534 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 8535 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 8536 | } |
| 8537 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8538 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 8539 | i40e_init_pf_fcoe(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8540 | |
| 8541 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8542 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 8543 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8544 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 8545 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 8546 | pf->num_req_vfs = min_t(int, |
| 8547 | pf->hw.func_caps.num_vfs, |
| 8548 | I40E_MAX_VF_COUNT); |
| 8549 | } |
| 8550 | #endif /* CONFIG_PCI_IOV */ |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8551 | if (pf->hw.mac.type == I40E_MAC_X722) { |
| 8552 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE | |
| 8553 | I40E_FLAG_128_QP_RSS_CAPABLE | |
| 8554 | I40E_FLAG_HW_ATR_EVICT_CAPABLE | |
| 8555 | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE | |
| 8556 | I40E_FLAG_WB_ON_ITR_CAPABLE | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8557 | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
Catherine Sullivan | f8db54cc | 2015-12-22 14:25:14 -0800 | [diff] [blame] | 8558 | I40E_FLAG_100M_SGMII_CAPABLE | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8559 | I40E_FLAG_USE_SET_LLDP_MIB | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8560 | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8561 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 8562 | ((pf->hw.aq.api_maj_ver == 1) && |
| 8563 | (pf->hw.aq.api_min_ver > 4))) { |
| 8564 | /* Supported in FW API version higher than 1.4 */ |
| 8565 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 8566 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
| 8567 | } else { |
| 8568 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8569 | } |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8570 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8571 | pf->eeprom_version = 0xDEAD; |
| 8572 | pf->lan_veb = I40E_NO_VEB; |
| 8573 | pf->lan_vsi = I40E_NO_VSI; |
| 8574 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 8575 | /* By default FW has this off for performance reasons */ |
| 8576 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 8577 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8578 | /* set up queue assignment tracking */ |
| 8579 | size = sizeof(struct i40e_lump_tracking) |
| 8580 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 8581 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 8582 | if (!pf->qp_pile) { |
| 8583 | err = -ENOMEM; |
| 8584 | goto sw_init_done; |
| 8585 | } |
| 8586 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 8587 | pf->qp_pile->search_hint = 0; |
| 8588 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 8589 | pf->tx_timeout_recovery_level = 1; |
| 8590 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8591 | mutex_init(&pf->switch_mutex); |
| 8592 | |
Greg Rose | c668a12 | 2015-02-26 16:10:39 +0000 | [diff] [blame] | 8593 | /* If NPAR is enabled nudge the Tx scheduler */ |
| 8594 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) |
| 8595 | i40e_set_npar_bw_setting(pf); |
| 8596 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8597 | sw_init_done: |
| 8598 | return err; |
| 8599 | } |
| 8600 | |
| 8601 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8602 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 8603 | * @pf: board private structure to initialize |
| 8604 | * @features: the feature set that the stack is suggesting |
| 8605 | * |
| 8606 | * returns a bool to indicate if reset needs to happen |
| 8607 | **/ |
| 8608 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 8609 | { |
| 8610 | bool need_reset = false; |
| 8611 | |
| 8612 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 8613 | * the state changed, we need to reset. |
| 8614 | */ |
| 8615 | if (features & NETIF_F_NTUPLE) { |
| 8616 | /* Enable filters and mark for reset */ |
| 8617 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 8618 | need_reset = true; |
| 8619 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
| 8620 | } else { |
| 8621 | /* turn off filters, mark for reset and clear SW filter list */ |
| 8622 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8623 | need_reset = true; |
| 8624 | i40e_fdir_filter_exit(pf); |
| 8625 | } |
| 8626 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8627 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 8628 | /* reset fd counters */ |
| 8629 | pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0; |
| 8630 | pf->fdir_pf_active_filters = 0; |
| 8631 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 8632 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 8633 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8634 | /* if ATR was auto disabled it can be re-enabled. */ |
| 8635 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 8636 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 8637 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8638 | } |
| 8639 | return need_reset; |
| 8640 | } |
| 8641 | |
| 8642 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8643 | * i40e_set_features - set the netdev feature flags |
| 8644 | * @netdev: ptr to the netdev being adjusted |
| 8645 | * @features: the feature set that the stack is suggesting |
| 8646 | **/ |
| 8647 | static int i40e_set_features(struct net_device *netdev, |
| 8648 | netdev_features_t features) |
| 8649 | { |
| 8650 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8651 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8652 | struct i40e_pf *pf = vsi->back; |
| 8653 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8654 | |
| 8655 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8656 | i40e_vlan_stripping_enable(vsi); |
| 8657 | else |
| 8658 | i40e_vlan_stripping_disable(vsi); |
| 8659 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8660 | need_reset = i40e_set_ntuple(pf, features); |
| 8661 | |
| 8662 | if (need_reset) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8663 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8664 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8665 | return 0; |
| 8666 | } |
| 8667 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8668 | #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8669 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8670 | * 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] | 8671 | * @pf: board private structure |
| 8672 | * @port: The UDP port to look up |
| 8673 | * |
| 8674 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 8675 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8676 | 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] | 8677 | { |
| 8678 | u8 i; |
| 8679 | |
| 8680 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8681 | if (pf->udp_ports[i].index == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8682 | return i; |
| 8683 | } |
| 8684 | |
| 8685 | return i; |
| 8686 | } |
| 8687 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8688 | #endif |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8689 | |
| 8690 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8691 | /** |
| 8692 | * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up |
| 8693 | * @netdev: This physical port's netdev |
| 8694 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 8695 | * @port: New UDP port number that VXLAN started listening to |
| 8696 | **/ |
| 8697 | static void i40e_add_vxlan_port(struct net_device *netdev, |
| 8698 | sa_family_t sa_family, __be16 port) |
| 8699 | { |
| 8700 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8701 | struct i40e_vsi *vsi = np->vsi; |
| 8702 | struct i40e_pf *pf = vsi->back; |
| 8703 | u8 next_idx; |
| 8704 | u8 idx; |
| 8705 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8706 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8707 | |
| 8708 | /* Check if port already exists */ |
| 8709 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8710 | netdev_info(netdev, "vxlan port %d already offloaded\n", |
| 8711 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8712 | return; |
| 8713 | } |
| 8714 | |
| 8715 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8716 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8717 | |
| 8718 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8719 | 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] | 8720 | ntohs(port)); |
| 8721 | return; |
| 8722 | } |
| 8723 | |
| 8724 | /* New port: add it and mark its index in the bitmap */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8725 | pf->udp_ports[next_idx].index = port; |
| 8726 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 8727 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8728 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8729 | } |
| 8730 | |
| 8731 | /** |
| 8732 | * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away |
| 8733 | * @netdev: This physical port's netdev |
| 8734 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 8735 | * @port: UDP port number that VXLAN stopped listening to |
| 8736 | **/ |
| 8737 | static void i40e_del_vxlan_port(struct net_device *netdev, |
| 8738 | sa_family_t sa_family, __be16 port) |
| 8739 | { |
| 8740 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8741 | struct i40e_vsi *vsi = np->vsi; |
| 8742 | struct i40e_pf *pf = vsi->back; |
| 8743 | u8 idx; |
| 8744 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8745 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8746 | |
| 8747 | /* Check if port already exists */ |
| 8748 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8749 | /* if port exists, set it to 0 (mark for deletion) |
| 8750 | * and make it pending |
| 8751 | */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8752 | pf->udp_ports[idx].index = 0; |
| 8753 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
| 8754 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8755 | } else { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8756 | netdev_warn(netdev, "vxlan port %d was not found, not deleting\n", |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8757 | ntohs(port)); |
| 8758 | } |
| 8759 | } |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8760 | #endif |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8761 | |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8762 | #if IS_ENABLED(CONFIG_GENEVE) |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8763 | /** |
| 8764 | * i40e_add_geneve_port - Get notifications about GENEVE ports that come up |
| 8765 | * @netdev: This physical port's netdev |
| 8766 | * @sa_family: Socket Family that GENEVE is notifying us about |
| 8767 | * @port: New UDP port number that GENEVE started listening to |
| 8768 | **/ |
| 8769 | static void i40e_add_geneve_port(struct net_device *netdev, |
| 8770 | sa_family_t sa_family, __be16 port) |
| 8771 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8772 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8773 | struct i40e_vsi *vsi = np->vsi; |
| 8774 | struct i40e_pf *pf = vsi->back; |
| 8775 | u8 next_idx; |
| 8776 | u8 idx; |
| 8777 | |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8778 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8779 | return; |
| 8780 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8781 | idx = i40e_get_udp_port_idx(pf, port); |
| 8782 | |
| 8783 | /* Check if port already exists */ |
| 8784 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8785 | netdev_info(netdev, "udp port %d already offloaded\n", |
| 8786 | ntohs(port)); |
| 8787 | return; |
| 8788 | } |
| 8789 | |
| 8790 | /* Now check if there is space to add the new port */ |
| 8791 | next_idx = i40e_get_udp_port_idx(pf, 0); |
| 8792 | |
| 8793 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8794 | netdev_info(netdev, "maximum number of UDP ports reached, not adding port %d\n", |
| 8795 | ntohs(port)); |
| 8796 | return; |
| 8797 | } |
| 8798 | |
| 8799 | /* New port: add it and mark its index in the bitmap */ |
| 8800 | pf->udp_ports[next_idx].index = port; |
| 8801 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 8802 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8803 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8804 | |
| 8805 | dev_info(&pf->pdev->dev, "adding geneve port %d\n", ntohs(port)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8806 | } |
| 8807 | |
| 8808 | /** |
| 8809 | * i40e_del_geneve_port - Get notifications about GENEVE ports that go away |
| 8810 | * @netdev: This physical port's netdev |
| 8811 | * @sa_family: Socket Family that GENEVE is notifying us about |
| 8812 | * @port: UDP port number that GENEVE stopped listening to |
| 8813 | **/ |
| 8814 | static void i40e_del_geneve_port(struct net_device *netdev, |
| 8815 | sa_family_t sa_family, __be16 port) |
| 8816 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8817 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8818 | struct i40e_vsi *vsi = np->vsi; |
| 8819 | struct i40e_pf *pf = vsi->back; |
| 8820 | u8 idx; |
| 8821 | |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8822 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8823 | return; |
| 8824 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8825 | idx = i40e_get_udp_port_idx(pf, port); |
| 8826 | |
| 8827 | /* Check if port already exists */ |
| 8828 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8829 | /* if port exists, set it to 0 (mark for deletion) |
| 8830 | * and make it pending |
| 8831 | */ |
| 8832 | pf->udp_ports[idx].index = 0; |
| 8833 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
| 8834 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8835 | |
| 8836 | dev_info(&pf->pdev->dev, "deleting geneve port %d\n", |
| 8837 | ntohs(port)); |
| 8838 | } else { |
| 8839 | netdev_warn(netdev, "geneve port %d was not found, not deleting\n", |
| 8840 | ntohs(port)); |
| 8841 | } |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8842 | } |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8843 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8844 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8845 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 8846 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8847 | { |
| 8848 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8849 | struct i40e_pf *pf = np->vsi->back; |
| 8850 | struct i40e_hw *hw = &pf->hw; |
| 8851 | |
| 8852 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 8853 | return -EOPNOTSUPP; |
| 8854 | |
| 8855 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 8856 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 8857 | |
| 8858 | return 0; |
| 8859 | } |
| 8860 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 8861 | /** |
| 8862 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 8863 | * @ndm: the input from the stack |
| 8864 | * @tb: pointer to array of nladdr (unused) |
| 8865 | * @dev: the net device pointer |
| 8866 | * @addr: the MAC address entry being added |
| 8867 | * @flags: instructions from stack about fdb operation |
| 8868 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8869 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 8870 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8871 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8872 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8873 | { |
| 8874 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8875 | struct i40e_pf *pf = np->vsi->back; |
| 8876 | int err = 0; |
| 8877 | |
| 8878 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 8879 | return -EOPNOTSUPP; |
| 8880 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 8881 | if (vid) { |
| 8882 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 8883 | return -EINVAL; |
| 8884 | } |
| 8885 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8886 | /* Hardware does not support aging addresses so if a |
| 8887 | * ndm_state is given only allow permanent addresses |
| 8888 | */ |
| 8889 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 8890 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 8891 | return -EINVAL; |
| 8892 | } |
| 8893 | |
| 8894 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 8895 | err = dev_uc_add_excl(dev, addr); |
| 8896 | else if (is_multicast_ether_addr(addr)) |
| 8897 | err = dev_mc_add_excl(dev, addr); |
| 8898 | else |
| 8899 | err = -EINVAL; |
| 8900 | |
| 8901 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 8902 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 8903 | err = 0; |
| 8904 | |
| 8905 | return err; |
| 8906 | } |
| 8907 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8908 | /** |
| 8909 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 8910 | * @dev: the netdev being configured |
| 8911 | * @nlh: RTNL message |
| 8912 | * |
| 8913 | * Inserts a new hardware bridge if not already created and |
| 8914 | * enables the bridging mode requested (VEB or VEPA). If the |
| 8915 | * hardware bridge has already been inserted and the request |
| 8916 | * is to change the mode then that requires a PF reset to |
| 8917 | * allow rebuild of the components with required hardware |
| 8918 | * bridge mode enabled. |
| 8919 | **/ |
| 8920 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 8921 | struct nlmsghdr *nlh, |
| 8922 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8923 | { |
| 8924 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8925 | struct i40e_vsi *vsi = np->vsi; |
| 8926 | struct i40e_pf *pf = vsi->back; |
| 8927 | struct i40e_veb *veb = NULL; |
| 8928 | struct nlattr *attr, *br_spec; |
| 8929 | int i, rem; |
| 8930 | |
| 8931 | /* Only for PF VSI for now */ |
| 8932 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8933 | return -EOPNOTSUPP; |
| 8934 | |
| 8935 | /* Find the HW bridge for PF VSI */ |
| 8936 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8937 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8938 | veb = pf->veb[i]; |
| 8939 | } |
| 8940 | |
| 8941 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 8942 | |
| 8943 | nla_for_each_nested(attr, br_spec, rem) { |
| 8944 | __u16 mode; |
| 8945 | |
| 8946 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 8947 | continue; |
| 8948 | |
| 8949 | mode = nla_get_u16(attr); |
| 8950 | if ((mode != BRIDGE_MODE_VEPA) && |
| 8951 | (mode != BRIDGE_MODE_VEB)) |
| 8952 | return -EINVAL; |
| 8953 | |
| 8954 | /* Insert a new HW bridge */ |
| 8955 | if (!veb) { |
| 8956 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 8957 | vsi->tc_config.enabled_tc); |
| 8958 | if (veb) { |
| 8959 | veb->bridge_mode = mode; |
| 8960 | i40e_config_bridge_mode(veb); |
| 8961 | } else { |
| 8962 | /* No Bridge HW offload available */ |
| 8963 | return -ENOENT; |
| 8964 | } |
| 8965 | break; |
| 8966 | } else if (mode != veb->bridge_mode) { |
| 8967 | /* Existing HW bridge but different mode needs reset */ |
| 8968 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 8969 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 8970 | if (mode == BRIDGE_MODE_VEB) |
| 8971 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 8972 | else |
| 8973 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 8974 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8975 | break; |
| 8976 | } |
| 8977 | } |
| 8978 | |
| 8979 | return 0; |
| 8980 | } |
| 8981 | |
| 8982 | /** |
| 8983 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 8984 | * @skb: skb buff |
| 8985 | * @pid: process id |
| 8986 | * @seq: RTNL message seq # |
| 8987 | * @dev: the netdev being configured |
| 8988 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 8989 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8990 | * |
| 8991 | * Return the mode in which the hardware bridge is operating in |
| 8992 | * i.e VEB or VEPA. |
| 8993 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8994 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 8995 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 8996 | u32 __always_unused filter_mask, |
| 8997 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8998 | { |
| 8999 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9000 | struct i40e_vsi *vsi = np->vsi; |
| 9001 | struct i40e_pf *pf = vsi->back; |
| 9002 | struct i40e_veb *veb = NULL; |
| 9003 | int i; |
| 9004 | |
| 9005 | /* Only for PF VSI for now */ |
| 9006 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9007 | return -EOPNOTSUPP; |
| 9008 | |
| 9009 | /* Find the HW bridge for the PF VSI */ |
| 9010 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9011 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9012 | veb = pf->veb[i]; |
| 9013 | } |
| 9014 | |
| 9015 | if (!veb) |
| 9016 | return 0; |
| 9017 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9018 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 9019 | nlflags, 0, 0, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9020 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9021 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9022 | /* Hardware supports L4 tunnel length of 128B (=2^7) which includes |
| 9023 | * inner mac plus all inner ethertypes. |
| 9024 | */ |
| 9025 | #define I40E_MAX_TUNNEL_HDR_LEN 128 |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9026 | /** |
| 9027 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 9028 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 9029 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9030 | * @features: Offload features that the stack believes apply |
| 9031 | **/ |
| 9032 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 9033 | struct net_device *dev, |
| 9034 | netdev_features_t features) |
| 9035 | { |
| 9036 | if (skb->encapsulation && |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9037 | ((skb_inner_network_header(skb) - skb_transport_header(skb)) > |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9038 | I40E_MAX_TUNNEL_HDR_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 9039 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9040 | |
| 9041 | return features; |
| 9042 | } |
| 9043 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 9044 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9045 | .ndo_open = i40e_open, |
| 9046 | .ndo_stop = i40e_close, |
| 9047 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 9048 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 9049 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 9050 | .ndo_validate_addr = eth_validate_addr, |
| 9051 | .ndo_set_mac_address = i40e_set_mac, |
| 9052 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 9053 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9054 | .ndo_tx_timeout = i40e_tx_timeout, |
| 9055 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 9056 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 9057 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9058 | .ndo_poll_controller = i40e_netpoll, |
| 9059 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9060 | .ndo_setup_tc = __i40e_setup_tc, |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9061 | #ifdef I40E_FCOE |
| 9062 | .ndo_fcoe_enable = i40e_fcoe_enable, |
| 9063 | .ndo_fcoe_disable = i40e_fcoe_disable, |
| 9064 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9065 | .ndo_set_features = i40e_set_features, |
| 9066 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 9067 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9068 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9069 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 9070 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 9071 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9072 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9073 | .ndo_add_vxlan_port = i40e_add_vxlan_port, |
| 9074 | .ndo_del_vxlan_port = i40e_del_vxlan_port, |
| 9075 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9076 | #if IS_ENABLED(CONFIG_GENEVE) |
| 9077 | .ndo_add_geneve_port = i40e_add_geneve_port, |
| 9078 | .ndo_del_geneve_port = i40e_del_geneve_port, |
| 9079 | #endif |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9080 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9081 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9082 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9083 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 9084 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9085 | }; |
| 9086 | |
| 9087 | /** |
| 9088 | * i40e_config_netdev - Setup the netdev flags |
| 9089 | * @vsi: the VSI being configured |
| 9090 | * |
| 9091 | * Returns 0 on success, negative value on failure |
| 9092 | **/ |
| 9093 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 9094 | { |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 9095 | u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9096 | struct i40e_pf *pf = vsi->back; |
| 9097 | struct i40e_hw *hw = &pf->hw; |
| 9098 | struct i40e_netdev_priv *np; |
| 9099 | struct net_device *netdev; |
| 9100 | u8 mac_addr[ETH_ALEN]; |
| 9101 | int etherdev_size; |
| 9102 | |
| 9103 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9104 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9105 | if (!netdev) |
| 9106 | return -ENOMEM; |
| 9107 | |
| 9108 | vsi->netdev = netdev; |
| 9109 | np = netdev_priv(netdev); |
| 9110 | np->vsi = vsi; |
| 9111 | |
Alexander Duyck | bc5d252 | 2016-01-24 21:17:50 -0800 | [diff] [blame] | 9112 | netdev->hw_enc_features |= NETIF_F_IP_CSUM | |
| 9113 | NETIF_F_IPV6_CSUM | |
| 9114 | NETIF_F_TSO | |
| 9115 | NETIF_F_TSO6 | |
| 9116 | NETIF_F_TSO_ECN | |
| 9117 | NETIF_F_GSO_GRE | |
| 9118 | NETIF_F_GSO_UDP_TUNNEL | |
| 9119 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
Jesse Brandeburg | 5afdaaa | 2015-12-10 11:38:50 -0800 | [diff] [blame] | 9120 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9121 | |
| 9122 | netdev->features = NETIF_F_SG | |
| 9123 | NETIF_F_IP_CSUM | |
Tom Herbert | 53692b1 | 2015-12-14 11:19:41 -0800 | [diff] [blame] | 9124 | NETIF_F_SCTP_CRC | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9125 | NETIF_F_HIGHDMA | |
| 9126 | NETIF_F_GSO_UDP_TUNNEL | |
Jesse Brandeburg | fec31ff | 2015-10-01 18:25:42 -0700 | [diff] [blame] | 9127 | NETIF_F_GSO_GRE | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9128 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9129 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9130 | NETIF_F_HW_VLAN_CTAG_FILTER | |
| 9131 | NETIF_F_IPV6_CSUM | |
| 9132 | NETIF_F_TSO | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 9133 | NETIF_F_TSO_ECN | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9134 | NETIF_F_TSO6 | |
| 9135 | NETIF_F_RXCSUM | |
| 9136 | NETIF_F_RXHASH | |
| 9137 | 0; |
| 9138 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9139 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 9140 | netdev->features |= NETIF_F_NTUPLE; |
Alexander Duyck | bc5d252 | 2016-01-24 21:17:50 -0800 | [diff] [blame] | 9141 | if (pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE) |
| 9142 | netdev->features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9143 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9144 | /* copy netdev features into list of user selectable features */ |
| 9145 | netdev->hw_features |= netdev->features; |
| 9146 | |
| 9147 | if (vsi->type == I40E_VSI_MAIN) { |
| 9148 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9149 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9150 | /* The following steps are necessary to prevent reception |
| 9151 | * of tagged packets - some older NVM configurations load a |
| 9152 | * default a MAC-VLAN filter that accepts any tagged packet |
| 9153 | * which must be replaced by a normal filter. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 9154 | */ |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9155 | if (!i40e_rm_default_mac_filter(vsi, mac_addr)) { |
| 9156 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9157 | i40e_add_filter(vsi, mac_addr, |
| 9158 | I40E_VLAN_ANY, false, true); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9159 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9160 | } |
Anjali Singhai Jain | 3845cce | 2016-03-18 12:18:05 -0700 | [diff] [blame] | 9161 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 9162 | ((pf->hw.aq.api_maj_ver == 1) && |
| 9163 | (pf->hw.aq.api_min_ver > 4))) { |
| 9164 | /* Supported in FW API version higher than 1.4 */ |
| 9165 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
| 9166 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9167 | } else { |
| 9168 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 9169 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 9170 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9171 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9172 | |
| 9173 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9174 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9175 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9176 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9177 | |
| 9178 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 9179 | i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9180 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9181 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9182 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9183 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9184 | /* vlan gets same features (except vlan offload) |
| 9185 | * after any tweaks for specific VSI types |
| 9186 | */ |
| 9187 | netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX | |
| 9188 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9189 | NETIF_F_HW_VLAN_CTAG_FILTER); |
| 9190 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9191 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9192 | /* Setup netdev TC information */ |
| 9193 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9194 | |
| 9195 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9196 | netdev->watchdog_timeo = 5 * HZ; |
| 9197 | i40e_set_ethtool_ops(netdev); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9198 | #ifdef I40E_FCOE |
| 9199 | i40e_fcoe_config_netdev(netdev, vsi); |
| 9200 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9201 | |
| 9202 | return 0; |
| 9203 | } |
| 9204 | |
| 9205 | /** |
| 9206 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9207 | * @vsi: the VSI being removed |
| 9208 | * |
| 9209 | * Returns 0 on success, negative value on failure |
| 9210 | **/ |
| 9211 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9212 | { |
| 9213 | /* remove default VSI is not allowed */ |
| 9214 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9215 | return; |
| 9216 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9217 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9218 | } |
| 9219 | |
| 9220 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9221 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9222 | * @vsi: the VSI being queried |
| 9223 | * |
| 9224 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9225 | **/ |
| 9226 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9227 | { |
| 9228 | struct i40e_veb *veb; |
| 9229 | struct i40e_pf *pf = vsi->back; |
| 9230 | |
| 9231 | /* Uplink is not a bridge so default to VEB */ |
| 9232 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9233 | return 1; |
| 9234 | |
| 9235 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9236 | if (!veb) { |
| 9237 | dev_info(&pf->pdev->dev, |
| 9238 | "There is no veb associated with the bridge\n"); |
| 9239 | return -ENOENT; |
| 9240 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9241 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9242 | /* Uplink is a bridge in VEPA mode */ |
| 9243 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9244 | return 0; |
| 9245 | } else { |
| 9246 | /* Uplink is a bridge in VEB mode */ |
| 9247 | return 1; |
| 9248 | } |
| 9249 | |
| 9250 | /* VEPA is now default bridge, so return 0 */ |
| 9251 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9252 | } |
| 9253 | |
| 9254 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9255 | * i40e_add_vsi - Add a VSI to the switch |
| 9256 | * @vsi: the VSI being configured |
| 9257 | * |
| 9258 | * This initializes a VSI context depending on the VSI type to be added and |
| 9259 | * passes it down to the add_vsi aq command. |
| 9260 | **/ |
| 9261 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9262 | { |
| 9263 | int ret = -ENODEV; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9264 | u8 laa_macaddr[ETH_ALEN]; |
| 9265 | bool found_laa_mac_filter = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9266 | struct i40e_pf *pf = vsi->back; |
| 9267 | struct i40e_hw *hw = &pf->hw; |
| 9268 | struct i40e_vsi_context ctxt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9269 | struct i40e_mac_filter *f, *ftmp; |
| 9270 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9271 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9272 | int f_count = 0; |
| 9273 | |
| 9274 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9275 | switch (vsi->type) { |
| 9276 | case I40E_VSI_MAIN: |
| 9277 | /* The PF's main VSI is already setup as part of the |
| 9278 | * device initialization, so we'll not bother with |
| 9279 | * the add_vsi call, but we will retrieve the current |
| 9280 | * VSI context. |
| 9281 | */ |
| 9282 | ctxt.seid = pf->main_vsi_seid; |
| 9283 | ctxt.pf_num = pf->hw.pf_id; |
| 9284 | ctxt.vf_num = 0; |
| 9285 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9286 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9287 | if (ret) { |
| 9288 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9289 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9290 | i40e_stat_str(&pf->hw, ret), |
| 9291 | i40e_aq_str(&pf->hw, |
| 9292 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9293 | return -ENOENT; |
| 9294 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9295 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9296 | vsi->info.valid_sections = 0; |
| 9297 | |
| 9298 | vsi->seid = ctxt.seid; |
| 9299 | vsi->id = ctxt.vsi_number; |
| 9300 | |
| 9301 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9302 | |
| 9303 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9304 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9305 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9306 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9307 | ctxt.seid = pf->main_vsi_seid; |
| 9308 | ctxt.pf_num = pf->hw.pf_id; |
| 9309 | ctxt.vf_num = 0; |
| 9310 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9311 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9312 | if (ret) { |
| 9313 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9314 | "update vsi failed, err %s aq_err %s\n", |
| 9315 | i40e_stat_str(&pf->hw, ret), |
| 9316 | i40e_aq_str(&pf->hw, |
| 9317 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9318 | ret = -ENOENT; |
| 9319 | goto err; |
| 9320 | } |
| 9321 | /* update the local VSI info queue map */ |
| 9322 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9323 | vsi->info.valid_sections = 0; |
| 9324 | } else { |
| 9325 | /* Default/Main VSI is only enabled for TC0 |
| 9326 | * reconfigure it to enable all TCs that are |
| 9327 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9328 | * For MFP case the iSCSI PF would use this |
| 9329 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9330 | */ |
| 9331 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9332 | if (ret) { |
| 9333 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9334 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9335 | enabled_tc, |
| 9336 | i40e_stat_str(&pf->hw, ret), |
| 9337 | i40e_aq_str(&pf->hw, |
| 9338 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9339 | ret = -ENOENT; |
| 9340 | } |
| 9341 | } |
| 9342 | break; |
| 9343 | |
| 9344 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9345 | ctxt.pf_num = hw->pf_id; |
| 9346 | ctxt.vf_num = 0; |
| 9347 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9348 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9349 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9350 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9351 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9352 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9353 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9354 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9355 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9356 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9357 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9358 | break; |
| 9359 | |
| 9360 | case I40E_VSI_VMDQ2: |
| 9361 | ctxt.pf_num = hw->pf_id; |
| 9362 | ctxt.vf_num = 0; |
| 9363 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9364 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9365 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9366 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9367 | /* This VSI is connected to VEB so the switch_id |
| 9368 | * should be set to zero by default. |
| 9369 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9370 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9371 | ctxt.info.valid_sections |= |
| 9372 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9373 | ctxt.info.switch_id = |
| 9374 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9375 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9376 | |
| 9377 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9378 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9379 | break; |
| 9380 | |
| 9381 | case I40E_VSI_SRIOV: |
| 9382 | ctxt.pf_num = hw->pf_id; |
| 9383 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9384 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9385 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9386 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9387 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9388 | /* This VSI is connected to VEB so the switch_id |
| 9389 | * should be set to zero by default. |
| 9390 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9391 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9392 | ctxt.info.valid_sections |= |
| 9393 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9394 | ctxt.info.switch_id = |
| 9395 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9396 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9397 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9398 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9399 | ctxt.info.valid_sections |= |
| 9400 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 9401 | ctxt.info.queueing_opt_flags |= |
| 9402 | I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 9403 | } |
| 9404 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9405 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9406 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9407 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9408 | ctxt.info.valid_sections |= |
| 9409 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9410 | ctxt.info.sec_flags |= |
| 9411 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9412 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9413 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9414 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9415 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9416 | break; |
| 9417 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9418 | #ifdef I40E_FCOE |
| 9419 | case I40E_VSI_FCOE: |
| 9420 | ret = i40e_fcoe_vsi_init(vsi, &ctxt); |
| 9421 | if (ret) { |
| 9422 | dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n"); |
| 9423 | return ret; |
| 9424 | } |
| 9425 | break; |
| 9426 | |
| 9427 | #endif /* I40E_FCOE */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9428 | case I40E_VSI_IWARP: |
| 9429 | /* send down message to iWARP */ |
| 9430 | break; |
| 9431 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9432 | default: |
| 9433 | return -ENODEV; |
| 9434 | } |
| 9435 | |
| 9436 | if (vsi->type != I40E_VSI_MAIN) { |
| 9437 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9438 | if (ret) { |
| 9439 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9440 | "add vsi failed, err %s aq_err %s\n", |
| 9441 | i40e_stat_str(&pf->hw, ret), |
| 9442 | i40e_aq_str(&pf->hw, |
| 9443 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9444 | ret = -ENOENT; |
| 9445 | goto err; |
| 9446 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9447 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9448 | vsi->info.valid_sections = 0; |
| 9449 | vsi->seid = ctxt.seid; |
| 9450 | vsi->id = ctxt.vsi_number; |
| 9451 | } |
| 9452 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9453 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9454 | /* If macvlan filters already exist, force them to get loaded */ |
| 9455 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 9456 | f->changed = true; |
| 9457 | f_count++; |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9458 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9459 | /* Expected to have only one MAC filter entry for LAA in list */ |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9460 | if (f->is_laa && vsi->type == I40E_VSI_MAIN) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9461 | ether_addr_copy(laa_macaddr, f->macaddr); |
| 9462 | found_laa_mac_filter = true; |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9463 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9464 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9465 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9466 | |
| 9467 | if (found_laa_mac_filter) { |
| 9468 | struct i40e_aqc_remove_macvlan_element_data element; |
| 9469 | |
| 9470 | memset(&element, 0, sizeof(element)); |
| 9471 | ether_addr_copy(element.mac_addr, laa_macaddr); |
| 9472 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 9473 | ret = i40e_aq_remove_macvlan(hw, vsi->seid, |
| 9474 | &element, 1, NULL); |
| 9475 | if (ret) { |
| 9476 | /* some older FW has a different default */ |
| 9477 | element.flags |= |
| 9478 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
| 9479 | i40e_aq_remove_macvlan(hw, vsi->seid, |
| 9480 | &element, 1, NULL); |
| 9481 | } |
| 9482 | |
| 9483 | i40e_aq_mac_address_write(hw, |
| 9484 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 9485 | laa_macaddr, NULL); |
| 9486 | } |
| 9487 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9488 | if (f_count) { |
| 9489 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 9490 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 9491 | } |
| 9492 | |
| 9493 | /* Update VSI BW information */ |
| 9494 | ret = i40e_vsi_get_bw_info(vsi); |
| 9495 | if (ret) { |
| 9496 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9497 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 9498 | i40e_stat_str(&pf->hw, ret), |
| 9499 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9500 | /* VSI is already added so not tearing that up */ |
| 9501 | ret = 0; |
| 9502 | } |
| 9503 | |
| 9504 | err: |
| 9505 | return ret; |
| 9506 | } |
| 9507 | |
| 9508 | /** |
| 9509 | * i40e_vsi_release - Delete a VSI and free its resources |
| 9510 | * @vsi: the VSI being removed |
| 9511 | * |
| 9512 | * Returns 0 on success or < 0 on error |
| 9513 | **/ |
| 9514 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 9515 | { |
| 9516 | struct i40e_mac_filter *f, *ftmp; |
| 9517 | struct i40e_veb *veb = NULL; |
| 9518 | struct i40e_pf *pf; |
| 9519 | u16 uplink_seid; |
| 9520 | int i, n; |
| 9521 | |
| 9522 | pf = vsi->back; |
| 9523 | |
| 9524 | /* release of a VEB-owner or last VSI is not allowed */ |
| 9525 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 9526 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 9527 | vsi->seid, vsi->uplink_seid); |
| 9528 | return -ENODEV; |
| 9529 | } |
| 9530 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 9531 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 9532 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 9533 | return -ENODEV; |
| 9534 | } |
| 9535 | |
| 9536 | uplink_seid = vsi->uplink_seid; |
| 9537 | if (vsi->type != I40E_VSI_SRIOV) { |
| 9538 | if (vsi->netdev_registered) { |
| 9539 | vsi->netdev_registered = false; |
| 9540 | if (vsi->netdev) { |
| 9541 | /* results in a call to i40e_close() */ |
| 9542 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9543 | } |
| 9544 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 9545 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9546 | } |
| 9547 | i40e_vsi_disable_irq(vsi); |
| 9548 | } |
| 9549 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9550 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9551 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
| 9552 | i40e_del_filter(vsi, f->macaddr, f->vlan, |
| 9553 | f->is_vf, f->is_netdev); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9554 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9555 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 9556 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9557 | |
| 9558 | i40e_vsi_delete(vsi); |
| 9559 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 9560 | if (vsi->netdev) { |
| 9561 | free_netdev(vsi->netdev); |
| 9562 | vsi->netdev = NULL; |
| 9563 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9564 | i40e_vsi_clear_rings(vsi); |
| 9565 | i40e_vsi_clear(vsi); |
| 9566 | |
| 9567 | /* If this was the last thing on the VEB, except for the |
| 9568 | * controlling VSI, remove the VEB, which puts the controlling |
| 9569 | * VSI onto the next level down in the switch. |
| 9570 | * |
| 9571 | * Well, okay, there's one more exception here: don't remove |
| 9572 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 9573 | * from up the network stack. |
| 9574 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9575 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9576 | if (pf->vsi[i] && |
| 9577 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 9578 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9579 | n++; /* count the VSIs */ |
| 9580 | } |
| 9581 | } |
| 9582 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9583 | if (!pf->veb[i]) |
| 9584 | continue; |
| 9585 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 9586 | n++; /* count the VEBs */ |
| 9587 | if (pf->veb[i]->seid == uplink_seid) |
| 9588 | veb = pf->veb[i]; |
| 9589 | } |
| 9590 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 9591 | i40e_veb_release(veb); |
| 9592 | |
| 9593 | return 0; |
| 9594 | } |
| 9595 | |
| 9596 | /** |
| 9597 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 9598 | * @vsi: ptr to the VSI |
| 9599 | * |
| 9600 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 9601 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 9602 | * newly allocated VSI. |
| 9603 | * |
| 9604 | * Returns 0 on success or negative on failure |
| 9605 | **/ |
| 9606 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 9607 | { |
| 9608 | int ret = -ENOENT; |
| 9609 | struct i40e_pf *pf = vsi->back; |
| 9610 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9611 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9612 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 9613 | vsi->seid); |
| 9614 | return -EEXIST; |
| 9615 | } |
| 9616 | |
| 9617 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 9618 | 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] | 9619 | vsi->seid, vsi->base_vector); |
| 9620 | return -EEXIST; |
| 9621 | } |
| 9622 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9623 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9624 | if (ret) { |
| 9625 | dev_info(&pf->pdev->dev, |
| 9626 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 9627 | vsi->num_q_vectors, vsi->seid, ret); |
| 9628 | vsi->num_q_vectors = 0; |
| 9629 | goto vector_setup_out; |
| 9630 | } |
| 9631 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 9632 | /* In Legacy mode, we do not have to get any other vector since we |
| 9633 | * piggyback on the misc/ICR0 for queue interrupts. |
| 9634 | */ |
| 9635 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9636 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9637 | if (vsi->num_q_vectors) |
| 9638 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 9639 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9640 | if (vsi->base_vector < 0) { |
| 9641 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9642 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 9643 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9644 | i40e_vsi_free_q_vectors(vsi); |
| 9645 | ret = -ENOENT; |
| 9646 | goto vector_setup_out; |
| 9647 | } |
| 9648 | |
| 9649 | vector_setup_out: |
| 9650 | return ret; |
| 9651 | } |
| 9652 | |
| 9653 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9654 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 9655 | * @vsi: pointer to the vsi. |
| 9656 | * |
| 9657 | * This re-allocates a vsi's queue resources. |
| 9658 | * |
| 9659 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 9660 | * on success, otherwise returns NULL on failure. |
| 9661 | **/ |
| 9662 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 9663 | { |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9664 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9665 | u8 enabled_tc; |
| 9666 | int ret; |
| 9667 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9668 | if (!vsi) |
| 9669 | return NULL; |
| 9670 | |
| 9671 | pf = vsi->back; |
| 9672 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9673 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9674 | i40e_vsi_clear_rings(vsi); |
| 9675 | |
| 9676 | i40e_vsi_free_arrays(vsi, false); |
| 9677 | i40e_set_num_rings_in_vsi(vsi); |
| 9678 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 9679 | if (ret) |
| 9680 | goto err_vsi; |
| 9681 | |
| 9682 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 9683 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9684 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9685 | "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] | 9686 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9687 | goto err_vsi; |
| 9688 | } |
| 9689 | vsi->base_queue = ret; |
| 9690 | |
| 9691 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 9692 | * layout configurations. |
| 9693 | */ |
| 9694 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9695 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9696 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9697 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 9698 | |
| 9699 | /* assign it some queues */ |
| 9700 | ret = i40e_alloc_rings(vsi); |
| 9701 | if (ret) |
| 9702 | goto err_rings; |
| 9703 | |
| 9704 | /* map all of the rings to the q_vectors */ |
| 9705 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9706 | return vsi; |
| 9707 | |
| 9708 | err_rings: |
| 9709 | i40e_vsi_free_q_vectors(vsi); |
| 9710 | if (vsi->netdev_registered) { |
| 9711 | vsi->netdev_registered = false; |
| 9712 | unregister_netdev(vsi->netdev); |
| 9713 | free_netdev(vsi->netdev); |
| 9714 | vsi->netdev = NULL; |
| 9715 | } |
| 9716 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9717 | err_vsi: |
| 9718 | i40e_vsi_clear(vsi); |
| 9719 | return NULL; |
| 9720 | } |
| 9721 | |
| 9722 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9723 | * i40e_macaddr_init - explicitly write the mac address filters. |
| 9724 | * |
| 9725 | * @vsi: pointer to the vsi. |
| 9726 | * @macaddr: the MAC address |
| 9727 | * |
| 9728 | * This is needed when the macaddr has been obtained by other |
| 9729 | * means than the default, e.g., from Open Firmware or IDPROM. |
| 9730 | * Returns 0 on success, negative on failure |
| 9731 | **/ |
| 9732 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) |
| 9733 | { |
| 9734 | int ret; |
| 9735 | struct i40e_aqc_add_macvlan_element_data element; |
| 9736 | |
| 9737 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 9738 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 9739 | macaddr, NULL); |
| 9740 | if (ret) { |
| 9741 | dev_info(&vsi->back->pdev->dev, |
| 9742 | "Addr change for VSI failed: %d\n", ret); |
| 9743 | return -EADDRNOTAVAIL; |
| 9744 | } |
| 9745 | |
| 9746 | memset(&element, 0, sizeof(element)); |
| 9747 | ether_addr_copy(element.mac_addr, macaddr); |
| 9748 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 9749 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); |
| 9750 | if (ret) { |
| 9751 | dev_info(&vsi->back->pdev->dev, |
| 9752 | "add filter failed err %s aq_err %s\n", |
| 9753 | i40e_stat_str(&vsi->back->hw, ret), |
| 9754 | i40e_aq_str(&vsi->back->hw, |
| 9755 | vsi->back->hw.aq.asq_last_status)); |
| 9756 | } |
| 9757 | return ret; |
| 9758 | } |
| 9759 | |
| 9760 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9761 | * i40e_vsi_setup - Set up a VSI by a given type |
| 9762 | * @pf: board private structure |
| 9763 | * @type: VSI type |
| 9764 | * @uplink_seid: the switch element to link to |
| 9765 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 9766 | * |
| 9767 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 9768 | * to the identified VEB. |
| 9769 | * |
| 9770 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 9771 | * success, otherwise returns NULL on failure. |
| 9772 | **/ |
| 9773 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 9774 | u16 uplink_seid, u32 param1) |
| 9775 | { |
| 9776 | struct i40e_vsi *vsi = NULL; |
| 9777 | struct i40e_veb *veb = NULL; |
| 9778 | int ret, i; |
| 9779 | int v_idx; |
| 9780 | |
| 9781 | /* The requested uplink_seid must be either |
| 9782 | * - the PF's port seid |
| 9783 | * no VEB is needed because this is the PF |
| 9784 | * or this is a Flow Director special case VSI |
| 9785 | * - seid of an existing VEB |
| 9786 | * - seid of a VSI that owns an existing VEB |
| 9787 | * - seid of a VSI that doesn't own a VEB |
| 9788 | * a new VEB is created and the VSI becomes the owner |
| 9789 | * - seid of the PF VSI, which is what creates the first VEB |
| 9790 | * this is a special case of the previous |
| 9791 | * |
| 9792 | * Find which uplink_seid we were given and create a new VEB if needed |
| 9793 | */ |
| 9794 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9795 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 9796 | veb = pf->veb[i]; |
| 9797 | break; |
| 9798 | } |
| 9799 | } |
| 9800 | |
| 9801 | if (!veb && uplink_seid != pf->mac_seid) { |
| 9802 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9803 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9804 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 9805 | vsi = pf->vsi[i]; |
| 9806 | break; |
| 9807 | } |
| 9808 | } |
| 9809 | if (!vsi) { |
| 9810 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 9811 | uplink_seid); |
| 9812 | return NULL; |
| 9813 | } |
| 9814 | |
| 9815 | if (vsi->uplink_seid == pf->mac_seid) |
| 9816 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 9817 | vsi->tc_config.enabled_tc); |
| 9818 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 9819 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9820 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9821 | if (veb) { |
| 9822 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 9823 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 9824 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9825 | return NULL; |
| 9826 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 9827 | /* We come up by default in VEPA mode if SRIOV is not |
| 9828 | * already enabled, in which case we can't force VEPA |
| 9829 | * mode. |
| 9830 | */ |
| 9831 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 9832 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 9833 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9834 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9835 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9836 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9837 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9838 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9839 | veb = pf->veb[i]; |
| 9840 | } |
| 9841 | if (!veb) { |
| 9842 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 9843 | return NULL; |
| 9844 | } |
| 9845 | |
| 9846 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 9847 | uplink_seid = veb->seid; |
| 9848 | } |
| 9849 | |
| 9850 | /* get vsi sw struct */ |
| 9851 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 9852 | if (v_idx < 0) |
| 9853 | goto err_alloc; |
| 9854 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9855 | if (!vsi) |
| 9856 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9857 | vsi->type = type; |
| 9858 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 9859 | |
| 9860 | if (type == I40E_VSI_MAIN) |
| 9861 | pf->lan_vsi = v_idx; |
| 9862 | else if (type == I40E_VSI_SRIOV) |
| 9863 | vsi->vf_id = param1; |
| 9864 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9865 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 9866 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9867 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9868 | dev_info(&pf->pdev->dev, |
| 9869 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 9870 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9871 | goto err_vsi; |
| 9872 | } |
| 9873 | vsi->base_queue = ret; |
| 9874 | |
| 9875 | /* get a VSI from the hardware */ |
| 9876 | vsi->uplink_seid = uplink_seid; |
| 9877 | ret = i40e_add_vsi(vsi); |
| 9878 | if (ret) |
| 9879 | goto err_vsi; |
| 9880 | |
| 9881 | switch (vsi->type) { |
| 9882 | /* setup the netdev if needed */ |
| 9883 | case I40E_VSI_MAIN: |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9884 | /* Apply relevant filters if a platform-specific mac |
| 9885 | * address was selected. |
| 9886 | */ |
| 9887 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 9888 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 9889 | if (ret) { |
| 9890 | dev_warn(&pf->pdev->dev, |
| 9891 | "could not set up macaddr; err %d\n", |
| 9892 | ret); |
| 9893 | } |
| 9894 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9895 | case I40E_VSI_VMDQ2: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9896 | case I40E_VSI_FCOE: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9897 | ret = i40e_config_netdev(vsi); |
| 9898 | if (ret) |
| 9899 | goto err_netdev; |
| 9900 | ret = register_netdev(vsi->netdev); |
| 9901 | if (ret) |
| 9902 | goto err_netdev; |
| 9903 | vsi->netdev_registered = true; |
| 9904 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9905 | #ifdef CONFIG_I40E_DCB |
| 9906 | /* Setup DCB netlink interface */ |
| 9907 | i40e_dcbnl_setup(vsi); |
| 9908 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9909 | /* fall through */ |
| 9910 | |
| 9911 | case I40E_VSI_FDIR: |
| 9912 | /* set up vectors and rings if needed */ |
| 9913 | ret = i40e_vsi_setup_vectors(vsi); |
| 9914 | if (ret) |
| 9915 | goto err_msix; |
| 9916 | |
| 9917 | ret = i40e_alloc_rings(vsi); |
| 9918 | if (ret) |
| 9919 | goto err_rings; |
| 9920 | |
| 9921 | /* map all of the rings to the q_vectors */ |
| 9922 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9923 | |
| 9924 | i40e_vsi_reset_stats(vsi); |
| 9925 | break; |
| 9926 | |
| 9927 | default: |
| 9928 | /* no netdev or rings for the other VSI types */ |
| 9929 | break; |
| 9930 | } |
| 9931 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9932 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
| 9933 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 9934 | ret = i40e_vsi_config_rss(vsi); |
| 9935 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9936 | return vsi; |
| 9937 | |
| 9938 | err_rings: |
| 9939 | i40e_vsi_free_q_vectors(vsi); |
| 9940 | err_msix: |
| 9941 | if (vsi->netdev_registered) { |
| 9942 | vsi->netdev_registered = false; |
| 9943 | unregister_netdev(vsi->netdev); |
| 9944 | free_netdev(vsi->netdev); |
| 9945 | vsi->netdev = NULL; |
| 9946 | } |
| 9947 | err_netdev: |
| 9948 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9949 | err_vsi: |
| 9950 | i40e_vsi_clear(vsi); |
| 9951 | err_alloc: |
| 9952 | return NULL; |
| 9953 | } |
| 9954 | |
| 9955 | /** |
| 9956 | * i40e_veb_get_bw_info - Query VEB BW information |
| 9957 | * @veb: the veb to query |
| 9958 | * |
| 9959 | * Query the Tx scheduler BW configuration data for given VEB |
| 9960 | **/ |
| 9961 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 9962 | { |
| 9963 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 9964 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 9965 | struct i40e_pf *pf = veb->pf; |
| 9966 | struct i40e_hw *hw = &pf->hw; |
| 9967 | u32 tc_bw_max; |
| 9968 | int ret = 0; |
| 9969 | int i; |
| 9970 | |
| 9971 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 9972 | &bw_data, NULL); |
| 9973 | if (ret) { |
| 9974 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9975 | "query veb bw config failed, err %s aq_err %s\n", |
| 9976 | i40e_stat_str(&pf->hw, ret), |
| 9977 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9978 | goto out; |
| 9979 | } |
| 9980 | |
| 9981 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 9982 | &ets_data, NULL); |
| 9983 | if (ret) { |
| 9984 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9985 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 9986 | i40e_stat_str(&pf->hw, ret), |
| 9987 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9988 | goto out; |
| 9989 | } |
| 9990 | |
| 9991 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 9992 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 9993 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 9994 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9995 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 9996 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 9997 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 9998 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 9999 | veb->bw_tc_limit_credits[i] = |
| 10000 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 10001 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 10002 | } |
| 10003 | |
| 10004 | out: |
| 10005 | return ret; |
| 10006 | } |
| 10007 | |
| 10008 | /** |
| 10009 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 10010 | * @pf: board private structure |
| 10011 | * |
| 10012 | * On error: returns error code (negative) |
| 10013 | * On success: returns vsi index in PF (positive) |
| 10014 | **/ |
| 10015 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 10016 | { |
| 10017 | int ret = -ENOENT; |
| 10018 | struct i40e_veb *veb; |
| 10019 | int i; |
| 10020 | |
| 10021 | /* Need to protect the allocation of switch elements at the PF level */ |
| 10022 | mutex_lock(&pf->switch_mutex); |
| 10023 | |
| 10024 | /* VEB list may be fragmented if VEB creation/destruction has |
| 10025 | * been happening. We can afford to do a quick scan to look |
| 10026 | * for any free slots in the list. |
| 10027 | * |
| 10028 | * find next empty veb slot, looping back around if necessary |
| 10029 | */ |
| 10030 | i = 0; |
| 10031 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 10032 | i++; |
| 10033 | if (i >= I40E_MAX_VEB) { |
| 10034 | ret = -ENOMEM; |
| 10035 | goto err_alloc_veb; /* out of VEB slots! */ |
| 10036 | } |
| 10037 | |
| 10038 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 10039 | if (!veb) { |
| 10040 | ret = -ENOMEM; |
| 10041 | goto err_alloc_veb; |
| 10042 | } |
| 10043 | veb->pf = pf; |
| 10044 | veb->idx = i; |
| 10045 | veb->enabled_tc = 1; |
| 10046 | |
| 10047 | pf->veb[i] = veb; |
| 10048 | ret = i; |
| 10049 | err_alloc_veb: |
| 10050 | mutex_unlock(&pf->switch_mutex); |
| 10051 | return ret; |
| 10052 | } |
| 10053 | |
| 10054 | /** |
| 10055 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 10056 | * @branch: where to start deleting |
| 10057 | * |
| 10058 | * This uses recursion to find the tips of the branch to be |
| 10059 | * removed, deleting until we get back to and can delete this VEB. |
| 10060 | **/ |
| 10061 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 10062 | { |
| 10063 | struct i40e_pf *pf = branch->pf; |
| 10064 | u16 branch_seid = branch->seid; |
| 10065 | u16 veb_idx = branch->idx; |
| 10066 | int i; |
| 10067 | |
| 10068 | /* release any VEBs on this VEB - RECURSION */ |
| 10069 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10070 | if (!pf->veb[i]) |
| 10071 | continue; |
| 10072 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 10073 | i40e_switch_branch_release(pf->veb[i]); |
| 10074 | } |
| 10075 | |
| 10076 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 10077 | * |
| 10078 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 10079 | * the VEB itself, so don't use (*branch) after this loop. |
| 10080 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10081 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10082 | if (!pf->vsi[i]) |
| 10083 | continue; |
| 10084 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 10085 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 10086 | i40e_vsi_release(pf->vsi[i]); |
| 10087 | } |
| 10088 | } |
| 10089 | |
| 10090 | /* There's one corner case where the VEB might not have been |
| 10091 | * removed, so double check it here and remove it if needed. |
| 10092 | * This case happens if the veb was created from the debugfs |
| 10093 | * commands and no VSIs were added to it. |
| 10094 | */ |
| 10095 | if (pf->veb[veb_idx]) |
| 10096 | i40e_veb_release(pf->veb[veb_idx]); |
| 10097 | } |
| 10098 | |
| 10099 | /** |
| 10100 | * i40e_veb_clear - remove veb struct |
| 10101 | * @veb: the veb to remove |
| 10102 | **/ |
| 10103 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 10104 | { |
| 10105 | if (!veb) |
| 10106 | return; |
| 10107 | |
| 10108 | if (veb->pf) { |
| 10109 | struct i40e_pf *pf = veb->pf; |
| 10110 | |
| 10111 | mutex_lock(&pf->switch_mutex); |
| 10112 | if (pf->veb[veb->idx] == veb) |
| 10113 | pf->veb[veb->idx] = NULL; |
| 10114 | mutex_unlock(&pf->switch_mutex); |
| 10115 | } |
| 10116 | |
| 10117 | kfree(veb); |
| 10118 | } |
| 10119 | |
| 10120 | /** |
| 10121 | * i40e_veb_release - Delete a VEB and free its resources |
| 10122 | * @veb: the VEB being removed |
| 10123 | **/ |
| 10124 | void i40e_veb_release(struct i40e_veb *veb) |
| 10125 | { |
| 10126 | struct i40e_vsi *vsi = NULL; |
| 10127 | struct i40e_pf *pf; |
| 10128 | int i, n = 0; |
| 10129 | |
| 10130 | pf = veb->pf; |
| 10131 | |
| 10132 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10133 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10134 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 10135 | n++; |
| 10136 | vsi = pf->vsi[i]; |
| 10137 | } |
| 10138 | } |
| 10139 | if (n != 1) { |
| 10140 | dev_info(&pf->pdev->dev, |
| 10141 | "can't remove VEB %d with %d VSIs left\n", |
| 10142 | veb->seid, n); |
| 10143 | return; |
| 10144 | } |
| 10145 | |
| 10146 | /* move the remaining VSI to uplink veb */ |
| 10147 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10148 | if (veb->uplink_seid) { |
| 10149 | vsi->uplink_seid = veb->uplink_seid; |
| 10150 | if (veb->uplink_seid == pf->mac_seid) |
| 10151 | vsi->veb_idx = I40E_NO_VEB; |
| 10152 | else |
| 10153 | vsi->veb_idx = veb->veb_idx; |
| 10154 | } else { |
| 10155 | /* floating VEB */ |
| 10156 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10157 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10158 | } |
| 10159 | |
| 10160 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10161 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10162 | } |
| 10163 | |
| 10164 | /** |
| 10165 | * i40e_add_veb - create the VEB in the switch |
| 10166 | * @veb: the VEB to be instantiated |
| 10167 | * @vsi: the controlling VSI |
| 10168 | **/ |
| 10169 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10170 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10171 | struct i40e_pf *pf = veb->pf; |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 10172 | bool is_default = veb->pf->cur_promisc; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10173 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10174 | int ret; |
| 10175 | |
| 10176 | /* get a VEB from the hardware */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10177 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 10178 | veb->enabled_tc, is_default, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10179 | &veb->seid, enable_stats, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10180 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10181 | dev_info(&pf->pdev->dev, |
| 10182 | "couldn't add VEB, err %s aq_err %s\n", |
| 10183 | i40e_stat_str(&pf->hw, ret), |
| 10184 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10185 | return -EPERM; |
| 10186 | } |
| 10187 | |
| 10188 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10189 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10190 | &veb->stats_idx, NULL, NULL, NULL); |
| 10191 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10192 | dev_info(&pf->pdev->dev, |
| 10193 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10194 | i40e_stat_str(&pf->hw, ret), |
| 10195 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10196 | return -EPERM; |
| 10197 | } |
| 10198 | ret = i40e_veb_get_bw_info(veb); |
| 10199 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10200 | dev_info(&pf->pdev->dev, |
| 10201 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10202 | i40e_stat_str(&pf->hw, ret), |
| 10203 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10204 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10205 | return -ENOENT; |
| 10206 | } |
| 10207 | |
| 10208 | vsi->uplink_seid = veb->seid; |
| 10209 | vsi->veb_idx = veb->idx; |
| 10210 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10211 | |
| 10212 | return 0; |
| 10213 | } |
| 10214 | |
| 10215 | /** |
| 10216 | * i40e_veb_setup - Set up a VEB |
| 10217 | * @pf: board private structure |
| 10218 | * @flags: VEB setup flags |
| 10219 | * @uplink_seid: the switch element to link to |
| 10220 | * @vsi_seid: the initial VSI seid |
| 10221 | * @enabled_tc: Enabled TC bit-map |
| 10222 | * |
| 10223 | * This allocates the sw VEB structure and links it into the switch |
| 10224 | * It is possible and legal for this to be a duplicate of an already |
| 10225 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10226 | * to be zero, in order to create a floating VEB. |
| 10227 | * |
| 10228 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10229 | * success, otherwise returns NULL on failure. |
| 10230 | **/ |
| 10231 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10232 | u16 uplink_seid, u16 vsi_seid, |
| 10233 | u8 enabled_tc) |
| 10234 | { |
| 10235 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10236 | int vsi_idx, veb_idx; |
| 10237 | int ret; |
| 10238 | |
| 10239 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10240 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10241 | (uplink_seid + vsi_seid != 0)) { |
| 10242 | dev_info(&pf->pdev->dev, |
| 10243 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10244 | uplink_seid, vsi_seid); |
| 10245 | return NULL; |
| 10246 | } |
| 10247 | |
| 10248 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10249 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10250 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10251 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10252 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10253 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10254 | vsi_seid); |
| 10255 | return NULL; |
| 10256 | } |
| 10257 | |
| 10258 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10259 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10260 | if (pf->veb[veb_idx] && |
| 10261 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10262 | uplink_veb = pf->veb[veb_idx]; |
| 10263 | break; |
| 10264 | } |
| 10265 | } |
| 10266 | if (!uplink_veb) { |
| 10267 | dev_info(&pf->pdev->dev, |
| 10268 | "uplink seid %d not found\n", uplink_seid); |
| 10269 | return NULL; |
| 10270 | } |
| 10271 | } |
| 10272 | |
| 10273 | /* get veb sw struct */ |
| 10274 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10275 | if (veb_idx < 0) |
| 10276 | goto err_alloc; |
| 10277 | veb = pf->veb[veb_idx]; |
| 10278 | veb->flags = flags; |
| 10279 | veb->uplink_seid = uplink_seid; |
| 10280 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10281 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10282 | |
| 10283 | /* create the VEB in the switch */ |
| 10284 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10285 | if (ret) |
| 10286 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10287 | if (vsi_idx == pf->lan_vsi) |
| 10288 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10289 | |
| 10290 | return veb; |
| 10291 | |
| 10292 | err_veb: |
| 10293 | i40e_veb_clear(veb); |
| 10294 | err_alloc: |
| 10295 | return NULL; |
| 10296 | } |
| 10297 | |
| 10298 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10299 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10300 | * @pf: board private structure |
| 10301 | * @ele: element we are building info from |
| 10302 | * @num_reported: total number of elements |
| 10303 | * @printconfig: should we print the contents |
| 10304 | * |
| 10305 | * helper function to assist in extracting a few useful SEID values. |
| 10306 | **/ |
| 10307 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10308 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10309 | u16 num_reported, bool printconfig) |
| 10310 | { |
| 10311 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10312 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10313 | u8 element_type = ele->element_type; |
| 10314 | u16 seid = le16_to_cpu(ele->seid); |
| 10315 | |
| 10316 | if (printconfig) |
| 10317 | dev_info(&pf->pdev->dev, |
| 10318 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10319 | element_type, seid, uplink_seid, downlink_seid); |
| 10320 | |
| 10321 | switch (element_type) { |
| 10322 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10323 | pf->mac_seid = seid; |
| 10324 | break; |
| 10325 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10326 | /* Main VEB? */ |
| 10327 | if (uplink_seid != pf->mac_seid) |
| 10328 | break; |
| 10329 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10330 | int v; |
| 10331 | |
| 10332 | /* find existing or else empty VEB */ |
| 10333 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10334 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10335 | pf->lan_veb = v; |
| 10336 | break; |
| 10337 | } |
| 10338 | } |
| 10339 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10340 | v = i40e_veb_mem_alloc(pf); |
| 10341 | if (v < 0) |
| 10342 | break; |
| 10343 | pf->lan_veb = v; |
| 10344 | } |
| 10345 | } |
| 10346 | |
| 10347 | pf->veb[pf->lan_veb]->seid = seid; |
| 10348 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10349 | pf->veb[pf->lan_veb]->pf = pf; |
| 10350 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10351 | break; |
| 10352 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10353 | if (num_reported != 1) |
| 10354 | break; |
| 10355 | /* This is immediately after a reset so we can assume this is |
| 10356 | * the PF's VSI |
| 10357 | */ |
| 10358 | pf->mac_seid = uplink_seid; |
| 10359 | pf->pf_seid = downlink_seid; |
| 10360 | pf->main_vsi_seid = seid; |
| 10361 | if (printconfig) |
| 10362 | dev_info(&pf->pdev->dev, |
| 10363 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10364 | pf->pf_seid, pf->main_vsi_seid); |
| 10365 | break; |
| 10366 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10367 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10368 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10369 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10370 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10371 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10372 | /* ignore these for now */ |
| 10373 | break; |
| 10374 | default: |
| 10375 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10376 | element_type, seid); |
| 10377 | break; |
| 10378 | } |
| 10379 | } |
| 10380 | |
| 10381 | /** |
| 10382 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10383 | * @pf: board private structure |
| 10384 | * @printconfig: should we print the contents |
| 10385 | * |
| 10386 | * Get the current switch configuration from the device and |
| 10387 | * extract a few useful SEID values. |
| 10388 | **/ |
| 10389 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10390 | { |
| 10391 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10392 | u16 next_seid = 0; |
| 10393 | int ret = 0; |
| 10394 | u8 *aq_buf; |
| 10395 | int i; |
| 10396 | |
| 10397 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10398 | if (!aq_buf) |
| 10399 | return -ENOMEM; |
| 10400 | |
| 10401 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10402 | do { |
| 10403 | u16 num_reported, num_total; |
| 10404 | |
| 10405 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10406 | I40E_AQ_LARGE_BUF, |
| 10407 | &next_seid, NULL); |
| 10408 | if (ret) { |
| 10409 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10410 | "get switch config failed err %s aq_err %s\n", |
| 10411 | i40e_stat_str(&pf->hw, ret), |
| 10412 | i40e_aq_str(&pf->hw, |
| 10413 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10414 | kfree(aq_buf); |
| 10415 | return -ENOENT; |
| 10416 | } |
| 10417 | |
| 10418 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10419 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10420 | |
| 10421 | if (printconfig) |
| 10422 | dev_info(&pf->pdev->dev, |
| 10423 | "header: %d reported %d total\n", |
| 10424 | num_reported, num_total); |
| 10425 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10426 | for (i = 0; i < num_reported; i++) { |
| 10427 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10428 | &sw_config->element[i]; |
| 10429 | |
| 10430 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10431 | printconfig); |
| 10432 | } |
| 10433 | } while (next_seid != 0); |
| 10434 | |
| 10435 | kfree(aq_buf); |
| 10436 | return ret; |
| 10437 | } |
| 10438 | |
| 10439 | /** |
| 10440 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10441 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10442 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10443 | * |
| 10444 | * Returns 0 on success, negative value on failure |
| 10445 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10446 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10447 | { |
| 10448 | int ret; |
| 10449 | |
| 10450 | /* find out what's out there already */ |
| 10451 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10452 | if (ret) { |
| 10453 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10454 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10455 | i40e_stat_str(&pf->hw, ret), |
| 10456 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10457 | return ret; |
| 10458 | } |
| 10459 | i40e_pf_reset_stats(pf); |
| 10460 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10461 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10462 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10463 | struct i40e_vsi *vsi = NULL; |
| 10464 | u16 uplink_seid; |
| 10465 | |
| 10466 | /* Set up the PF VSI associated with the PF's main VSI |
| 10467 | * that is already in the HW switch |
| 10468 | */ |
| 10469 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10470 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10471 | else |
| 10472 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10473 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10474 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10475 | else if (reinit) |
| 10476 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10477 | if (!vsi) { |
| 10478 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10479 | i40e_fdir_teardown(pf); |
| 10480 | return -EAGAIN; |
| 10481 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10482 | } else { |
| 10483 | /* force a reset of TC and queue layout configurations */ |
| 10484 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10485 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10486 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10487 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10488 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10489 | } |
| 10490 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 10491 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10492 | i40e_fdir_sb_setup(pf); |
| 10493 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10494 | /* Setup static PF queue filter control settings */ |
| 10495 | ret = i40e_setup_pf_filter_control(pf); |
| 10496 | if (ret) { |
| 10497 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 10498 | ret); |
| 10499 | /* Failure here should not stop continuing other steps */ |
| 10500 | } |
| 10501 | |
| 10502 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 10503 | * the hash |
| 10504 | */ |
| 10505 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 10506 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10507 | |
| 10508 | /* fill in link information and enable LSE reporting */ |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 10509 | i40e_update_link_info(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10510 | i40e_link_event(pf); |
| 10511 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10512 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10513 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 10514 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10515 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10516 | i40e_ptp_init(pf); |
| 10517 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10518 | return ret; |
| 10519 | } |
| 10520 | |
| 10521 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10522 | * i40e_determine_queue_usage - Work out queue distribution |
| 10523 | * @pf: board private structure |
| 10524 | **/ |
| 10525 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 10526 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10527 | int queues_left; |
| 10528 | |
| 10529 | pf->num_lan_qps = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10530 | #ifdef I40E_FCOE |
| 10531 | pf->num_fcoe_qps = 0; |
| 10532 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10533 | |
| 10534 | /* Find the max queues to be put into basic use. We'll always be |
| 10535 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 10536 | * big RSS set. |
| 10537 | */ |
| 10538 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 10539 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10540 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10541 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10542 | /* one qp for PF, no queues for anything else */ |
| 10543 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10544 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10545 | |
| 10546 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10547 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10548 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10549 | #ifdef I40E_FCOE |
| 10550 | I40E_FLAG_FCOE_ENABLED | |
| 10551 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10552 | I40E_FLAG_FD_SB_ENABLED | |
| 10553 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10554 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10555 | I40E_FLAG_SRIOV_ENABLED | |
| 10556 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10557 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 10558 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 10559 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10560 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10561 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10562 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10563 | queues_left -= pf->num_lan_qps; |
| 10564 | |
| 10565 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10566 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10567 | #ifdef I40E_FCOE |
| 10568 | I40E_FLAG_FCOE_ENABLED | |
| 10569 | #endif |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10570 | I40E_FLAG_FD_SB_ENABLED | |
| 10571 | I40E_FLAG_FD_ATR_ENABLED | |
| 10572 | I40E_FLAG_DCB_ENABLED | |
| 10573 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10574 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10575 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10576 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10577 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10578 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10579 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 10580 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 10581 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 10582 | num_online_cpus()); |
| 10583 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 10584 | pf->hw.func_caps.num_tx_qp); |
| 10585 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10586 | queues_left -= pf->num_lan_qps; |
| 10587 | } |
| 10588 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10589 | #ifdef I40E_FCOE |
| 10590 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 10591 | if (I40E_DEFAULT_FCOE <= queues_left) { |
| 10592 | pf->num_fcoe_qps = I40E_DEFAULT_FCOE; |
| 10593 | } else if (I40E_MINIMUM_FCOE <= queues_left) { |
| 10594 | pf->num_fcoe_qps = I40E_MINIMUM_FCOE; |
| 10595 | } else { |
| 10596 | pf->num_fcoe_qps = 0; |
| 10597 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 10598 | dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n"); |
| 10599 | } |
| 10600 | |
| 10601 | queues_left -= pf->num_fcoe_qps; |
| 10602 | } |
| 10603 | |
| 10604 | #endif |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10605 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10606 | if (queues_left > 1) { |
| 10607 | queues_left -= 1; /* save 1 queue for FD */ |
| 10608 | } else { |
| 10609 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 10610 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 10611 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10612 | } |
| 10613 | |
| 10614 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10615 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10616 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 10617 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10618 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 10619 | } |
| 10620 | |
| 10621 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 10622 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 10623 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 10624 | (queues_left / pf->num_vmdq_qps)); |
| 10625 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 10626 | } |
| 10627 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10628 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10629 | dev_dbg(&pf->pdev->dev, |
| 10630 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 10631 | pf->hw.func_caps.num_tx_qp, |
| 10632 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10633 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 10634 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 10635 | queues_left); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10636 | #ifdef I40E_FCOE |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10637 | 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] | 10638 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10639 | } |
| 10640 | |
| 10641 | /** |
| 10642 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 10643 | * @pf: PF to be setup |
| 10644 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10645 | * 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] | 10646 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 10647 | * based filter sizes required for them. It also enables Flow director, |
| 10648 | * ethertype and macvlan type filter settings for the pf. |
| 10649 | * |
| 10650 | * Returns 0 on success, negative on failure |
| 10651 | **/ |
| 10652 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 10653 | { |
| 10654 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 10655 | |
| 10656 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 10657 | |
| 10658 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10659 | 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] | 10660 | settings->enable_fdir = true; |
| 10661 | |
| 10662 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 10663 | settings->enable_ethtype = true; |
| 10664 | settings->enable_macvlan = true; |
| 10665 | |
| 10666 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 10667 | return -ENOENT; |
| 10668 | |
| 10669 | return 0; |
| 10670 | } |
| 10671 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10672 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10673 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10674 | static void i40e_print_features(struct i40e_pf *pf) |
| 10675 | { |
| 10676 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10677 | char *buf; |
| 10678 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10679 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10680 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 10681 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10682 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10683 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10684 | 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] | 10685 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10686 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10687 | #endif |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10688 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d RX: %s", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10689 | pf->hw.func_caps.num_vsis, |
| 10690 | pf->vsi[pf->lan_vsi]->num_queue_pairs, |
| 10691 | pf->flags & I40E_FLAG_RX_PS_ENABLED ? "PS" : "1BUF"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10692 | |
| 10693 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10694 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10695 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10696 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10697 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10698 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 10699 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10700 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10701 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10702 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Jesse Brandeburg | ce6fcb3 | 2015-08-28 17:55:59 -0400 | [diff] [blame] | 10703 | #if IS_ENABLED(CONFIG_VXLAN) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10704 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Jesse Brandeburg | ce6fcb3 | 2015-08-28 17:55:59 -0400 | [diff] [blame] | 10705 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10706 | #if IS_ENABLED(CONFIG_GENEVE) |
| 10707 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
| 10708 | #endif |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10709 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10710 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10711 | #ifdef I40E_FCOE |
| 10712 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10713 | i += snprintf(&buf[i], REMAIN(i), " FCOE"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10714 | #endif |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10715 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10716 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10717 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10718 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10719 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10720 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 10721 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10722 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10723 | } |
| 10724 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10725 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10726 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
| 10727 | * |
| 10728 | * @pdev: PCI device information struct |
| 10729 | * @pf: board private structure |
| 10730 | * |
| 10731 | * Look up the MAC address in Open Firmware on systems that support it, |
| 10732 | * and use IDPROM on SPARC if no OF address is found. On return, the |
| 10733 | * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value |
| 10734 | * has been selected. |
| 10735 | **/ |
| 10736 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 10737 | { |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10738 | pf->flags &= ~I40E_FLAG_PF_MAC; |
Sowmini Varadhan | ba94272 | 2016-01-12 19:32:31 -0800 | [diff] [blame] | 10739 | if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10740 | pf->flags |= I40E_FLAG_PF_MAC; |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10741 | } |
| 10742 | |
| 10743 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10744 | * i40e_probe - Device initialization routine |
| 10745 | * @pdev: PCI device information struct |
| 10746 | * @ent: entry in i40e_pci_tbl |
| 10747 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10748 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 10749 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10750 | * and a hardware reset occur. |
| 10751 | * |
| 10752 | * Returns 0 on success, negative on failure |
| 10753 | **/ |
| 10754 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 10755 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 10756 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10757 | struct i40e_pf *pf; |
| 10758 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10759 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10760 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10761 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 10762 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10763 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10764 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10765 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10766 | |
| 10767 | err = pci_enable_device_mem(pdev); |
| 10768 | if (err) |
| 10769 | return err; |
| 10770 | |
| 10771 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10772 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10773 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 10774 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10775 | if (err) { |
| 10776 | dev_err(&pdev->dev, |
| 10777 | "DMA configuration failed: 0x%x\n", err); |
| 10778 | goto err_dma; |
| 10779 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10780 | } |
| 10781 | |
| 10782 | /* set up pci connections */ |
| 10783 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 10784 | IORESOURCE_MEM), i40e_driver_name); |
| 10785 | if (err) { |
| 10786 | dev_info(&pdev->dev, |
| 10787 | "pci_request_selected_regions failed %d\n", err); |
| 10788 | goto err_pci_reg; |
| 10789 | } |
| 10790 | |
| 10791 | pci_enable_pcie_error_reporting(pdev); |
| 10792 | pci_set_master(pdev); |
| 10793 | |
| 10794 | /* Now that we have a PCI connection, we need to do the |
| 10795 | * low level device setup. This is primarily setting up |
| 10796 | * the Admin Queue structures and then querying for the |
| 10797 | * device's current profile information. |
| 10798 | */ |
| 10799 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 10800 | if (!pf) { |
| 10801 | err = -ENOMEM; |
| 10802 | goto err_pf_alloc; |
| 10803 | } |
| 10804 | pf->next_vsi = 0; |
| 10805 | pf->pdev = pdev; |
| 10806 | set_bit(__I40E_DOWN, &pf->state); |
| 10807 | |
| 10808 | hw = &pf->hw; |
| 10809 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10810 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10811 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 10812 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10813 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10814 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10815 | if (!hw->hw_addr) { |
| 10816 | err = -EIO; |
| 10817 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 10818 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10819 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10820 | goto err_ioremap; |
| 10821 | } |
| 10822 | hw->vendor_id = pdev->vendor; |
| 10823 | hw->device_id = pdev->device; |
| 10824 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 10825 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 10826 | hw->subsystem_device_id = pdev->subsystem_device; |
| 10827 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 10828 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10829 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10830 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 10831 | /* set up the locks for the AQ, do this only once in probe |
| 10832 | * and destroy them only once in remove |
| 10833 | */ |
| 10834 | mutex_init(&hw->aq.asq_mutex); |
| 10835 | mutex_init(&hw->aq.arq_mutex); |
| 10836 | |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 10837 | if (debug != -1) { |
| 10838 | pf->msg_enable = pf->hw.debug_mask; |
| 10839 | pf->msg_enable = debug; |
| 10840 | } |
| 10841 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10842 | /* do a special CORER for clearing PXE mode once at init */ |
| 10843 | if (hw->revision_id == 0 && |
| 10844 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 10845 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 10846 | i40e_flush(hw); |
| 10847 | msleep(200); |
| 10848 | pf->corer_count++; |
| 10849 | |
| 10850 | i40e_clear_pxe_mode(hw); |
| 10851 | } |
| 10852 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10853 | /* 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] | 10854 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10855 | err = i40e_pf_reset(hw); |
| 10856 | if (err) { |
| 10857 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 10858 | goto err_pf_reset; |
| 10859 | } |
| 10860 | pf->pfr_count++; |
| 10861 | |
| 10862 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 10863 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 10864 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10865 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10866 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10867 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 10868 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10869 | "%s-%s:misc", |
| 10870 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10871 | |
| 10872 | err = i40e_init_shared_code(hw); |
| 10873 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 10874 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 10875 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10876 | goto err_pf_reset; |
| 10877 | } |
| 10878 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10879 | /* set up a default setting for link flow control */ |
| 10880 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 10881 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10882 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 10883 | if (err) { |
| 10884 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 10885 | dev_info(&pdev->dev, |
| 10886 | "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"); |
| 10887 | else |
| 10888 | dev_info(&pdev->dev, |
| 10889 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 10890 | |
| 10891 | goto err_pf_reset; |
| 10892 | } |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10893 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10894 | /* provide nvm, fw, api versions */ |
| 10895 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 10896 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 10897 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 10898 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10899 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10900 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 10901 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10902 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10903 | "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"); |
| 10904 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 10905 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10906 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10907 | "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] | 10908 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 10909 | i40e_verify_eeprom(pf); |
| 10910 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 10911 | /* Rev 0 hardware was never productized */ |
| 10912 | if (hw->revision_id < 1) |
| 10913 | 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"); |
| 10914 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 10915 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10916 | err = i40e_get_capabilities(pf); |
| 10917 | if (err) |
| 10918 | goto err_adminq_setup; |
| 10919 | |
| 10920 | err = i40e_sw_init(pf); |
| 10921 | if (err) { |
| 10922 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 10923 | goto err_sw_init; |
| 10924 | } |
| 10925 | |
| 10926 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 10927 | hw->func_caps.num_rx_qp, |
| 10928 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 10929 | if (err) { |
| 10930 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 10931 | goto err_init_lan_hmc; |
| 10932 | } |
| 10933 | |
| 10934 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 10935 | if (err) { |
| 10936 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 10937 | err = -ENOENT; |
| 10938 | goto err_configure_lan_hmc; |
| 10939 | } |
| 10940 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10941 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 10942 | * Ignore error return codes because if it was already disabled via |
| 10943 | * hardware settings this will fail |
| 10944 | */ |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 10945 | if (pf->flags & I40E_FLAG_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10946 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 10947 | i40e_aq_stop_lldp(hw, true, NULL); |
| 10948 | } |
| 10949 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10950 | i40e_get_mac_addr(hw, hw->mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10951 | /* allow a platform config to override the HW addr */ |
| 10952 | i40e_get_platform_mac_addr(pdev, pf); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 10953 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10954 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 10955 | err = -EIO; |
| 10956 | goto err_mac_addr; |
| 10957 | } |
| 10958 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 10959 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10960 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 10961 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 10962 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10963 | #ifdef I40E_FCOE |
| 10964 | err = i40e_get_san_mac_addr(hw, hw->mac.san_addr); |
| 10965 | if (err) |
| 10966 | dev_info(&pdev->dev, |
| 10967 | "(non-fatal) SAN MAC retrieval failed: %d\n", err); |
| 10968 | if (!is_valid_ether_addr(hw->mac.san_addr)) { |
| 10969 | dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n", |
| 10970 | hw->mac.san_addr); |
| 10971 | ether_addr_copy(hw->mac.san_addr, hw->mac.addr); |
| 10972 | } |
| 10973 | dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr); |
| 10974 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10975 | |
| 10976 | pci_set_drvdata(pdev, pf); |
| 10977 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10978 | #ifdef CONFIG_I40E_DCB |
| 10979 | err = i40e_init_pf_dcb(pf); |
| 10980 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 10981 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10982 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 10983 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10984 | } |
| 10985 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10986 | |
| 10987 | /* set up periodic task facility */ |
| 10988 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 10989 | pf->service_timer_period = HZ; |
| 10990 | |
| 10991 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 10992 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 10993 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10994 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10995 | /* NVM bit on means WoL disabled for the port */ |
| 10996 | 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] | 10997 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10998 | pf->wol_en = false; |
| 10999 | else |
| 11000 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11001 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 11002 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11003 | /* set up the main switch operations */ |
| 11004 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 11005 | err = i40e_init_interrupt_scheme(pf); |
| 11006 | if (err) |
| 11007 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11008 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11009 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 11010 | * to us; HW supports far more and we share the remaining pool with |
| 11011 | * the other PFs. We allocate space for more than the guarantee with |
| 11012 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11013 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11014 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 11015 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 11016 | else |
| 11017 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 11018 | |
| 11019 | /* 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] | 11020 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 11021 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11022 | if (!pf->vsi) { |
| 11023 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11024 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11025 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11026 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 11027 | #ifdef CONFIG_PCI_IOV |
| 11028 | /* prep for VF support */ |
| 11029 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 11030 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11031 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 11032 | if (pci_num_vf(pdev)) |
| 11033 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 11034 | } |
| 11035 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11036 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11037 | if (err) { |
| 11038 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 11039 | goto err_vsis; |
| 11040 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11041 | |
| 11042 | /* Make sure flow control is set according to current settings */ |
| 11043 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 11044 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 11045 | dev_dbg(&pf->pdev->dev, |
| 11046 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 11047 | i40e_stat_str(hw, err), |
| 11048 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11049 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 11050 | dev_dbg(&pf->pdev->dev, |
| 11051 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 11052 | i40e_stat_str(hw, err), |
| 11053 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11054 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 11055 | dev_dbg(&pf->pdev->dev, |
| 11056 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 11057 | i40e_stat_str(hw, err), |
| 11058 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11059 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11060 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11061 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11062 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 11063 | i40e_vsi_open(pf->vsi[i]); |
| 11064 | break; |
| 11065 | } |
| 11066 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11067 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11068 | /* The driver only wants link up/down and module qualification |
| 11069 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11070 | */ |
| 11071 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11072 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
| 11073 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11074 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11075 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 11076 | i40e_stat_str(&pf->hw, err), |
| 11077 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11078 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11079 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 11080 | * of TSO, so that we avoid the MDD being fired and causing |
| 11081 | * a reset in the case of small MSS+TSO. |
| 11082 | */ |
| 11083 | val = rd32(hw, I40E_REG_MSS); |
| 11084 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 11085 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 11086 | val |= I40E_64BYTE_MSS; |
| 11087 | wr32(hw, I40E_REG_MSS, val); |
| 11088 | } |
| 11089 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 11090 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 11091 | msleep(75); |
| 11092 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 11093 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11094 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 11095 | i40e_stat_str(&pf->hw, err), |
| 11096 | i40e_aq_str(&pf->hw, |
| 11097 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 11098 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11099 | /* The main driver is (mostly) up and happy. We need to set this state |
| 11100 | * before setting up the misc vector or we get a race and the vector |
| 11101 | * ends up disabled forever. |
| 11102 | */ |
| 11103 | clear_bit(__I40E_DOWN, &pf->state); |
| 11104 | |
| 11105 | /* In case of MSIX we are going to setup the misc vector right here |
| 11106 | * to handle admin queue events etc. In case of legacy and MSI |
| 11107 | * the misc functionality and queue processing is combined in |
| 11108 | * the same vector and that gets setup at open. |
| 11109 | */ |
| 11110 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 11111 | err = i40e_setup_misc_vector(pf); |
| 11112 | if (err) { |
| 11113 | dev_info(&pdev->dev, |
| 11114 | "setup of misc vector failed: %d\n", err); |
| 11115 | goto err_vsis; |
| 11116 | } |
| 11117 | } |
| 11118 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11119 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11120 | /* prep for VF support */ |
| 11121 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11122 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11123 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11124 | /* disable link interrupts for VFs */ |
| 11125 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11126 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11127 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11128 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11129 | |
| 11130 | if (pci_num_vf(pdev)) { |
| 11131 | dev_info(&pdev->dev, |
| 11132 | "Active VFs found, allocating resources.\n"); |
| 11133 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11134 | if (err) |
| 11135 | dev_info(&pdev->dev, |
| 11136 | "Error %d allocating resources for existing VFs\n", |
| 11137 | err); |
| 11138 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11139 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11140 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11141 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11142 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11143 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11144 | pf->num_iwarp_msix, |
| 11145 | I40E_IWARP_IRQ_PILE_ID); |
| 11146 | if (pf->iwarp_base_vector < 0) { |
| 11147 | dev_info(&pdev->dev, |
| 11148 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 11149 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 11150 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 11151 | } |
| 11152 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11153 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11154 | i40e_dbg_pf_init(pf); |
| 11155 | |
| 11156 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11157 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11158 | |
| 11159 | /* since everything's happy, start the service_task timer */ |
| 11160 | mod_timer(&pf->service_timer, |
| 11161 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11162 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11163 | /* add this PF to client device list and launch a client service task */ |
| 11164 | err = i40e_lan_add_device(pf); |
| 11165 | if (err) |
| 11166 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 11167 | err); |
| 11168 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11169 | #ifdef I40E_FCOE |
| 11170 | /* create FCoE interface */ |
| 11171 | i40e_fcoe_vsi_setup(pf); |
| 11172 | |
| 11173 | #endif |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11174 | #define PCI_SPEED_SIZE 8 |
| 11175 | #define PCI_WIDTH_SIZE 8 |
| 11176 | /* Devices on the IOSF bus do not have this information |
| 11177 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11178 | * checking them. |
| 11179 | */ |
| 11180 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { |
| 11181 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11182 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11183 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11184 | /* Get the negotiated link width and speed from PCI config |
| 11185 | * space |
| 11186 | */ |
| 11187 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11188 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11189 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11190 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11191 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11192 | switch (hw->bus.speed) { |
| 11193 | case i40e_bus_speed_8000: |
| 11194 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11195 | case i40e_bus_speed_5000: |
| 11196 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11197 | case i40e_bus_speed_2500: |
| 11198 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11199 | default: |
| 11200 | break; |
| 11201 | } |
| 11202 | switch (hw->bus.width) { |
| 11203 | case i40e_bus_width_pcie_x8: |
| 11204 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11205 | case i40e_bus_width_pcie_x4: |
| 11206 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11207 | case i40e_bus_width_pcie_x2: |
| 11208 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11209 | case i40e_bus_width_pcie_x1: |
| 11210 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11211 | default: |
| 11212 | break; |
| 11213 | } |
| 11214 | |
| 11215 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11216 | speed, width); |
| 11217 | |
| 11218 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11219 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11220 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11221 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11222 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11223 | } |
| 11224 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11225 | /* get the requested speeds from the fw */ |
| 11226 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11227 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11228 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11229 | i40e_stat_str(&pf->hw, err), |
| 11230 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11231 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11232 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11233 | /* get the supported phy types from the fw */ |
| 11234 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11235 | if (err) |
| 11236 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11237 | i40e_stat_str(&pf->hw, err), |
| 11238 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 11239 | pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type); |
| 11240 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11241 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11242 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11243 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11244 | * PF/VF VSIs. |
| 11245 | * The FW can still send Flow control frames if enabled. |
| 11246 | */ |
| 11247 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11248 | pf->main_vsi_seid); |
| 11249 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 11250 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
| 11251 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
| 11252 | pf->flags |= I40E_FLAG_HAVE_10GBASET_PHY; |
| 11253 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11254 | /* print a string summarizing features */ |
| 11255 | i40e_print_features(pf); |
| 11256 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11257 | return 0; |
| 11258 | |
| 11259 | /* Unwind what we've done if something failed in the setup */ |
| 11260 | err_vsis: |
| 11261 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11262 | i40e_clear_interrupt_scheme(pf); |
| 11263 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11264 | err_switch_setup: |
| 11265 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11266 | del_timer_sync(&pf->service_timer); |
| 11267 | err_mac_addr: |
| 11268 | err_configure_lan_hmc: |
| 11269 | (void)i40e_shutdown_lan_hmc(hw); |
| 11270 | err_init_lan_hmc: |
| 11271 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11272 | err_sw_init: |
| 11273 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11274 | err_pf_reset: |
| 11275 | iounmap(hw->hw_addr); |
| 11276 | err_ioremap: |
| 11277 | kfree(pf); |
| 11278 | err_pf_alloc: |
| 11279 | pci_disable_pcie_error_reporting(pdev); |
| 11280 | pci_release_selected_regions(pdev, |
| 11281 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 11282 | err_pci_reg: |
| 11283 | err_dma: |
| 11284 | pci_disable_device(pdev); |
| 11285 | return err; |
| 11286 | } |
| 11287 | |
| 11288 | /** |
| 11289 | * i40e_remove - Device removal routine |
| 11290 | * @pdev: PCI device information struct |
| 11291 | * |
| 11292 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11293 | * that is should release a PCI device. This could be caused by a |
| 11294 | * Hot-Plug event, or because the driver is going to be removed from |
| 11295 | * memory. |
| 11296 | **/ |
| 11297 | static void i40e_remove(struct pci_dev *pdev) |
| 11298 | { |
| 11299 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11300 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11301 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11302 | int i; |
| 11303 | |
| 11304 | i40e_dbg_pf_exit(pf); |
| 11305 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11306 | i40e_ptp_stop(pf); |
| 11307 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11308 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 11309 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 11310 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11311 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11312 | /* no more scheduling of any task */ |
Pandi Kumar Maharajan | a4618ec | 2016-02-18 09:19:25 -0800 | [diff] [blame] | 11313 | set_bit(__I40E_SUSPENDED, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11314 | set_bit(__I40E_DOWN, &pf->state); |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 11315 | if (pf->service_timer.data) |
| 11316 | del_timer_sync(&pf->service_timer); |
| 11317 | if (pf->service_task.func) |
| 11318 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11319 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11320 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11321 | i40e_free_vfs(pf); |
| 11322 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11323 | } |
| 11324 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11325 | i40e_fdir_teardown(pf); |
| 11326 | |
| 11327 | /* If there is a switch structure or any orphans, remove them. |
| 11328 | * This will leave only the PF's VSI remaining. |
| 11329 | */ |
| 11330 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11331 | if (!pf->veb[i]) |
| 11332 | continue; |
| 11333 | |
| 11334 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11335 | pf->veb[i]->uplink_seid == 0) |
| 11336 | i40e_switch_branch_release(pf->veb[i]); |
| 11337 | } |
| 11338 | |
| 11339 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11340 | * adminq and hmc. |
| 11341 | */ |
| 11342 | if (pf->vsi[pf->lan_vsi]) |
| 11343 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11344 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11345 | /* remove attached clients */ |
| 11346 | ret_code = i40e_lan_del_device(pf); |
| 11347 | if (ret_code) { |
| 11348 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 11349 | ret_code); |
| 11350 | } |
| 11351 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11352 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11353 | if (hw->hmc.hmc_obj) { |
| 11354 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11355 | if (ret_code) |
| 11356 | dev_warn(&pdev->dev, |
| 11357 | "Failed to destroy the HMC resources: %d\n", |
| 11358 | ret_code); |
| 11359 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11360 | |
| 11361 | /* shutdown the adminq */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11362 | ret_code = i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11363 | if (ret_code) |
| 11364 | dev_warn(&pdev->dev, |
| 11365 | "Failed to destroy the Admin Queue resources: %d\n", |
| 11366 | ret_code); |
| 11367 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11368 | /* destroy the locks only once, here */ |
| 11369 | mutex_destroy(&hw->aq.arq_mutex); |
| 11370 | mutex_destroy(&hw->aq.asq_mutex); |
| 11371 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11372 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11373 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11374 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11375 | if (pf->vsi[i]) { |
| 11376 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11377 | i40e_vsi_clear(pf->vsi[i]); |
| 11378 | pf->vsi[i] = NULL; |
| 11379 | } |
| 11380 | } |
| 11381 | |
| 11382 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11383 | kfree(pf->veb[i]); |
| 11384 | pf->veb[i] = NULL; |
| 11385 | } |
| 11386 | |
| 11387 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11388 | kfree(pf->vsi); |
| 11389 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11390 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11391 | kfree(pf); |
| 11392 | pci_release_selected_regions(pdev, |
| 11393 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 11394 | |
| 11395 | pci_disable_pcie_error_reporting(pdev); |
| 11396 | pci_disable_device(pdev); |
| 11397 | } |
| 11398 | |
| 11399 | /** |
| 11400 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11401 | * @pdev: PCI device information struct |
| 11402 | * |
| 11403 | * Called to warn that something happened and the error handling steps |
| 11404 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11405 | * remediation. |
| 11406 | **/ |
| 11407 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11408 | enum pci_channel_state error) |
| 11409 | { |
| 11410 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11411 | |
| 11412 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11413 | |
| 11414 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11415 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11416 | rtnl_lock(); |
| 11417 | i40e_prep_for_reset(pf); |
| 11418 | rtnl_unlock(); |
| 11419 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11420 | |
| 11421 | /* Request a slot reset */ |
| 11422 | return PCI_ERS_RESULT_NEED_RESET; |
| 11423 | } |
| 11424 | |
| 11425 | /** |
| 11426 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11427 | * @pdev: PCI device information struct |
| 11428 | * |
| 11429 | * Called to find if the driver can work with the device now that |
| 11430 | * the pci slot has been reset. If a basic connection seems good |
| 11431 | * (registers are readable and have sane content) then return a |
| 11432 | * happy little PCI_ERS_RESULT_xxx. |
| 11433 | **/ |
| 11434 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11435 | { |
| 11436 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11437 | pci_ers_result_t result; |
| 11438 | int err; |
| 11439 | u32 reg; |
| 11440 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11441 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11442 | if (pci_enable_device_mem(pdev)) { |
| 11443 | dev_info(&pdev->dev, |
| 11444 | "Cannot re-enable PCI device after reset.\n"); |
| 11445 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11446 | } else { |
| 11447 | pci_set_master(pdev); |
| 11448 | pci_restore_state(pdev); |
| 11449 | pci_save_state(pdev); |
| 11450 | pci_wake_from_d3(pdev, false); |
| 11451 | |
| 11452 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11453 | if (reg == 0) |
| 11454 | result = PCI_ERS_RESULT_RECOVERED; |
| 11455 | else |
| 11456 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11457 | } |
| 11458 | |
| 11459 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11460 | if (err) { |
| 11461 | dev_info(&pdev->dev, |
| 11462 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11463 | err); |
| 11464 | /* non-fatal, continue */ |
| 11465 | } |
| 11466 | |
| 11467 | return result; |
| 11468 | } |
| 11469 | |
| 11470 | /** |
| 11471 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11472 | * @pdev: PCI device information struct |
| 11473 | * |
| 11474 | * Called to allow the driver to bring things back up after PCI error |
| 11475 | * and/or reset recovery has finished. |
| 11476 | **/ |
| 11477 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11478 | { |
| 11479 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11480 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11481 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11482 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 11483 | return; |
| 11484 | |
| 11485 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11486 | i40e_handle_reset_warning(pf); |
Vasily Averin | 4c4935a | 2015-07-08 15:04:26 +0300 | [diff] [blame] | 11487 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11488 | } |
| 11489 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11490 | /** |
| 11491 | * i40e_shutdown - PCI callback for shutting down |
| 11492 | * @pdev: PCI device information struct |
| 11493 | **/ |
| 11494 | static void i40e_shutdown(struct pci_dev *pdev) |
| 11495 | { |
| 11496 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11497 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11498 | |
| 11499 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11500 | set_bit(__I40E_DOWN, &pf->state); |
| 11501 | rtnl_lock(); |
| 11502 | i40e_prep_for_reset(pf); |
| 11503 | rtnl_unlock(); |
| 11504 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11505 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11506 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11507 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11508 | del_timer_sync(&pf->service_timer); |
| 11509 | cancel_work_sync(&pf->service_task); |
| 11510 | i40e_fdir_teardown(pf); |
| 11511 | |
| 11512 | rtnl_lock(); |
| 11513 | i40e_prep_for_reset(pf); |
| 11514 | rtnl_unlock(); |
| 11515 | |
| 11516 | wr32(hw, I40E_PFPM_APM, |
| 11517 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11518 | wr32(hw, I40E_PFPM_WUFC, |
| 11519 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11520 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 11521 | i40e_clear_interrupt_scheme(pf); |
| 11522 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11523 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11524 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11525 | pci_set_power_state(pdev, PCI_D3hot); |
| 11526 | } |
| 11527 | } |
| 11528 | |
| 11529 | #ifdef CONFIG_PM |
| 11530 | /** |
| 11531 | * i40e_suspend - PCI callback for moving to D3 |
| 11532 | * @pdev: PCI device information struct |
| 11533 | **/ |
| 11534 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11535 | { |
| 11536 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11537 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11538 | |
| 11539 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11540 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 11541 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11542 | rtnl_lock(); |
| 11543 | i40e_prep_for_reset(pf); |
| 11544 | rtnl_unlock(); |
| 11545 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11546 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11547 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11548 | |
| 11549 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11550 | pci_set_power_state(pdev, PCI_D3hot); |
| 11551 | |
| 11552 | return 0; |
| 11553 | } |
| 11554 | |
| 11555 | /** |
| 11556 | * i40e_resume - PCI callback for waking up from D3 |
| 11557 | * @pdev: PCI device information struct |
| 11558 | **/ |
| 11559 | static int i40e_resume(struct pci_dev *pdev) |
| 11560 | { |
| 11561 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11562 | u32 err; |
| 11563 | |
| 11564 | pci_set_power_state(pdev, PCI_D0); |
| 11565 | pci_restore_state(pdev); |
| 11566 | /* pci_restore_state() clears dev->state_saves, so |
| 11567 | * call pci_save_state() again to restore it. |
| 11568 | */ |
| 11569 | pci_save_state(pdev); |
| 11570 | |
| 11571 | err = pci_enable_device_mem(pdev); |
| 11572 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11573 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11574 | return err; |
| 11575 | } |
| 11576 | pci_set_master(pdev); |
| 11577 | |
| 11578 | /* no wakeup events while running */ |
| 11579 | pci_wake_from_d3(pdev, false); |
| 11580 | |
| 11581 | /* handling the reset will rebuild the device state */ |
| 11582 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11583 | clear_bit(__I40E_DOWN, &pf->state); |
| 11584 | rtnl_lock(); |
| 11585 | i40e_reset_and_rebuild(pf, false); |
| 11586 | rtnl_unlock(); |
| 11587 | } |
| 11588 | |
| 11589 | return 0; |
| 11590 | } |
| 11591 | |
| 11592 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11593 | static const struct pci_error_handlers i40e_err_handler = { |
| 11594 | .error_detected = i40e_pci_error_detected, |
| 11595 | .slot_reset = i40e_pci_error_slot_reset, |
| 11596 | .resume = i40e_pci_error_resume, |
| 11597 | }; |
| 11598 | |
| 11599 | static struct pci_driver i40e_driver = { |
| 11600 | .name = i40e_driver_name, |
| 11601 | .id_table = i40e_pci_tbl, |
| 11602 | .probe = i40e_probe, |
| 11603 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11604 | #ifdef CONFIG_PM |
| 11605 | .suspend = i40e_suspend, |
| 11606 | .resume = i40e_resume, |
| 11607 | #endif |
| 11608 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11609 | .err_handler = &i40e_err_handler, |
| 11610 | .sriov_configure = i40e_pci_sriov_configure, |
| 11611 | }; |
| 11612 | |
| 11613 | /** |
| 11614 | * i40e_init_module - Driver registration routine |
| 11615 | * |
| 11616 | * i40e_init_module is the first routine called when the driver is |
| 11617 | * loaded. All it does is register with the PCI subsystem. |
| 11618 | **/ |
| 11619 | static int __init i40e_init_module(void) |
| 11620 | { |
| 11621 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 11622 | i40e_driver_string, i40e_driver_version_str); |
| 11623 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 11624 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11625 | /* we will see if single thread per module is enough for now, |
| 11626 | * it can't be any worse than using the system workqueue which |
| 11627 | * was already single threaded |
| 11628 | */ |
| 11629 | i40e_wq = create_singlethread_workqueue(i40e_driver_name); |
| 11630 | if (!i40e_wq) { |
| 11631 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 11632 | return -ENOMEM; |
| 11633 | } |
| 11634 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11635 | i40e_dbg_init(); |
| 11636 | return pci_register_driver(&i40e_driver); |
| 11637 | } |
| 11638 | module_init(i40e_init_module); |
| 11639 | |
| 11640 | /** |
| 11641 | * i40e_exit_module - Driver exit cleanup routine |
| 11642 | * |
| 11643 | * i40e_exit_module is called just before the driver is removed |
| 11644 | * from memory. |
| 11645 | **/ |
| 11646 | static void __exit i40e_exit_module(void) |
| 11647 | { |
| 11648 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11649 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11650 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11651 | } |
| 11652 | module_exit(i40e_exit_module); |