Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2016 Intel Corporation. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 27 | #include <linux/etherdevice.h> |
| 28 | #include <linux/of_net.h> |
| 29 | #include <linux/pci.h> |
| 30 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 31 | /* Local includes */ |
| 32 | #include "i40e.h" |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 33 | #include "i40e_diag.h" |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 34 | #include <net/udp_tunnel.h> |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 35 | |
| 36 | const char i40e_driver_name[] = "i40e"; |
| 37 | static const char i40e_driver_string[] = |
| 38 | "Intel(R) Ethernet Connection XL710 Network Driver"; |
| 39 | |
| 40 | #define DRV_KERN "-k" |
| 41 | |
Catherine Sullivan | e8e724d | 2014-07-10 07:58:26 +0000 | [diff] [blame] | 42 | #define DRV_VERSION_MAJOR 1 |
Bimmy Pujari | 0706195 | 2016-05-16 10:26:45 -0700 | [diff] [blame] | 43 | #define DRV_VERSION_MINOR 6 |
Bimmy Pujari | 4adbb64 | 2016-09-14 16:24:39 -0700 | [diff] [blame] | 44 | #define DRV_VERSION_BUILD 19 |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 45 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 46 | __stringify(DRV_VERSION_MINOR) "." \ |
| 47 | __stringify(DRV_VERSION_BUILD) DRV_KERN |
| 48 | const char i40e_driver_version_str[] = DRV_VERSION; |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 49 | static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation."; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 50 | |
| 51 | /* a bit of forward declarations */ |
| 52 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); |
| 53 | static void i40e_handle_reset_warning(struct i40e_pf *pf); |
| 54 | static int i40e_add_vsi(struct i40e_vsi *vsi); |
| 55 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 56 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 57 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
| 58 | static void i40e_determine_queue_usage(struct i40e_pf *pf); |
| 59 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 60 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 61 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 62 | |
| 63 | /* i40e_pci_tbl - PCI Device ID Table |
| 64 | * |
| 65 | * Last entry must be all 0s |
| 66 | * |
| 67 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 68 | * Class, Class Mask, private data (not used) } |
| 69 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 70 | static const struct pci_device_id i40e_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 71 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 72 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 73 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, |
| 74 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 75 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, |
| 76 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, |
| 77 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 78 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0}, |
Shannon Nelson | bc5166b9 | 2015-08-26 15:14:10 -0400 | [diff] [blame] | 79 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0}, |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 80 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
Anjali Singhai Jain | 35dae51 | 2015-12-22 14:25:03 -0800 | [diff] [blame] | 81 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0}, |
| 82 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame] | 83 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0}, |
| 84 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0}, |
| 85 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0}, |
Catherine Sullivan | d6bf58c | 2016-03-18 12:18:08 -0700 | [diff] [blame] | 86 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0}, |
Shannon Nelson | 48a3b51 | 2015-07-23 16:54:39 -0400 | [diff] [blame] | 87 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
| 88 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 89 | /* required last entry */ |
| 90 | {0, } |
| 91 | }; |
| 92 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 93 | |
| 94 | #define I40E_MAX_VF_COUNT 128 |
| 95 | static int debug = -1; |
| 96 | module_param(debug, int, 0); |
| 97 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 98 | |
| 99 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 100 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 101 | MODULE_LICENSE("GPL"); |
| 102 | MODULE_VERSION(DRV_VERSION); |
| 103 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 104 | static struct workqueue_struct *i40e_wq; |
| 105 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 106 | /** |
| 107 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 108 | * @hw: pointer to the HW structure |
| 109 | * @mem: ptr to mem struct to fill out |
| 110 | * @size: size of memory requested |
| 111 | * @alignment: what to align the allocation to |
| 112 | **/ |
| 113 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 114 | u64 size, u32 alignment) |
| 115 | { |
| 116 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 117 | |
| 118 | mem->size = ALIGN(size, alignment); |
| 119 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 120 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 121 | if (!mem->va) |
| 122 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 123 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 124 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /** |
| 128 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 129 | * @hw: pointer to the HW structure |
| 130 | * @mem: ptr to mem struct to free |
| 131 | **/ |
| 132 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 133 | { |
| 134 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 135 | |
| 136 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 137 | mem->va = NULL; |
| 138 | mem->pa = 0; |
| 139 | mem->size = 0; |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 146 | * @hw: pointer to the HW structure |
| 147 | * @mem: ptr to mem struct to fill out |
| 148 | * @size: size of memory requested |
| 149 | **/ |
| 150 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 151 | u32 size) |
| 152 | { |
| 153 | mem->size = size; |
| 154 | mem->va = kzalloc(size, GFP_KERNEL); |
| 155 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 156 | if (!mem->va) |
| 157 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 158 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 159 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /** |
| 163 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 164 | * @hw: pointer to the HW structure |
| 165 | * @mem: ptr to mem struct to free |
| 166 | **/ |
| 167 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 168 | { |
| 169 | /* it's ok to kfree a NULL pointer */ |
| 170 | kfree(mem->va); |
| 171 | mem->va = NULL; |
| 172 | mem->size = 0; |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * i40e_get_lump - find a lump of free generic resource |
| 179 | * @pf: board private structure |
| 180 | * @pile: the pile of resource to search |
| 181 | * @needed: the number of items needed |
| 182 | * @id: an owner id to stick on the items assigned |
| 183 | * |
| 184 | * Returns the base item index of the lump, or negative for error |
| 185 | * |
| 186 | * The search_hint trick and lack of advanced fit-finding only work |
| 187 | * because we're highly likely to have all the same size lump requests. |
| 188 | * Linear search time and any fragmentation should be minimal. |
| 189 | **/ |
| 190 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 191 | u16 needed, u16 id) |
| 192 | { |
| 193 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 194 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 195 | |
| 196 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 197 | dev_info(&pf->pdev->dev, |
| 198 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 199 | pile, needed, id); |
| 200 | return -EINVAL; |
| 201 | } |
| 202 | |
| 203 | /* start the linear search with an imperfect hint */ |
| 204 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 205 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 206 | /* skip already allocated entries */ |
| 207 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 208 | i++; |
| 209 | continue; |
| 210 | } |
| 211 | |
| 212 | /* do we have enough in this lump? */ |
| 213 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 214 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 215 | break; |
| 216 | } |
| 217 | |
| 218 | if (j == needed) { |
| 219 | /* there was enough, so assign it to the requestor */ |
| 220 | for (j = 0; j < needed; j++) |
| 221 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 222 | ret = i; |
| 223 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 224 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 225 | } |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 226 | |
| 227 | /* not enough, so skip over it and continue looking */ |
| 228 | i += j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | return ret; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * i40e_put_lump - return a lump of generic resource |
| 236 | * @pile: the pile of resource to search |
| 237 | * @index: the base item index |
| 238 | * @id: the owner id of the items assigned |
| 239 | * |
| 240 | * Returns the count of items in the lump |
| 241 | **/ |
| 242 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 243 | { |
| 244 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 245 | int count = 0; |
| 246 | int i; |
| 247 | |
| 248 | if (!pile || index >= pile->num_entries) |
| 249 | return -EINVAL; |
| 250 | |
| 251 | for (i = index; |
| 252 | i < pile->num_entries && pile->list[i] == valid_id; |
| 253 | i++) { |
| 254 | pile->list[i] = 0; |
| 255 | count++; |
| 256 | } |
| 257 | |
| 258 | if (count && index < pile->search_hint) |
| 259 | pile->search_hint = index; |
| 260 | |
| 261 | return count; |
| 262 | } |
| 263 | |
| 264 | /** |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 265 | * i40e_find_vsi_from_id - searches for the vsi with the given id |
| 266 | * @pf - the pf structure to search for the vsi |
| 267 | * @id - id of the vsi it is searching for |
| 268 | **/ |
| 269 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) |
| 270 | { |
| 271 | int i; |
| 272 | |
| 273 | for (i = 0; i < pf->num_alloc_vsi; i++) |
| 274 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) |
| 275 | return pf->vsi[i]; |
| 276 | |
| 277 | return NULL; |
| 278 | } |
| 279 | |
| 280 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 281 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 282 | * @pf: board private structure |
| 283 | * |
| 284 | * If not already scheduled, this puts the task into the work queue |
| 285 | **/ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 286 | void i40e_service_event_schedule(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 287 | { |
| 288 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 289 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && |
| 290 | !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 291 | queue_work(i40e_wq, &pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /** |
| 295 | * i40e_tx_timeout - Respond to a Tx Hang |
| 296 | * @netdev: network interface device structure |
| 297 | * |
| 298 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 299 | * device is munged, not just the one netdev port, so go for the full |
| 300 | * reset. |
| 301 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 302 | #ifdef I40E_FCOE |
| 303 | void i40e_tx_timeout(struct net_device *netdev) |
| 304 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 305 | static void i40e_tx_timeout(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 306 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 307 | { |
| 308 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 309 | struct i40e_vsi *vsi = np->vsi; |
| 310 | struct i40e_pf *pf = vsi->back; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 311 | struct i40e_ring *tx_ring = NULL; |
| 312 | unsigned int i, hung_queue = 0; |
| 313 | u32 head, val; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 314 | |
| 315 | pf->tx_timeout_count++; |
| 316 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 317 | /* find the stopped queue the same way the stack does */ |
| 318 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 319 | struct netdev_queue *q; |
| 320 | unsigned long trans_start; |
| 321 | |
| 322 | q = netdev_get_tx_queue(netdev, i); |
Florian Westphal | 9b36627 | 2016-05-03 16:33:14 +0200 | [diff] [blame] | 323 | trans_start = q->trans_start; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 324 | if (netif_xmit_stopped(q) && |
| 325 | time_after(jiffies, |
| 326 | (trans_start + netdev->watchdog_timeo))) { |
| 327 | hung_queue = i; |
| 328 | break; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | if (i == netdev->num_tx_queues) { |
| 333 | netdev_info(netdev, "tx_timeout: no netdev hung queue found\n"); |
| 334 | } else { |
| 335 | /* now that we have an index, find the tx_ring struct */ |
| 336 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 337 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 338 | if (hung_queue == |
| 339 | vsi->tx_rings[i]->queue_index) { |
| 340 | tx_ring = vsi->tx_rings[i]; |
| 341 | break; |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 347 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 348 | pf->tx_timeout_recovery_level = 1; /* reset after some time */ |
| 349 | else if (time_before(jiffies, |
| 350 | (pf->tx_timeout_last_recovery + netdev->watchdog_timeo))) |
| 351 | return; /* don't do any new action before the next timeout */ |
| 352 | |
| 353 | if (tx_ring) { |
| 354 | head = i40e_get_head(tx_ring); |
| 355 | /* Read interrupt register */ |
| 356 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 357 | val = rd32(&pf->hw, |
| 358 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 359 | tx_ring->vsi->base_vector - 1)); |
| 360 | else |
| 361 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 362 | |
| 363 | 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", |
| 364 | vsi->seid, hung_queue, tx_ring->next_to_clean, |
| 365 | head, tx_ring->next_to_use, |
| 366 | readl(tx_ring->tail), val); |
| 367 | } |
| 368 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 369 | pf->tx_timeout_last_recovery = jiffies; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 370 | netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n", |
| 371 | pf->tx_timeout_recovery_level, hung_queue); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 372 | |
| 373 | switch (pf->tx_timeout_recovery_level) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 374 | case 1: |
| 375 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 376 | break; |
| 377 | case 2: |
| 378 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 379 | break; |
| 380 | case 3: |
| 381 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 382 | break; |
| 383 | default: |
| 384 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 385 | break; |
| 386 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 387 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 388 | i40e_service_event_schedule(pf); |
| 389 | pf->tx_timeout_recovery_level++; |
| 390 | } |
| 391 | |
| 392 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 393 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 394 | * @vsi: the VSI we care about |
| 395 | * |
| 396 | * Returns the address of the device statistics structure. |
| 397 | * The statistics are actually updated from the service task. |
| 398 | **/ |
| 399 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 400 | { |
| 401 | return &vsi->net_stats; |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 406 | * @netdev: network interface device structure |
| 407 | * |
| 408 | * Returns the address of the device statistics structure. |
| 409 | * The statistics are actually updated from the service task. |
| 410 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 411 | #ifdef I40E_FCOE |
| 412 | struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 413 | struct net_device *netdev, |
| 414 | struct rtnl_link_stats64 *stats) |
| 415 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 416 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 417 | struct net_device *netdev, |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 418 | struct rtnl_link_stats64 *stats) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 419 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 420 | { |
| 421 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 422 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 423 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 424 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 425 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 426 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 427 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 428 | return stats; |
| 429 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 430 | if (!vsi->tx_rings) |
| 431 | return stats; |
| 432 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 433 | rcu_read_lock(); |
| 434 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 435 | u64 bytes, packets; |
| 436 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 437 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 438 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 439 | if (!tx_ring) |
| 440 | continue; |
| 441 | |
| 442 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 443 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 444 | packets = tx_ring->stats.packets; |
| 445 | bytes = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 446 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 447 | |
| 448 | stats->tx_packets += packets; |
| 449 | stats->tx_bytes += bytes; |
| 450 | rx_ring = &tx_ring[1]; |
| 451 | |
| 452 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 453 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 454 | packets = rx_ring->stats.packets; |
| 455 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 456 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 457 | |
| 458 | stats->rx_packets += packets; |
| 459 | stats->rx_bytes += bytes; |
| 460 | } |
| 461 | rcu_read_unlock(); |
| 462 | |
Akeem G Abodunrin | a5282f4 | 2014-05-10 04:49:03 +0000 | [diff] [blame] | 463 | /* following stats updated by i40e_watchdog_subtask() */ |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 464 | stats->multicast = vsi_stats->multicast; |
| 465 | stats->tx_errors = vsi_stats->tx_errors; |
| 466 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 467 | stats->rx_errors = vsi_stats->rx_errors; |
Jesse Brandeburg | d8201e2 | 2015-07-23 16:54:35 -0400 | [diff] [blame] | 468 | stats->rx_dropped = vsi_stats->rx_dropped; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 469 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 470 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
| 471 | |
| 472 | return stats; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /** |
| 476 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 477 | * @vsi: the VSI to have its stats reset |
| 478 | **/ |
| 479 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 480 | { |
| 481 | struct rtnl_link_stats64 *ns; |
| 482 | int i; |
| 483 | |
| 484 | if (!vsi) |
| 485 | return; |
| 486 | |
| 487 | ns = i40e_get_vsi_stats_struct(vsi); |
| 488 | memset(ns, 0, sizeof(*ns)); |
| 489 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 490 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 491 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 492 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 493 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 494 | memset(&vsi->rx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 495 | sizeof(vsi->rx_rings[i]->stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 496 | memset(&vsi->rx_rings[i]->rx_stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 497 | sizeof(vsi->rx_rings[i]->rx_stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 498 | memset(&vsi->tx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 499 | sizeof(vsi->tx_rings[i]->stats)); |
| 500 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 501 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 502 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 503 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 504 | vsi->stat_offsets_loaded = false; |
| 505 | } |
| 506 | |
| 507 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 508 | * 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] | 509 | * @pf: the PF to be reset |
| 510 | **/ |
| 511 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 512 | { |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 513 | int i; |
| 514 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 515 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 516 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 517 | pf->stat_offsets_loaded = false; |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 518 | |
| 519 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 520 | if (pf->veb[i]) { |
| 521 | memset(&pf->veb[i]->stats, 0, |
| 522 | sizeof(pf->veb[i]->stats)); |
| 523 | memset(&pf->veb[i]->stats_offsets, 0, |
| 524 | sizeof(pf->veb[i]->stats_offsets)); |
| 525 | pf->veb[i]->stat_offsets_loaded = false; |
| 526 | } |
| 527 | } |
Catherine Sullivan | 42bce04 | 2016-07-27 12:02:32 -0700 | [diff] [blame] | 528 | pf->hw_csum_rx_error = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /** |
| 532 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 533 | * @hw: ptr to the hardware info |
| 534 | * @hireg: the high 32 bit reg to read |
| 535 | * @loreg: the low 32 bit reg to read |
| 536 | * @offset_loaded: has the initial offset been loaded yet |
| 537 | * @offset: ptr to current offset value |
| 538 | * @stat: ptr to the stat |
| 539 | * |
| 540 | * Since the device stats are not reset at PFReset, they likely will not |
| 541 | * be zeroed when the driver starts. We'll save the first values read |
| 542 | * and use them as offsets to be subtracted from the raw values in order |
| 543 | * to report stats that count from zero. In the process, we also manage |
| 544 | * the potential roll-over. |
| 545 | **/ |
| 546 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 547 | bool offset_loaded, u64 *offset, u64 *stat) |
| 548 | { |
| 549 | u64 new_data; |
| 550 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 551 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 552 | new_data = rd32(hw, loreg); |
| 553 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 554 | } else { |
| 555 | new_data = rd64(hw, loreg); |
| 556 | } |
| 557 | if (!offset_loaded) |
| 558 | *offset = new_data; |
| 559 | if (likely(new_data >= *offset)) |
| 560 | *stat = new_data - *offset; |
| 561 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 562 | *stat = (new_data + BIT_ULL(48)) - *offset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 563 | *stat &= 0xFFFFFFFFFFFFULL; |
| 564 | } |
| 565 | |
| 566 | /** |
| 567 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 568 | * @hw: ptr to the hardware info |
| 569 | * @reg: the hw reg to read |
| 570 | * @offset_loaded: has the initial offset been loaded yet |
| 571 | * @offset: ptr to current offset value |
| 572 | * @stat: ptr to the stat |
| 573 | **/ |
| 574 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 575 | bool offset_loaded, u64 *offset, u64 *stat) |
| 576 | { |
| 577 | u32 new_data; |
| 578 | |
| 579 | new_data = rd32(hw, reg); |
| 580 | if (!offset_loaded) |
| 581 | *offset = new_data; |
| 582 | if (likely(new_data >= *offset)) |
| 583 | *stat = (u32)(new_data - *offset); |
| 584 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 585 | *stat = (u32)((new_data + BIT_ULL(32)) - *offset); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /** |
| 589 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 590 | * @vsi: the VSI to be updated |
| 591 | **/ |
| 592 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 593 | { |
| 594 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 595 | struct i40e_pf *pf = vsi->back; |
| 596 | struct i40e_hw *hw = &pf->hw; |
| 597 | struct i40e_eth_stats *oes; |
| 598 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 599 | |
| 600 | es = &vsi->eth_stats; |
| 601 | oes = &vsi->eth_stats_offsets; |
| 602 | |
| 603 | /* Gather up the stats that the hw collects */ |
| 604 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 605 | vsi->stat_offsets_loaded, |
| 606 | &oes->tx_errors, &es->tx_errors); |
| 607 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 608 | vsi->stat_offsets_loaded, |
| 609 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 610 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 611 | vsi->stat_offsets_loaded, |
| 612 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 613 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 614 | vsi->stat_offsets_loaded, |
| 615 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 616 | |
| 617 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 618 | I40E_GLV_GORCL(stat_idx), |
| 619 | vsi->stat_offsets_loaded, |
| 620 | &oes->rx_bytes, &es->rx_bytes); |
| 621 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 622 | I40E_GLV_UPRCL(stat_idx), |
| 623 | vsi->stat_offsets_loaded, |
| 624 | &oes->rx_unicast, &es->rx_unicast); |
| 625 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 626 | I40E_GLV_MPRCL(stat_idx), |
| 627 | vsi->stat_offsets_loaded, |
| 628 | &oes->rx_multicast, &es->rx_multicast); |
| 629 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 630 | I40E_GLV_BPRCL(stat_idx), |
| 631 | vsi->stat_offsets_loaded, |
| 632 | &oes->rx_broadcast, &es->rx_broadcast); |
| 633 | |
| 634 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 635 | I40E_GLV_GOTCL(stat_idx), |
| 636 | vsi->stat_offsets_loaded, |
| 637 | &oes->tx_bytes, &es->tx_bytes); |
| 638 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 639 | I40E_GLV_UPTCL(stat_idx), |
| 640 | vsi->stat_offsets_loaded, |
| 641 | &oes->tx_unicast, &es->tx_unicast); |
| 642 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 643 | I40E_GLV_MPTCL(stat_idx), |
| 644 | vsi->stat_offsets_loaded, |
| 645 | &oes->tx_multicast, &es->tx_multicast); |
| 646 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 647 | I40E_GLV_BPTCL(stat_idx), |
| 648 | vsi->stat_offsets_loaded, |
| 649 | &oes->tx_broadcast, &es->tx_broadcast); |
| 650 | vsi->stat_offsets_loaded = true; |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * i40e_update_veb_stats - Update Switch component statistics |
| 655 | * @veb: the VEB being updated |
| 656 | **/ |
| 657 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 658 | { |
| 659 | struct i40e_pf *pf = veb->pf; |
| 660 | struct i40e_hw *hw = &pf->hw; |
| 661 | struct i40e_eth_stats *oes; |
| 662 | struct i40e_eth_stats *es; /* device's eth stats */ |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 663 | struct i40e_veb_tc_stats *veb_oes; |
| 664 | struct i40e_veb_tc_stats *veb_es; |
| 665 | int i, idx = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 666 | |
| 667 | idx = veb->stats_idx; |
| 668 | es = &veb->stats; |
| 669 | oes = &veb->stats_offsets; |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 670 | veb_es = &veb->tc_stats; |
| 671 | veb_oes = &veb->tc_stats_offsets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 672 | |
| 673 | /* Gather up the stats that the hw collects */ |
| 674 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 675 | veb->stat_offsets_loaded, |
| 676 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 677 | if (hw->revision_id > 0) |
| 678 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 679 | veb->stat_offsets_loaded, |
| 680 | &oes->rx_unknown_protocol, |
| 681 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 682 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 683 | veb->stat_offsets_loaded, |
| 684 | &oes->rx_bytes, &es->rx_bytes); |
| 685 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 686 | veb->stat_offsets_loaded, |
| 687 | &oes->rx_unicast, &es->rx_unicast); |
| 688 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 689 | veb->stat_offsets_loaded, |
| 690 | &oes->rx_multicast, &es->rx_multicast); |
| 691 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 692 | veb->stat_offsets_loaded, |
| 693 | &oes->rx_broadcast, &es->rx_broadcast); |
| 694 | |
| 695 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 696 | veb->stat_offsets_loaded, |
| 697 | &oes->tx_bytes, &es->tx_bytes); |
| 698 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 699 | veb->stat_offsets_loaded, |
| 700 | &oes->tx_unicast, &es->tx_unicast); |
| 701 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 702 | veb->stat_offsets_loaded, |
| 703 | &oes->tx_multicast, &es->tx_multicast); |
| 704 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 705 | veb->stat_offsets_loaded, |
| 706 | &oes->tx_broadcast, &es->tx_broadcast); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 707 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 708 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), |
| 709 | I40E_GLVEBTC_RPCL(i, idx), |
| 710 | veb->stat_offsets_loaded, |
| 711 | &veb_oes->tc_rx_packets[i], |
| 712 | &veb_es->tc_rx_packets[i]); |
| 713 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), |
| 714 | I40E_GLVEBTC_RBCL(i, idx), |
| 715 | veb->stat_offsets_loaded, |
| 716 | &veb_oes->tc_rx_bytes[i], |
| 717 | &veb_es->tc_rx_bytes[i]); |
| 718 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), |
| 719 | I40E_GLVEBTC_TPCL(i, idx), |
| 720 | veb->stat_offsets_loaded, |
| 721 | &veb_oes->tc_tx_packets[i], |
| 722 | &veb_es->tc_tx_packets[i]); |
| 723 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), |
| 724 | I40E_GLVEBTC_TBCL(i, idx), |
| 725 | veb->stat_offsets_loaded, |
| 726 | &veb_oes->tc_tx_bytes[i], |
| 727 | &veb_es->tc_tx_bytes[i]); |
| 728 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 729 | veb->stat_offsets_loaded = true; |
| 730 | } |
| 731 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 732 | #ifdef I40E_FCOE |
| 733 | /** |
| 734 | * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters. |
| 735 | * @vsi: the VSI that is capable of doing FCoE |
| 736 | **/ |
| 737 | static void i40e_update_fcoe_stats(struct i40e_vsi *vsi) |
| 738 | { |
| 739 | struct i40e_pf *pf = vsi->back; |
| 740 | struct i40e_hw *hw = &pf->hw; |
| 741 | struct i40e_fcoe_stats *ofs; |
| 742 | struct i40e_fcoe_stats *fs; /* device's eth stats */ |
| 743 | int idx; |
| 744 | |
| 745 | if (vsi->type != I40E_VSI_FCOE) |
| 746 | return; |
| 747 | |
Kiran Patil | 4147e2c | 2016-01-15 14:33:14 -0800 | [diff] [blame] | 748 | idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 749 | fs = &vsi->fcoe_stats; |
| 750 | ofs = &vsi->fcoe_stats_offsets; |
| 751 | |
| 752 | i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx), |
| 753 | vsi->fcoe_stat_offsets_loaded, |
| 754 | &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets); |
| 755 | i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx), |
| 756 | vsi->fcoe_stat_offsets_loaded, |
| 757 | &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords); |
| 758 | i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx), |
| 759 | vsi->fcoe_stat_offsets_loaded, |
| 760 | &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped); |
| 761 | i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx), |
| 762 | vsi->fcoe_stat_offsets_loaded, |
| 763 | &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets); |
| 764 | i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx), |
| 765 | vsi->fcoe_stat_offsets_loaded, |
| 766 | &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords); |
| 767 | i40e_stat_update32(hw, I40E_GL_FCOECRC(idx), |
| 768 | vsi->fcoe_stat_offsets_loaded, |
| 769 | &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc); |
| 770 | i40e_stat_update32(hw, I40E_GL_FCOELAST(idx), |
| 771 | vsi->fcoe_stat_offsets_loaded, |
| 772 | &ofs->fcoe_last_error, &fs->fcoe_last_error); |
| 773 | i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx), |
| 774 | vsi->fcoe_stat_offsets_loaded, |
| 775 | &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count); |
| 776 | |
| 777 | vsi->fcoe_stat_offsets_loaded = true; |
| 778 | } |
| 779 | |
| 780 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 781 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 782 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 783 | * @vsi: the VSI to be updated |
| 784 | * |
| 785 | * There are a few instances where we store the same stat in a |
| 786 | * couple of different structs. This is partly because we have |
| 787 | * the netdev stats that need to be filled out, which is slightly |
| 788 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 789 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 790 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 791 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 792 | { |
| 793 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 794 | struct rtnl_link_stats64 *ons; |
| 795 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 796 | struct i40e_eth_stats *oes; |
| 797 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 798 | u32 tx_restart, tx_busy; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 799 | u64 tx_lost_interrupt; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 800 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 801 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 802 | u64 bytes, packets; |
| 803 | unsigned int start; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 804 | u64 tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 805 | u64 tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 806 | u64 rx_p, rx_b; |
| 807 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 808 | u16 q; |
| 809 | |
| 810 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 811 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 812 | return; |
| 813 | |
| 814 | ns = i40e_get_vsi_stats_struct(vsi); |
| 815 | ons = &vsi->net_stats_offsets; |
| 816 | es = &vsi->eth_stats; |
| 817 | oes = &vsi->eth_stats_offsets; |
| 818 | |
| 819 | /* Gather up the netdev and vsi stats that the driver collects |
| 820 | * on the fly during packet processing |
| 821 | */ |
| 822 | rx_b = rx_p = 0; |
| 823 | tx_b = tx_p = 0; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 824 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 825 | tx_lost_interrupt = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 826 | rx_page = 0; |
| 827 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 828 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 829 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 830 | /* locate Tx ring */ |
| 831 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 832 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 833 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 834 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 835 | packets = p->stats.packets; |
| 836 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 837 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 838 | tx_b += bytes; |
| 839 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 840 | tx_restart += p->tx_stats.restart_queue; |
| 841 | tx_busy += p->tx_stats.tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 842 | tx_linearize += p->tx_stats.tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 843 | tx_force_wb += p->tx_stats.tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 844 | tx_lost_interrupt += p->tx_stats.tx_lost_interrupt; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 845 | |
| 846 | /* Rx queue is part of the same block as Tx queue */ |
| 847 | p = &p[1]; |
| 848 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 849 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 850 | packets = p->stats.packets; |
| 851 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 852 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 853 | rx_b += bytes; |
| 854 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 855 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 856 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 857 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 858 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 859 | vsi->tx_restart = tx_restart; |
| 860 | vsi->tx_busy = tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 861 | vsi->tx_linearize = tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 862 | vsi->tx_force_wb = tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 863 | vsi->tx_lost_interrupt = tx_lost_interrupt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 864 | vsi->rx_page_failed = rx_page; |
| 865 | vsi->rx_buf_failed = rx_buf; |
| 866 | |
| 867 | ns->rx_packets = rx_p; |
| 868 | ns->rx_bytes = rx_b; |
| 869 | ns->tx_packets = tx_p; |
| 870 | ns->tx_bytes = tx_b; |
| 871 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 872 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 873 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 874 | ons->tx_errors = oes->tx_errors; |
| 875 | ns->tx_errors = es->tx_errors; |
| 876 | ons->multicast = oes->rx_multicast; |
| 877 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 878 | ons->rx_dropped = oes->rx_discards; |
| 879 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 880 | ons->tx_dropped = oes->tx_discards; |
| 881 | ns->tx_dropped = es->tx_discards; |
| 882 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 883 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 884 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 885 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 886 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 887 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 888 | } |
| 889 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 890 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 891 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 892 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 893 | * @pf: the PF to be updated |
| 894 | **/ |
| 895 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 896 | { |
| 897 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 898 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 899 | struct i40e_hw *hw = &pf->hw; |
| 900 | u32 val; |
| 901 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 902 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 903 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 904 | I40E_GLPRT_GORCL(hw->port), |
| 905 | pf->stat_offsets_loaded, |
| 906 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 907 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 908 | I40E_GLPRT_GOTCL(hw->port), |
| 909 | pf->stat_offsets_loaded, |
| 910 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 911 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 912 | pf->stat_offsets_loaded, |
| 913 | &osd->eth.rx_discards, |
| 914 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 915 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 916 | I40E_GLPRT_UPRCL(hw->port), |
| 917 | pf->stat_offsets_loaded, |
| 918 | &osd->eth.rx_unicast, |
| 919 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 920 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 921 | I40E_GLPRT_MPRCL(hw->port), |
| 922 | pf->stat_offsets_loaded, |
| 923 | &osd->eth.rx_multicast, |
| 924 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 925 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 926 | I40E_GLPRT_BPRCL(hw->port), |
| 927 | pf->stat_offsets_loaded, |
| 928 | &osd->eth.rx_broadcast, |
| 929 | &nsd->eth.rx_broadcast); |
| 930 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 931 | I40E_GLPRT_UPTCL(hw->port), |
| 932 | pf->stat_offsets_loaded, |
| 933 | &osd->eth.tx_unicast, |
| 934 | &nsd->eth.tx_unicast); |
| 935 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 936 | I40E_GLPRT_MPTCL(hw->port), |
| 937 | pf->stat_offsets_loaded, |
| 938 | &osd->eth.tx_multicast, |
| 939 | &nsd->eth.tx_multicast); |
| 940 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 941 | I40E_GLPRT_BPTCL(hw->port), |
| 942 | pf->stat_offsets_loaded, |
| 943 | &osd->eth.tx_broadcast, |
| 944 | &nsd->eth.tx_broadcast); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 945 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 946 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 947 | pf->stat_offsets_loaded, |
| 948 | &osd->tx_dropped_link_down, |
| 949 | &nsd->tx_dropped_link_down); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 950 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 951 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 952 | pf->stat_offsets_loaded, |
| 953 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 954 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 955 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 956 | pf->stat_offsets_loaded, |
| 957 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 958 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 959 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 960 | pf->stat_offsets_loaded, |
| 961 | &osd->mac_local_faults, |
| 962 | &nsd->mac_local_faults); |
| 963 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 964 | pf->stat_offsets_loaded, |
| 965 | &osd->mac_remote_faults, |
| 966 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 967 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 968 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 969 | pf->stat_offsets_loaded, |
| 970 | &osd->rx_length_errors, |
| 971 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 972 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 973 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 974 | pf->stat_offsets_loaded, |
| 975 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 976 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 977 | pf->stat_offsets_loaded, |
| 978 | &osd->link_xon_tx, &nsd->link_xon_tx); |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 979 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 980 | pf->stat_offsets_loaded, |
| 981 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 982 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 983 | pf->stat_offsets_loaded, |
| 984 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 985 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 986 | for (i = 0; i < 8; i++) { |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 987 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 988 | pf->stat_offsets_loaded, |
| 989 | &osd->priority_xoff_rx[i], |
| 990 | &nsd->priority_xoff_rx[i]); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 991 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 992 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 993 | &osd->priority_xon_rx[i], |
| 994 | &nsd->priority_xon_rx[i]); |
| 995 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 996 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 997 | &osd->priority_xon_tx[i], |
| 998 | &nsd->priority_xon_tx[i]); |
| 999 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1000 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1001 | &osd->priority_xoff_tx[i], |
| 1002 | &nsd->priority_xoff_tx[i]); |
| 1003 | i40e_stat_update32(hw, |
| 1004 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1005 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1006 | &osd->priority_xon_2_xoff[i], |
| 1007 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1010 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 1011 | I40E_GLPRT_PRC64L(hw->port), |
| 1012 | pf->stat_offsets_loaded, |
| 1013 | &osd->rx_size_64, &nsd->rx_size_64); |
| 1014 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 1015 | I40E_GLPRT_PRC127L(hw->port), |
| 1016 | pf->stat_offsets_loaded, |
| 1017 | &osd->rx_size_127, &nsd->rx_size_127); |
| 1018 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 1019 | I40E_GLPRT_PRC255L(hw->port), |
| 1020 | pf->stat_offsets_loaded, |
| 1021 | &osd->rx_size_255, &nsd->rx_size_255); |
| 1022 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 1023 | I40E_GLPRT_PRC511L(hw->port), |
| 1024 | pf->stat_offsets_loaded, |
| 1025 | &osd->rx_size_511, &nsd->rx_size_511); |
| 1026 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 1027 | I40E_GLPRT_PRC1023L(hw->port), |
| 1028 | pf->stat_offsets_loaded, |
| 1029 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 1030 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 1031 | I40E_GLPRT_PRC1522L(hw->port), |
| 1032 | pf->stat_offsets_loaded, |
| 1033 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 1034 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 1035 | I40E_GLPRT_PRC9522L(hw->port), |
| 1036 | pf->stat_offsets_loaded, |
| 1037 | &osd->rx_size_big, &nsd->rx_size_big); |
| 1038 | |
| 1039 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 1040 | I40E_GLPRT_PTC64L(hw->port), |
| 1041 | pf->stat_offsets_loaded, |
| 1042 | &osd->tx_size_64, &nsd->tx_size_64); |
| 1043 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 1044 | I40E_GLPRT_PTC127L(hw->port), |
| 1045 | pf->stat_offsets_loaded, |
| 1046 | &osd->tx_size_127, &nsd->tx_size_127); |
| 1047 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 1048 | I40E_GLPRT_PTC255L(hw->port), |
| 1049 | pf->stat_offsets_loaded, |
| 1050 | &osd->tx_size_255, &nsd->tx_size_255); |
| 1051 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 1052 | I40E_GLPRT_PTC511L(hw->port), |
| 1053 | pf->stat_offsets_loaded, |
| 1054 | &osd->tx_size_511, &nsd->tx_size_511); |
| 1055 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 1056 | I40E_GLPRT_PTC1023L(hw->port), |
| 1057 | pf->stat_offsets_loaded, |
| 1058 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 1059 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 1060 | I40E_GLPRT_PTC1522L(hw->port), |
| 1061 | pf->stat_offsets_loaded, |
| 1062 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1063 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1064 | I40E_GLPRT_PTC9522L(hw->port), |
| 1065 | pf->stat_offsets_loaded, |
| 1066 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1067 | |
| 1068 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1069 | pf->stat_offsets_loaded, |
| 1070 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1071 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1072 | pf->stat_offsets_loaded, |
| 1073 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1074 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1075 | pf->stat_offsets_loaded, |
| 1076 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1077 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1078 | pf->stat_offsets_loaded, |
| 1079 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1080 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1081 | /* FDIR stats */ |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1082 | i40e_stat_update32(hw, |
| 1083 | 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] | 1084 | pf->stat_offsets_loaded, |
| 1085 | &osd->fd_atr_match, &nsd->fd_atr_match); |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1086 | i40e_stat_update32(hw, |
| 1087 | 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] | 1088 | pf->stat_offsets_loaded, |
| 1089 | &osd->fd_sb_match, &nsd->fd_sb_match); |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 1090 | i40e_stat_update32(hw, |
| 1091 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), |
| 1092 | pf->stat_offsets_loaded, |
| 1093 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1094 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1095 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1096 | nsd->tx_lpi_status = |
| 1097 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1098 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1099 | nsd->rx_lpi_status = |
| 1100 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1101 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1102 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1103 | pf->stat_offsets_loaded, |
| 1104 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1105 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1106 | pf->stat_offsets_loaded, |
| 1107 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1108 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1109 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
| 1110 | !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) |
| 1111 | nsd->fd_sb_status = true; |
| 1112 | else |
| 1113 | nsd->fd_sb_status = false; |
| 1114 | |
| 1115 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
| 1116 | !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 1117 | nsd->fd_atr_status = true; |
| 1118 | else |
| 1119 | nsd->fd_atr_status = false; |
| 1120 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1121 | pf->stat_offsets_loaded = true; |
| 1122 | } |
| 1123 | |
| 1124 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1125 | * i40e_update_stats - Update the various statistics counters. |
| 1126 | * @vsi: the VSI to be updated |
| 1127 | * |
| 1128 | * Update the various stats for this VSI and its related entities. |
| 1129 | **/ |
| 1130 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1131 | { |
| 1132 | struct i40e_pf *pf = vsi->back; |
| 1133 | |
| 1134 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1135 | i40e_update_pf_stats(pf); |
| 1136 | |
| 1137 | i40e_update_vsi_stats(vsi); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1138 | #ifdef I40E_FCOE |
| 1139 | i40e_update_fcoe_stats(vsi); |
| 1140 | #endif |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1144 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1145 | * @vsi: the VSI to be searched |
| 1146 | * @macaddr: the MAC address |
| 1147 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1148 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1149 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1150 | * |
| 1151 | * Returns ptr to the filter object or NULL |
| 1152 | **/ |
| 1153 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
| 1154 | u8 *macaddr, s16 vlan, |
| 1155 | bool is_vf, bool is_netdev) |
| 1156 | { |
| 1157 | struct i40e_mac_filter *f; |
| 1158 | |
| 1159 | if (!vsi || !macaddr) |
| 1160 | return NULL; |
| 1161 | |
| 1162 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1163 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1164 | (vlan == f->vlan) && |
| 1165 | (!is_vf || f->is_vf) && |
| 1166 | (!is_netdev || f->is_netdev)) |
| 1167 | return f; |
| 1168 | } |
| 1169 | return NULL; |
| 1170 | } |
| 1171 | |
| 1172 | /** |
| 1173 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1174 | * @vsi: the VSI to be searched |
| 1175 | * @macaddr: the MAC address we are searching for |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1176 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1177 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1178 | * |
| 1179 | * Returns the first filter with the provided MAC address or NULL if |
| 1180 | * MAC address was not found |
| 1181 | **/ |
| 1182 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr, |
| 1183 | bool is_vf, bool is_netdev) |
| 1184 | { |
| 1185 | struct i40e_mac_filter *f; |
| 1186 | |
| 1187 | if (!vsi || !macaddr) |
| 1188 | return NULL; |
| 1189 | |
| 1190 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1191 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1192 | (!is_vf || f->is_vf) && |
| 1193 | (!is_netdev || f->is_netdev)) |
| 1194 | return f; |
| 1195 | } |
| 1196 | return NULL; |
| 1197 | } |
| 1198 | |
| 1199 | /** |
| 1200 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1201 | * @vsi: the VSI to be searched |
| 1202 | * |
| 1203 | * Returns true if VSI is in vlan mode or false otherwise |
| 1204 | **/ |
| 1205 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1206 | { |
| 1207 | struct i40e_mac_filter *f; |
| 1208 | |
| 1209 | /* Only -1 for all the filters denotes not in vlan mode |
| 1210 | * so we have to go through all the list in order to make sure |
| 1211 | */ |
| 1212 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Greg Rose | d9b68f8 | 2015-07-23 16:54:31 -0400 | [diff] [blame] | 1213 | if (f->vlan >= 0 || vsi->info.pvid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1214 | return true; |
| 1215 | } |
| 1216 | |
| 1217 | return false; |
| 1218 | } |
| 1219 | |
| 1220 | /** |
| 1221 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1222 | * @vsi: the VSI to be searched |
| 1223 | * @macaddr: the mac address to be filtered |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1224 | * @is_vf: true if it is a VF |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1225 | * @is_netdev: true if it is a netdev |
| 1226 | * |
| 1227 | * Goes through all the macvlan filters and adds a |
| 1228 | * macvlan filter for each unique vlan that already exists |
| 1229 | * |
| 1230 | * Returns first filter found on success, else NULL |
| 1231 | **/ |
| 1232 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1233 | bool is_vf, bool is_netdev) |
| 1234 | { |
| 1235 | struct i40e_mac_filter *f; |
| 1236 | |
| 1237 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Mitch Williams | ecbb44e | 2015-07-10 19:35:56 -0400 | [diff] [blame] | 1238 | if (vsi->info.pvid) |
| 1239 | f->vlan = le16_to_cpu(vsi->info.pvid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1240 | if (!i40e_find_filter(vsi, macaddr, f->vlan, |
| 1241 | is_vf, is_netdev)) { |
| 1242 | if (!i40e_add_filter(vsi, macaddr, f->vlan, |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 1243 | is_vf, is_netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1244 | return NULL; |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | return list_first_entry_or_null(&vsi->mac_filter_list, |
| 1249 | struct i40e_mac_filter, list); |
| 1250 | } |
| 1251 | |
| 1252 | /** |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1253 | * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS |
| 1254 | * @vsi: the VSI to be searched |
| 1255 | * @macaddr: the mac address to be removed |
| 1256 | * @is_vf: true if it is a VF |
| 1257 | * @is_netdev: true if it is a netdev |
| 1258 | * |
| 1259 | * Removes a given MAC address from a VSI, regardless of VLAN |
| 1260 | * |
| 1261 | * Returns 0 for success, or error |
| 1262 | **/ |
| 1263 | int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1264 | bool is_vf, bool is_netdev) |
| 1265 | { |
| 1266 | struct i40e_mac_filter *f = NULL; |
| 1267 | int changed = 0; |
| 1268 | |
| 1269 | WARN(!spin_is_locked(&vsi->mac_filter_list_lock), |
| 1270 | "Missing mac_filter_list_lock\n"); |
| 1271 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1272 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1273 | (is_vf == f->is_vf) && |
| 1274 | (is_netdev == f->is_netdev)) { |
| 1275 | f->counter--; |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1276 | changed = 1; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1277 | if (f->counter == 0) |
| 1278 | f->state = I40E_FILTER_REMOVE; |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1279 | } |
| 1280 | } |
| 1281 | if (changed) { |
| 1282 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1283 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1284 | return 0; |
| 1285 | } |
| 1286 | return -ENOENT; |
| 1287 | } |
| 1288 | |
| 1289 | /** |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1290 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM |
| 1291 | * @vsi: the PF Main VSI - inappropriate for any other VSI |
| 1292 | * @macaddr: the MAC address |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1293 | * |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1294 | * Remove whatever filter the firmware set up so the driver can manage |
| 1295 | * its own filtering intelligently. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1296 | **/ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1297 | static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr) |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1298 | { |
| 1299 | struct i40e_aqc_remove_macvlan_element_data element; |
| 1300 | struct i40e_pf *pf = vsi->back; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1301 | |
| 1302 | /* Only appropriate for the PF main VSI */ |
| 1303 | if (vsi->type != I40E_VSI_MAIN) |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1304 | return; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1305 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1306 | memset(&element, 0, sizeof(element)); |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1307 | ether_addr_copy(element.mac_addr, macaddr); |
| 1308 | element.vlan_tag = 0; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1309 | /* Ignore error returns, some firmware does it this way... */ |
| 1310 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1311 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1312 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1313 | memset(&element, 0, sizeof(element)); |
| 1314 | ether_addr_copy(element.mac_addr, macaddr); |
| 1315 | element.vlan_tag = 0; |
| 1316 | /* ...and some firmware does it this way. */ |
| 1317 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | |
Alan Brady | a6cb914 | 2016-09-06 18:05:07 -0700 | [diff] [blame] | 1318 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1319 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1323 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1324 | * @vsi: the VSI to be searched |
| 1325 | * @macaddr: the MAC address |
| 1326 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1327 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1328 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1329 | * |
| 1330 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1331 | * |
| 1332 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1333 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1334 | **/ |
| 1335 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
| 1336 | u8 *macaddr, s16 vlan, |
| 1337 | bool is_vf, bool is_netdev) |
| 1338 | { |
| 1339 | struct i40e_mac_filter *f; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1340 | int changed = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1341 | |
| 1342 | if (!vsi || !macaddr) |
| 1343 | return NULL; |
| 1344 | |
Kiran Patil | f6bd096 | 2016-06-20 09:10:34 -0700 | [diff] [blame] | 1345 | /* Do not allow broadcast filter to be added since broadcast filter |
| 1346 | * is added as part of add VSI for any newly created VSI except |
| 1347 | * FDIR VSI |
| 1348 | */ |
| 1349 | if (is_broadcast_ether_addr(macaddr)) |
| 1350 | return NULL; |
| 1351 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1352 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1353 | if (!f) { |
| 1354 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1355 | if (!f) |
| 1356 | goto add_filter_out; |
| 1357 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1358 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1359 | f->vlan = vlan; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1360 | /* If we're in overflow promisc mode, set the state directly |
| 1361 | * to failed, so we don't bother to try sending the filter |
| 1362 | * to the hardware. |
| 1363 | */ |
| 1364 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state)) |
| 1365 | f->state = I40E_FILTER_FAILED; |
| 1366 | else |
| 1367 | f->state = I40E_FILTER_NEW; |
| 1368 | changed = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1369 | INIT_LIST_HEAD(&f->list); |
Kiran Patil | 04d5a21 | 2015-12-09 15:50:23 -0800 | [diff] [blame] | 1370 | list_add_tail(&f->list, &vsi->mac_filter_list); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | /* increment counter and add a new flag if needed */ |
| 1374 | if (is_vf) { |
| 1375 | if (!f->is_vf) { |
| 1376 | f->is_vf = true; |
| 1377 | f->counter++; |
| 1378 | } |
| 1379 | } else if (is_netdev) { |
| 1380 | if (!f->is_netdev) { |
| 1381 | f->is_netdev = true; |
| 1382 | f->counter++; |
| 1383 | } |
| 1384 | } else { |
| 1385 | f->counter++; |
| 1386 | } |
| 1387 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1388 | if (changed) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1389 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1390 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1391 | } |
| 1392 | |
| 1393 | add_filter_out: |
| 1394 | return f; |
| 1395 | } |
| 1396 | |
| 1397 | /** |
| 1398 | * i40e_del_filter - Remove a mac/vlan filter from the VSI |
| 1399 | * @vsi: the VSI to be searched |
| 1400 | * @macaddr: the MAC address |
| 1401 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1402 | * @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] | 1403 | * @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] | 1404 | * |
| 1405 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1406 | * being held. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1407 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1408 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1409 | * instead of list_for_each_entry(). |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1410 | **/ |
| 1411 | void i40e_del_filter(struct i40e_vsi *vsi, |
| 1412 | u8 *macaddr, s16 vlan, |
| 1413 | bool is_vf, bool is_netdev) |
| 1414 | { |
| 1415 | struct i40e_mac_filter *f; |
| 1416 | |
| 1417 | if (!vsi || !macaddr) |
| 1418 | return; |
| 1419 | |
| 1420 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1421 | if (!f || f->counter == 0) |
| 1422 | return; |
| 1423 | |
| 1424 | if (is_vf) { |
| 1425 | if (f->is_vf) { |
| 1426 | f->is_vf = false; |
| 1427 | f->counter--; |
| 1428 | } |
| 1429 | } else if (is_netdev) { |
| 1430 | if (f->is_netdev) { |
| 1431 | f->is_netdev = false; |
| 1432 | f->counter--; |
| 1433 | } |
| 1434 | } else { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1435 | /* 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] | 1436 | int min_f = 0; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1437 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1438 | min_f += (f->is_vf ? 1 : 0); |
| 1439 | min_f += (f->is_netdev ? 1 : 0); |
| 1440 | |
| 1441 | if (f->counter > min_f) |
| 1442 | f->counter--; |
| 1443 | } |
| 1444 | |
| 1445 | /* counter == 0 tells sync_filters_subtask to |
| 1446 | * remove the filter from the firmware's list |
| 1447 | */ |
| 1448 | if (f->counter == 0) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1449 | if ((f->state == I40E_FILTER_FAILED) || |
| 1450 | (f->state == I40E_FILTER_NEW)) { |
| 1451 | /* this one never got added by the FW. Just remove it, |
| 1452 | * no need to sync anything. |
| 1453 | */ |
| 1454 | list_del(&f->list); |
| 1455 | kfree(f); |
| 1456 | } else { |
| 1457 | f->state = I40E_FILTER_REMOVE; |
| 1458 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1459 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1460 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | /** |
| 1465 | * i40e_set_mac - NDO callback to set mac address |
| 1466 | * @netdev: network interface device structure |
| 1467 | * @p: pointer to an address structure |
| 1468 | * |
| 1469 | * Returns 0 on success, negative on failure |
| 1470 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1471 | #ifdef I40E_FCOE |
| 1472 | int i40e_set_mac(struct net_device *netdev, void *p) |
| 1473 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1474 | static int i40e_set_mac(struct net_device *netdev, void *p) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1475 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1476 | { |
| 1477 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1478 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1479 | struct i40e_pf *pf = vsi->back; |
| 1480 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1481 | struct sockaddr *addr = p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1482 | |
| 1483 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1484 | return -EADDRNOTAVAIL; |
| 1485 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1486 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1487 | netdev_info(netdev, "already using mac address %pM\n", |
| 1488 | addr->sa_data); |
| 1489 | return 0; |
| 1490 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1491 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1492 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1493 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1494 | return -EADDRNOTAVAIL; |
| 1495 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1496 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1497 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1498 | hw->mac.addr); |
| 1499 | else |
| 1500 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1501 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1502 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1503 | i40e_del_mac_all_vlan(vsi, netdev->dev_addr, false, true); |
| 1504 | i40e_put_mac_in_vlan(vsi, addr->sa_data, false, true); |
| 1505 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 1506 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1507 | if (vsi->type == I40E_VSI_MAIN) { |
| 1508 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1509 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1510 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1511 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1512 | addr->sa_data, NULL); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1513 | if (ret) |
| 1514 | netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n", |
| 1515 | i40e_stat_str(hw, ret), |
| 1516 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1519 | /* schedule our worker thread which will take care of |
| 1520 | * applying the new filter changes |
| 1521 | */ |
| 1522 | i40e_service_event_schedule(vsi->back); |
| 1523 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | /** |
| 1527 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1528 | * @vsi: the VSI being setup |
| 1529 | * @ctxt: VSI context structure |
| 1530 | * @enabled_tc: Enabled TCs bitmap |
| 1531 | * @is_add: True if called before Add VSI |
| 1532 | * |
| 1533 | * Setup VSI queue mapping for enabled traffic classes. |
| 1534 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1535 | #ifdef I40E_FCOE |
| 1536 | void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1537 | struct i40e_vsi_context *ctxt, |
| 1538 | u8 enabled_tc, |
| 1539 | bool is_add) |
| 1540 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1541 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1542 | struct i40e_vsi_context *ctxt, |
| 1543 | u8 enabled_tc, |
| 1544 | bool is_add) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1545 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1546 | { |
| 1547 | struct i40e_pf *pf = vsi->back; |
| 1548 | u16 sections = 0; |
| 1549 | u8 netdev_tc = 0; |
| 1550 | u16 numtc = 0; |
| 1551 | u16 qcount; |
| 1552 | u8 offset; |
| 1553 | u16 qmap; |
| 1554 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1555 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1556 | |
| 1557 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1558 | offset = 0; |
| 1559 | |
| 1560 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1561 | /* Find numtc from enabled TC bitmap */ |
| 1562 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1563 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1564 | numtc++; |
| 1565 | } |
| 1566 | if (!numtc) { |
| 1567 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1568 | numtc = 1; |
| 1569 | } |
| 1570 | } else { |
| 1571 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1572 | numtc = 1; |
| 1573 | } |
| 1574 | |
| 1575 | vsi->tc_config.numtc = numtc; |
| 1576 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1577 | /* Number of queues per enabled TC */ |
Catherine Sullivan | 7d64402 | 2016-05-16 10:26:41 -0700 | [diff] [blame] | 1578 | qcount = vsi->alloc_queue_pairs; |
| 1579 | |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1580 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1581 | 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] | 1582 | |
| 1583 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1584 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1585 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1586 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1587 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1588 | int pow, num_qps; |
| 1589 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1590 | switch (vsi->type) { |
| 1591 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1592 | qcount = min_t(int, pf->alloc_rss_size, |
| 1593 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1594 | break; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1595 | #ifdef I40E_FCOE |
| 1596 | case I40E_VSI_FCOE: |
| 1597 | qcount = num_tc_qps; |
| 1598 | break; |
| 1599 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1600 | case I40E_VSI_FDIR: |
| 1601 | case I40E_VSI_SRIOV: |
| 1602 | case I40E_VSI_VMDQ2: |
| 1603 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1604 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1605 | WARN_ON(i != 0); |
| 1606 | break; |
| 1607 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1608 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1609 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1610 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1611 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1612 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1613 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1614 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1615 | pow++; |
| 1616 | num_qps >>= 1; |
| 1617 | } |
| 1618 | |
| 1619 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1620 | qmap = |
| 1621 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1622 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1623 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1624 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1625 | } else { |
| 1626 | /* TC is not enabled so set the offset to |
| 1627 | * default queue and allocate one queue |
| 1628 | * for the given TC. |
| 1629 | */ |
| 1630 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1631 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1632 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1633 | |
| 1634 | qmap = 0; |
| 1635 | } |
| 1636 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1637 | } |
| 1638 | |
| 1639 | /* Set actual Tx/Rx queue pairs */ |
| 1640 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1641 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1642 | if (vsi->req_queue_pairs > 0) |
| 1643 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1644 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1645 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1646 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1647 | |
| 1648 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1649 | if (is_add) { |
| 1650 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1651 | |
| 1652 | ctxt->info.up_enable_bits = enabled_tc; |
| 1653 | } |
| 1654 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1655 | ctxt->info.mapping_flags |= |
| 1656 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1657 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1658 | ctxt->info.queue_mapping[i] = |
| 1659 | cpu_to_le16(vsi->base_queue + i); |
| 1660 | } else { |
| 1661 | ctxt->info.mapping_flags |= |
| 1662 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1663 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1664 | } |
| 1665 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1666 | } |
| 1667 | |
| 1668 | /** |
| 1669 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1670 | * @netdev: network interface device structure |
| 1671 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1672 | #ifdef I40E_FCOE |
| 1673 | void i40e_set_rx_mode(struct net_device *netdev) |
| 1674 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1675 | static void i40e_set_rx_mode(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1676 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1677 | { |
| 1678 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1679 | struct i40e_mac_filter *f, *ftmp; |
| 1680 | struct i40e_vsi *vsi = np->vsi; |
| 1681 | struct netdev_hw_addr *uca; |
| 1682 | struct netdev_hw_addr *mca; |
| 1683 | struct netdev_hw_addr *ha; |
| 1684 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1685 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1686 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1687 | /* add addr if not already in the filter list */ |
| 1688 | netdev_for_each_uc_addr(uca, netdev) { |
| 1689 | if (!i40e_find_mac(vsi, uca->addr, false, true)) { |
| 1690 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1691 | i40e_put_mac_in_vlan(vsi, uca->addr, |
| 1692 | false, true); |
| 1693 | else |
| 1694 | i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY, |
| 1695 | false, true); |
| 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | netdev_for_each_mc_addr(mca, netdev) { |
| 1700 | if (!i40e_find_mac(vsi, mca->addr, false, true)) { |
| 1701 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1702 | i40e_put_mac_in_vlan(vsi, mca->addr, |
| 1703 | false, true); |
| 1704 | else |
| 1705 | i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY, |
| 1706 | false, true); |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | /* remove filter if not in netdev list */ |
| 1711 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1712 | |
| 1713 | if (!f->is_netdev) |
| 1714 | continue; |
| 1715 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1716 | netdev_for_each_mc_addr(mca, netdev) |
| 1717 | if (ether_addr_equal(mca->addr, f->macaddr)) |
| 1718 | goto bottom_of_search_loop; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1719 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1720 | netdev_for_each_uc_addr(uca, netdev) |
| 1721 | if (ether_addr_equal(uca->addr, f->macaddr)) |
| 1722 | goto bottom_of_search_loop; |
| 1723 | |
| 1724 | for_each_dev_addr(netdev, ha) |
| 1725 | if (ether_addr_equal(ha->addr, f->macaddr)) |
| 1726 | goto bottom_of_search_loop; |
| 1727 | |
| 1728 | /* f->macaddr wasn't found in uc, mc, or ha list so delete it */ |
| 1729 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true); |
| 1730 | |
| 1731 | bottom_of_search_loop: |
| 1732 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1733 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1734 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1735 | |
| 1736 | /* check for other flag changes */ |
| 1737 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1738 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1739 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1740 | } |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1741 | |
| 1742 | /* schedule our worker thread which will take care of |
| 1743 | * applying the new filter changes |
| 1744 | */ |
| 1745 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | /** |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1749 | * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries |
| 1750 | * @vsi: pointer to vsi struct |
| 1751 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1752 | * those entries needs to be undone. |
| 1753 | * |
| 1754 | * MAC filter entries from list were slated to be removed from device. |
| 1755 | **/ |
| 1756 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1757 | struct list_head *from) |
| 1758 | { |
| 1759 | struct i40e_mac_filter *f, *ftmp; |
| 1760 | |
| 1761 | list_for_each_entry_safe(f, ftmp, from, list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1762 | /* Move the element back into MAC filter list*/ |
| 1763 | list_move_tail(&f->list, &vsi->mac_filter_list); |
| 1764 | } |
| 1765 | } |
| 1766 | |
| 1767 | /** |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1768 | * i40e_update_filter_state - Update filter state based on return data |
| 1769 | * from firmware |
| 1770 | * @count: Number of filters added |
| 1771 | * @add_list: return data from fw |
| 1772 | * @head: pointer to first filter in current batch |
| 1773 | * @aq_err: status from fw |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1774 | * |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1775 | * MAC filter entries from list were slated to be added to device. Returns |
| 1776 | * number of successful filters. Note that 0 does NOT mean success! |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1777 | **/ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1778 | static int |
| 1779 | i40e_update_filter_state(int count, |
| 1780 | struct i40e_aqc_add_macvlan_element_data *add_list, |
| 1781 | struct i40e_mac_filter *add_head, int aq_err) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1782 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1783 | int retval = 0; |
| 1784 | int i; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1785 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1786 | |
| 1787 | if (!aq_err) { |
| 1788 | retval = count; |
| 1789 | /* Everything's good, mark all filters active. */ |
| 1790 | for (i = 0; i < count ; i++) { |
| 1791 | add_head->state = I40E_FILTER_ACTIVE; |
| 1792 | add_head = list_next_entry(add_head, list); |
| 1793 | } |
| 1794 | } else if (aq_err == I40E_AQ_RC_ENOSPC) { |
| 1795 | /* Device ran out of filter space. Check the return value |
| 1796 | * for each filter to see which ones are active. |
| 1797 | */ |
| 1798 | for (i = 0; i < count ; i++) { |
| 1799 | if (add_list[i].match_method == |
| 1800 | I40E_AQC_MM_ERR_NO_RES) { |
| 1801 | add_head->state = I40E_FILTER_FAILED; |
| 1802 | } else { |
| 1803 | add_head->state = I40E_FILTER_ACTIVE; |
| 1804 | retval++; |
| 1805 | } |
| 1806 | add_head = list_next_entry(add_head, list); |
| 1807 | } |
| 1808 | } else { |
| 1809 | /* Some other horrible thing happened, fail all filters */ |
| 1810 | retval = 0; |
| 1811 | for (i = 0; i < count ; i++) { |
| 1812 | add_head->state = I40E_FILTER_FAILED; |
| 1813 | add_head = list_next_entry(add_head, list); |
| 1814 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1815 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1816 | return retval; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1820 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1821 | * @vsi: ptr to the VSI |
| 1822 | * |
| 1823 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1824 | * |
| 1825 | * Returns 0 or error value |
| 1826 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 1827 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1828 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1829 | struct i40e_mac_filter *f, *ftmp, *add_head = NULL; |
| 1830 | struct list_head tmp_add_list, tmp_del_list; |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1831 | struct i40e_hw *hw = &vsi->back->hw; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1832 | bool promisc_changed = false; |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1833 | char vsi_name[16] = "PF"; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1834 | int filter_list_len = 0; |
| 1835 | u32 changed_flags = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1836 | i40e_status aq_ret = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1837 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1838 | struct i40e_pf *pf; |
| 1839 | int num_add = 0; |
| 1840 | int num_del = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1841 | int aq_err = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1842 | u16 cmd_flags; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1843 | int list_size; |
| 1844 | int fcnt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1845 | |
| 1846 | /* empty array typed pointers, kcalloc later */ |
| 1847 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1848 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1849 | |
| 1850 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1851 | usleep_range(1000, 2000); |
| 1852 | pf = vsi->back; |
| 1853 | |
| 1854 | if (vsi->netdev) { |
| 1855 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1856 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1857 | } |
| 1858 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1859 | INIT_LIST_HEAD(&tmp_add_list); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1860 | INIT_LIST_HEAD(&tmp_del_list); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1861 | |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1862 | if (vsi->type == I40E_VSI_SRIOV) |
| 1863 | snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id); |
| 1864 | else if (vsi->type != I40E_VSI_MAIN) |
| 1865 | snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid); |
| 1866 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1867 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1868 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1869 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1870 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1871 | /* Create a list of filters to delete. */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1872 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1873 | if (f->state == I40E_FILTER_REMOVE) { |
| 1874 | WARN_ON(f->counter != 0); |
| 1875 | /* Move the element into temporary del_list */ |
| 1876 | list_move_tail(&f->list, &tmp_del_list); |
| 1877 | vsi->active_filters--; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1878 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1879 | if (f->state == I40E_FILTER_NEW) { |
| 1880 | WARN_ON(f->counter == 0); |
| 1881 | /* Move the element into temporary add_list */ |
| 1882 | list_move_tail(&f->list, &tmp_add_list); |
| 1883 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1884 | } |
| 1885 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | /* Now process 'del_list' outside the lock */ |
| 1889 | if (!list_empty(&tmp_del_list)) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1890 | filter_list_len = hw->aq.asq_buf_size / |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1891 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1892 | list_size = filter_list_len * |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1893 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1894 | del_list = kzalloc(list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1895 | if (!del_list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1896 | /* Undo VSI's MAC filter entry element updates */ |
| 1897 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1898 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1899 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1900 | retval = -ENOMEM; |
| 1901 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1905 | cmd_flags = 0; |
| 1906 | |
| 1907 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1908 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1909 | if (f->vlan == I40E_VLAN_ANY) { |
| 1910 | del_list[num_del].vlan_tag = 0; |
Alan Brady | a6cb914 | 2016-09-06 18:05:07 -0700 | [diff] [blame] | 1911 | cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1912 | } else { |
| 1913 | del_list[num_del].vlan_tag = |
| 1914 | cpu_to_le16((u16)(f->vlan)); |
| 1915 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1916 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1917 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1918 | del_list[num_del].flags = cmd_flags; |
| 1919 | num_del++; |
| 1920 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1921 | /* flush a full buffer */ |
| 1922 | if (num_del == filter_list_len) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1923 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, |
| 1924 | del_list, |
| 1925 | num_del, NULL); |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1926 | aq_err = hw->aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1927 | num_del = 0; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1928 | memset(del_list, 0, list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1929 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1930 | /* Explicitly ignore and do not report when |
| 1931 | * firmware returns ENOENT. |
| 1932 | */ |
| 1933 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1934 | retval = -EIO; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1935 | dev_info(&pf->pdev->dev, |
| 1936 | "ignoring delete macvlan error on %s, err %s, aq_err %s\n", |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1937 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1938 | i40e_stat_str(hw, aq_ret), |
| 1939 | i40e_aq_str(hw, aq_err)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1940 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1941 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1942 | /* Release memory for MAC filter entries which were |
| 1943 | * synced up with HW. |
| 1944 | */ |
| 1945 | list_del(&f->list); |
| 1946 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1947 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1948 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1949 | if (num_del) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1950 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, del_list, |
| 1951 | num_del, NULL); |
| 1952 | aq_err = hw->aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1953 | num_del = 0; |
| 1954 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1955 | /* Explicitly ignore and do not report when firmware |
| 1956 | * returns ENOENT. |
| 1957 | */ |
| 1958 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { |
| 1959 | retval = -EIO; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1960 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1961 | "ignoring delete macvlan error on %s, err %s aq_err %s\n", |
| 1962 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1963 | i40e_stat_str(hw, aq_ret), |
| 1964 | i40e_aq_str(hw, aq_err)); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1965 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | kfree(del_list); |
| 1969 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | if (!list_empty(&tmp_add_list)) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1973 | /* Do all the adds now. */ |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1974 | filter_list_len = hw->aq.asq_buf_size / |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1975 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1976 | list_size = filter_list_len * |
| 1977 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
| 1978 | add_list = kzalloc(list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1979 | if (!add_list) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1980 | retval = -ENOMEM; |
| 1981 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1982 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1983 | num_add = 0; |
| 1984 | list_for_each_entry(f, &tmp_add_list, list) { |
| 1985 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1986 | &vsi->state)) { |
| 1987 | f->state = I40E_FILTER_FAILED; |
| 1988 | continue; |
| 1989 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1990 | /* add to add array */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1991 | if (num_add == 0) |
| 1992 | add_head = f; |
| 1993 | cmd_flags = 0; |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1994 | ether_addr_copy(add_list[num_add].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1995 | if (f->vlan == I40E_VLAN_ANY) { |
| 1996 | add_list[num_add].vlan_tag = 0; |
| 1997 | cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; |
| 1998 | } else { |
| 1999 | add_list[num_add].vlan_tag = |
| 2000 | cpu_to_le16((u16)(f->vlan)); |
| 2001 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2002 | add_list[num_add].queue_number = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2003 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2004 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2005 | num_add++; |
| 2006 | |
| 2007 | /* flush a full buffer */ |
| 2008 | if (num_add == filter_list_len) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2009 | aq_ret = i40e_aq_add_macvlan(hw, vsi->seid, |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2010 | add_list, num_add, |
| 2011 | NULL); |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2012 | aq_err = hw->aq.asq_last_status; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2013 | fcnt = i40e_update_filter_state(num_add, |
| 2014 | add_list, |
| 2015 | add_head, |
| 2016 | aq_ret); |
| 2017 | vsi->active_filters += fcnt; |
| 2018 | |
| 2019 | if (fcnt != num_add) { |
| 2020 | promisc_changed = true; |
| 2021 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2022 | &vsi->state); |
| 2023 | vsi->promisc_threshold = |
| 2024 | (vsi->active_filters * 3) / 4; |
| 2025 | dev_warn(&pf->pdev->dev, |
| 2026 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", |
| 2027 | i40e_aq_str(hw, aq_err), |
| 2028 | vsi_name); |
| 2029 | } |
| 2030 | memset(add_list, 0, list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2031 | num_add = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2032 | } |
| 2033 | } |
| 2034 | if (num_add) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2035 | aq_ret = i40e_aq_add_macvlan(hw, vsi->seid, |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2036 | add_list, num_add, NULL); |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2037 | aq_err = hw->aq.asq_last_status; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2038 | fcnt = i40e_update_filter_state(num_add, add_list, |
| 2039 | add_head, aq_ret); |
| 2040 | vsi->active_filters += fcnt; |
| 2041 | if (fcnt != num_add) { |
| 2042 | promisc_changed = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2043 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2044 | &vsi->state); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2045 | vsi->promisc_threshold = |
| 2046 | (vsi->active_filters * 3) / 4; |
| 2047 | dev_warn(&pf->pdev->dev, |
| 2048 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", |
| 2049 | i40e_aq_str(hw, aq_err), vsi_name); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2050 | } |
| 2051 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2052 | /* Now move all of the filters from the temp add list back to |
| 2053 | * the VSI's list. |
| 2054 | */ |
| 2055 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2056 | list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) { |
| 2057 | list_move_tail(&f->list, &vsi->mac_filter_list); |
| 2058 | } |
| 2059 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2060 | kfree(add_list); |
| 2061 | add_list = NULL; |
| 2062 | } |
| 2063 | |
| 2064 | /* Check to see if we can drop out of overflow promiscuous mode. */ |
| 2065 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) && |
| 2066 | (vsi->active_filters < vsi->promisc_threshold)) { |
| 2067 | int failed_count = 0; |
| 2068 | /* See if we have any failed filters. We can't drop out of |
| 2069 | * promiscuous until these have all been deleted. |
| 2070 | */ |
| 2071 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2072 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2073 | if (f->state == I40E_FILTER_FAILED) |
| 2074 | failed_count++; |
| 2075 | } |
| 2076 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2077 | if (!failed_count) { |
| 2078 | dev_info(&pf->pdev->dev, |
| 2079 | "filter logjam cleared on %s, leaving overflow promiscuous mode\n", |
| 2080 | vsi_name); |
| 2081 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2082 | promisc_changed = true; |
| 2083 | vsi->promisc_threshold = 0; |
| 2084 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2085 | } |
| 2086 | |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2087 | /* if the VF is not trusted do not do promisc */ |
| 2088 | if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) { |
| 2089 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2090 | goto out; |
| 2091 | } |
| 2092 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2093 | /* check for changes in promiscuous modes */ |
| 2094 | if (changed_flags & IFF_ALLMULTI) { |
| 2095 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2096 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2097 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2098 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2099 | vsi->seid, |
| 2100 | cur_multipromisc, |
| 2101 | NULL); |
| 2102 | if (aq_ret) { |
| 2103 | retval = i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2104 | hw->aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2105 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2106 | "set multi promisc failed on %s, err %s aq_err %s\n", |
| 2107 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2108 | i40e_stat_str(hw, aq_ret), |
| 2109 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2110 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2111 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2112 | if ((changed_flags & IFF_PROMISC) || |
| 2113 | (promisc_changed && |
| 2114 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2115 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2116 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2117 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 2118 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2119 | &vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2120 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2121 | (pf->lan_veb != I40E_NO_VEB) && |
| 2122 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2123 | /* set defport ON for Main VSI instead of true promisc |
| 2124 | * this way we will get all unicast/multicast and VLAN |
| 2125 | * promisc behavior but will not get VF or VMDq traffic |
| 2126 | * replicated on the Main VSI. |
| 2127 | */ |
| 2128 | if (pf->cur_promisc != cur_promisc) { |
| 2129 | pf->cur_promisc = cur_promisc; |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2130 | if (cur_promisc) |
| 2131 | aq_ret = |
| 2132 | i40e_aq_set_default_vsi(hw, |
| 2133 | vsi->seid, |
| 2134 | NULL); |
| 2135 | else |
| 2136 | aq_ret = |
| 2137 | i40e_aq_clear_default_vsi(hw, |
| 2138 | vsi->seid, |
| 2139 | NULL); |
| 2140 | if (aq_ret) { |
| 2141 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2142 | hw->aq.asq_last_status); |
| 2143 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2144 | "Set default VSI failed on %s, err %s, aq_err %s\n", |
| 2145 | vsi_name, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2146 | i40e_stat_str(hw, aq_ret), |
| 2147 | i40e_aq_str(hw, |
| 2148 | hw->aq.asq_last_status)); |
| 2149 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2150 | } |
| 2151 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2152 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2153 | hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2154 | vsi->seid, |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 2155 | cur_promisc, NULL, |
| 2156 | true); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2157 | if (aq_ret) { |
| 2158 | retval = |
| 2159 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2160 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2161 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2162 | "set unicast promisc failed on %s, err %s, aq_err %s\n", |
| 2163 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2164 | i40e_stat_str(hw, aq_ret), |
| 2165 | i40e_aq_str(hw, |
| 2166 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2167 | } |
| 2168 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2169 | hw, |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2170 | vsi->seid, |
| 2171 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2172 | if (aq_ret) { |
| 2173 | retval = |
| 2174 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2175 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2176 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2177 | "set multicast promisc failed on %s, err %s, aq_err %s\n", |
| 2178 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2179 | i40e_stat_str(hw, aq_ret), |
| 2180 | i40e_aq_str(hw, |
| 2181 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2182 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2183 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2184 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2185 | vsi->seid, |
| 2186 | cur_promisc, NULL); |
| 2187 | if (aq_ret) { |
| 2188 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2189 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2190 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2191 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2192 | i40e_stat_str(hw, aq_ret), |
| 2193 | i40e_aq_str(hw, |
| 2194 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2195 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2196 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2197 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2198 | /* if something went wrong then set the changed flag so we try again */ |
| 2199 | if (retval) |
| 2200 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2201 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2202 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2203 | return retval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | /** |
| 2207 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2208 | * @pf: board private structure |
| 2209 | **/ |
| 2210 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2211 | { |
| 2212 | int v; |
| 2213 | |
| 2214 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2215 | return; |
| 2216 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2217 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2218 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2219 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2220 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2221 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2222 | |
| 2223 | if (ret) { |
| 2224 | /* come back and try again later */ |
| 2225 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2226 | break; |
| 2227 | } |
| 2228 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | /** |
| 2233 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2234 | * @netdev: network interface device structure |
| 2235 | * @new_mtu: new value for maximum frame size |
| 2236 | * |
| 2237 | * Returns 0 on success, negative on failure |
| 2238 | **/ |
| 2239 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2240 | { |
| 2241 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2242 | struct i40e_vsi *vsi = np->vsi; |
| 2243 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2244 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2245 | netdev->mtu, new_mtu); |
| 2246 | netdev->mtu = new_mtu; |
| 2247 | if (netif_running(netdev)) |
| 2248 | i40e_vsi_reinit_locked(vsi); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 2249 | i40e_notify_client_of_l2_param_changes(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2250 | return 0; |
| 2251 | } |
| 2252 | |
| 2253 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2254 | * i40e_ioctl - Access the hwtstamp interface |
| 2255 | * @netdev: network interface device structure |
| 2256 | * @ifr: interface request data |
| 2257 | * @cmd: ioctl command |
| 2258 | **/ |
| 2259 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2260 | { |
| 2261 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2262 | struct i40e_pf *pf = np->vsi->back; |
| 2263 | |
| 2264 | switch (cmd) { |
| 2265 | case SIOCGHWTSTAMP: |
| 2266 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2267 | case SIOCSHWTSTAMP: |
| 2268 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2269 | default: |
| 2270 | return -EOPNOTSUPP; |
| 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2275 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2276 | * @vsi: the vsi being adjusted |
| 2277 | **/ |
| 2278 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2279 | { |
| 2280 | struct i40e_vsi_context ctxt; |
| 2281 | i40e_status ret; |
| 2282 | |
| 2283 | if ((vsi->info.valid_sections & |
| 2284 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2285 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2286 | return; /* already enabled */ |
| 2287 | |
| 2288 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2289 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2290 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2291 | |
| 2292 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2293 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2294 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2295 | if (ret) { |
| 2296 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2297 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2298 | i40e_stat_str(&vsi->back->hw, ret), |
| 2299 | i40e_aq_str(&vsi->back->hw, |
| 2300 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | /** |
| 2305 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2306 | * @vsi: the vsi being adjusted |
| 2307 | **/ |
| 2308 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2309 | { |
| 2310 | struct i40e_vsi_context ctxt; |
| 2311 | i40e_status ret; |
| 2312 | |
| 2313 | if ((vsi->info.valid_sections & |
| 2314 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2315 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2316 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2317 | return; /* already disabled */ |
| 2318 | |
| 2319 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2320 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2321 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2322 | |
| 2323 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2324 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2325 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2326 | if (ret) { |
| 2327 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2328 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2329 | i40e_stat_str(&vsi->back->hw, ret), |
| 2330 | i40e_aq_str(&vsi->back->hw, |
| 2331 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | |
| 2335 | /** |
| 2336 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2337 | * @netdev: network interface to be adjusted |
| 2338 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2339 | **/ |
| 2340 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2341 | { |
| 2342 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2343 | struct i40e_vsi *vsi = np->vsi; |
| 2344 | |
| 2345 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2346 | i40e_vlan_stripping_enable(vsi); |
| 2347 | else |
| 2348 | i40e_vlan_stripping_disable(vsi); |
| 2349 | } |
| 2350 | |
| 2351 | /** |
| 2352 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 2353 | * @vsi: the vsi being configured |
| 2354 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 2355 | **/ |
| 2356 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2357 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2358 | struct i40e_mac_filter *f, *ftmp, *add_f; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2359 | bool is_netdev, is_vf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2360 | |
| 2361 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2362 | is_netdev = !!(vsi->netdev); |
| 2363 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2364 | /* Locked once because all functions invoked below iterates list*/ |
| 2365 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2366 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2367 | if (is_netdev) { |
| 2368 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid, |
| 2369 | is_vf, is_netdev); |
| 2370 | if (!add_f) { |
| 2371 | dev_info(&vsi->back->pdev->dev, |
| 2372 | "Could not add vlan filter %d for %pM\n", |
| 2373 | vid, vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2374 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2375 | return -ENOMEM; |
| 2376 | } |
| 2377 | } |
| 2378 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2379 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2380 | add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2381 | if (!add_f) { |
| 2382 | dev_info(&vsi->back->pdev->dev, |
| 2383 | "Could not add vlan filter %d for %pM\n", |
| 2384 | vid, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2385 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2386 | return -ENOMEM; |
| 2387 | } |
| 2388 | } |
| 2389 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2390 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 2391 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 2392 | * with 0, so we now accept untagged and specified tagged traffic |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2393 | * (and not all tags along with untagged) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2394 | */ |
| 2395 | if (vid > 0) { |
| 2396 | if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 2397 | I40E_VLAN_ANY, |
| 2398 | is_vf, is_netdev)) { |
| 2399 | i40e_del_filter(vsi, vsi->netdev->dev_addr, |
| 2400 | I40E_VLAN_ANY, is_vf, is_netdev); |
| 2401 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0, |
| 2402 | is_vf, is_netdev); |
| 2403 | if (!add_f) { |
| 2404 | dev_info(&vsi->back->pdev->dev, |
| 2405 | "Could not add filter 0 for %pM\n", |
| 2406 | vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2407 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2408 | return -ENOMEM; |
| 2409 | } |
| 2410 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2411 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2412 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2413 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
| 2414 | if (vid > 0 && !vsi->info.pvid) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2415 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2416 | if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2417 | is_vf, is_netdev)) |
| 2418 | continue; |
| 2419 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2420 | is_vf, is_netdev); |
| 2421 | add_f = i40e_add_filter(vsi, f->macaddr, |
| 2422 | 0, is_vf, is_netdev); |
| 2423 | if (!add_f) { |
| 2424 | dev_info(&vsi->back->pdev->dev, |
| 2425 | "Could not add filter 0 for %pM\n", |
| 2426 | f->macaddr); |
| 2427 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2428 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2429 | } |
| 2430 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2431 | } |
| 2432 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2433 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2434 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2435 | /* schedule our worker thread which will take care of |
| 2436 | * applying the new filter changes |
| 2437 | */ |
| 2438 | i40e_service_event_schedule(vsi->back); |
| 2439 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | /** |
| 2443 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 2444 | * @vsi: the vsi being configured |
| 2445 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2446 | * |
| 2447 | * Return: 0 on success or negative otherwise |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2448 | **/ |
| 2449 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2450 | { |
| 2451 | struct net_device *netdev = vsi->netdev; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2452 | struct i40e_mac_filter *f, *ftmp, *add_f; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2453 | bool is_vf, is_netdev; |
| 2454 | int filter_count = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2455 | |
| 2456 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2457 | is_netdev = !!(netdev); |
| 2458 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2459 | /* Locked once because all functions invoked below iterates list */ |
| 2460 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2461 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2462 | if (is_netdev) |
| 2463 | i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev); |
| 2464 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2465 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2466 | i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2467 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2468 | /* go through all the filters for this VSI and if there is only |
| 2469 | * vid == 0 it means there are no other filters, so vid 0 must |
| 2470 | * be replaced with -1. This signifies that we should from now |
| 2471 | * on accept any traffic (with any tag present, or untagged) |
| 2472 | */ |
| 2473 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2474 | if (is_netdev) { |
| 2475 | if (f->vlan && |
| 2476 | ether_addr_equal(netdev->dev_addr, f->macaddr)) |
| 2477 | filter_count++; |
| 2478 | } |
| 2479 | |
| 2480 | if (f->vlan) |
| 2481 | filter_count++; |
| 2482 | } |
| 2483 | |
| 2484 | if (!filter_count && is_netdev) { |
| 2485 | i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev); |
| 2486 | f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 2487 | is_vf, is_netdev); |
| 2488 | if (!f) { |
| 2489 | dev_info(&vsi->back->pdev->dev, |
| 2490 | "Could not add filter %d for %pM\n", |
| 2491 | I40E_VLAN_ANY, netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2492 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2493 | return -ENOMEM; |
| 2494 | } |
| 2495 | } |
| 2496 | |
| 2497 | if (!filter_count) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2498 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2499 | i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev); |
| 2500 | add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2501 | is_vf, is_netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2502 | if (!add_f) { |
| 2503 | dev_info(&vsi->back->pdev->dev, |
| 2504 | "Could not add filter %d for %pM\n", |
| 2505 | I40E_VLAN_ANY, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2506 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2507 | return -ENOMEM; |
| 2508 | } |
| 2509 | } |
| 2510 | } |
| 2511 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2512 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2513 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2514 | /* schedule our worker thread which will take care of |
| 2515 | * applying the new filter changes |
| 2516 | */ |
| 2517 | i40e_service_event_schedule(vsi->back); |
| 2518 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | /** |
| 2522 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2523 | * @netdev: network interface to be adjusted |
| 2524 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2525 | * |
| 2526 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2527 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2528 | #ifdef I40E_FCOE |
| 2529 | int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2530 | __always_unused __be16 proto, u16 vid) |
| 2531 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2532 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2533 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2534 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2535 | { |
| 2536 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2537 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2538 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2539 | |
| 2540 | if (vid > 4095) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2541 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2542 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2543 | /* If the network stack called us with vid = 0 then |
| 2544 | * it is asking to receive priority tagged packets with |
| 2545 | * vlan id 0. Our HW receives them by default when configured |
| 2546 | * to receive untagged packets so there is no need to add an |
| 2547 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2548 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2549 | if (vid) |
| 2550 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2551 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2552 | if (!ret && (vid < VLAN_N_VID)) |
| 2553 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2554 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2555 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | /** |
| 2559 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2560 | * @netdev: network interface to be adjusted |
| 2561 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2562 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2563 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2564 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2565 | #ifdef I40E_FCOE |
| 2566 | int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2567 | __always_unused __be16 proto, u16 vid) |
| 2568 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2569 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2570 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2571 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2572 | { |
| 2573 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2574 | struct i40e_vsi *vsi = np->vsi; |
| 2575 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2576 | /* return code is ignored as there is nothing a user |
| 2577 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2578 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2579 | */ |
| 2580 | i40e_vsi_kill_vlan(vsi, vid); |
| 2581 | |
| 2582 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2583 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2584 | return 0; |
| 2585 | } |
| 2586 | |
| 2587 | /** |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 2588 | * i40e_macaddr_init - explicitly write the mac address filters |
| 2589 | * |
| 2590 | * @vsi: pointer to the vsi |
| 2591 | * @macaddr: the MAC address |
| 2592 | * |
| 2593 | * This is needed when the macaddr has been obtained by other |
| 2594 | * means than the default, e.g., from Open Firmware or IDPROM. |
| 2595 | * Returns 0 on success, negative on failure |
| 2596 | **/ |
| 2597 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) |
| 2598 | { |
| 2599 | int ret; |
| 2600 | struct i40e_aqc_add_macvlan_element_data element; |
| 2601 | |
| 2602 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 2603 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 2604 | macaddr, NULL); |
| 2605 | if (ret) { |
| 2606 | dev_info(&vsi->back->pdev->dev, |
| 2607 | "Addr change for VSI failed: %d\n", ret); |
| 2608 | return -EADDRNOTAVAIL; |
| 2609 | } |
| 2610 | |
| 2611 | memset(&element, 0, sizeof(element)); |
| 2612 | ether_addr_copy(element.mac_addr, macaddr); |
| 2613 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 2614 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); |
| 2615 | if (ret) { |
| 2616 | dev_info(&vsi->back->pdev->dev, |
| 2617 | "add filter failed err %s aq_err %s\n", |
| 2618 | i40e_stat_str(&vsi->back->hw, ret), |
| 2619 | i40e_aq_str(&vsi->back->hw, |
| 2620 | vsi->back->hw.aq.asq_last_status)); |
| 2621 | } |
| 2622 | return ret; |
| 2623 | } |
| 2624 | |
| 2625 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2626 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2627 | * @vsi: the vsi being brought back up |
| 2628 | **/ |
| 2629 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2630 | { |
| 2631 | u16 vid; |
| 2632 | |
| 2633 | if (!vsi->netdev) |
| 2634 | return; |
| 2635 | |
| 2636 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2637 | |
| 2638 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2639 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2640 | vid); |
| 2641 | } |
| 2642 | |
| 2643 | /** |
| 2644 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2645 | * @vsi: the vsi being adjusted |
| 2646 | * @vid: the vlan id to set as a PVID |
| 2647 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2648 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2649 | { |
| 2650 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2651 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2652 | |
| 2653 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2654 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2655 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2656 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2657 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2658 | |
| 2659 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2660 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2661 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2662 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2663 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2664 | "add pvid failed, err %s aq_err %s\n", |
| 2665 | i40e_stat_str(&vsi->back->hw, ret), |
| 2666 | i40e_aq_str(&vsi->back->hw, |
| 2667 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2668 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2669 | } |
| 2670 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2671 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | /** |
| 2675 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2676 | * @vsi: the vsi being adjusted |
| 2677 | * |
| 2678 | * Just use the vlan_rx_register() service to put it back to normal |
| 2679 | **/ |
| 2680 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2681 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2682 | i40e_vlan_stripping_disable(vsi); |
| 2683 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2684 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | /** |
| 2688 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2689 | * @vsi: ptr to the VSI |
| 2690 | * |
| 2691 | * If this function returns with an error, then it's possible one or |
| 2692 | * more of the rings is populated (while the rest are not). It is the |
| 2693 | * callers duty to clean those orphaned rings. |
| 2694 | * |
| 2695 | * Return 0 on success, negative on failure |
| 2696 | **/ |
| 2697 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2698 | { |
| 2699 | int i, err = 0; |
| 2700 | |
| 2701 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2702 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2703 | |
| 2704 | return err; |
| 2705 | } |
| 2706 | |
| 2707 | /** |
| 2708 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2709 | * @vsi: ptr to the VSI |
| 2710 | * |
| 2711 | * Free VSI's transmit software resources |
| 2712 | **/ |
| 2713 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2714 | { |
| 2715 | int i; |
| 2716 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2717 | if (!vsi->tx_rings) |
| 2718 | return; |
| 2719 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2720 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2721 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2722 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | /** |
| 2726 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2727 | * @vsi: ptr to the VSI |
| 2728 | * |
| 2729 | * If this function returns with an error, then it's possible one or |
| 2730 | * more of the rings is populated (while the rest are not). It is the |
| 2731 | * callers duty to clean those orphaned rings. |
| 2732 | * |
| 2733 | * Return 0 on success, negative on failure |
| 2734 | **/ |
| 2735 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2736 | { |
| 2737 | int i, err = 0; |
| 2738 | |
| 2739 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2740 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2741 | #ifdef I40E_FCOE |
| 2742 | i40e_fcoe_setup_ddp_resources(vsi); |
| 2743 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2744 | return err; |
| 2745 | } |
| 2746 | |
| 2747 | /** |
| 2748 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2749 | * @vsi: ptr to the VSI |
| 2750 | * |
| 2751 | * Free all receive software resources |
| 2752 | **/ |
| 2753 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2754 | { |
| 2755 | int i; |
| 2756 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2757 | if (!vsi->rx_rings) |
| 2758 | return; |
| 2759 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2760 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2761 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2762 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2763 | #ifdef I40E_FCOE |
| 2764 | i40e_fcoe_free_ddp_resources(vsi); |
| 2765 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2769 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2770 | * @ring: The Tx ring to configure |
| 2771 | * |
| 2772 | * This enables/disables XPS for a given Tx descriptor ring |
| 2773 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2774 | **/ |
| 2775 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2776 | { |
| 2777 | struct i40e_vsi *vsi = ring->vsi; |
| 2778 | cpumask_var_t mask; |
| 2779 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2780 | if (!ring->q_vector || !ring->netdev) |
| 2781 | return; |
| 2782 | |
| 2783 | /* Single TC mode enable XPS */ |
| 2784 | if (vsi->tc_config.numtc <= 1) { |
| 2785 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2786 | netif_set_xps_queue(ring->netdev, |
| 2787 | &ring->q_vector->affinity_mask, |
| 2788 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2789 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2790 | /* Disable XPS to allow selection based on TC */ |
| 2791 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2792 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2793 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2794 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2795 | |
| 2796 | /* schedule our worker thread which will take care of |
| 2797 | * applying the new filter changes |
| 2798 | */ |
| 2799 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2803 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2804 | * @ring: The Tx ring to configure |
| 2805 | * |
| 2806 | * Configure the Tx descriptor ring in the HMC context. |
| 2807 | **/ |
| 2808 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2809 | { |
| 2810 | struct i40e_vsi *vsi = ring->vsi; |
| 2811 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2812 | struct i40e_hw *hw = &vsi->back->hw; |
| 2813 | struct i40e_hmc_obj_txq tx_ctx; |
| 2814 | i40e_status err = 0; |
| 2815 | u32 qtx_ctl = 0; |
| 2816 | |
| 2817 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2818 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2819 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2820 | ring->atr_count = 0; |
| 2821 | } else { |
| 2822 | ring->atr_sample_rate = 0; |
| 2823 | } |
| 2824 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2825 | /* configure XPS */ |
| 2826 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2827 | |
| 2828 | /* clear the context structure first */ |
| 2829 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2830 | |
| 2831 | tx_ctx.new_context = 1; |
| 2832 | tx_ctx.base = (ring->dma / 128); |
| 2833 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2834 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2835 | I40E_FLAG_FD_ATR_ENABLED)); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2836 | #ifdef I40E_FCOE |
| 2837 | tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2838 | #endif |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2839 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2840 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2841 | if (vsi->type != I40E_VSI_FDIR) |
| 2842 | tx_ctx.head_wb_ena = 1; |
| 2843 | tx_ctx.head_wb_addr = ring->dma + |
| 2844 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2845 | |
| 2846 | /* As part of VSI creation/update, FW allocates certain |
| 2847 | * Tx arbitration queue sets for each TC enabled for |
| 2848 | * the VSI. The FW returns the handles to these queue |
| 2849 | * sets as part of the response buffer to Add VSI, |
| 2850 | * Update VSI, etc. AQ commands. It is expected that |
| 2851 | * these queue set handles be associated with the Tx |
| 2852 | * queues by the driver as part of the TX queue context |
| 2853 | * initialization. This has to be done regardless of |
| 2854 | * DCB as by default everything is mapped to TC0. |
| 2855 | */ |
| 2856 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2857 | tx_ctx.rdylist_act = 0; |
| 2858 | |
| 2859 | /* clear the context in the HMC */ |
| 2860 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2861 | if (err) { |
| 2862 | dev_info(&vsi->back->pdev->dev, |
| 2863 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2864 | ring->queue_index, pf_q, err); |
| 2865 | return -ENOMEM; |
| 2866 | } |
| 2867 | |
| 2868 | /* set the context in the HMC */ |
| 2869 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2870 | if (err) { |
| 2871 | dev_info(&vsi->back->pdev->dev, |
| 2872 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2873 | ring->queue_index, pf_q, err); |
| 2874 | return -ENOMEM; |
| 2875 | } |
| 2876 | |
| 2877 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2878 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2879 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2880 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2881 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2882 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2883 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2884 | } |
| 2885 | |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2886 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2887 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2888 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2889 | i40e_flush(hw); |
| 2890 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2891 | /* cache tail off for easier writes later */ |
| 2892 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2893 | |
| 2894 | return 0; |
| 2895 | } |
| 2896 | |
| 2897 | /** |
| 2898 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2899 | * @ring: The Rx ring to configure |
| 2900 | * |
| 2901 | * Configure the Rx descriptor ring in the HMC context. |
| 2902 | **/ |
| 2903 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2904 | { |
| 2905 | struct i40e_vsi *vsi = ring->vsi; |
| 2906 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2907 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2908 | struct i40e_hw *hw = &vsi->back->hw; |
| 2909 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2910 | i40e_status err = 0; |
| 2911 | |
| 2912 | ring->state = 0; |
| 2913 | |
| 2914 | /* clear the context structure first */ |
| 2915 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2916 | |
| 2917 | ring->rx_buf_len = vsi->rx_buf_len; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2918 | |
| 2919 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2920 | |
| 2921 | rx_ctx.base = (ring->dma / 128); |
| 2922 | rx_ctx.qlen = ring->count; |
| 2923 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 2924 | /* use 32 byte descriptors */ |
| 2925 | rx_ctx.dsize = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2926 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 2927 | /* descriptor type is always zero |
| 2928 | * rx_ctx.dtype = 0; |
| 2929 | */ |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 2930 | rx_ctx.hsplit_0 = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2931 | |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 2932 | rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 2933 | if (hw->revision_id == 0) |
| 2934 | rx_ctx.lrxqthresh = 0; |
| 2935 | else |
| 2936 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2937 | rx_ctx.crcstrip = 1; |
| 2938 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 2939 | /* this controls whether VLAN is stripped from inner headers */ |
| 2940 | rx_ctx.showiv = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2941 | #ifdef I40E_FCOE |
| 2942 | rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2943 | #endif |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 2944 | /* set the prefena field to 1 because the manual says to */ |
| 2945 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2946 | |
| 2947 | /* clear the context in the HMC */ |
| 2948 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 2949 | if (err) { |
| 2950 | dev_info(&vsi->back->pdev->dev, |
| 2951 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2952 | ring->queue_index, pf_q, err); |
| 2953 | return -ENOMEM; |
| 2954 | } |
| 2955 | |
| 2956 | /* set the context in the HMC */ |
| 2957 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 2958 | if (err) { |
| 2959 | dev_info(&vsi->back->pdev->dev, |
| 2960 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2961 | ring->queue_index, pf_q, err); |
| 2962 | return -ENOMEM; |
| 2963 | } |
| 2964 | |
| 2965 | /* cache tail for quicker writes, and clear the reg before use */ |
| 2966 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 2967 | writel(0, ring->tail); |
| 2968 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 2969 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2970 | |
| 2971 | return 0; |
| 2972 | } |
| 2973 | |
| 2974 | /** |
| 2975 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 2976 | * @vsi: VSI structure describing this set of rings and resources |
| 2977 | * |
| 2978 | * Configure the Tx VSI for operation. |
| 2979 | **/ |
| 2980 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 2981 | { |
| 2982 | int err = 0; |
| 2983 | u16 i; |
| 2984 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2985 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 2986 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2987 | |
| 2988 | return err; |
| 2989 | } |
| 2990 | |
| 2991 | /** |
| 2992 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 2993 | * @vsi: the VSI being configured |
| 2994 | * |
| 2995 | * Configure the Rx VSI for operation. |
| 2996 | **/ |
| 2997 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 2998 | { |
| 2999 | int err = 0; |
| 3000 | u16 i; |
| 3001 | |
| 3002 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 3003 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 3004 | + ETH_FCS_LEN + VLAN_HLEN; |
| 3005 | else |
| 3006 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 3007 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 3008 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3009 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3010 | #ifdef I40E_FCOE |
| 3011 | /* setup rx buffer for FCoE */ |
| 3012 | if ((vsi->type == I40E_VSI_FCOE) && |
| 3013 | (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) { |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3014 | vsi->rx_buf_len = I40E_RXBUFFER_3072; |
| 3015 | vsi->max_frame = I40E_RXBUFFER_3072; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
| 3018 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3019 | /* round up for the chip's needs */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3020 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3021 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3022 | |
| 3023 | /* set up individual rings */ |
| 3024 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3025 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3026 | |
| 3027 | return err; |
| 3028 | } |
| 3029 | |
| 3030 | /** |
| 3031 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3032 | * @vsi: ptr to the VSI |
| 3033 | **/ |
| 3034 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3035 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3036 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3037 | u16 qoffset, qcount; |
| 3038 | int i, n; |
| 3039 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3040 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3041 | /* Reset the TC information */ |
| 3042 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3043 | rx_ring = vsi->rx_rings[i]; |
| 3044 | tx_ring = vsi->tx_rings[i]; |
| 3045 | rx_ring->dcb_tc = 0; |
| 3046 | tx_ring->dcb_tc = 0; |
| 3047 | } |
| 3048 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3049 | |
| 3050 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3051 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3052 | continue; |
| 3053 | |
| 3054 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3055 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3056 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3057 | rx_ring = vsi->rx_rings[i]; |
| 3058 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3059 | rx_ring->dcb_tc = n; |
| 3060 | tx_ring->dcb_tc = n; |
| 3061 | } |
| 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | /** |
| 3066 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3067 | * @vsi: ptr to the VSI |
| 3068 | **/ |
| 3069 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3070 | { |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 3071 | struct i40e_pf *pf = vsi->back; |
| 3072 | int err; |
| 3073 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3074 | if (vsi->netdev) |
| 3075 | i40e_set_rx_mode(vsi->netdev); |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 3076 | |
| 3077 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 3078 | err = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 3079 | if (err) { |
| 3080 | dev_warn(&pf->pdev->dev, |
| 3081 | "could not set up macaddr; err %d\n", err); |
| 3082 | } |
| 3083 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3084 | } |
| 3085 | |
| 3086 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3087 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3088 | * @vsi: Pointer to the targeted VSI |
| 3089 | * |
| 3090 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3091 | * filters were saved. |
| 3092 | **/ |
| 3093 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3094 | { |
| 3095 | struct i40e_fdir_filter *filter; |
| 3096 | struct i40e_pf *pf = vsi->back; |
| 3097 | struct hlist_node *node; |
| 3098 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3099 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3100 | return; |
| 3101 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3102 | hlist_for_each_entry_safe(filter, node, |
| 3103 | &pf->fdir_filter_list, fdir_node) { |
| 3104 | i40e_add_del_fdir(vsi, filter, true); |
| 3105 | } |
| 3106 | } |
| 3107 | |
| 3108 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3109 | * i40e_vsi_configure - Set up the VSI for action |
| 3110 | * @vsi: the VSI being configured |
| 3111 | **/ |
| 3112 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3113 | { |
| 3114 | int err; |
| 3115 | |
| 3116 | i40e_set_vsi_rx_mode(vsi); |
| 3117 | i40e_restore_vlan(vsi); |
| 3118 | i40e_vsi_config_dcb_rings(vsi); |
| 3119 | err = i40e_vsi_configure_tx(vsi); |
| 3120 | if (!err) |
| 3121 | err = i40e_vsi_configure_rx(vsi); |
| 3122 | |
| 3123 | return err; |
| 3124 | } |
| 3125 | |
| 3126 | /** |
| 3127 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3128 | * @vsi: the VSI being configured |
| 3129 | **/ |
| 3130 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3131 | { |
| 3132 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3133 | struct i40e_hw *hw = &pf->hw; |
| 3134 | u16 vector; |
| 3135 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3136 | u32 qp; |
| 3137 | |
| 3138 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3139 | * and PFINT_LNKLSTn registers, e.g.: |
| 3140 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3141 | */ |
| 3142 | qp = vsi->base_queue; |
| 3143 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3144 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3145 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3146 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3147 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3148 | 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] | 3149 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3150 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3151 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3152 | 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] | 3153 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3154 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3155 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3156 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
| 3157 | INTRL_USEC_TO_REG(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3158 | |
| 3159 | /* Linked list for the queuepairs assigned to this vector */ |
| 3160 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3161 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3162 | u32 val; |
| 3163 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3164 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3165 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3166 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3167 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 3168 | (I40E_QUEUE_TYPE_TX |
| 3169 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 3170 | |
| 3171 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3172 | |
| 3173 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3174 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3175 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3176 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 3177 | (I40E_QUEUE_TYPE_RX |
| 3178 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3179 | |
| 3180 | /* Terminate the linked list */ |
| 3181 | if (q == (q_vector->num_ringpairs - 1)) |
| 3182 | val |= (I40E_QUEUE_END_OF_LIST |
| 3183 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3184 | |
| 3185 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3186 | qp++; |
| 3187 | } |
| 3188 | } |
| 3189 | |
| 3190 | i40e_flush(hw); |
| 3191 | } |
| 3192 | |
| 3193 | /** |
| 3194 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3195 | * @hw: ptr to the hardware info |
| 3196 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3197 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3198 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3199 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3200 | u32 val; |
| 3201 | |
| 3202 | /* clear things first */ |
| 3203 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3204 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3205 | |
| 3206 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3207 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3208 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3209 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3210 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3211 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3212 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3213 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3214 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3215 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3216 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3217 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3218 | if (pf->flags & I40E_FLAG_PTP) |
| 3219 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3220 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3221 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3222 | |
| 3223 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3224 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3225 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3226 | |
| 3227 | /* OTHER_ITR_IDX = 0 */ |
| 3228 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3229 | } |
| 3230 | |
| 3231 | /** |
| 3232 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3233 | * @vsi: the VSI being configured |
| 3234 | **/ |
| 3235 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3236 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3237 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3238 | struct i40e_pf *pf = vsi->back; |
| 3239 | struct i40e_hw *hw = &pf->hw; |
| 3240 | u32 val; |
| 3241 | |
| 3242 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3243 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3244 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3245 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3246 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3247 | 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] | 3248 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3249 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3250 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3251 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3252 | |
| 3253 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3254 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3255 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3256 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3257 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3258 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3259 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3260 | |
| 3261 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3262 | |
| 3263 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3264 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3265 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3266 | |
| 3267 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3268 | i40e_flush(hw); |
| 3269 | } |
| 3270 | |
| 3271 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3272 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3273 | * @pf: board private structure |
| 3274 | **/ |
| 3275 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3276 | { |
| 3277 | struct i40e_hw *hw = &pf->hw; |
| 3278 | |
| 3279 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3280 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3281 | i40e_flush(hw); |
| 3282 | } |
| 3283 | |
| 3284 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3285 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3286 | * @pf: board private structure |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3287 | * @clearpba: true when all pending interrupt events should be cleared |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3288 | **/ |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3289 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3290 | { |
| 3291 | struct i40e_hw *hw = &pf->hw; |
| 3292 | u32 val; |
| 3293 | |
| 3294 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3295 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3296 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3297 | |
| 3298 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3299 | i40e_flush(hw); |
| 3300 | } |
| 3301 | |
| 3302 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3303 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3304 | * @irq: interrupt number |
| 3305 | * @data: pointer to a q_vector |
| 3306 | **/ |
| 3307 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3308 | { |
| 3309 | struct i40e_q_vector *q_vector = data; |
| 3310 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3311 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3312 | return IRQ_HANDLED; |
| 3313 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3314 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3315 | |
| 3316 | return IRQ_HANDLED; |
| 3317 | } |
| 3318 | |
| 3319 | /** |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3320 | * i40e_irq_affinity_notify - Callback for affinity changes |
| 3321 | * @notify: context as to what irq was changed |
| 3322 | * @mask: the new affinity mask |
| 3323 | * |
| 3324 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3325 | * so that we may register to receive changes to the irq affinity masks. |
| 3326 | **/ |
| 3327 | static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify, |
| 3328 | const cpumask_t *mask) |
| 3329 | { |
| 3330 | struct i40e_q_vector *q_vector = |
| 3331 | container_of(notify, struct i40e_q_vector, affinity_notify); |
| 3332 | |
| 3333 | q_vector->affinity_mask = *mask; |
| 3334 | } |
| 3335 | |
| 3336 | /** |
| 3337 | * i40e_irq_affinity_release - Callback for affinity notifier release |
| 3338 | * @ref: internal core kernel usage |
| 3339 | * |
| 3340 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3341 | * to inform the current notification subscriber that they will no longer |
| 3342 | * receive notifications. |
| 3343 | **/ |
| 3344 | static void i40e_irq_affinity_release(struct kref *ref) {} |
| 3345 | |
| 3346 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3347 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3348 | * @vsi: the VSI being configured |
| 3349 | * @basename: name for the vector |
| 3350 | * |
| 3351 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3352 | **/ |
| 3353 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3354 | { |
| 3355 | int q_vectors = vsi->num_q_vectors; |
| 3356 | struct i40e_pf *pf = vsi->back; |
| 3357 | int base = vsi->base_vector; |
| 3358 | int rx_int_idx = 0; |
| 3359 | int tx_int_idx = 0; |
| 3360 | int vector, err; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3361 | int irq_num; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3362 | |
| 3363 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3364 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3365 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3366 | irq_num = pf->msix_entries[base + vector].vector; |
| 3367 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3368 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3369 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3370 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3371 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3372 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3373 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3374 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3375 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3376 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3377 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3378 | } else { |
| 3379 | /* skip this unused q_vector */ |
| 3380 | continue; |
| 3381 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3382 | err = request_irq(irq_num, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3383 | vsi->irq_handler, |
| 3384 | 0, |
| 3385 | q_vector->name, |
| 3386 | q_vector); |
| 3387 | if (err) { |
| 3388 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3389 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3390 | goto free_queue_irqs; |
| 3391 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3392 | |
| 3393 | /* register for affinity change notifications */ |
| 3394 | q_vector->affinity_notify.notify = i40e_irq_affinity_notify; |
| 3395 | q_vector->affinity_notify.release = i40e_irq_affinity_release; |
| 3396 | irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3397 | /* assign the mask for this irq */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3398 | irq_set_affinity_hint(irq_num, &q_vector->affinity_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3399 | } |
| 3400 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3401 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3402 | return 0; |
| 3403 | |
| 3404 | free_queue_irqs: |
| 3405 | while (vector) { |
| 3406 | vector--; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3407 | irq_num = pf->msix_entries[base + vector].vector; |
| 3408 | irq_set_affinity_notifier(irq_num, NULL); |
| 3409 | irq_set_affinity_hint(irq_num, NULL); |
| 3410 | free_irq(irq_num, &vsi->q_vectors[vector]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3411 | } |
| 3412 | return err; |
| 3413 | } |
| 3414 | |
| 3415 | /** |
| 3416 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3417 | * @vsi: the VSI being un-configured |
| 3418 | **/ |
| 3419 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3420 | { |
| 3421 | struct i40e_pf *pf = vsi->back; |
| 3422 | struct i40e_hw *hw = &pf->hw; |
| 3423 | int base = vsi->base_vector; |
| 3424 | int i; |
| 3425 | |
| 3426 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3427 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3428 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3429 | } |
| 3430 | |
| 3431 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3432 | for (i = vsi->base_vector; |
| 3433 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3434 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3435 | |
| 3436 | i40e_flush(hw); |
| 3437 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3438 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3439 | } else { |
| 3440 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3441 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3442 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3443 | i40e_flush(hw); |
| 3444 | synchronize_irq(pf->pdev->irq); |
| 3445 | } |
| 3446 | } |
| 3447 | |
| 3448 | /** |
| 3449 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3450 | * @vsi: the VSI being configured |
| 3451 | **/ |
| 3452 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3453 | { |
| 3454 | struct i40e_pf *pf = vsi->back; |
| 3455 | int i; |
| 3456 | |
| 3457 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3458 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3459 | i40e_irq_dynamic_enable(vsi, i); |
| 3460 | } else { |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3461 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3462 | } |
| 3463 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3464 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3465 | return 0; |
| 3466 | } |
| 3467 | |
| 3468 | /** |
| 3469 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3470 | * @pf: board private structure |
| 3471 | **/ |
| 3472 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3473 | { |
| 3474 | /* Disable ICR 0 */ |
| 3475 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3476 | i40e_flush(&pf->hw); |
| 3477 | } |
| 3478 | |
| 3479 | /** |
| 3480 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3481 | * @irq: interrupt number |
| 3482 | * @data: pointer to a q_vector |
| 3483 | * |
| 3484 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3485 | * with both queue and non-queue interrupts. This is also used in |
| 3486 | * MSIX mode to handle the non-queue interrupts. |
| 3487 | **/ |
| 3488 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3489 | { |
| 3490 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3491 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3492 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3493 | u32 icr0, icr0_remaining; |
| 3494 | u32 val, ena_mask; |
| 3495 | |
| 3496 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3497 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3498 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3499 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3500 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3501 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3502 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3503 | /* if interrupt but no bits showing, must be SWINT */ |
| 3504 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3505 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3506 | pf->sw_int_count++; |
| 3507 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3508 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 3509 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
| 3510 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3511 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3512 | dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
| 3513 | } |
| 3514 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3515 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3516 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3517 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3518 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3519 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3520 | /* We do not have a way to disarm Queue causes while leaving |
| 3521 | * interrupt enabled for all other causes, ideally |
| 3522 | * interrupt should be disabled while we are in NAPI but |
| 3523 | * this is not a performance path and napi_schedule() |
| 3524 | * can deal with rescheduling. |
| 3525 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3526 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3527 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3528 | } |
| 3529 | |
| 3530 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3531 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3532 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3533 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3534 | } |
| 3535 | |
| 3536 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3537 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3538 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3539 | } |
| 3540 | |
| 3541 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3542 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3543 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3544 | } |
| 3545 | |
| 3546 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3547 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3548 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3549 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3550 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3551 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3552 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3553 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3554 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3555 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3556 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3557 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3558 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3559 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3560 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3561 | } |
| 3562 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3563 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3564 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3565 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3566 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3567 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3568 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3569 | } |
| 3570 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3571 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3572 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3573 | |
| 3574 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3575 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3576 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3577 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3578 | } |
| 3579 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3580 | /* If a critical error is pending we have no choice but to reset the |
| 3581 | * device. |
| 3582 | * Report and mask out any remaining unexpected interrupts. |
| 3583 | */ |
| 3584 | icr0_remaining = icr0 & ena_mask; |
| 3585 | if (icr0_remaining) { |
| 3586 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3587 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3588 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3589 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3590 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3591 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3592 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3593 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3594 | } |
| 3595 | ena_mask &= ~icr0_remaining; |
| 3596 | } |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3597 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3598 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3599 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3600 | /* re-enable interrupt causes */ |
| 3601 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3602 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3603 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3604 | i40e_irq_dynamic_enable_icr0(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3605 | } |
| 3606 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3607 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3611 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3612 | * @tx_ring: tx ring to clean |
| 3613 | * @budget: how many cleans we're allowed |
| 3614 | * |
| 3615 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3616 | **/ |
| 3617 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3618 | { |
| 3619 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3620 | u16 i = tx_ring->next_to_clean; |
| 3621 | struct i40e_tx_buffer *tx_buf; |
| 3622 | struct i40e_tx_desc *tx_desc; |
| 3623 | |
| 3624 | tx_buf = &tx_ring->tx_bi[i]; |
| 3625 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3626 | i -= tx_ring->count; |
| 3627 | |
| 3628 | do { |
| 3629 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3630 | |
| 3631 | /* if next_to_watch is not set then there is no work pending */ |
| 3632 | if (!eop_desc) |
| 3633 | break; |
| 3634 | |
| 3635 | /* prevent any other reads prior to eop_desc */ |
| 3636 | read_barrier_depends(); |
| 3637 | |
| 3638 | /* if the descriptor isn't done, no work yet to do */ |
| 3639 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3640 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3641 | break; |
| 3642 | |
| 3643 | /* clear next_to_watch to prevent false hangs */ |
| 3644 | tx_buf->next_to_watch = NULL; |
| 3645 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3646 | tx_desc->buffer_addr = 0; |
| 3647 | tx_desc->cmd_type_offset_bsz = 0; |
| 3648 | /* move past filter desc */ |
| 3649 | tx_buf++; |
| 3650 | tx_desc++; |
| 3651 | i++; |
| 3652 | if (unlikely(!i)) { |
| 3653 | i -= tx_ring->count; |
| 3654 | tx_buf = tx_ring->tx_bi; |
| 3655 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3656 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3657 | /* unmap skb header data */ |
| 3658 | dma_unmap_single(tx_ring->dev, |
| 3659 | dma_unmap_addr(tx_buf, dma), |
| 3660 | dma_unmap_len(tx_buf, len), |
| 3661 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3662 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3663 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3664 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3665 | tx_buf->raw_buf = NULL; |
| 3666 | tx_buf->tx_flags = 0; |
| 3667 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3668 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3669 | tx_desc->buffer_addr = 0; |
| 3670 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3671 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3672 | /* 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] | 3673 | tx_buf++; |
| 3674 | tx_desc++; |
| 3675 | i++; |
| 3676 | if (unlikely(!i)) { |
| 3677 | i -= tx_ring->count; |
| 3678 | tx_buf = tx_ring->tx_bi; |
| 3679 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3680 | } |
| 3681 | |
| 3682 | /* update budget accounting */ |
| 3683 | budget--; |
| 3684 | } while (likely(budget)); |
| 3685 | |
| 3686 | i += tx_ring->count; |
| 3687 | tx_ring->next_to_clean = i; |
| 3688 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3689 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3690 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3691 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3692 | return budget > 0; |
| 3693 | } |
| 3694 | |
| 3695 | /** |
| 3696 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3697 | * @irq: interrupt number |
| 3698 | * @data: pointer to a q_vector |
| 3699 | **/ |
| 3700 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3701 | { |
| 3702 | struct i40e_q_vector *q_vector = data; |
| 3703 | struct i40e_vsi *vsi; |
| 3704 | |
| 3705 | if (!q_vector->tx.ring) |
| 3706 | return IRQ_HANDLED; |
| 3707 | |
| 3708 | vsi = q_vector->tx.ring->vsi; |
| 3709 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3710 | |
| 3711 | return IRQ_HANDLED; |
| 3712 | } |
| 3713 | |
| 3714 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3715 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3716 | * @vsi: the VSI being configured |
| 3717 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3718 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3719 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3720 | 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] | 3721 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3722 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3723 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3724 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3725 | |
| 3726 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3727 | tx_ring->next = q_vector->tx.ring; |
| 3728 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3729 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3730 | |
| 3731 | rx_ring->q_vector = q_vector; |
| 3732 | rx_ring->next = q_vector->rx.ring; |
| 3733 | q_vector->rx.ring = rx_ring; |
| 3734 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3735 | } |
| 3736 | |
| 3737 | /** |
| 3738 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3739 | * @vsi: the VSI being configured |
| 3740 | * |
| 3741 | * This function maps descriptor rings to the queue-specific vectors |
| 3742 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3743 | * one vector per queue pair, but on a constrained vector budget, we |
| 3744 | * group the queue pairs as "efficiently" as possible. |
| 3745 | **/ |
| 3746 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3747 | { |
| 3748 | int qp_remaining = vsi->num_queue_pairs; |
| 3749 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3750 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3751 | int v_start = 0; |
| 3752 | int qp_idx = 0; |
| 3753 | |
| 3754 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3755 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3756 | * It is also important to go through all the vectors available to be |
| 3757 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3758 | * are cleared. This is especially important when decreasing the |
| 3759 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3760 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3761 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3762 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3763 | |
| 3764 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3765 | |
| 3766 | q_vector->num_ringpairs = num_ringpairs; |
| 3767 | |
| 3768 | q_vector->rx.count = 0; |
| 3769 | q_vector->tx.count = 0; |
| 3770 | q_vector->rx.ring = NULL; |
| 3771 | q_vector->tx.ring = NULL; |
| 3772 | |
| 3773 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3774 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3775 | qp_idx++; |
| 3776 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3777 | } |
| 3778 | } |
| 3779 | } |
| 3780 | |
| 3781 | /** |
| 3782 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3783 | * @vsi: the VSI being configured |
| 3784 | * @basename: name for the vector |
| 3785 | **/ |
| 3786 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3787 | { |
| 3788 | struct i40e_pf *pf = vsi->back; |
| 3789 | int err; |
| 3790 | |
| 3791 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3792 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3793 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3794 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3795 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3796 | else |
| 3797 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3798 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3799 | |
| 3800 | if (err) |
| 3801 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3802 | |
| 3803 | return err; |
| 3804 | } |
| 3805 | |
| 3806 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3807 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3808 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3809 | * @netdev: network interface device structure |
| 3810 | * |
| 3811 | * This is used by netconsole to send skbs without having to re-enable |
| 3812 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3813 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3814 | #ifdef I40E_FCOE |
| 3815 | void i40e_netpoll(struct net_device *netdev) |
| 3816 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3817 | static void i40e_netpoll(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3818 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3819 | { |
| 3820 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3821 | struct i40e_vsi *vsi = np->vsi; |
| 3822 | struct i40e_pf *pf = vsi->back; |
| 3823 | int i; |
| 3824 | |
| 3825 | /* if interface is down do nothing */ |
| 3826 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3827 | return; |
| 3828 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3829 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3830 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3831 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3832 | } else { |
| 3833 | i40e_intr(pf->pdev->irq, netdev); |
| 3834 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3835 | } |
| 3836 | #endif |
| 3837 | |
| 3838 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3839 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3840 | * @pf: the PF being configured |
| 3841 | * @pf_q: the PF queue |
| 3842 | * @enable: enable or disable state of the queue |
| 3843 | * |
| 3844 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3845 | * enabled or disabled state. |
| 3846 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3847 | * multiple retries; else will return 0 in case of success. |
| 3848 | **/ |
| 3849 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3850 | { |
| 3851 | int i; |
| 3852 | u32 tx_reg; |
| 3853 | |
| 3854 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3855 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3856 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3857 | break; |
| 3858 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3859 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3860 | } |
| 3861 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3862 | return -ETIMEDOUT; |
| 3863 | |
| 3864 | return 0; |
| 3865 | } |
| 3866 | |
| 3867 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3868 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3869 | * @vsi: the VSI being configured |
| 3870 | * @enable: start or stop the rings |
| 3871 | **/ |
| 3872 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3873 | { |
| 3874 | struct i40e_pf *pf = vsi->back; |
| 3875 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3876 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3877 | u32 tx_reg; |
| 3878 | |
| 3879 | pf_q = vsi->base_queue; |
| 3880 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3881 | |
| 3882 | /* warn the TX unit of coming changes */ |
| 3883 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3884 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3885 | usleep_range(10, 20); |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3886 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3887 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3888 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3889 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3890 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3891 | break; |
| 3892 | usleep_range(1000, 2000); |
| 3893 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3894 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3895 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3896 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3897 | |
| 3898 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3899 | if (enable) { |
| 3900 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3901 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3902 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3903 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3904 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3905 | |
| 3906 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 3907 | /* No waiting for the Tx queue to disable */ |
| 3908 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3909 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3910 | |
| 3911 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3912 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 3913 | if (ret) { |
| 3914 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3915 | "VSI seid %d Tx ring %d %sable timeout\n", |
| 3916 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3917 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3918 | } |
| 3919 | } |
| 3920 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3921 | if (hw->revision_id == 0) |
| 3922 | mdelay(50); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3923 | return ret; |
| 3924 | } |
| 3925 | |
| 3926 | /** |
| 3927 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 3928 | * @pf: the PF being configured |
| 3929 | * @pf_q: the PF queue |
| 3930 | * @enable: enable or disable state of the queue |
| 3931 | * |
| 3932 | * This routine will wait for the given Rx queue of the PF to reach the |
| 3933 | * enabled or disabled state. |
| 3934 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3935 | * multiple retries; else will return 0 in case of success. |
| 3936 | **/ |
| 3937 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3938 | { |
| 3939 | int i; |
| 3940 | u32 rx_reg; |
| 3941 | |
| 3942 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3943 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 3944 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3945 | break; |
| 3946 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3947 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3948 | } |
| 3949 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3950 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3951 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3952 | return 0; |
| 3953 | } |
| 3954 | |
| 3955 | /** |
| 3956 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 3957 | * @vsi: the VSI being configured |
| 3958 | * @enable: start or stop the rings |
| 3959 | **/ |
| 3960 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 3961 | { |
| 3962 | struct i40e_pf *pf = vsi->back; |
| 3963 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3964 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3965 | u32 rx_reg; |
| 3966 | |
| 3967 | pf_q = vsi->base_queue; |
| 3968 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3969 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3970 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3971 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3972 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3973 | break; |
| 3974 | usleep_range(1000, 2000); |
| 3975 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3976 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3977 | /* Skip if the queue is already in the requested state */ |
| 3978 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3979 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3980 | |
| 3981 | /* turn on/off the queue */ |
| 3982 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3983 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3984 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3985 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3986 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 3987 | /* No waiting for the Tx queue to disable */ |
| 3988 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3989 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3990 | |
| 3991 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3992 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 3993 | if (ret) { |
| 3994 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3995 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 3996 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3997 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3998 | } |
| 3999 | } |
| 4000 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4001 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4002 | } |
| 4003 | |
| 4004 | /** |
| 4005 | * i40e_vsi_control_rings - Start or stop a VSI's rings |
| 4006 | * @vsi: the VSI being configured |
| 4007 | * @enable: start or stop the rings |
| 4008 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 4009 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4010 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 4011 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4012 | |
| 4013 | /* do rx first for enable and last for disable */ |
| 4014 | if (request) { |
| 4015 | ret = i40e_vsi_control_rx(vsi, request); |
| 4016 | if (ret) |
| 4017 | return ret; |
| 4018 | ret = i40e_vsi_control_tx(vsi, request); |
| 4019 | } else { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 4020 | /* Ignore return value, we need to shutdown whatever we can */ |
| 4021 | i40e_vsi_control_tx(vsi, request); |
| 4022 | i40e_vsi_control_rx(vsi, request); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4023 | } |
| 4024 | |
| 4025 | return ret; |
| 4026 | } |
| 4027 | |
| 4028 | /** |
| 4029 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 4030 | * @vsi: the VSI being configured |
| 4031 | **/ |
| 4032 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 4033 | { |
| 4034 | struct i40e_pf *pf = vsi->back; |
| 4035 | struct i40e_hw *hw = &pf->hw; |
| 4036 | int base = vsi->base_vector; |
| 4037 | u32 val, qp; |
| 4038 | int i; |
| 4039 | |
| 4040 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4041 | if (!vsi->q_vectors) |
| 4042 | return; |
| 4043 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 4044 | if (!vsi->irqs_ready) |
| 4045 | return; |
| 4046 | |
| 4047 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4048 | for (i = 0; i < vsi->num_q_vectors; i++) { |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4049 | int irq_num; |
| 4050 | u16 vector; |
| 4051 | |
| 4052 | vector = i + base; |
| 4053 | irq_num = pf->msix_entries[vector].vector; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4054 | |
| 4055 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 4056 | if (!vsi->q_vectors[i] || |
| 4057 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4058 | continue; |
| 4059 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4060 | /* clear the affinity notifier in the IRQ descriptor */ |
| 4061 | irq_set_affinity_notifier(irq_num, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4062 | /* clear the affinity_mask in the IRQ descriptor */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4063 | irq_set_affinity_hint(irq_num, NULL); |
| 4064 | synchronize_irq(irq_num); |
| 4065 | free_irq(irq_num, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4066 | |
| 4067 | /* Tear down the interrupt queue link list |
| 4068 | * |
| 4069 | * We know that they come in pairs and always |
| 4070 | * the Rx first, then the Tx. To clear the |
| 4071 | * link list, stick the EOL value into the |
| 4072 | * next_q field of the registers. |
| 4073 | */ |
| 4074 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4075 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4076 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4077 | val |= I40E_QUEUE_END_OF_LIST |
| 4078 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4079 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4080 | |
| 4081 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4082 | u32 next; |
| 4083 | |
| 4084 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4085 | |
| 4086 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4087 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4088 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4089 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4090 | |
| 4091 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4092 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4093 | |
| 4094 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4095 | |
| 4096 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4097 | |
| 4098 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4099 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4100 | |
| 4101 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4102 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4103 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4104 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4105 | |
| 4106 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4107 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4108 | |
| 4109 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4110 | qp = next; |
| 4111 | } |
| 4112 | } |
| 4113 | } else { |
| 4114 | free_irq(pf->pdev->irq, pf); |
| 4115 | |
| 4116 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4117 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4118 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4119 | val |= I40E_QUEUE_END_OF_LIST |
| 4120 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4121 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4122 | |
| 4123 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4124 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4125 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4126 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4127 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4128 | |
| 4129 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4130 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4131 | |
| 4132 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4133 | |
| 4134 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4135 | |
| 4136 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4137 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4138 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4139 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4140 | |
| 4141 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4142 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4143 | |
| 4144 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4145 | } |
| 4146 | } |
| 4147 | |
| 4148 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4149 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4150 | * @vsi: the VSI being configured |
| 4151 | * @v_idx: Index of vector to be freed |
| 4152 | * |
| 4153 | * This function frees the memory allocated to the q_vector. In addition if |
| 4154 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4155 | * to freeing the q_vector. |
| 4156 | **/ |
| 4157 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4158 | { |
| 4159 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4160 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4161 | |
| 4162 | if (!q_vector) |
| 4163 | return; |
| 4164 | |
| 4165 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4166 | i40e_for_each_ring(ring, q_vector->tx) |
| 4167 | ring->q_vector = NULL; |
| 4168 | |
| 4169 | i40e_for_each_ring(ring, q_vector->rx) |
| 4170 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4171 | |
| 4172 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4173 | if (vsi->netdev) |
| 4174 | netif_napi_del(&q_vector->napi); |
| 4175 | |
| 4176 | vsi->q_vectors[v_idx] = NULL; |
| 4177 | |
| 4178 | kfree_rcu(q_vector, rcu); |
| 4179 | } |
| 4180 | |
| 4181 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4182 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4183 | * @vsi: the VSI being un-configured |
| 4184 | * |
| 4185 | * This frees the memory allocated to the q_vectors and |
| 4186 | * deletes references to the NAPI struct. |
| 4187 | **/ |
| 4188 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4189 | { |
| 4190 | int v_idx; |
| 4191 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4192 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4193 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | /** |
| 4197 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4198 | * @pf: board private structure |
| 4199 | **/ |
| 4200 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4201 | { |
| 4202 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4203 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4204 | pci_disable_msix(pf->pdev); |
| 4205 | kfree(pf->msix_entries); |
| 4206 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4207 | kfree(pf->irq_pile); |
| 4208 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4209 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4210 | pci_disable_msi(pf->pdev); |
| 4211 | } |
| 4212 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4213 | } |
| 4214 | |
| 4215 | /** |
| 4216 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4217 | * @pf: board private structure |
| 4218 | * |
| 4219 | * We go through and clear interrupt specific resources and reset the structure |
| 4220 | * to pre-load conditions |
| 4221 | **/ |
| 4222 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4223 | { |
| 4224 | int i; |
| 4225 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4226 | i40e_stop_misc_vector(pf); |
Shannon Nelson | 6927839 | 2016-03-10 14:59:43 -0800 | [diff] [blame] | 4227 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4228 | synchronize_irq(pf->msix_entries[0].vector); |
| 4229 | free_irq(pf->msix_entries[0].vector, pf); |
| 4230 | } |
| 4231 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4232 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4233 | I40E_IWARP_IRQ_PILE_ID); |
| 4234 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4235 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4236 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4237 | if (pf->vsi[i]) |
| 4238 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4239 | i40e_reset_interrupt_capability(pf); |
| 4240 | } |
| 4241 | |
| 4242 | /** |
| 4243 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4244 | * @vsi: the VSI being configured |
| 4245 | **/ |
| 4246 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4247 | { |
| 4248 | int q_idx; |
| 4249 | |
| 4250 | if (!vsi->netdev) |
| 4251 | return; |
| 4252 | |
| 4253 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4254 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | /** |
| 4258 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4259 | * @vsi: the VSI being configured |
| 4260 | **/ |
| 4261 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4262 | { |
| 4263 | int q_idx; |
| 4264 | |
| 4265 | if (!vsi->netdev) |
| 4266 | return; |
| 4267 | |
| 4268 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4269 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4273 | * i40e_vsi_close - Shut down a VSI |
| 4274 | * @vsi: the vsi to be quelled |
| 4275 | **/ |
| 4276 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4277 | { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4278 | bool reset = false; |
| 4279 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4280 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4281 | i40e_down(vsi); |
| 4282 | i40e_vsi_free_irq(vsi); |
| 4283 | i40e_vsi_free_tx_resources(vsi); |
| 4284 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4285 | vsi->current_netdev_flags = 0; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4286 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4287 | reset = true; |
| 4288 | i40e_notify_client_of_netdev_close(vsi, reset); |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4289 | } |
| 4290 | |
| 4291 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4292 | * i40e_quiesce_vsi - Pause a given VSI |
| 4293 | * @vsi: the VSI being paused |
| 4294 | **/ |
| 4295 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4296 | { |
| 4297 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4298 | return; |
| 4299 | |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4300 | /* No need to disable FCoE VSI when Tx suspended */ |
| 4301 | if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) && |
| 4302 | vsi->type == I40E_VSI_FCOE) { |
| 4303 | dev_dbg(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4304 | "VSI seid %d skipping FCoE VSI disable\n", vsi->seid); |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4305 | return; |
| 4306 | } |
| 4307 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4308 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4309 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4310 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4311 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4312 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | /** |
| 4316 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4317 | * @vsi: the VSI being resumed |
| 4318 | **/ |
| 4319 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4320 | { |
| 4321 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 4322 | return; |
| 4323 | |
| 4324 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4325 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4326 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4327 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4328 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4329 | } |
| 4330 | |
| 4331 | /** |
| 4332 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4333 | * @pf: the PF |
| 4334 | **/ |
| 4335 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4336 | { |
| 4337 | int v; |
| 4338 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4339 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4340 | if (pf->vsi[v]) |
| 4341 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4342 | } |
| 4343 | } |
| 4344 | |
| 4345 | /** |
| 4346 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4347 | * @pf: the PF |
| 4348 | **/ |
| 4349 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4350 | { |
| 4351 | int v; |
| 4352 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4353 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4354 | if (pf->vsi[v]) |
| 4355 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4356 | } |
| 4357 | } |
| 4358 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4359 | #ifdef CONFIG_I40E_DCB |
| 4360 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4361 | * 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] | 4362 | * @vsi: the VSI being configured |
| 4363 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4364 | * This function waits for the given VSI's queues to be disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4365 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4366 | static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4367 | { |
| 4368 | struct i40e_pf *pf = vsi->back; |
| 4369 | int i, pf_q, ret; |
| 4370 | |
| 4371 | pf_q = vsi->base_queue; |
| 4372 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4373 | /* Check and wait for the disable status of the queue */ |
| 4374 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4375 | if (ret) { |
| 4376 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4377 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4378 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4379 | return ret; |
| 4380 | } |
| 4381 | } |
| 4382 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4383 | pf_q = vsi->base_queue; |
| 4384 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4385 | /* Check and wait for the disable status of the queue */ |
| 4386 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4387 | if (ret) { |
| 4388 | dev_info(&pf->pdev->dev, |
| 4389 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4390 | vsi->seid, pf_q); |
| 4391 | return ret; |
| 4392 | } |
| 4393 | } |
| 4394 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4395 | return 0; |
| 4396 | } |
| 4397 | |
| 4398 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4399 | * 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] | 4400 | * @pf: the PF |
| 4401 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4402 | * 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] | 4403 | * VSIs that are managed by this PF. |
| 4404 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4405 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4406 | { |
| 4407 | int v, ret = 0; |
| 4408 | |
| 4409 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4410 | /* No need to wait for FCoE VSI queues */ |
| 4411 | if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4412 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4413 | if (ret) |
| 4414 | break; |
| 4415 | } |
| 4416 | } |
| 4417 | |
| 4418 | return ret; |
| 4419 | } |
| 4420 | |
| 4421 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4422 | |
| 4423 | /** |
| 4424 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4425 | * @q_idx: TX queue number |
| 4426 | * @vsi: Pointer to VSI struct |
| 4427 | * |
| 4428 | * This function checks specified queue for given VSI. Detects hung condition. |
| 4429 | * Sets hung bit since it is two step process. Before next run of service task |
| 4430 | * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not, |
| 4431 | * hung condition remain unchanged and during subsequent run, this function |
| 4432 | * issues SW interrupt to recover from hung condition. |
| 4433 | **/ |
| 4434 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4435 | { |
| 4436 | struct i40e_ring *tx_ring = NULL; |
| 4437 | struct i40e_pf *pf; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4438 | u32 head, val, tx_pending_hw; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4439 | int i; |
| 4440 | |
| 4441 | pf = vsi->back; |
| 4442 | |
| 4443 | /* now that we have an index, find the tx_ring struct */ |
| 4444 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4445 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4446 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4447 | tx_ring = vsi->tx_rings[i]; |
| 4448 | break; |
| 4449 | } |
| 4450 | } |
| 4451 | } |
| 4452 | |
| 4453 | if (!tx_ring) |
| 4454 | return; |
| 4455 | |
| 4456 | /* Read interrupt register */ |
| 4457 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4458 | val = rd32(&pf->hw, |
| 4459 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4460 | tx_ring->vsi->base_vector - 1)); |
| 4461 | else |
| 4462 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4463 | |
| 4464 | head = i40e_get_head(tx_ring); |
| 4465 | |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4466 | tx_pending_hw = i40e_get_tx_pending(tx_ring, false); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4467 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4468 | /* HW is done executing descriptors, updated HEAD write back, |
| 4469 | * but SW hasn't processed those descriptors. If interrupt is |
| 4470 | * not generated from this point ON, it could result into |
| 4471 | * dev_watchdog detecting timeout on those netdev_queue, |
| 4472 | * hence proactively trigger SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4473 | */ |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4474 | if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4475 | /* NAPI Poll didn't run and clear since it was set */ |
| 4476 | if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4477 | &tx_ring->q_vector->hung_detected)) { |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4478 | 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", |
| 4479 | vsi->seid, q_idx, tx_pending_hw, |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4480 | tx_ring->next_to_clean, head, |
| 4481 | tx_ring->next_to_use, |
| 4482 | readl(tx_ring->tail)); |
| 4483 | netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n", |
| 4484 | vsi->seid, q_idx, val); |
| 4485 | i40e_force_wb(vsi, tx_ring->q_vector); |
| 4486 | } else { |
| 4487 | /* First Chance - detected possible hung */ |
| 4488 | set_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4489 | &tx_ring->q_vector->hung_detected); |
| 4490 | } |
| 4491 | } |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4492 | |
| 4493 | /* This is the case where we have interrupts missing, |
| 4494 | * so the tx_pending in HW will most likely be 0, but we |
| 4495 | * will have tx_pending in SW since the WB happened but the |
| 4496 | * interrupt got lost. |
| 4497 | */ |
| 4498 | if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) && |
| 4499 | (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
| 4500 | if (napi_reschedule(&tx_ring->q_vector->napi)) |
| 4501 | tx_ring->tx_stats.tx_lost_interrupt++; |
| 4502 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4503 | } |
| 4504 | |
| 4505 | /** |
| 4506 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4507 | * @pf: pointer to PF struct |
| 4508 | * |
| 4509 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4510 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4511 | * SW interrupt. |
| 4512 | **/ |
| 4513 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4514 | { |
| 4515 | struct net_device *netdev; |
| 4516 | struct i40e_vsi *vsi; |
| 4517 | int i; |
| 4518 | |
| 4519 | /* Only for LAN VSI */ |
| 4520 | vsi = pf->vsi[pf->lan_vsi]; |
| 4521 | |
| 4522 | if (!vsi) |
| 4523 | return; |
| 4524 | |
| 4525 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
| 4526 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 4527 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4528 | return; |
| 4529 | |
| 4530 | /* Make sure type is MAIN VSI */ |
| 4531 | if (vsi->type != I40E_VSI_MAIN) |
| 4532 | return; |
| 4533 | |
| 4534 | netdev = vsi->netdev; |
| 4535 | if (!netdev) |
| 4536 | return; |
| 4537 | |
| 4538 | /* Bail out if netif_carrier is not OK */ |
| 4539 | if (!netif_carrier_ok(netdev)) |
| 4540 | return; |
| 4541 | |
| 4542 | /* Go thru' TX queues for netdev */ |
| 4543 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4544 | struct netdev_queue *q; |
| 4545 | |
| 4546 | q = netdev_get_tx_queue(netdev, i); |
| 4547 | if (q) |
| 4548 | i40e_detect_recover_hung_queue(i, vsi); |
| 4549 | } |
| 4550 | } |
| 4551 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4552 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4553 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4554 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4555 | * |
| 4556 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4557 | * and LAN TC. |
| 4558 | **/ |
| 4559 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4560 | { |
| 4561 | struct i40e_dcb_app_priority_table app; |
| 4562 | struct i40e_hw *hw = &pf->hw; |
| 4563 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4564 | u8 tc, i; |
| 4565 | /* Get the iSCSI APP TLV */ |
| 4566 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4567 | |
| 4568 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4569 | app = dcbcfg->app[i]; |
| 4570 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4571 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4572 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4573 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4574 | break; |
| 4575 | } |
| 4576 | } |
| 4577 | |
| 4578 | return enabled_tc; |
| 4579 | } |
| 4580 | |
| 4581 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4582 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4583 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4584 | * |
| 4585 | * Return the number of TCs from given DCBx configuration |
| 4586 | **/ |
| 4587 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4588 | { |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4589 | int i, tc_unused = 0; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4590 | u8 num_tc = 0; |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4591 | u8 ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4592 | |
| 4593 | /* Scan the ETS Config Priority Table to find |
| 4594 | * traffic class enabled for a given priority |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4595 | * and create a bitmask of enabled TCs |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4596 | */ |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4597 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) |
| 4598 | num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]); |
| 4599 | |
| 4600 | /* Now scan the bitmask to check for |
| 4601 | * contiguous TCs starting with TC0 |
| 4602 | */ |
| 4603 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4604 | if (num_tc & BIT(i)) { |
| 4605 | if (!tc_unused) { |
| 4606 | ret++; |
| 4607 | } else { |
| 4608 | pr_err("Non-contiguous TC - Disabling DCB\n"); |
| 4609 | return 1; |
| 4610 | } |
| 4611 | } else { |
| 4612 | tc_unused = 1; |
| 4613 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4614 | } |
| 4615 | |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4616 | /* There is always at least TC0 */ |
| 4617 | if (!ret) |
| 4618 | ret = 1; |
| 4619 | |
| 4620 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4621 | } |
| 4622 | |
| 4623 | /** |
| 4624 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4625 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4626 | * |
| 4627 | * Query the current DCB configuration and return the number of |
| 4628 | * traffic classes enabled from the given DCBX config |
| 4629 | **/ |
| 4630 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4631 | { |
| 4632 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4633 | u8 enabled_tc = 1; |
| 4634 | u8 i; |
| 4635 | |
| 4636 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4637 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4638 | |
| 4639 | return enabled_tc; |
| 4640 | } |
| 4641 | |
| 4642 | /** |
| 4643 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4644 | * @pf: PF being queried |
| 4645 | * |
| 4646 | * Return number of traffic classes enabled for the given PF |
| 4647 | **/ |
| 4648 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4649 | { |
| 4650 | struct i40e_hw *hw = &pf->hw; |
Dave Ertman | 52a08ca | 2016-07-27 12:02:34 -0700 | [diff] [blame] | 4651 | u8 i, enabled_tc = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4652 | u8 num_tc = 0; |
| 4653 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4654 | |
| 4655 | /* If DCB is not enabled then always in single TC */ |
| 4656 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4657 | return 1; |
| 4658 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4659 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4660 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4661 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4662 | |
| 4663 | /* MFP mode return count of enabled TCs for this PF */ |
| 4664 | if (pf->hw.func_caps.iscsi) |
| 4665 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4666 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4667 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4668 | |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4669 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4670 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4671 | num_tc++; |
| 4672 | } |
| 4673 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4674 | } |
| 4675 | |
| 4676 | /** |
| 4677 | * i40e_pf_get_default_tc - Get bitmap for first enabled TC |
| 4678 | * @pf: PF being queried |
| 4679 | * |
| 4680 | * Return a bitmap for first enabled traffic class for this PF. |
| 4681 | **/ |
| 4682 | static u8 i40e_pf_get_default_tc(struct i40e_pf *pf) |
| 4683 | { |
| 4684 | u8 enabled_tc = pf->hw.func_caps.enabled_tcmap; |
| 4685 | u8 i = 0; |
| 4686 | |
| 4687 | if (!enabled_tc) |
| 4688 | return 0x1; /* TC0 */ |
| 4689 | |
| 4690 | /* Find the first enabled TC */ |
| 4691 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4692 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4693 | break; |
| 4694 | } |
| 4695 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4696 | return BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | /** |
| 4700 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4701 | * @pf: PF being queried |
| 4702 | * |
| 4703 | * Return a bitmap for enabled traffic classes for this PF. |
| 4704 | **/ |
| 4705 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4706 | { |
| 4707 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4708 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4709 | return i40e_pf_get_default_tc(pf); |
| 4710 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4711 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4712 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4713 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4714 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4715 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4716 | if (pf->hw.func_caps.iscsi) |
| 4717 | return i40e_get_iscsi_tc_map(pf); |
| 4718 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4719 | return i40e_pf_get_default_tc(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | /** |
| 4723 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4724 | * @vsi: the VSI being queried |
| 4725 | * |
| 4726 | * Returns 0 on success, negative value on failure |
| 4727 | **/ |
| 4728 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4729 | { |
| 4730 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4731 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4732 | struct i40e_pf *pf = vsi->back; |
| 4733 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4734 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4735 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4736 | int i; |
| 4737 | |
| 4738 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4739 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4740 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4741 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4742 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4743 | i40e_stat_str(&pf->hw, ret), |
| 4744 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4745 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4749 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4750 | NULL); |
| 4751 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4752 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4753 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4754 | i40e_stat_str(&pf->hw, ret), |
| 4755 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4756 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4757 | } |
| 4758 | |
| 4759 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4760 | dev_info(&pf->pdev->dev, |
| 4761 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4762 | bw_config.tc_valid_bits, |
| 4763 | bw_ets_config.tc_valid_bits); |
| 4764 | /* Still continuing */ |
| 4765 | } |
| 4766 | |
| 4767 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4768 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4769 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4770 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4771 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4772 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4773 | vsi->bw_ets_limit_credits[i] = |
| 4774 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4775 | /* 3 bits out of 4 for each TC */ |
| 4776 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4777 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4778 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4779 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4780 | } |
| 4781 | |
| 4782 | /** |
| 4783 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4784 | * @vsi: the VSI being configured |
| 4785 | * @enabled_tc: TC bitmap |
| 4786 | * @bw_credits: BW shared credits per TC |
| 4787 | * |
| 4788 | * Returns 0 on success, negative value on failure |
| 4789 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4790 | 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] | 4791 | u8 *bw_share) |
| 4792 | { |
| 4793 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4794 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4795 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4796 | |
| 4797 | bw_data.tc_valid_bits = enabled_tc; |
| 4798 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4799 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4800 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4801 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4802 | NULL); |
| 4803 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4804 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4805 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4806 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4807 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4811 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4812 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4813 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | /** |
| 4817 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4818 | * @vsi: the VSI being configured |
| 4819 | * @enabled_tc: TC map to be enabled |
| 4820 | * |
| 4821 | **/ |
| 4822 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4823 | { |
| 4824 | struct net_device *netdev = vsi->netdev; |
| 4825 | struct i40e_pf *pf = vsi->back; |
| 4826 | struct i40e_hw *hw = &pf->hw; |
| 4827 | u8 netdev_tc = 0; |
| 4828 | int i; |
| 4829 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4830 | |
| 4831 | if (!netdev) |
| 4832 | return; |
| 4833 | |
| 4834 | if (!enabled_tc) { |
| 4835 | netdev_reset_tc(netdev); |
| 4836 | return; |
| 4837 | } |
| 4838 | |
| 4839 | /* Set up actual enabled TCs on the VSI */ |
| 4840 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 4841 | return; |
| 4842 | |
| 4843 | /* set per TC queues for the VSI */ |
| 4844 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4845 | /* Only set TC queues for enabled tcs |
| 4846 | * |
| 4847 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 4848 | * enabled_tc bitmap would be 0x00001001; the driver |
| 4849 | * will set the numtc for netdev as 2 that will be |
| 4850 | * referenced by the netdev layer as TC 0 and 1. |
| 4851 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4852 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4853 | netdev_set_tc_queue(netdev, |
| 4854 | vsi->tc_config.tc_info[i].netdev_tc, |
| 4855 | vsi->tc_config.tc_info[i].qcount, |
| 4856 | vsi->tc_config.tc_info[i].qoffset); |
| 4857 | } |
| 4858 | |
| 4859 | /* Assign UP2TC map for the VSI */ |
| 4860 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4861 | /* Get the actual TC# for the UP */ |
| 4862 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4863 | /* Get the mapped netdev TC# for the UP */ |
| 4864 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 4865 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 4866 | } |
| 4867 | } |
| 4868 | |
| 4869 | /** |
| 4870 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 4871 | * @vsi: the VSI being configured |
| 4872 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 4873 | **/ |
| 4874 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 4875 | struct i40e_vsi_context *ctxt) |
| 4876 | { |
| 4877 | /* copy just the sections touched not the entire info |
| 4878 | * since not all sections are valid as returned by |
| 4879 | * update vsi params |
| 4880 | */ |
| 4881 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 4882 | memcpy(&vsi->info.queue_mapping, |
| 4883 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 4884 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 4885 | sizeof(vsi->info.tc_mapping)); |
| 4886 | } |
| 4887 | |
| 4888 | /** |
| 4889 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 4890 | * @vsi: VSI to be configured |
| 4891 | * @enabled_tc: TC bitmap |
| 4892 | * |
| 4893 | * This configures a particular VSI for TCs that are mapped to the |
| 4894 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 4895 | * VSIs to configure TC for a particular VSI. |
| 4896 | * |
| 4897 | * NOTE: |
| 4898 | * It is expected that the VSI queues have been quisced before calling |
| 4899 | * this function. |
| 4900 | **/ |
| 4901 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4902 | { |
| 4903 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 4904 | struct i40e_vsi_context ctxt; |
| 4905 | int ret = 0; |
| 4906 | int i; |
| 4907 | |
| 4908 | /* Check if enabled_tc is same as existing or new TCs */ |
| 4909 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 4910 | return ret; |
| 4911 | |
| 4912 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 4913 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4914 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4915 | bw_share[i] = 1; |
| 4916 | } |
| 4917 | |
| 4918 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 4919 | if (ret) { |
| 4920 | dev_info(&vsi->back->pdev->dev, |
| 4921 | "Failed configuring TC map %d for VSI %d\n", |
| 4922 | enabled_tc, vsi->seid); |
| 4923 | goto out; |
| 4924 | } |
| 4925 | |
| 4926 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 4927 | ctxt.seid = vsi->seid; |
| 4928 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 4929 | ctxt.vf_num = 0; |
| 4930 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 4931 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4932 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 4933 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4934 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 4935 | ctxt.info.valid_sections |= |
| 4936 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 4937 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 4938 | } |
| 4939 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4940 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 4941 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 4942 | if (ret) { |
| 4943 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4944 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 4945 | i40e_stat_str(&vsi->back->hw, ret), |
| 4946 | i40e_aq_str(&vsi->back->hw, |
| 4947 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4948 | goto out; |
| 4949 | } |
| 4950 | /* update the local VSI info with updated queue map */ |
| 4951 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 4952 | vsi->info.valid_sections = 0; |
| 4953 | |
| 4954 | /* Update current VSI BW information */ |
| 4955 | ret = i40e_vsi_get_bw_info(vsi); |
| 4956 | if (ret) { |
| 4957 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4958 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 4959 | i40e_stat_str(&vsi->back->hw, ret), |
| 4960 | i40e_aq_str(&vsi->back->hw, |
| 4961 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4962 | goto out; |
| 4963 | } |
| 4964 | |
| 4965 | /* Update the netdev TC setup */ |
| 4966 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 4967 | out: |
| 4968 | return ret; |
| 4969 | } |
| 4970 | |
| 4971 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4972 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 4973 | * @veb: given VEB |
| 4974 | * @enabled_tc: TC bitmap |
| 4975 | * |
| 4976 | * Configures given TC bitmap for VEB (switching) element |
| 4977 | **/ |
| 4978 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 4979 | { |
| 4980 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 4981 | struct i40e_pf *pf = veb->pf; |
| 4982 | int ret = 0; |
| 4983 | int i; |
| 4984 | |
| 4985 | /* No TCs or already enabled TCs just return */ |
| 4986 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 4987 | return ret; |
| 4988 | |
| 4989 | bw_data.tc_valid_bits = enabled_tc; |
| 4990 | /* bw_data.absolute_credits is not set (relative) */ |
| 4991 | |
| 4992 | /* Enable ETS TCs with equal BW Share for now */ |
| 4993 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4994 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4995 | bw_data.tc_bw_share_credits[i] = 1; |
| 4996 | } |
| 4997 | |
| 4998 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 4999 | &bw_data, NULL); |
| 5000 | if (ret) { |
| 5001 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5002 | "VEB bw config failed, err %s aq_err %s\n", |
| 5003 | i40e_stat_str(&pf->hw, ret), |
| 5004 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5005 | goto out; |
| 5006 | } |
| 5007 | |
| 5008 | /* Update the BW information */ |
| 5009 | ret = i40e_veb_get_bw_info(veb); |
| 5010 | if (ret) { |
| 5011 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5012 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 5013 | i40e_stat_str(&pf->hw, ret), |
| 5014 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | out: |
| 5018 | return ret; |
| 5019 | } |
| 5020 | |
| 5021 | #ifdef CONFIG_I40E_DCB |
| 5022 | /** |
| 5023 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 5024 | * @pf: PF struct |
| 5025 | * |
| 5026 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 5027 | * the caller would've quiesce all the VSIs before calling |
| 5028 | * this function |
| 5029 | **/ |
| 5030 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 5031 | { |
| 5032 | u8 tc_map = 0; |
| 5033 | int ret; |
| 5034 | u8 v; |
| 5035 | |
| 5036 | /* Enable the TCs available on PF to all VEBs */ |
| 5037 | tc_map = i40e_pf_get_tc_map(pf); |
| 5038 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 5039 | if (!pf->veb[v]) |
| 5040 | continue; |
| 5041 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 5042 | if (ret) { |
| 5043 | dev_info(&pf->pdev->dev, |
| 5044 | "Failed configuring TC for VEB seid=%d\n", |
| 5045 | pf->veb[v]->seid); |
| 5046 | /* Will try to configure as many components */ |
| 5047 | } |
| 5048 | } |
| 5049 | |
| 5050 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5051 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5052 | if (!pf->vsi[v]) |
| 5053 | continue; |
| 5054 | |
| 5055 | /* - Enable all TCs for the LAN VSI |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5056 | #ifdef I40E_FCOE |
| 5057 | * - For FCoE VSI only enable the TC configured |
| 5058 | * as per the APP TLV |
| 5059 | #endif |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5060 | * - For all others keep them at TC0 for now |
| 5061 | */ |
| 5062 | if (v == pf->lan_vsi) |
| 5063 | tc_map = i40e_pf_get_tc_map(pf); |
| 5064 | else |
| 5065 | tc_map = i40e_pf_get_default_tc(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5066 | #ifdef I40E_FCOE |
| 5067 | if (pf->vsi[v]->type == I40E_VSI_FCOE) |
| 5068 | tc_map = i40e_get_fcoe_tc_map(pf); |
| 5069 | #endif /* #ifdef I40E_FCOE */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5070 | |
| 5071 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 5072 | if (ret) { |
| 5073 | dev_info(&pf->pdev->dev, |
| 5074 | "Failed configuring TC for VSI seid=%d\n", |
| 5075 | pf->vsi[v]->seid); |
| 5076 | /* Will try to configure as many components */ |
| 5077 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 5078 | /* Re-configure VSI vectors based on updated TC map */ |
| 5079 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5080 | if (pf->vsi[v]->netdev) |
| 5081 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 5082 | } |
| 5083 | } |
| 5084 | } |
| 5085 | |
| 5086 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5087 | * i40e_resume_port_tx - Resume port Tx |
| 5088 | * @pf: PF struct |
| 5089 | * |
| 5090 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 5091 | * resume. |
| 5092 | **/ |
| 5093 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 5094 | { |
| 5095 | struct i40e_hw *hw = &pf->hw; |
| 5096 | int ret; |
| 5097 | |
| 5098 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 5099 | if (ret) { |
| 5100 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5101 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 5102 | i40e_stat_str(&pf->hw, ret), |
| 5103 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5104 | /* Schedule PF reset to recover */ |
| 5105 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5106 | i40e_service_event_schedule(pf); |
| 5107 | } |
| 5108 | |
| 5109 | return ret; |
| 5110 | } |
| 5111 | |
| 5112 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5113 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 5114 | * @pf: PF being configured |
| 5115 | * |
| 5116 | * Query the current DCB configuration and cache it |
| 5117 | * in the hardware structure |
| 5118 | **/ |
| 5119 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 5120 | { |
| 5121 | struct i40e_hw *hw = &pf->hw; |
| 5122 | int err = 0; |
| 5123 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5124 | /* 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] | 5125 | if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5126 | goto out; |
| 5127 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5128 | /* Get the initial DCB configuration */ |
| 5129 | err = i40e_init_dcb(hw); |
| 5130 | if (!err) { |
| 5131 | /* Device/Function is not DCBX capable */ |
| 5132 | if ((!hw->func_caps.dcb) || |
| 5133 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5134 | dev_info(&pf->pdev->dev, |
| 5135 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 5136 | |
| 5137 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 5138 | goto out; |
| 5139 | |
| 5140 | } else { |
| 5141 | /* When status is not DISABLED then DCBX in FW */ |
| 5142 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5143 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5144 | |
| 5145 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5146 | /* Enable DCB tagging only when more than one TC |
| 5147 | * or explicitly disable if only one TC |
| 5148 | */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5149 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5150 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5151 | else |
| 5152 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5153 | dev_dbg(&pf->pdev->dev, |
| 5154 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5155 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5156 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5157 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5158 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5159 | i40e_stat_str(&pf->hw, err), |
| 5160 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | out: |
| 5164 | return err; |
| 5165 | } |
| 5166 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5167 | #define SPEED_SIZE 14 |
| 5168 | #define FC_SIZE 8 |
| 5169 | /** |
| 5170 | * i40e_print_link_message - print link up or down |
| 5171 | * @vsi: the VSI for which link needs a message |
| 5172 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5173 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5174 | { |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5175 | char *speed = "Unknown"; |
| 5176 | char *fc = "Unknown"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5177 | |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5178 | if (vsi->current_isup == isup) |
| 5179 | return; |
| 5180 | vsi->current_isup = isup; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5181 | if (!isup) { |
| 5182 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5183 | return; |
| 5184 | } |
| 5185 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5186 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5187 | * least 10GB |
| 5188 | */ |
| 5189 | if (vsi->back->hw.func_caps.npar_enable && |
| 5190 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5191 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5192 | netdev_warn(vsi->netdev, |
| 5193 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5194 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5195 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5196 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5197 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5198 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5199 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5200 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5201 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5202 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5203 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5204 | break; |
| 5205 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5206 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5207 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5208 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5209 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5210 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5211 | default: |
| 5212 | break; |
| 5213 | } |
| 5214 | |
| 5215 | switch (vsi->back->hw.fc.current_mode) { |
| 5216 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5217 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5218 | break; |
| 5219 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5220 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5221 | break; |
| 5222 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5223 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5224 | break; |
| 5225 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5226 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5227 | break; |
| 5228 | } |
| 5229 | |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5230 | 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] | 5231 | speed, fc); |
| 5232 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5233 | |
| 5234 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5235 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5236 | * @vsi: the VSI being configured |
| 5237 | **/ |
| 5238 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5239 | { |
| 5240 | struct i40e_pf *pf = vsi->back; |
| 5241 | int err; |
| 5242 | |
| 5243 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5244 | i40e_vsi_configure_msix(vsi); |
| 5245 | else |
| 5246 | i40e_configure_msi_and_legacy(vsi); |
| 5247 | |
| 5248 | /* start rings */ |
| 5249 | err = i40e_vsi_control_rings(vsi, true); |
| 5250 | if (err) |
| 5251 | return err; |
| 5252 | |
| 5253 | clear_bit(__I40E_DOWN, &vsi->state); |
| 5254 | i40e_napi_enable_all(vsi); |
| 5255 | i40e_vsi_enable_irq(vsi); |
| 5256 | |
| 5257 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5258 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5259 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5260 | netif_tx_start_all_queues(vsi->netdev); |
| 5261 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5262 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5263 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5264 | /* need to check for qualified module here*/ |
| 5265 | if ((pf->hw.phy.link_info.link_info & |
| 5266 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5267 | (!(pf->hw.phy.link_info.an_info & |
| 5268 | I40E_AQ_QUALIFIED_MODULE))) |
| 5269 | netdev_err(vsi->netdev, |
| 5270 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5271 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5272 | |
| 5273 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5274 | if (vsi->type == I40E_VSI_FDIR) { |
| 5275 | /* reset fd counters */ |
| 5276 | pf->fd_add_err = pf->fd_atr_cnt = 0; |
| 5277 | if (pf->fd_tcp_rule > 0) { |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 5278 | pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5279 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5280 | 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] | 5281 | pf->fd_tcp_rule = 0; |
| 5282 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5283 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5284 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5285 | |
| 5286 | /* On the next run of the service_task, notify any clients of the new |
| 5287 | * opened netdev |
| 5288 | */ |
| 5289 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5290 | i40e_service_event_schedule(pf); |
| 5291 | |
| 5292 | return 0; |
| 5293 | } |
| 5294 | |
| 5295 | /** |
| 5296 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5297 | * @vsi: the VSI being configured |
| 5298 | * |
| 5299 | * Rebuild the ring structs after some configuration |
| 5300 | * has changed, e.g. MTU size. |
| 5301 | **/ |
| 5302 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5303 | { |
| 5304 | struct i40e_pf *pf = vsi->back; |
| 5305 | |
| 5306 | WARN_ON(in_interrupt()); |
| 5307 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5308 | usleep_range(1000, 2000); |
| 5309 | i40e_down(vsi); |
| 5310 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5311 | i40e_up(vsi); |
| 5312 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 5313 | } |
| 5314 | |
| 5315 | /** |
| 5316 | * i40e_up - Bring the connection back up after being down |
| 5317 | * @vsi: the VSI being configured |
| 5318 | **/ |
| 5319 | int i40e_up(struct i40e_vsi *vsi) |
| 5320 | { |
| 5321 | int err; |
| 5322 | |
| 5323 | err = i40e_vsi_configure(vsi); |
| 5324 | if (!err) |
| 5325 | err = i40e_up_complete(vsi); |
| 5326 | |
| 5327 | return err; |
| 5328 | } |
| 5329 | |
| 5330 | /** |
| 5331 | * i40e_down - Shutdown the connection processing |
| 5332 | * @vsi: the VSI being stopped |
| 5333 | **/ |
| 5334 | void i40e_down(struct i40e_vsi *vsi) |
| 5335 | { |
| 5336 | int i; |
| 5337 | |
| 5338 | /* It is assumed that the caller of this function |
| 5339 | * sets the vsi->state __I40E_DOWN bit. |
| 5340 | */ |
| 5341 | if (vsi->netdev) { |
| 5342 | netif_carrier_off(vsi->netdev); |
| 5343 | netif_tx_disable(vsi->netdev); |
| 5344 | } |
| 5345 | i40e_vsi_disable_irq(vsi); |
| 5346 | i40e_vsi_control_rings(vsi, false); |
| 5347 | i40e_napi_disable_all(vsi); |
| 5348 | |
| 5349 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5350 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 5351 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5352 | } |
Catherine Sullivan | f980d44 | 2016-05-16 10:26:34 -0700 | [diff] [blame] | 5353 | |
| 5354 | i40e_notify_client_of_netdev_close(vsi, false); |
| 5355 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | /** |
| 5359 | * i40e_setup_tc - configure multiple traffic classes |
| 5360 | * @netdev: net device to configure |
| 5361 | * @tc: number of traffic classes to enable |
| 5362 | **/ |
| 5363 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5364 | { |
| 5365 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5366 | struct i40e_vsi *vsi = np->vsi; |
| 5367 | struct i40e_pf *pf = vsi->back; |
| 5368 | u8 enabled_tc = 0; |
| 5369 | int ret = -EINVAL; |
| 5370 | int i; |
| 5371 | |
| 5372 | /* Check if DCB enabled to continue */ |
| 5373 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5374 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5375 | goto exit; |
| 5376 | } |
| 5377 | |
| 5378 | /* Check if MFP enabled */ |
| 5379 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5380 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5381 | goto exit; |
| 5382 | } |
| 5383 | |
| 5384 | /* Check whether tc count is within enabled limit */ |
| 5385 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5386 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5387 | goto exit; |
| 5388 | } |
| 5389 | |
| 5390 | /* Generate TC map for number of tc requested */ |
| 5391 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5392 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5393 | |
| 5394 | /* Requesting same TC configuration as already enabled */ |
| 5395 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5396 | return 0; |
| 5397 | |
| 5398 | /* Quiesce VSI queues */ |
| 5399 | i40e_quiesce_vsi(vsi); |
| 5400 | |
| 5401 | /* Configure VSI for enabled TCs */ |
| 5402 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5403 | if (ret) { |
| 5404 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5405 | vsi->seid); |
| 5406 | goto exit; |
| 5407 | } |
| 5408 | |
| 5409 | /* Unquiesce VSI */ |
| 5410 | i40e_unquiesce_vsi(vsi); |
| 5411 | |
| 5412 | exit: |
| 5413 | return ret; |
| 5414 | } |
| 5415 | |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5416 | #ifdef I40E_FCOE |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5417 | int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5418 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5419 | #else |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5420 | static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5421 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5422 | #endif |
| 5423 | { |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5424 | if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5425 | return -EINVAL; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5426 | return i40e_setup_tc(netdev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5427 | } |
| 5428 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5429 | /** |
| 5430 | * i40e_open - Called when a network interface is made active |
| 5431 | * @netdev: network interface device structure |
| 5432 | * |
| 5433 | * The open entry point is called when a network interface is made |
| 5434 | * active by the system (IFF_UP). At this point all resources needed |
| 5435 | * for transmit and receive operations are allocated, the interrupt |
| 5436 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5437 | * enabled, and the stack is notified that the interface is ready. |
| 5438 | * |
| 5439 | * Returns 0 on success, negative value on failure |
| 5440 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5441 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5442 | { |
| 5443 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5444 | struct i40e_vsi *vsi = np->vsi; |
| 5445 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5446 | int err; |
| 5447 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5448 | /* disallow open during test or if eeprom is broken */ |
| 5449 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 5450 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5451 | return -EBUSY; |
| 5452 | |
| 5453 | netif_carrier_off(netdev); |
| 5454 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5455 | err = i40e_vsi_open(vsi); |
| 5456 | if (err) |
| 5457 | return err; |
| 5458 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5459 | /* configure global TSO hardware offload settings */ |
| 5460 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5461 | TCP_FLAG_FIN) >> 16); |
| 5462 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5463 | TCP_FLAG_FIN | |
| 5464 | TCP_FLAG_CWR) >> 16); |
| 5465 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5466 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 5467 | udp_tunnel_get_rx_info(netdev); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5468 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5469 | return 0; |
| 5470 | } |
| 5471 | |
| 5472 | /** |
| 5473 | * i40e_vsi_open - |
| 5474 | * @vsi: the VSI to open |
| 5475 | * |
| 5476 | * Finish initialization of the VSI. |
| 5477 | * |
| 5478 | * Returns 0 on success, negative value on failure |
| 5479 | **/ |
| 5480 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5481 | { |
| 5482 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5483 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5484 | int err; |
| 5485 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5486 | /* allocate descriptors */ |
| 5487 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5488 | if (err) |
| 5489 | goto err_setup_tx; |
| 5490 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5491 | if (err) |
| 5492 | goto err_setup_rx; |
| 5493 | |
| 5494 | err = i40e_vsi_configure(vsi); |
| 5495 | if (err) |
| 5496 | goto err_setup_rx; |
| 5497 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5498 | if (vsi->netdev) { |
| 5499 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5500 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5501 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5502 | if (err) |
| 5503 | goto err_setup_rx; |
| 5504 | |
| 5505 | /* Notify the stack of the actual queue counts. */ |
| 5506 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5507 | vsi->num_queue_pairs); |
| 5508 | if (err) |
| 5509 | goto err_set_queues; |
| 5510 | |
| 5511 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5512 | vsi->num_queue_pairs); |
| 5513 | if (err) |
| 5514 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5515 | |
| 5516 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5517 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5518 | dev_driver_string(&pf->pdev->dev), |
| 5519 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5520 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5521 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5522 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5523 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5524 | goto err_setup_rx; |
| 5525 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5526 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5527 | err = i40e_up_complete(vsi); |
| 5528 | if (err) |
| 5529 | goto err_up_complete; |
| 5530 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5531 | return 0; |
| 5532 | |
| 5533 | err_up_complete: |
| 5534 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5535 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5536 | i40e_vsi_free_irq(vsi); |
| 5537 | err_setup_rx: |
| 5538 | i40e_vsi_free_rx_resources(vsi); |
| 5539 | err_setup_tx: |
| 5540 | i40e_vsi_free_tx_resources(vsi); |
| 5541 | if (vsi == pf->vsi[pf->lan_vsi]) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5542 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5543 | |
| 5544 | return err; |
| 5545 | } |
| 5546 | |
| 5547 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5548 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5549 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5550 | * |
| 5551 | * This function destroys the hlist where all the Flow Director |
| 5552 | * filters were saved. |
| 5553 | **/ |
| 5554 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5555 | { |
| 5556 | struct i40e_fdir_filter *filter; |
| 5557 | struct hlist_node *node2; |
| 5558 | |
| 5559 | hlist_for_each_entry_safe(filter, node2, |
| 5560 | &pf->fdir_filter_list, fdir_node) { |
| 5561 | hlist_del(&filter->fdir_node); |
| 5562 | kfree(filter); |
| 5563 | } |
| 5564 | pf->fdir_pf_active_filters = 0; |
| 5565 | } |
| 5566 | |
| 5567 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5568 | * i40e_close - Disables a network interface |
| 5569 | * @netdev: network interface device structure |
| 5570 | * |
| 5571 | * The close entry point is called when an interface is de-activated |
| 5572 | * by the OS. The hardware is still under the driver's control, but |
| 5573 | * this netdev interface is disabled. |
| 5574 | * |
| 5575 | * Returns 0, this is not allowed to fail |
| 5576 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5577 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5578 | { |
| 5579 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5580 | struct i40e_vsi *vsi = np->vsi; |
| 5581 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5582 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5583 | |
| 5584 | return 0; |
| 5585 | } |
| 5586 | |
| 5587 | /** |
| 5588 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5589 | * @pf: board private structure |
| 5590 | * @reset_flags: which reset is requested |
| 5591 | * |
| 5592 | * The essential difference in resets is that the PF Reset |
| 5593 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5594 | * firmware, and doesn't bother the other PFs on the chip. |
| 5595 | **/ |
| 5596 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5597 | { |
| 5598 | u32 val; |
| 5599 | |
| 5600 | WARN_ON(in_interrupt()); |
| 5601 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5602 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5603 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5604 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5605 | |
| 5606 | /* Request a Global Reset |
| 5607 | * |
| 5608 | * This will start the chip's countdown to the actual full |
| 5609 | * chip reset event, and a warning interrupt to be sent |
| 5610 | * to all PFs, including the requestor. Our handler |
| 5611 | * for the warning interrupt will deal with the shutdown |
| 5612 | * and recovery of the switch setup. |
| 5613 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5614 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5615 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5616 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5617 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5618 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5619 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5620 | |
| 5621 | /* Request a Core Reset |
| 5622 | * |
| 5623 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5624 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5625 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5626 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5627 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5628 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5629 | i40e_flush(&pf->hw); |
| 5630 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5631 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5632 | |
| 5633 | /* Request a PF Reset |
| 5634 | * |
| 5635 | * Resets only the PF-specific registers |
| 5636 | * |
| 5637 | * This goes directly to the tear-down and rebuild of |
| 5638 | * the switch, since we need to do all the recovery as |
| 5639 | * for the Core Reset. |
| 5640 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5641 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5642 | i40e_handle_reset_warning(pf); |
| 5643 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5644 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5645 | int v; |
| 5646 | |
| 5647 | /* Find the VSI(s) that requested a re-init */ |
| 5648 | dev_info(&pf->pdev->dev, |
| 5649 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5650 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5651 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5652 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5653 | if (vsi != NULL && |
| 5654 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5655 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5656 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5657 | } |
| 5658 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5659 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5660 | int v; |
| 5661 | |
| 5662 | /* Find the VSI(s) that needs to be brought down */ |
| 5663 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5664 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5665 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5666 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5667 | if (vsi != NULL && |
| 5668 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5669 | set_bit(__I40E_DOWN, &vsi->state); |
| 5670 | i40e_down(vsi); |
| 5671 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5672 | } |
| 5673 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5674 | } else { |
| 5675 | dev_info(&pf->pdev->dev, |
| 5676 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5677 | } |
| 5678 | } |
| 5679 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5680 | #ifdef CONFIG_I40E_DCB |
| 5681 | /** |
| 5682 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5683 | * @pf: board private structure |
| 5684 | * @old_cfg: current DCB config |
| 5685 | * @new_cfg: new DCB config |
| 5686 | **/ |
| 5687 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5688 | struct i40e_dcbx_config *old_cfg, |
| 5689 | struct i40e_dcbx_config *new_cfg) |
| 5690 | { |
| 5691 | bool need_reconfig = false; |
| 5692 | |
| 5693 | /* Check if ETS configuration has changed */ |
| 5694 | if (memcmp(&new_cfg->etscfg, |
| 5695 | &old_cfg->etscfg, |
| 5696 | sizeof(new_cfg->etscfg))) { |
| 5697 | /* If Priority Table has changed reconfig is needed */ |
| 5698 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5699 | &old_cfg->etscfg.prioritytable, |
| 5700 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5701 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5702 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5703 | } |
| 5704 | |
| 5705 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5706 | &old_cfg->etscfg.tcbwtable, |
| 5707 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5708 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5709 | |
| 5710 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5711 | &old_cfg->etscfg.tsatable, |
| 5712 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5713 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5714 | } |
| 5715 | |
| 5716 | /* Check if PFC configuration has changed */ |
| 5717 | if (memcmp(&new_cfg->pfc, |
| 5718 | &old_cfg->pfc, |
| 5719 | sizeof(new_cfg->pfc))) { |
| 5720 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5721 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | /* Check if APP Table has changed */ |
| 5725 | if (memcmp(&new_cfg->app, |
| 5726 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5727 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5728 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5729 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5730 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5731 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5732 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5733 | return need_reconfig; |
| 5734 | } |
| 5735 | |
| 5736 | /** |
| 5737 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5738 | * @pf: board private structure |
| 5739 | * @e: event info posted on ARQ |
| 5740 | **/ |
| 5741 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5742 | struct i40e_arq_event_info *e) |
| 5743 | { |
| 5744 | struct i40e_aqc_lldp_get_mib *mib = |
| 5745 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5746 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5747 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5748 | bool need_reconfig = false; |
| 5749 | int ret = 0; |
| 5750 | u8 type; |
| 5751 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5752 | /* Not DCB capable or capability disabled */ |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5753 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5754 | return ret; |
| 5755 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5756 | /* Ignore if event is not for Nearest Bridge */ |
| 5757 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5758 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5759 | 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] | 5760 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5761 | return ret; |
| 5762 | |
| 5763 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5764 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5765 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5766 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5767 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5768 | /* Update the remote cached instance and return */ |
| 5769 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5770 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5771 | &hw->remote_dcbx_config); |
| 5772 | goto exit; |
| 5773 | } |
| 5774 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5775 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5776 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5777 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5778 | /* Reset the old DCBx configuration data */ |
| 5779 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5780 | /* Get updated DCBX data from firmware */ |
| 5781 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5782 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5783 | dev_info(&pf->pdev->dev, |
| 5784 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 5785 | i40e_stat_str(&pf->hw, ret), |
| 5786 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5787 | goto exit; |
| 5788 | } |
| 5789 | |
| 5790 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5791 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5792 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5793 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5794 | goto exit; |
| 5795 | } |
| 5796 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5797 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5798 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5799 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5800 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5801 | |
| 5802 | if (!need_reconfig) |
| 5803 | goto exit; |
| 5804 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5805 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5806 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5807 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5808 | else |
| 5809 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5810 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5811 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5812 | /* Reconfiguration needed quiesce all VSIs */ |
| 5813 | i40e_pf_quiesce_all_vsi(pf); |
| 5814 | |
| 5815 | /* Changes in configuration update VEB/VSI */ |
| 5816 | i40e_dcb_reconfigure(pf); |
| 5817 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5818 | ret = i40e_resume_port_tx(pf); |
| 5819 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5820 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5821 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5822 | if (ret) |
| 5823 | goto exit; |
| 5824 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 5825 | /* Wait for the PF's queues to be disabled */ |
| 5826 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5827 | if (ret) { |
| 5828 | /* Schedule PF reset to recover */ |
| 5829 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5830 | i40e_service_event_schedule(pf); |
| 5831 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5832 | i40e_pf_unquiesce_all_vsi(pf); |
Neerav Parikh | 85a1aab | 2016-06-07 09:14:55 -0700 | [diff] [blame] | 5833 | /* Notify the client for the DCB changes */ |
| 5834 | i40e_notify_client_of_l2_param_changes(pf->vsi[pf->lan_vsi]); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5835 | } |
| 5836 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5837 | exit: |
| 5838 | return ret; |
| 5839 | } |
| 5840 | #endif /* CONFIG_I40E_DCB */ |
| 5841 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5842 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5843 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 5844 | * @pf: board private structure |
| 5845 | * @reset_flags: which reset is requested |
| 5846 | * |
| 5847 | **/ |
| 5848 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 5849 | { |
| 5850 | rtnl_lock(); |
| 5851 | i40e_do_reset(pf, reset_flags); |
| 5852 | rtnl_unlock(); |
| 5853 | } |
| 5854 | |
| 5855 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5856 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 5857 | * @pf: board private structure |
| 5858 | * @e: event info posted on ARQ |
| 5859 | * |
| 5860 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 5861 | * and VF queues |
| 5862 | **/ |
| 5863 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 5864 | struct i40e_arq_event_info *e) |
| 5865 | { |
| 5866 | struct i40e_aqc_lan_overflow *data = |
| 5867 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 5868 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 5869 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 5870 | struct i40e_hw *hw = &pf->hw; |
| 5871 | struct i40e_vf *vf; |
| 5872 | u16 vf_id; |
| 5873 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5874 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 5875 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5876 | |
| 5877 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 5878 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 5879 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 5880 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 5881 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 5882 | vf_id -= hw->func_caps.vf_base_id; |
| 5883 | vf = &pf->vf[vf_id]; |
| 5884 | i40e_vc_notify_vf_reset(vf); |
| 5885 | /* Allow VF to process pending reset notification */ |
| 5886 | msleep(20); |
| 5887 | i40e_reset_vf(vf, false); |
| 5888 | } |
| 5889 | } |
| 5890 | |
| 5891 | /** |
| 5892 | * i40e_service_event_complete - Finish up the service event |
| 5893 | * @pf: board private structure |
| 5894 | **/ |
| 5895 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 5896 | { |
Shannon Nelson | b875f99 | 2015-10-21 19:47:03 -0400 | [diff] [blame] | 5897 | WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5898 | |
| 5899 | /* flush memory to make sure state is correct before next watchog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5900 | smp_mb__before_atomic(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5901 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 5902 | } |
| 5903 | |
| 5904 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5905 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 5906 | * @pf: board private structure |
| 5907 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5908 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5909 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5910 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5911 | |
| 5912 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5913 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 5914 | return fcnt_prog; |
| 5915 | } |
| 5916 | |
| 5917 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5918 | * 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] | 5919 | * @pf: board private structure |
| 5920 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5921 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5922 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5923 | u32 val, fcnt_prog; |
| 5924 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5925 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5926 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 5927 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 5928 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 5929 | return fcnt_prog; |
| 5930 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5931 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5932 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5933 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 5934 | * @pf: board private structure |
| 5935 | **/ |
| 5936 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 5937 | { |
| 5938 | u32 val, fcnt_prog; |
| 5939 | |
| 5940 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 5941 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 5942 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 5943 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 5944 | return fcnt_prog; |
| 5945 | } |
| 5946 | |
| 5947 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5948 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 5949 | * @pf: board private structure |
| 5950 | **/ |
| 5951 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 5952 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5953 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5954 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5955 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5956 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5957 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 5958 | return; |
| 5959 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5960 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 5961 | * to re-enable |
| 5962 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5963 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5964 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5965 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 5966 | (pf->fd_add_err == 0) || |
| 5967 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5968 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 5969 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 5970 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5971 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5972 | 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] | 5973 | } |
| 5974 | } |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 5975 | |
| 5976 | /* Wait for some more space to be available to turn on ATR. We also |
| 5977 | * must check that no existing ntuple rules for TCP are in effect |
| 5978 | */ |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5979 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 5980 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 5981 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 5982 | (pf->fd_tcp_rule == 0)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5983 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5984 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 5985 | dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n"); |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5986 | } |
| 5987 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5988 | |
| 5989 | /* if hw had a problem adding a filter, delete it */ |
| 5990 | if (pf->fd_inv > 0) { |
| 5991 | hlist_for_each_entry_safe(filter, node, |
| 5992 | &pf->fdir_filter_list, fdir_node) { |
| 5993 | if (filter->fd_id == pf->fd_inv) { |
| 5994 | hlist_del(&filter->fdir_node); |
| 5995 | kfree(filter); |
| 5996 | pf->fdir_pf_active_filters--; |
| 5997 | } |
| 5998 | } |
| 5999 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6000 | } |
| 6001 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6002 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6003 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6004 | /** |
| 6005 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 6006 | * @pf: board private structure |
| 6007 | **/ |
| 6008 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 6009 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6010 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6011 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6012 | bool disable_atr = false; |
| 6013 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6014 | int reg; |
| 6015 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6016 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 6017 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 6018 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6019 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6020 | /* If the flush is happening too quick and we have mostly SB rules we |
| 6021 | * should not re-enable ATR for some time. |
| 6022 | */ |
| 6023 | min_flush_time = pf->fd_flush_timestamp + |
| 6024 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 6025 | 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] | 6026 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6027 | if (!(time_after(jiffies, min_flush_time)) && |
| 6028 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 6029 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6030 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 6031 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6032 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6033 | |
| 6034 | pf->fd_flush_timestamp = jiffies; |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 6035 | pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6036 | /* flush all filters */ |
| 6037 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 6038 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 6039 | i40e_flush(&pf->hw); |
| 6040 | pf->fd_flush_cnt++; |
| 6041 | pf->fd_add_err = 0; |
| 6042 | do { |
| 6043 | /* Check FD flush status every 5-6msec */ |
| 6044 | usleep_range(5000, 6000); |
| 6045 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 6046 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 6047 | break; |
| 6048 | } while (flush_wait_retry--); |
| 6049 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 6050 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 6051 | } else { |
| 6052 | /* replay sideband filters */ |
| 6053 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
| 6054 | if (!disable_atr) |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 6055 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6056 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
| 6057 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6058 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 6059 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6060 | } |
| 6061 | |
| 6062 | /** |
| 6063 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 6064 | * @pf: board private structure |
| 6065 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6066 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6067 | { |
| 6068 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 6069 | } |
| 6070 | |
| 6071 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 6072 | * being applied really fast; before we see the first |
| 6073 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 6074 | * reacting will make sure we don't cause flush too often. |
| 6075 | */ |
| 6076 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 6077 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6078 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6079 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 6080 | * @pf: board private structure |
| 6081 | **/ |
| 6082 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 6083 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6084 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6085 | /* if interface is down do nothing */ |
| 6086 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 6087 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6088 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6089 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6090 | i40e_fdir_flush_and_replay(pf); |
| 6091 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6092 | i40e_fdir_check_and_reenable(pf); |
| 6093 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6094 | } |
| 6095 | |
| 6096 | /** |
| 6097 | * i40e_vsi_link_event - notify VSI of a link event |
| 6098 | * @vsi: vsi to be notified |
| 6099 | * @link_up: link up or down |
| 6100 | **/ |
| 6101 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 6102 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 6103 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6104 | return; |
| 6105 | |
| 6106 | switch (vsi->type) { |
| 6107 | case I40E_VSI_MAIN: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6108 | #ifdef I40E_FCOE |
| 6109 | case I40E_VSI_FCOE: |
| 6110 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6111 | if (!vsi->netdev || !vsi->netdev_registered) |
| 6112 | break; |
| 6113 | |
| 6114 | if (link_up) { |
| 6115 | netif_carrier_on(vsi->netdev); |
| 6116 | netif_tx_wake_all_queues(vsi->netdev); |
| 6117 | } else { |
| 6118 | netif_carrier_off(vsi->netdev); |
| 6119 | netif_tx_stop_all_queues(vsi->netdev); |
| 6120 | } |
| 6121 | break; |
| 6122 | |
| 6123 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6124 | case I40E_VSI_VMDQ2: |
| 6125 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6126 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6127 | case I40E_VSI_MIRROR: |
| 6128 | default: |
| 6129 | /* there is no notification for other VSIs */ |
| 6130 | break; |
| 6131 | } |
| 6132 | } |
| 6133 | |
| 6134 | /** |
| 6135 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6136 | * @veb: veb to be notified |
| 6137 | * @link_up: link up or down |
| 6138 | **/ |
| 6139 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6140 | { |
| 6141 | struct i40e_pf *pf; |
| 6142 | int i; |
| 6143 | |
| 6144 | if (!veb || !veb->pf) |
| 6145 | return; |
| 6146 | pf = veb->pf; |
| 6147 | |
| 6148 | /* depth first... */ |
| 6149 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6150 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6151 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6152 | |
| 6153 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6154 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6155 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6156 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6157 | } |
| 6158 | |
| 6159 | /** |
| 6160 | * i40e_link_event - Update netif_carrier status |
| 6161 | * @pf: board private structure |
| 6162 | **/ |
| 6163 | static void i40e_link_event(struct i40e_pf *pf) |
| 6164 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6165 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6166 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6167 | i40e_status status; |
| 6168 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6169 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6170 | /* save off old link status information */ |
| 6171 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6172 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6173 | /* set this to force the get_link_status call to refresh state */ |
| 6174 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6175 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6176 | 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] | 6177 | |
| 6178 | status = i40e_get_link_status(&pf->hw, &new_link); |
| 6179 | if (status) { |
| 6180 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6181 | status); |
| 6182 | return; |
| 6183 | } |
| 6184 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6185 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6186 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6187 | |
| 6188 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6189 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6190 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 6191 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6192 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6193 | |
| 6194 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 6195 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6196 | |
| 6197 | /* Notify the base of the switch tree connected to |
| 6198 | * the link. Floating VEBs are not notified. |
| 6199 | */ |
| 6200 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6201 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6202 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6203 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6204 | |
| 6205 | if (pf->vf) |
| 6206 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6207 | |
| 6208 | if (pf->flags & I40E_FLAG_PTP) |
| 6209 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6210 | } |
| 6211 | |
| 6212 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6213 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6214 | * @pf: board private structure |
| 6215 | **/ |
| 6216 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6217 | { |
| 6218 | int i; |
| 6219 | |
| 6220 | /* if interface is down do nothing */ |
| 6221 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 6222 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6223 | return; |
| 6224 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6225 | /* make sure we don't do these things too often */ |
| 6226 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6227 | pf->service_timer_period))) |
| 6228 | return; |
| 6229 | pf->service_timer_previous = jiffies; |
| 6230 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6231 | if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) |
| 6232 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6233 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6234 | /* Update the stats for active netdevs so the network stack |
| 6235 | * can look at updated numbers whenever it cares to |
| 6236 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6237 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6238 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6239 | i40e_update_stats(pf->vsi[i]); |
| 6240 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6241 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6242 | /* Update the stats for the active switching components */ |
| 6243 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6244 | if (pf->veb[i]) |
| 6245 | i40e_update_veb_stats(pf->veb[i]); |
| 6246 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6247 | |
| 6248 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6249 | } |
| 6250 | |
| 6251 | /** |
| 6252 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6253 | * @pf: board private structure |
| 6254 | **/ |
| 6255 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6256 | { |
| 6257 | u32 reset_flags = 0; |
| 6258 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6259 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6260 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6261 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6262 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 6263 | } |
| 6264 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6265 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6266 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6267 | } |
| 6268 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6269 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6270 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 6271 | } |
| 6272 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6273 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6274 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 6275 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6276 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6277 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6278 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 6279 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6280 | |
| 6281 | /* If there's a recovery already waiting, it takes |
| 6282 | * precedence before starting a new reset sequence. |
| 6283 | */ |
| 6284 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 6285 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6286 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6287 | } |
| 6288 | |
| 6289 | /* If we're already down or resetting, just bail */ |
| 6290 | if (reset_flags && |
| 6291 | !test_bit(__I40E_DOWN, &pf->state) && |
| 6292 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6293 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6294 | |
| 6295 | unlock: |
| 6296 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6297 | } |
| 6298 | |
| 6299 | /** |
| 6300 | * i40e_handle_link_event - Handle link event |
| 6301 | * @pf: board private structure |
| 6302 | * @e: event info posted on ARQ |
| 6303 | **/ |
| 6304 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6305 | struct i40e_arq_event_info *e) |
| 6306 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6307 | struct i40e_aqc_get_link_status *status = |
| 6308 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6309 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6310 | /* Do a new status request to re-enable LSE reporting |
| 6311 | * and load new status information into the hw struct |
| 6312 | * This completely ignores any state information |
| 6313 | * in the ARQ event info, instead choosing to always |
| 6314 | * issue the AQ update link status command. |
| 6315 | */ |
| 6316 | i40e_link_event(pf); |
| 6317 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6318 | /* check for unqualified module, if link is down */ |
| 6319 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6320 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6321 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6322 | dev_err(&pf->pdev->dev, |
| 6323 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6324 | } |
| 6325 | |
| 6326 | /** |
| 6327 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6328 | * @pf: board private structure |
| 6329 | **/ |
| 6330 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6331 | { |
| 6332 | struct i40e_arq_event_info event; |
| 6333 | struct i40e_hw *hw = &pf->hw; |
| 6334 | u16 pending, i = 0; |
| 6335 | i40e_status ret; |
| 6336 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6337 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6338 | u32 val; |
| 6339 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6340 | /* Do not run clean AQ when PF reset fails */ |
| 6341 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 6342 | return; |
| 6343 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6344 | /* check for error indications */ |
| 6345 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6346 | oldval = val; |
| 6347 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6348 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6349 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6350 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6351 | } |
| 6352 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6353 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6354 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6355 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6356 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6357 | } |
| 6358 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6359 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6360 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6361 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6362 | } |
| 6363 | if (oldval != val) |
| 6364 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6365 | |
| 6366 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6367 | oldval = val; |
| 6368 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6369 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6370 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6371 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6372 | } |
| 6373 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6374 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6375 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6376 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6377 | } |
| 6378 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6379 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6380 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6381 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6382 | } |
| 6383 | if (oldval != val) |
| 6384 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6385 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6386 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6387 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6388 | if (!event.msg_buf) |
| 6389 | return; |
| 6390 | |
| 6391 | do { |
| 6392 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6393 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6394 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6395 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6396 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6397 | break; |
| 6398 | } |
| 6399 | |
| 6400 | opcode = le16_to_cpu(event.desc.opcode); |
| 6401 | switch (opcode) { |
| 6402 | |
| 6403 | case i40e_aqc_opc_get_link_status: |
| 6404 | i40e_handle_link_event(pf, &event); |
| 6405 | break; |
| 6406 | case i40e_aqc_opc_send_msg_to_pf: |
| 6407 | ret = i40e_vc_process_vf_msg(pf, |
| 6408 | le16_to_cpu(event.desc.retval), |
| 6409 | le32_to_cpu(event.desc.cookie_high), |
| 6410 | le32_to_cpu(event.desc.cookie_low), |
| 6411 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6412 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6413 | break; |
| 6414 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6415 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6416 | #ifdef CONFIG_I40E_DCB |
| 6417 | rtnl_lock(); |
| 6418 | ret = i40e_handle_lldp_event(pf, &event); |
| 6419 | rtnl_unlock(); |
| 6420 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6421 | break; |
| 6422 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6423 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6424 | i40e_handle_lan_overflow_event(pf, &event); |
| 6425 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6426 | case i40e_aqc_opc_send_msg_to_peer: |
| 6427 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6428 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6429 | case i40e_aqc_opc_nvm_erase: |
| 6430 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6431 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 6432 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 6433 | "ARQ NVM operation 0x%04x completed\n", |
| 6434 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6435 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6436 | default: |
| 6437 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 6438 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6439 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6440 | break; |
| 6441 | } |
| 6442 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 6443 | |
| 6444 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 6445 | /* re-enable Admin queue interrupt cause */ |
| 6446 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6447 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6448 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6449 | i40e_flush(hw); |
| 6450 | |
| 6451 | kfree(event.msg_buf); |
| 6452 | } |
| 6453 | |
| 6454 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6455 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6456 | * @pf: board private structure |
| 6457 | **/ |
| 6458 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6459 | { |
| 6460 | int err; |
| 6461 | |
| 6462 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6463 | if (err) { |
| 6464 | /* retry in case of garbage read */ |
| 6465 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6466 | if (err) { |
| 6467 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6468 | err); |
| 6469 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6470 | } |
| 6471 | } |
| 6472 | |
| 6473 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 6474 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 6475 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6476 | } |
| 6477 | } |
| 6478 | |
| 6479 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6480 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6481 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6482 | * |
| 6483 | * enable switch loop back or die - no point in a return value |
| 6484 | **/ |
| 6485 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6486 | { |
| 6487 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6488 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6489 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6490 | |
| 6491 | ctxt.seid = pf->main_vsi_seid; |
| 6492 | ctxt.pf_num = pf->hw.pf_id; |
| 6493 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6494 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6495 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6496 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6497 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6498 | i40e_stat_str(&pf->hw, ret), |
| 6499 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6500 | return; |
| 6501 | } |
| 6502 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6503 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6504 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6505 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6506 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6507 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6508 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6509 | "update vsi switch failed, err %s aq_err %s\n", |
| 6510 | i40e_stat_str(&pf->hw, ret), |
| 6511 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6512 | } |
| 6513 | } |
| 6514 | |
| 6515 | /** |
| 6516 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6517 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6518 | * |
| 6519 | * disable switch loop back or die - no point in a return value |
| 6520 | **/ |
| 6521 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6522 | { |
| 6523 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6524 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6525 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6526 | |
| 6527 | ctxt.seid = pf->main_vsi_seid; |
| 6528 | ctxt.pf_num = pf->hw.pf_id; |
| 6529 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6530 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6531 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6532 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6533 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6534 | i40e_stat_str(&pf->hw, ret), |
| 6535 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6536 | return; |
| 6537 | } |
| 6538 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6539 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6540 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6541 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6542 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6543 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6544 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6545 | "update vsi switch failed, err %s aq_err %s\n", |
| 6546 | i40e_stat_str(&pf->hw, ret), |
| 6547 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6548 | } |
| 6549 | } |
| 6550 | |
| 6551 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6552 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6553 | * @veb: pointer to the bridge instance |
| 6554 | * |
| 6555 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6556 | * specified HW bridge instance. It is expected this function is called |
| 6557 | * when a new HW bridge is instantiated. |
| 6558 | **/ |
| 6559 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6560 | { |
| 6561 | struct i40e_pf *pf = veb->pf; |
| 6562 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6563 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6564 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6565 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6566 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6567 | i40e_disable_pf_switch_lb(pf); |
| 6568 | else |
| 6569 | i40e_enable_pf_switch_lb(pf); |
| 6570 | } |
| 6571 | |
| 6572 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6573 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6574 | * @veb: pointer to the VEB instance |
| 6575 | * |
| 6576 | * This is a recursive function that first builds the attached VSIs then |
| 6577 | * recurses in to build the next layer of VEB. We track the connections |
| 6578 | * through our own index numbers because the seid's from the HW could |
| 6579 | * change across the reset. |
| 6580 | **/ |
| 6581 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6582 | { |
| 6583 | struct i40e_vsi *ctl_vsi = NULL; |
| 6584 | struct i40e_pf *pf = veb->pf; |
| 6585 | int v, veb_idx; |
| 6586 | int ret; |
| 6587 | |
| 6588 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6589 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6590 | if (pf->vsi[v] && |
| 6591 | pf->vsi[v]->veb_idx == veb->idx && |
| 6592 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6593 | ctl_vsi = pf->vsi[v]; |
| 6594 | break; |
| 6595 | } |
| 6596 | } |
| 6597 | if (!ctl_vsi) { |
| 6598 | dev_info(&pf->pdev->dev, |
| 6599 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6600 | ret = -ENOENT; |
| 6601 | goto end_reconstitute; |
| 6602 | } |
| 6603 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6604 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6605 | ret = i40e_add_vsi(ctl_vsi); |
| 6606 | if (ret) { |
| 6607 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6608 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6609 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6610 | goto end_reconstitute; |
| 6611 | } |
| 6612 | i40e_vsi_reset_stats(ctl_vsi); |
| 6613 | |
| 6614 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6615 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6616 | if (ret) |
| 6617 | goto end_reconstitute; |
| 6618 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6619 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6620 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6621 | else |
| 6622 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6623 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6624 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6625 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6626 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6627 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6628 | continue; |
| 6629 | |
| 6630 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6631 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6632 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6633 | vsi->uplink_seid = veb->seid; |
| 6634 | ret = i40e_add_vsi(vsi); |
| 6635 | if (ret) { |
| 6636 | dev_info(&pf->pdev->dev, |
| 6637 | "rebuild of vsi_idx %d failed: %d\n", |
| 6638 | v, ret); |
| 6639 | goto end_reconstitute; |
| 6640 | } |
| 6641 | i40e_vsi_reset_stats(vsi); |
| 6642 | } |
| 6643 | } |
| 6644 | |
| 6645 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6646 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6647 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6648 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6649 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6650 | if (ret) |
| 6651 | break; |
| 6652 | } |
| 6653 | } |
| 6654 | |
| 6655 | end_reconstitute: |
| 6656 | return ret; |
| 6657 | } |
| 6658 | |
| 6659 | /** |
| 6660 | * i40e_get_capabilities - get info about the HW |
| 6661 | * @pf: the PF struct |
| 6662 | **/ |
| 6663 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6664 | { |
| 6665 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6666 | u16 data_size; |
| 6667 | int buf_len; |
| 6668 | int err; |
| 6669 | |
| 6670 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6671 | do { |
| 6672 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6673 | if (!cap_buf) |
| 6674 | return -ENOMEM; |
| 6675 | |
| 6676 | /* this loads the data into the hw struct for us */ |
| 6677 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6678 | &data_size, |
| 6679 | i40e_aqc_opc_list_func_capabilities, |
| 6680 | NULL); |
| 6681 | /* data loaded, buffer no longer needed */ |
| 6682 | kfree(cap_buf); |
| 6683 | |
| 6684 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6685 | /* retry with a larger buffer */ |
| 6686 | buf_len = data_size; |
| 6687 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6688 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6689 | "capability discovery failed, err %s aq_err %s\n", |
| 6690 | i40e_stat_str(&pf->hw, err), |
| 6691 | i40e_aq_str(&pf->hw, |
| 6692 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6693 | return -ENODEV; |
| 6694 | } |
| 6695 | } while (err); |
| 6696 | |
| 6697 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6698 | dev_info(&pf->pdev->dev, |
| 6699 | "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", |
| 6700 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6701 | pf->hw.func_caps.num_msix_vectors, |
| 6702 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6703 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6704 | pf->hw.func_caps.fd_filters_best_effort, |
| 6705 | pf->hw.func_caps.num_tx_qp, |
| 6706 | pf->hw.func_caps.num_vsis); |
| 6707 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6708 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6709 | + pf->hw.func_caps.num_vfs) |
| 6710 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6711 | dev_info(&pf->pdev->dev, |
| 6712 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6713 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6714 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6715 | } |
| 6716 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6717 | return 0; |
| 6718 | } |
| 6719 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6720 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6721 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6722 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6723 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6724 | * @pf: board private structure |
| 6725 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6726 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6727 | { |
| 6728 | struct i40e_vsi *vsi; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6729 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6730 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6731 | /* quick workaround for an NVM issue that leaves a critical register |
| 6732 | * uninitialized |
| 6733 | */ |
| 6734 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6735 | static const u32 hkey[] = { |
| 6736 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6737 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6738 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6739 | 0x95b3a76d}; |
| 6740 | |
| 6741 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6742 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6743 | } |
| 6744 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6745 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6746 | return; |
| 6747 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6748 | /* find existing VSI and see if it needs configuring */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6749 | vsi = NULL; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6750 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6751 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6752 | vsi = pf->vsi[i]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6753 | break; |
| 6754 | } |
| 6755 | } |
| 6756 | |
| 6757 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6758 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6759 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6760 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6761 | if (!vsi) { |
| 6762 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6763 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6764 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6765 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6766 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6767 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6768 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6769 | } |
| 6770 | |
| 6771 | /** |
| 6772 | * i40e_fdir_teardown - release the Flow Director resources |
| 6773 | * @pf: board private structure |
| 6774 | **/ |
| 6775 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6776 | { |
| 6777 | int i; |
| 6778 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6779 | i40e_fdir_filter_exit(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6780 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6781 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 6782 | i40e_vsi_release(pf->vsi[i]); |
| 6783 | break; |
| 6784 | } |
| 6785 | } |
| 6786 | } |
| 6787 | |
| 6788 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6789 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6790 | * @pf: board private structure |
| 6791 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6792 | * 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] | 6793 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6794 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6795 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6796 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6797 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6798 | u32 v; |
| 6799 | |
| 6800 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6801 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6802 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 6803 | if (i40e_check_asq_alive(&pf->hw)) |
| 6804 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6805 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6806 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6807 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6808 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6809 | i40e_pf_quiesce_all_vsi(pf); |
| 6810 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6811 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6812 | if (pf->vsi[v]) |
| 6813 | pf->vsi[v]->seid = 0; |
| 6814 | } |
| 6815 | |
| 6816 | i40e_shutdown_adminq(&pf->hw); |
| 6817 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6818 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6819 | if (hw->hmc.hmc_obj) { |
| 6820 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6821 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6822 | dev_warn(&pf->pdev->dev, |
| 6823 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6824 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6825 | } |
| 6826 | |
| 6827 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6828 | * i40e_send_version - update firmware with driver version |
| 6829 | * @pf: PF struct |
| 6830 | */ |
| 6831 | static void i40e_send_version(struct i40e_pf *pf) |
| 6832 | { |
| 6833 | struct i40e_driver_version dv; |
| 6834 | |
| 6835 | dv.major_version = DRV_VERSION_MAJOR; |
| 6836 | dv.minor_version = DRV_VERSION_MINOR; |
| 6837 | dv.build_version = DRV_VERSION_BUILD; |
| 6838 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 6839 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6840 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 6841 | } |
| 6842 | |
| 6843 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 6844 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6845 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6846 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6847 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6848 | 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] | 6849 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6850 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6851 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6852 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6853 | u32 val; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6854 | u32 v; |
| 6855 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6856 | /* Now we wait for GRST to settle out. |
| 6857 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 6858 | * because the reset will make them disappear. |
| 6859 | */ |
| 6860 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6861 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6862 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6863 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 6864 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6865 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6866 | pf->pfr_count++; |
| 6867 | |
| 6868 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6869 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6870 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6871 | |
| 6872 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 6873 | ret = i40e_init_adminq(&pf->hw); |
| 6874 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6875 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 6876 | i40e_stat_str(&pf->hw, ret), |
| 6877 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6878 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6879 | } |
| 6880 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6881 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 6882 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6883 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6884 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 6885 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6886 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6887 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6888 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6889 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6890 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 6891 | hw->func_caps.num_rx_qp, |
| 6892 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 6893 | if (ret) { |
| 6894 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 6895 | goto end_core_reset; |
| 6896 | } |
| 6897 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 6898 | if (ret) { |
| 6899 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 6900 | goto end_core_reset; |
| 6901 | } |
| 6902 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6903 | #ifdef CONFIG_I40E_DCB |
| 6904 | ret = i40e_init_pf_dcb(pf); |
| 6905 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6906 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 6907 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 6908 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6909 | } |
| 6910 | #endif /* CONFIG_I40E_DCB */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6911 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 6912 | i40e_init_pf_fcoe(pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6913 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6914 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6915 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6916 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6917 | if (ret) |
| 6918 | goto end_core_reset; |
| 6919 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6920 | /* The driver only wants link up/down and module qualification |
| 6921 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6922 | */ |
| 6923 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6924 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 6925 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6926 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6927 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6928 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 6929 | i40e_stat_str(&pf->hw, ret), |
| 6930 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6931 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6932 | /* make sure our flow control settings are restored */ |
| 6933 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 6934 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 6935 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 6936 | i40e_stat_str(&pf->hw, ret), |
| 6937 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6938 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6939 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 6940 | * They are still in our local switch element arrays, so only |
| 6941 | * need to rebuild the switch model in the HW. |
| 6942 | * |
| 6943 | * If there were VEBs but the reconstitution failed, we'll try |
| 6944 | * try to recover minimal use by getting the basic PF VSI working. |
| 6945 | */ |
| 6946 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6947 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6948 | /* find the one VEB connected to the MAC, and find orphans */ |
| 6949 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6950 | if (!pf->veb[v]) |
| 6951 | continue; |
| 6952 | |
| 6953 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 6954 | pf->veb[v]->uplink_seid == 0) { |
| 6955 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 6956 | |
| 6957 | if (!ret) |
| 6958 | continue; |
| 6959 | |
| 6960 | /* If Main VEB failed, we're in deep doodoo, |
| 6961 | * so give up rebuilding the switch and set up |
| 6962 | * for minimal rebuild of PF VSI. |
| 6963 | * If orphan failed, we'll report the error |
| 6964 | * but try to keep going. |
| 6965 | */ |
| 6966 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 6967 | dev_info(&pf->pdev->dev, |
| 6968 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 6969 | ret); |
| 6970 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 6971 | = pf->mac_seid; |
| 6972 | break; |
| 6973 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 6974 | dev_info(&pf->pdev->dev, |
| 6975 | "rebuild of orphan VEB failed: %d\n", |
| 6976 | ret); |
| 6977 | } |
| 6978 | } |
| 6979 | } |
| 6980 | } |
| 6981 | |
| 6982 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 6983 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6984 | /* no VEB, so rebuild only the Main VSI */ |
| 6985 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 6986 | if (ret) { |
| 6987 | dev_info(&pf->pdev->dev, |
| 6988 | "rebuild of Main VSI failed: %d\n", ret); |
| 6989 | goto end_core_reset; |
| 6990 | } |
| 6991 | } |
| 6992 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6993 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 6994 | * of TSO, so that we avoid the MDD being fired and causing |
| 6995 | * a reset in the case of small MSS+TSO. |
| 6996 | */ |
| 6997 | #define I40E_REG_MSS 0x000E64DC |
| 6998 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 6999 | #define I40E_64BYTE_MSS 0x400000 |
| 7000 | val = rd32(hw, I40E_REG_MSS); |
| 7001 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 7002 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 7003 | val |= I40E_64BYTE_MSS; |
| 7004 | wr32(hw, I40E_REG_MSS, val); |
| 7005 | } |
| 7006 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 7007 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 7008 | msleep(75); |
| 7009 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 7010 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7011 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 7012 | i40e_stat_str(&pf->hw, ret), |
| 7013 | i40e_aq_str(&pf->hw, |
| 7014 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7015 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7016 | /* reinit the misc interrupt */ |
| 7017 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7018 | ret = i40e_setup_misc_vector(pf); |
| 7019 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 7020 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 7021 | * transmitted. By doing so we stop a malicious VF from sending out |
| 7022 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 7023 | * PF/VF VSIs. |
| 7024 | * The FW can still send Flow control frames if enabled. |
| 7025 | */ |
| 7026 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 7027 | pf->main_vsi_seid); |
| 7028 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7029 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 7030 | i40e_pf_unquiesce_all_vsi(pf); |
| 7031 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 7032 | if (pf->num_alloc_vfs) { |
| 7033 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 7034 | i40e_reset_vf(&pf->vf[v], true); |
| 7035 | } |
| 7036 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7037 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 7038 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7039 | |
| 7040 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7041 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 7042 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7043 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 7044 | } |
| 7045 | |
| 7046 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7047 | * 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] | 7048 | * @pf: board private structure |
| 7049 | * |
| 7050 | * Close up the VFs and other things in prep for a Core Reset, |
| 7051 | * then get ready to rebuild the world. |
| 7052 | **/ |
| 7053 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 7054 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 7055 | i40e_prep_for_reset(pf); |
| 7056 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7057 | } |
| 7058 | |
| 7059 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7060 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7061 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7062 | * |
| 7063 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 7064 | **/ |
| 7065 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 7066 | { |
| 7067 | struct i40e_hw *hw = &pf->hw; |
| 7068 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7069 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7070 | struct i40e_vf *vf; |
| 7071 | u32 reg; |
| 7072 | int i; |
| 7073 | |
| 7074 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 7075 | return; |
| 7076 | |
| 7077 | /* find what triggered the MDD event */ |
| 7078 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 7079 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7080 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 7081 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7082 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7083 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7084 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7085 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7086 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 7087 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 7088 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7089 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7090 | 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] | 7091 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7092 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 7093 | mdd_detected = true; |
| 7094 | } |
| 7095 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 7096 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7097 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 7098 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7099 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7100 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7101 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 7102 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 7103 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7104 | if (netif_msg_rx_err(pf)) |
| 7105 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 7106 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7107 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 7108 | mdd_detected = true; |
| 7109 | } |
| 7110 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7111 | if (mdd_detected) { |
| 7112 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 7113 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 7114 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7115 | 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] | 7116 | pf_mdd_detected = true; |
| 7117 | } |
| 7118 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 7119 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 7120 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7121 | 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] | 7122 | pf_mdd_detected = true; |
| 7123 | } |
| 7124 | /* Queue belongs to the PF, initiate a reset */ |
| 7125 | if (pf_mdd_detected) { |
| 7126 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 7127 | i40e_service_event_schedule(pf); |
| 7128 | } |
| 7129 | } |
| 7130 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7131 | /* see if one of the VFs needs its hand slapped */ |
| 7132 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7133 | vf = &(pf->vf[i]); |
| 7134 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7135 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7136 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7137 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7138 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7139 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7140 | } |
| 7141 | |
| 7142 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7143 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7144 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7145 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7146 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7147 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7148 | } |
| 7149 | |
| 7150 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7151 | dev_info(&pf->pdev->dev, |
| 7152 | "Too many MDD events on VF %d, disabled\n", i); |
| 7153 | dev_info(&pf->pdev->dev, |
| 7154 | "Use PF Control I/F to re-enable the VF\n"); |
| 7155 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 7156 | } |
| 7157 | } |
| 7158 | |
| 7159 | /* re-enable mdd interrupt cause */ |
| 7160 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 7161 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7162 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7163 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7164 | i40e_flush(hw); |
| 7165 | } |
| 7166 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7167 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7168 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7169 | * @pf: board private structure |
| 7170 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7171 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7172 | { |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7173 | struct i40e_hw *hw = &pf->hw; |
| 7174 | i40e_status ret; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7175 | __be16 port; |
| 7176 | int i; |
| 7177 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7178 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7179 | return; |
| 7180 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7181 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7182 | |
| 7183 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7184 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7185 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
| 7186 | port = pf->udp_ports[i].index; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7187 | if (port) |
Carolyn Wyborny | b3f5c7b | 2016-08-24 11:33:51 -0700 | [diff] [blame] | 7188 | ret = i40e_aq_add_udp_tunnel(hw, port, |
| 7189 | pf->udp_ports[i].type, |
| 7190 | NULL, NULL); |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7191 | else |
| 7192 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7193 | |
| 7194 | if (ret) { |
Carolyn Wyborny | 730a8f8 | 2016-02-17 16:12:16 -0800 | [diff] [blame] | 7195 | dev_dbg(&pf->pdev->dev, |
| 7196 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 7197 | pf->udp_ports[i].type ? "vxlan" : "geneve", |
| 7198 | port ? "add" : "delete", |
| 7199 | ntohs(port), i, |
| 7200 | i40e_stat_str(&pf->hw, ret), |
| 7201 | i40e_aq_str(&pf->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7202 | pf->hw.aq.asq_last_status)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7203 | pf->udp_ports[i].index = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7204 | } |
| 7205 | } |
| 7206 | } |
| 7207 | } |
| 7208 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7209 | /** |
| 7210 | * i40e_service_task - Run the driver's async subtasks |
| 7211 | * @work: pointer to work_struct containing our data |
| 7212 | **/ |
| 7213 | static void i40e_service_task(struct work_struct *work) |
| 7214 | { |
| 7215 | struct i40e_pf *pf = container_of(work, |
| 7216 | struct i40e_pf, |
| 7217 | service_task); |
| 7218 | unsigned long start_time = jiffies; |
| 7219 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7220 | /* don't bother with service tasks if a reset is in progress */ |
| 7221 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7222 | i40e_service_event_complete(pf); |
| 7223 | return; |
| 7224 | } |
| 7225 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7226 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 7227 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7228 | i40e_reset_subtask(pf); |
| 7229 | i40e_handle_mdd_event(pf); |
| 7230 | i40e_vc_process_vflr_event(pf); |
| 7231 | i40e_watchdog_subtask(pf); |
| 7232 | i40e_fdir_reinit_subtask(pf); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7233 | i40e_client_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7234 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7235 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7236 | i40e_clean_adminq_subtask(pf); |
| 7237 | |
| 7238 | i40e_service_event_complete(pf); |
| 7239 | |
| 7240 | /* If the tasks have taken longer than one timer cycle or there |
| 7241 | * is more work to be done, reschedule the service task now |
| 7242 | * rather than wait for the timer to tick again. |
| 7243 | */ |
| 7244 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 7245 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 7246 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 7247 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 7248 | i40e_service_event_schedule(pf); |
| 7249 | } |
| 7250 | |
| 7251 | /** |
| 7252 | * i40e_service_timer - timer callback |
| 7253 | * @data: pointer to PF struct |
| 7254 | **/ |
| 7255 | static void i40e_service_timer(unsigned long data) |
| 7256 | { |
| 7257 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7258 | |
| 7259 | mod_timer(&pf->service_timer, |
| 7260 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7261 | i40e_service_event_schedule(pf); |
| 7262 | } |
| 7263 | |
| 7264 | /** |
| 7265 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7266 | * @vsi: the VSI being configured |
| 7267 | **/ |
| 7268 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7269 | { |
| 7270 | struct i40e_pf *pf = vsi->back; |
| 7271 | |
| 7272 | switch (vsi->type) { |
| 7273 | case I40E_VSI_MAIN: |
| 7274 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7275 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7276 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7277 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7278 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7279 | else |
| 7280 | vsi->num_q_vectors = 1; |
| 7281 | |
| 7282 | break; |
| 7283 | |
| 7284 | case I40E_VSI_FDIR: |
| 7285 | vsi->alloc_queue_pairs = 1; |
| 7286 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7287 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7288 | vsi->num_q_vectors = pf->num_fdsb_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7289 | break; |
| 7290 | |
| 7291 | case I40E_VSI_VMDQ2: |
| 7292 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7293 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7294 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7295 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7296 | break; |
| 7297 | |
| 7298 | case I40E_VSI_SRIOV: |
| 7299 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7300 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7301 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7302 | break; |
| 7303 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7304 | #ifdef I40E_FCOE |
| 7305 | case I40E_VSI_FCOE: |
| 7306 | vsi->alloc_queue_pairs = pf->num_fcoe_qps; |
| 7307 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7308 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7309 | vsi->num_q_vectors = pf->num_fcoe_msix; |
| 7310 | break; |
| 7311 | |
| 7312 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7313 | default: |
| 7314 | WARN_ON(1); |
| 7315 | return -ENODATA; |
| 7316 | } |
| 7317 | |
| 7318 | return 0; |
| 7319 | } |
| 7320 | |
| 7321 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7322 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7323 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7324 | * @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] | 7325 | * |
| 7326 | * On error: returns error code (negative) |
| 7327 | * On success: returns 0 |
| 7328 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7329 | 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] | 7330 | { |
| 7331 | int size; |
| 7332 | int ret = 0; |
| 7333 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7334 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7335 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 7336 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7337 | if (!vsi->tx_rings) |
| 7338 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7339 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 7340 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7341 | if (alloc_qvectors) { |
| 7342 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7343 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7344 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7345 | if (!vsi->q_vectors) { |
| 7346 | ret = -ENOMEM; |
| 7347 | goto err_vectors; |
| 7348 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7349 | } |
| 7350 | return ret; |
| 7351 | |
| 7352 | err_vectors: |
| 7353 | kfree(vsi->tx_rings); |
| 7354 | return ret; |
| 7355 | } |
| 7356 | |
| 7357 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7358 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7359 | * @pf: board private structure |
| 7360 | * @type: type of VSI |
| 7361 | * |
| 7362 | * On error: returns error code (negative) |
| 7363 | * On success: returns vsi index in PF (positive) |
| 7364 | **/ |
| 7365 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7366 | { |
| 7367 | int ret = -ENODEV; |
| 7368 | struct i40e_vsi *vsi; |
| 7369 | int vsi_idx; |
| 7370 | int i; |
| 7371 | |
| 7372 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7373 | mutex_lock(&pf->switch_mutex); |
| 7374 | |
| 7375 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7376 | * been happening. We can afford to do a quick scan to look |
| 7377 | * for any free VSIs in the list. |
| 7378 | * |
| 7379 | * find next empty vsi slot, looping back around if necessary |
| 7380 | */ |
| 7381 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7382 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7383 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7384 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7385 | i = 0; |
| 7386 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7387 | i++; |
| 7388 | } |
| 7389 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7390 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7391 | vsi_idx = i; /* Found one! */ |
| 7392 | } else { |
| 7393 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7394 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7395 | } |
| 7396 | pf->next_vsi = ++i; |
| 7397 | |
| 7398 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7399 | if (!vsi) { |
| 7400 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7401 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7402 | } |
| 7403 | vsi->type = type; |
| 7404 | vsi->back = pf; |
| 7405 | set_bit(__I40E_DOWN, &vsi->state); |
| 7406 | vsi->flags = 0; |
| 7407 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7408 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7409 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7410 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7411 | vsi->netdev_registered = false; |
| 7412 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
| 7413 | INIT_LIST_HEAD(&vsi->mac_filter_list); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7414 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7415 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7416 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7417 | if (ret) |
| 7418 | goto err_rings; |
| 7419 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7420 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7421 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7422 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7423 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7424 | /* Setup default MSIX irq handler for VSI */ |
| 7425 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7426 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7427 | /* Initialize VSI lock */ |
| 7428 | spin_lock_init(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7429 | pf->vsi[vsi_idx] = vsi; |
| 7430 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7431 | goto unlock_pf; |
| 7432 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7433 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7434 | pf->next_vsi = i - 1; |
| 7435 | kfree(vsi); |
| 7436 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7437 | mutex_unlock(&pf->switch_mutex); |
| 7438 | return ret; |
| 7439 | } |
| 7440 | |
| 7441 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7442 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7443 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7444 | * @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] | 7445 | * |
| 7446 | * On error: returns error code (negative) |
| 7447 | * On success: returns 0 |
| 7448 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7449 | 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] | 7450 | { |
| 7451 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7452 | if (free_qvectors) { |
| 7453 | kfree(vsi->q_vectors); |
| 7454 | vsi->q_vectors = NULL; |
| 7455 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7456 | kfree(vsi->tx_rings); |
| 7457 | vsi->tx_rings = NULL; |
| 7458 | vsi->rx_rings = NULL; |
| 7459 | } |
| 7460 | |
| 7461 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7462 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7463 | * and lookup table |
| 7464 | * @vsi: Pointer to VSI structure |
| 7465 | */ |
| 7466 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7467 | { |
| 7468 | if (!vsi) |
| 7469 | return; |
| 7470 | |
| 7471 | kfree(vsi->rss_hkey_user); |
| 7472 | vsi->rss_hkey_user = NULL; |
| 7473 | |
| 7474 | kfree(vsi->rss_lut_user); |
| 7475 | vsi->rss_lut_user = NULL; |
| 7476 | } |
| 7477 | |
| 7478 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7479 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7480 | * @vsi: the VSI being un-configured |
| 7481 | **/ |
| 7482 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7483 | { |
| 7484 | struct i40e_pf *pf; |
| 7485 | |
| 7486 | if (!vsi) |
| 7487 | return 0; |
| 7488 | |
| 7489 | if (!vsi->back) |
| 7490 | goto free_vsi; |
| 7491 | pf = vsi->back; |
| 7492 | |
| 7493 | mutex_lock(&pf->switch_mutex); |
| 7494 | if (!pf->vsi[vsi->idx]) { |
| 7495 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7496 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7497 | goto unlock_vsi; |
| 7498 | } |
| 7499 | |
| 7500 | if (pf->vsi[vsi->idx] != vsi) { |
| 7501 | dev_err(&pf->pdev->dev, |
| 7502 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7503 | pf->vsi[vsi->idx]->idx, |
| 7504 | pf->vsi[vsi->idx], |
| 7505 | pf->vsi[vsi->idx]->type, |
| 7506 | vsi->idx, vsi, vsi->type); |
| 7507 | goto unlock_vsi; |
| 7508 | } |
| 7509 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7510 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7511 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7512 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7513 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7514 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7515 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7516 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7517 | pf->vsi[vsi->idx] = NULL; |
| 7518 | if (vsi->idx < pf->next_vsi) |
| 7519 | pf->next_vsi = vsi->idx; |
| 7520 | |
| 7521 | unlock_vsi: |
| 7522 | mutex_unlock(&pf->switch_mutex); |
| 7523 | free_vsi: |
| 7524 | kfree(vsi); |
| 7525 | |
| 7526 | return 0; |
| 7527 | } |
| 7528 | |
| 7529 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7530 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7531 | * @vsi: the VSI being cleaned |
| 7532 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7533 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7534 | { |
| 7535 | int i; |
| 7536 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7537 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7538 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7539 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7540 | vsi->tx_rings[i] = NULL; |
| 7541 | vsi->rx_rings[i] = NULL; |
| 7542 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7543 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7544 | } |
| 7545 | |
| 7546 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7547 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7548 | * @vsi: the VSI being configured |
| 7549 | **/ |
| 7550 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7551 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7552 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7553 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7554 | int i; |
| 7555 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7556 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7557 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7558 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7559 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7560 | if (!tx_ring) |
| 7561 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7562 | |
| 7563 | tx_ring->queue_index = i; |
| 7564 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7565 | tx_ring->ring_active = false; |
| 7566 | tx_ring->vsi = vsi; |
| 7567 | tx_ring->netdev = vsi->netdev; |
| 7568 | tx_ring->dev = &pf->pdev->dev; |
| 7569 | tx_ring->count = vsi->num_desc; |
| 7570 | tx_ring->size = 0; |
| 7571 | tx_ring->dcb_tc = 0; |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 7572 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 7573 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7574 | tx_ring->tx_itr_setting = pf->tx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7575 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7576 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7577 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7578 | rx_ring->queue_index = i; |
| 7579 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7580 | rx_ring->ring_active = false; |
| 7581 | rx_ring->vsi = vsi; |
| 7582 | rx_ring->netdev = vsi->netdev; |
| 7583 | rx_ring->dev = &pf->pdev->dev; |
| 7584 | rx_ring->count = vsi->num_desc; |
| 7585 | rx_ring->size = 0; |
| 7586 | rx_ring->dcb_tc = 0; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7587 | rx_ring->rx_itr_setting = pf->rx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7588 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7589 | } |
| 7590 | |
| 7591 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7592 | |
| 7593 | err_out: |
| 7594 | i40e_vsi_clear_rings(vsi); |
| 7595 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7596 | } |
| 7597 | |
| 7598 | /** |
| 7599 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7600 | * @pf: board private structure |
| 7601 | * @vectors: the number of MSI-X vectors to request |
| 7602 | * |
| 7603 | * Returns the number of vectors reserved, or error |
| 7604 | **/ |
| 7605 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7606 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7607 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7608 | I40E_MIN_MSIX, vectors); |
| 7609 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7610 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7611 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7612 | vectors = 0; |
| 7613 | } |
| 7614 | |
| 7615 | return vectors; |
| 7616 | } |
| 7617 | |
| 7618 | /** |
| 7619 | * i40e_init_msix - Setup the MSIX capability |
| 7620 | * @pf: board private structure |
| 7621 | * |
| 7622 | * Work with the OS to set up the MSIX vectors needed. |
| 7623 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7624 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7625 | **/ |
| 7626 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7627 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7628 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7629 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7630 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7631 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7632 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7633 | |
| 7634 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7635 | return -ENODEV; |
| 7636 | |
| 7637 | /* The number of vectors we'll request will be comprised of: |
| 7638 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7639 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7640 | * - Queues being used for RSS. |
| 7641 | * We don't need as many as max_rss_size vectors. |
| 7642 | * use rss_size instead in the calculation since that |
| 7643 | * is governed by number of cpus in the system. |
| 7644 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7645 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7646 | * - The CPU count within the NUMA node if iWARP is enabled |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7647 | #ifdef I40E_FCOE |
| 7648 | * - The number of FCOE qps. |
| 7649 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7650 | * Once we count this up, try the request. |
| 7651 | * |
| 7652 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7653 | * and try again. If that still fails, we punt. |
| 7654 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7655 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7656 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7657 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7658 | /* reserve one vector for miscellaneous handler */ |
| 7659 | if (vectors_left) { |
| 7660 | v_budget++; |
| 7661 | vectors_left--; |
| 7662 | } |
| 7663 | |
| 7664 | /* reserve vectors for the main PF traffic queues */ |
| 7665 | pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left); |
| 7666 | vectors_left -= pf->num_lan_msix; |
| 7667 | v_budget += pf->num_lan_msix; |
| 7668 | |
| 7669 | /* reserve one vector for sideband flow director */ |
| 7670 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7671 | if (vectors_left) { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7672 | pf->num_fdsb_msix = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7673 | v_budget++; |
| 7674 | vectors_left--; |
| 7675 | } else { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7676 | pf->num_fdsb_msix = 0; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7677 | } |
| 7678 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7679 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7680 | #ifdef I40E_FCOE |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7681 | /* can we reserve enough for FCoE? */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7682 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7683 | if (!vectors_left) |
| 7684 | pf->num_fcoe_msix = 0; |
| 7685 | else if (vectors_left >= pf->num_fcoe_qps) |
| 7686 | pf->num_fcoe_msix = pf->num_fcoe_qps; |
| 7687 | else |
| 7688 | pf->num_fcoe_msix = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7689 | v_budget += pf->num_fcoe_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7690 | vectors_left -= pf->num_fcoe_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7691 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7692 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7693 | #endif |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7694 | /* can we reserve enough for iWARP? */ |
| 7695 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7696 | iwarp_requested = pf->num_iwarp_msix; |
| 7697 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7698 | if (!vectors_left) |
| 7699 | pf->num_iwarp_msix = 0; |
| 7700 | else if (vectors_left < pf->num_iwarp_msix) |
| 7701 | pf->num_iwarp_msix = 1; |
| 7702 | v_budget += pf->num_iwarp_msix; |
| 7703 | vectors_left -= pf->num_iwarp_msix; |
| 7704 | } |
| 7705 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7706 | /* any vectors left over go for VMDq support */ |
| 7707 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7708 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7709 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7710 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 7711 | if (!vectors_left) { |
| 7712 | pf->num_vmdq_msix = 0; |
| 7713 | pf->num_vmdq_qps = 0; |
| 7714 | } else { |
| 7715 | /* if we're short on vectors for what's desired, we limit |
| 7716 | * the queues per vmdq. If this is still more than are |
| 7717 | * available, the user will need to change the number of |
| 7718 | * queues/vectors used by the PF later with the ethtool |
| 7719 | * channels command |
| 7720 | */ |
| 7721 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7722 | pf->num_vmdq_qps = 1; |
| 7723 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7724 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 7725 | v_budget += vmdq_vecs; |
| 7726 | vectors_left -= vmdq_vecs; |
| 7727 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7728 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7729 | |
| 7730 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7731 | GFP_KERNEL); |
| 7732 | if (!pf->msix_entries) |
| 7733 | return -ENOMEM; |
| 7734 | |
| 7735 | for (i = 0; i < v_budget; i++) |
| 7736 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7737 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7738 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7739 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7740 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7741 | kfree(pf->msix_entries); |
| 7742 | pf->msix_entries = NULL; |
| 7743 | return -ENODEV; |
| 7744 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7745 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7746 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7747 | pf->num_vmdq_vsis = 0; |
| 7748 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7749 | pf->num_lan_qps = 1; |
| 7750 | pf->num_lan_msix = 1; |
| 7751 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7752 | } else if (!vectors_left) { |
| 7753 | /* If we have limited resources, we will start with no vectors |
| 7754 | * for the special features and then allocate vectors to some |
| 7755 | * of these features based on the policy and at the end disable |
| 7756 | * the features that did not get any vectors. |
| 7757 | */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7758 | int vec; |
| 7759 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7760 | dev_info(&pf->pdev->dev, |
| 7761 | "MSI-X vector limit reached, attempting to redistribute vectors\n"); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7762 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7763 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7764 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7765 | /* Scale vector usage down */ |
| 7766 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7767 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7768 | pf->num_vmdq_qps = 1; |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7769 | #ifdef I40E_FCOE |
| 7770 | pf->num_fcoe_qps = 0; |
| 7771 | pf->num_fcoe_msix = 0; |
| 7772 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7773 | |
| 7774 | /* partition out the remaining vectors */ |
| 7775 | switch (vec) { |
| 7776 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7777 | pf->num_lan_msix = 1; |
| 7778 | break; |
| 7779 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7780 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7781 | pf->num_lan_msix = 1; |
| 7782 | pf->num_iwarp_msix = 1; |
| 7783 | } else { |
| 7784 | pf->num_lan_msix = 2; |
| 7785 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7786 | #ifdef I40E_FCOE |
| 7787 | /* give one vector to FCoE */ |
| 7788 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7789 | pf->num_lan_msix = 1; |
| 7790 | pf->num_fcoe_msix = 1; |
| 7791 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7792 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7793 | break; |
| 7794 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7795 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7796 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 7797 | iwarp_requested); |
| 7798 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 7799 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7800 | } else { |
| 7801 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 7802 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7803 | } |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 7804 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7805 | pf->num_fdsb_msix = 1; |
| 7806 | vec--; |
| 7807 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7808 | pf->num_lan_msix = min_t(int, |
| 7809 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 7810 | pf->num_lan_msix); |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7811 | pf->num_lan_qps = pf->num_lan_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7812 | #ifdef I40E_FCOE |
| 7813 | /* give one vector to FCoE */ |
| 7814 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7815 | pf->num_fcoe_msix = 1; |
| 7816 | vec--; |
| 7817 | } |
| 7818 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7819 | break; |
| 7820 | } |
| 7821 | } |
| 7822 | |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 7823 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 7824 | (pf->num_fdsb_msix == 0)) { |
| 7825 | dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n"); |
| 7826 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7827 | } |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7828 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7829 | (pf->num_vmdq_msix == 0)) { |
| 7830 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 7831 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 7832 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7833 | |
| 7834 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 7835 | (pf->num_iwarp_msix == 0)) { |
| 7836 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 7837 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 7838 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7839 | #ifdef I40E_FCOE |
| 7840 | |
| 7841 | if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { |
| 7842 | dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n"); |
| 7843 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 7844 | } |
| 7845 | #endif |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7846 | i40e_debug(&pf->hw, I40E_DEBUG_INIT, |
| 7847 | "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n", |
| 7848 | pf->num_lan_msix, |
| 7849 | pf->num_vmdq_msix * pf->num_vmdq_vsis, |
| 7850 | pf->num_fdsb_msix, |
| 7851 | pf->num_iwarp_msix); |
| 7852 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7853 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7854 | } |
| 7855 | |
| 7856 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7857 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7858 | * @vsi: the VSI being configured |
| 7859 | * @v_idx: index of the vector in the vsi struct |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7860 | * @cpu: cpu to be used on affinity_mask |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7861 | * |
| 7862 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 7863 | **/ |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7864 | static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7865 | { |
| 7866 | struct i40e_q_vector *q_vector; |
| 7867 | |
| 7868 | /* allocate q_vector */ |
| 7869 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 7870 | if (!q_vector) |
| 7871 | return -ENOMEM; |
| 7872 | |
| 7873 | q_vector->vsi = vsi; |
| 7874 | q_vector->v_idx = v_idx; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7875 | cpumask_set_cpu(cpu, &q_vector->affinity_mask); |
| 7876 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7877 | if (vsi->netdev) |
| 7878 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 7879 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7880 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 7881 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 7882 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 7883 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7884 | /* tie q_vector and vsi together */ |
| 7885 | vsi->q_vectors[v_idx] = q_vector; |
| 7886 | |
| 7887 | return 0; |
| 7888 | } |
| 7889 | |
| 7890 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7891 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7892 | * @vsi: the VSI being configured |
| 7893 | * |
| 7894 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 7895 | * return -ENOMEM. |
| 7896 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7897 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7898 | { |
| 7899 | struct i40e_pf *pf = vsi->back; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7900 | int err, v_idx, num_q_vectors, current_cpu; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7901 | |
| 7902 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 7903 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7904 | num_q_vectors = vsi->num_q_vectors; |
| 7905 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 7906 | num_q_vectors = 1; |
| 7907 | else |
| 7908 | return -EINVAL; |
| 7909 | |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7910 | current_cpu = cpumask_first(cpu_online_mask); |
| 7911 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7912 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7913 | err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7914 | if (err) |
| 7915 | goto err_out; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7916 | current_cpu = cpumask_next(current_cpu, cpu_online_mask); |
| 7917 | if (unlikely(current_cpu >= nr_cpu_ids)) |
| 7918 | current_cpu = cpumask_first(cpu_online_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7919 | } |
| 7920 | |
| 7921 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7922 | |
| 7923 | err_out: |
| 7924 | while (v_idx--) |
| 7925 | i40e_free_q_vector(vsi, v_idx); |
| 7926 | |
| 7927 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7928 | } |
| 7929 | |
| 7930 | /** |
| 7931 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 7932 | * @pf: board private structure to initialize |
| 7933 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7934 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7935 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7936 | int vectors = 0; |
| 7937 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7938 | |
| 7939 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7940 | vectors = i40e_init_msix(pf); |
| 7941 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7942 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7943 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7944 | #ifdef I40E_FCOE |
| 7945 | I40E_FLAG_FCOE_ENABLED | |
| 7946 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7947 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7948 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 7949 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7950 | I40E_FLAG_SRIOV_ENABLED | |
| 7951 | I40E_FLAG_FD_SB_ENABLED | |
| 7952 | I40E_FLAG_FD_ATR_ENABLED | |
| 7953 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7954 | |
| 7955 | /* rework the queue expectations without MSIX */ |
| 7956 | i40e_determine_queue_usage(pf); |
| 7957 | } |
| 7958 | } |
| 7959 | |
| 7960 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 7961 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7962 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7963 | vectors = pci_enable_msi(pf->pdev); |
| 7964 | if (vectors < 0) { |
| 7965 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 7966 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7967 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 7968 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7969 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7970 | } |
| 7971 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 7972 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7973 | 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] | 7974 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7975 | /* set up vector assignment tracking */ |
| 7976 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 7977 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7978 | if (!pf->irq_pile) { |
| 7979 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 7980 | return -ENOMEM; |
| 7981 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7982 | pf->irq_pile->num_entries = vectors; |
| 7983 | pf->irq_pile->search_hint = 0; |
| 7984 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7985 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7986 | (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] | 7987 | |
| 7988 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7989 | } |
| 7990 | |
| 7991 | /** |
| 7992 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 7993 | * @pf: board private structure |
| 7994 | * |
| 7995 | * This sets up the handler for MSIX 0, which is used to manage the |
| 7996 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 7997 | * when in MSI or Legacy interrupt mode. |
| 7998 | **/ |
| 7999 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 8000 | { |
| 8001 | struct i40e_hw *hw = &pf->hw; |
| 8002 | int err = 0; |
| 8003 | |
| 8004 | /* Only request the irq if this is the first time through, and |
| 8005 | * not when we're rebuilding after a Reset |
| 8006 | */ |
| 8007 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 8008 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8009 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8010 | if (err) { |
| 8011 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8012 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8013 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8014 | return -EFAULT; |
| 8015 | } |
| 8016 | } |
| 8017 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 8018 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8019 | |
| 8020 | /* associate no queues to the misc vector */ |
| 8021 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 8022 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 8023 | |
| 8024 | i40e_flush(hw); |
| 8025 | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 8026 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8027 | |
| 8028 | return err; |
| 8029 | } |
| 8030 | |
| 8031 | /** |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8032 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 8033 | * @vsi: vsi structure |
| 8034 | * @seed: RSS hash seed |
| 8035 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8036 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8037 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8038 | { |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8039 | struct i40e_pf *pf = vsi->back; |
| 8040 | struct i40e_hw *hw = &pf->hw; |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8041 | int ret = 0; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8042 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8043 | if (seed) { |
| 8044 | struct i40e_aqc_get_set_rss_key_data *seed_dw = |
| 8045 | (struct i40e_aqc_get_set_rss_key_data *)seed; |
| 8046 | ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw); |
| 8047 | if (ret) { |
| 8048 | dev_info(&pf->pdev->dev, |
| 8049 | "Cannot set RSS key, err %s aq_err %s\n", |
| 8050 | i40e_stat_str(hw, ret), |
| 8051 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8052 | return ret; |
| 8053 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8054 | } |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8055 | if (lut) { |
| 8056 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8057 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8058 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8059 | if (ret) { |
| 8060 | dev_info(&pf->pdev->dev, |
| 8061 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 8062 | i40e_stat_str(hw, ret), |
| 8063 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8064 | return ret; |
| 8065 | } |
| 8066 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8067 | return ret; |
| 8068 | } |
| 8069 | |
| 8070 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8071 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 8072 | * @vsi: Pointer to vsi structure |
| 8073 | * @seed: Buffter to store the hash keys |
| 8074 | * @lut: Buffer to store the lookup table entries |
| 8075 | * @lut_size: Size of buffer to store the lookup table entries |
| 8076 | * |
| 8077 | * Return 0 on success, negative on failure |
| 8078 | */ |
| 8079 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8080 | u8 *lut, u16 lut_size) |
| 8081 | { |
| 8082 | struct i40e_pf *pf = vsi->back; |
| 8083 | struct i40e_hw *hw = &pf->hw; |
| 8084 | int ret = 0; |
| 8085 | |
| 8086 | if (seed) { |
| 8087 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 8088 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 8089 | if (ret) { |
| 8090 | dev_info(&pf->pdev->dev, |
| 8091 | "Cannot get RSS key, err %s aq_err %s\n", |
| 8092 | i40e_stat_str(&pf->hw, ret), |
| 8093 | i40e_aq_str(&pf->hw, |
| 8094 | pf->hw.aq.asq_last_status)); |
| 8095 | return ret; |
| 8096 | } |
| 8097 | } |
| 8098 | |
| 8099 | if (lut) { |
| 8100 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 8101 | |
| 8102 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8103 | if (ret) { |
| 8104 | dev_info(&pf->pdev->dev, |
| 8105 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 8106 | i40e_stat_str(&pf->hw, ret), |
| 8107 | i40e_aq_str(&pf->hw, |
| 8108 | pf->hw.aq.asq_last_status)); |
| 8109 | return ret; |
| 8110 | } |
| 8111 | } |
| 8112 | |
| 8113 | return ret; |
| 8114 | } |
| 8115 | |
| 8116 | /** |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8117 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 8118 | * @vsi: VSI structure |
| 8119 | **/ |
| 8120 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 8121 | { |
| 8122 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 8123 | struct i40e_pf *pf = vsi->back; |
| 8124 | u8 *lut; |
| 8125 | int ret; |
| 8126 | |
| 8127 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) |
| 8128 | return 0; |
| 8129 | |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8130 | if (!vsi->rss_size) |
| 8131 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8132 | vsi->num_queue_pairs); |
| 8133 | if (!vsi->rss_size) |
| 8134 | return -EINVAL; |
| 8135 | |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8136 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8137 | if (!lut) |
| 8138 | return -ENOMEM; |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8139 | /* Use the user configured hash keys and lookup table if there is one, |
| 8140 | * otherwise use default |
| 8141 | */ |
| 8142 | if (vsi->rss_lut_user) |
| 8143 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8144 | else |
| 8145 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
| 8146 | if (vsi->rss_hkey_user) |
| 8147 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8148 | else |
| 8149 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8150 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 8151 | kfree(lut); |
| 8152 | |
| 8153 | return ret; |
| 8154 | } |
| 8155 | |
| 8156 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8157 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8158 | * @vsi: Pointer to vsi structure |
| 8159 | * @seed: RSS hash seed |
| 8160 | * @lut: Lookup table |
| 8161 | * @lut_size: Lookup table size |
| 8162 | * |
| 8163 | * Returns 0 on success, negative on failure |
| 8164 | **/ |
| 8165 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8166 | const u8 *lut, u16 lut_size) |
| 8167 | { |
| 8168 | struct i40e_pf *pf = vsi->back; |
| 8169 | struct i40e_hw *hw = &pf->hw; |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8170 | u16 vf_id = vsi->vf_id; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8171 | u8 i; |
| 8172 | |
| 8173 | /* Fill out hash function seed */ |
| 8174 | if (seed) { |
| 8175 | u32 *seed_dw = (u32 *)seed; |
| 8176 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8177 | if (vsi->type == I40E_VSI_MAIN) { |
| 8178 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 8179 | i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), |
| 8180 | seed_dw[i]); |
| 8181 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8182 | for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++) |
| 8183 | i40e_write_rx_ctl(hw, |
| 8184 | I40E_VFQF_HKEY1(i, vf_id), |
| 8185 | seed_dw[i]); |
| 8186 | } else { |
| 8187 | dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n"); |
| 8188 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8189 | } |
| 8190 | |
| 8191 | if (lut) { |
| 8192 | u32 *lut_dw = (u32 *)lut; |
| 8193 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8194 | if (vsi->type == I40E_VSI_MAIN) { |
| 8195 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8196 | return -EINVAL; |
| 8197 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8198 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8199 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8200 | if (lut_size != I40E_VF_HLUT_ARRAY_SIZE) |
| 8201 | return -EINVAL; |
| 8202 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8203 | i40e_write_rx_ctl(hw, |
| 8204 | I40E_VFQF_HLUT1(i, vf_id), |
| 8205 | lut_dw[i]); |
| 8206 | } else { |
| 8207 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8208 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8209 | } |
| 8210 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8211 | |
| 8212 | return 0; |
| 8213 | } |
| 8214 | |
| 8215 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8216 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8217 | * @vsi: Pointer to VSI structure |
| 8218 | * @seed: Buffer to store the keys |
| 8219 | * @lut: Buffer to store the lookup table entries |
| 8220 | * @lut_size: Size of buffer to store the lookup table entries |
| 8221 | * |
| 8222 | * Returns 0 on success, negative on failure |
| 8223 | */ |
| 8224 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8225 | u8 *lut, u16 lut_size) |
| 8226 | { |
| 8227 | struct i40e_pf *pf = vsi->back; |
| 8228 | struct i40e_hw *hw = &pf->hw; |
| 8229 | u16 i; |
| 8230 | |
| 8231 | if (seed) { |
| 8232 | u32 *seed_dw = (u32 *)seed; |
| 8233 | |
| 8234 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8235 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8236 | } |
| 8237 | if (lut) { |
| 8238 | u32 *lut_dw = (u32 *)lut; |
| 8239 | |
| 8240 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8241 | return -EINVAL; |
| 8242 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8243 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8244 | } |
| 8245 | |
| 8246 | return 0; |
| 8247 | } |
| 8248 | |
| 8249 | /** |
| 8250 | * i40e_config_rss - Configure RSS keys and lut |
| 8251 | * @vsi: Pointer to VSI structure |
| 8252 | * @seed: RSS hash seed |
| 8253 | * @lut: Lookup table |
| 8254 | * @lut_size: Lookup table size |
| 8255 | * |
| 8256 | * Returns 0 on success, negative on failure |
| 8257 | */ |
| 8258 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8259 | { |
| 8260 | struct i40e_pf *pf = vsi->back; |
| 8261 | |
| 8262 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8263 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8264 | else |
| 8265 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8266 | } |
| 8267 | |
| 8268 | /** |
| 8269 | * i40e_get_rss - Get RSS keys and lut |
| 8270 | * @vsi: Pointer to VSI structure |
| 8271 | * @seed: Buffer to store the keys |
| 8272 | * @lut: Buffer to store the lookup table entries |
| 8273 | * lut_size: Size of buffer to store the lookup table entries |
| 8274 | * |
| 8275 | * Returns 0 on success, negative on failure |
| 8276 | */ |
| 8277 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8278 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8279 | struct i40e_pf *pf = vsi->back; |
| 8280 | |
| 8281 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8282 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8283 | else |
| 8284 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8285 | } |
| 8286 | |
| 8287 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8288 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8289 | * @pf: Pointer to board private structure |
| 8290 | * @lut: Lookup table |
| 8291 | * @rss_table_size: Lookup table size |
| 8292 | * @rss_size: Range of queue number for hashing |
| 8293 | */ |
Alan Brady | f158235 | 2016-08-24 11:33:46 -0700 | [diff] [blame] | 8294 | void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8295 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8296 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8297 | u16 i; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8298 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8299 | for (i = 0; i < rss_table_size; i++) |
| 8300 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8301 | } |
| 8302 | |
| 8303 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8304 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8305 | * @pf: board private structure |
| 8306 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8307 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8308 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8309 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8310 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8311 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8312 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8313 | u32 reg_val; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8314 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8315 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8316 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8317 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8318 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 8319 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8320 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8321 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8322 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8323 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8324 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8325 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8326 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8327 | reg_val = (pf->rss_table_size == 512) ? |
| 8328 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8329 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8330 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8331 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8332 | /* Determine the RSS size of the VSI */ |
| 8333 | if (!vsi->rss_size) |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8334 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8335 | vsi->num_queue_pairs); |
Mitch Williams | a4fa59c | 2016-09-12 14:18:43 -0700 | [diff] [blame] | 8336 | if (!vsi->rss_size) |
| 8337 | return -EINVAL; |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8338 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8339 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8340 | if (!lut) |
| 8341 | return -ENOMEM; |
| 8342 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8343 | /* Use user configured lut if there is one, otherwise use default */ |
| 8344 | if (vsi->rss_lut_user) |
| 8345 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8346 | else |
| 8347 | 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] | 8348 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8349 | /* Use user configured hash key if there is one, otherwise |
| 8350 | * use default. |
| 8351 | */ |
| 8352 | if (vsi->rss_hkey_user) |
| 8353 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8354 | else |
| 8355 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8356 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8357 | kfree(lut); |
| 8358 | |
| 8359 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8360 | } |
| 8361 | |
| 8362 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8363 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8364 | * @pf: board private structure |
| 8365 | * @queue_count: the requested queue count for rss. |
| 8366 | * |
| 8367 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8368 | * count which may be different from the requested queue count. |
| 8369 | **/ |
| 8370 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8371 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8372 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8373 | int new_rss_size; |
| 8374 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8375 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8376 | return 0; |
| 8377 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8378 | 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] | 8379 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8380 | if (queue_count != vsi->num_queue_pairs) { |
| 8381 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8382 | i40e_prep_for_reset(pf); |
| 8383 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8384 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8385 | |
| 8386 | i40e_reset_and_rebuild(pf, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8387 | |
| 8388 | /* Discard the user configured hash keys and lut, if less |
| 8389 | * queues are enabled. |
| 8390 | */ |
| 8391 | if (queue_count < vsi->rss_size) { |
| 8392 | i40e_clear_rss_config_user(vsi); |
| 8393 | dev_dbg(&pf->pdev->dev, |
| 8394 | "discard user configured hash keys and lut\n"); |
| 8395 | } |
| 8396 | |
| 8397 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8398 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8399 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8400 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8401 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8402 | } |
Lihong Yang | 1281505 | 2016-09-27 11:28:48 -0700 | [diff] [blame^] | 8403 | dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n", |
| 8404 | vsi->req_queue_pairs, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8405 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8406 | } |
| 8407 | |
| 8408 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8409 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 8410 | * @pf: board private structure |
| 8411 | **/ |
| 8412 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 8413 | { |
| 8414 | i40e_status status; |
| 8415 | bool min_valid, max_valid; |
| 8416 | u32 max_bw, min_bw; |
| 8417 | |
| 8418 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8419 | &min_valid, &max_valid); |
| 8420 | |
| 8421 | if (!status) { |
| 8422 | if (min_valid) |
| 8423 | pf->npar_min_bw = min_bw; |
| 8424 | if (max_valid) |
| 8425 | pf->npar_max_bw = max_bw; |
| 8426 | } |
| 8427 | |
| 8428 | return status; |
| 8429 | } |
| 8430 | |
| 8431 | /** |
| 8432 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 8433 | * @pf: board private structure |
| 8434 | **/ |
| 8435 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 8436 | { |
| 8437 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8438 | i40e_status status; |
| 8439 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8440 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8441 | 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] | 8442 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8443 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 8444 | |
| 8445 | /* Set the new bandwidths */ |
| 8446 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8447 | |
| 8448 | return status; |
| 8449 | } |
| 8450 | |
| 8451 | /** |
| 8452 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 8453 | * @pf: board private structure |
| 8454 | **/ |
| 8455 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 8456 | { |
| 8457 | /* Commit temporary BW setting to permanent NVM image */ |
| 8458 | enum i40e_admin_queue_err last_aq_status; |
| 8459 | i40e_status ret; |
| 8460 | u16 nvm_word; |
| 8461 | |
| 8462 | if (pf->hw.partition_id != 1) { |
| 8463 | dev_info(&pf->pdev->dev, |
| 8464 | "Commit BW only works on partition 1! This is partition %d", |
| 8465 | pf->hw.partition_id); |
| 8466 | ret = I40E_NOT_SUPPORTED; |
| 8467 | goto bw_commit_out; |
| 8468 | } |
| 8469 | |
| 8470 | /* Acquire NVM for read access */ |
| 8471 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8472 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8473 | if (ret) { |
| 8474 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8475 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8476 | i40e_stat_str(&pf->hw, ret), |
| 8477 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8478 | goto bw_commit_out; |
| 8479 | } |
| 8480 | |
| 8481 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8482 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8483 | I40E_SR_NVM_CONTROL_WORD, |
| 8484 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8485 | false, NULL); |
| 8486 | /* Save off last admin queue command status before releasing |
| 8487 | * the NVM |
| 8488 | */ |
| 8489 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8490 | i40e_release_nvm(&pf->hw); |
| 8491 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8492 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8493 | i40e_stat_str(&pf->hw, ret), |
| 8494 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8495 | goto bw_commit_out; |
| 8496 | } |
| 8497 | |
| 8498 | /* Wait a bit for NVM release to complete */ |
| 8499 | msleep(50); |
| 8500 | |
| 8501 | /* Acquire NVM for write access */ |
| 8502 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8503 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8504 | if (ret) { |
| 8505 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8506 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8507 | i40e_stat_str(&pf->hw, ret), |
| 8508 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8509 | goto bw_commit_out; |
| 8510 | } |
| 8511 | /* Write it back out unchanged to initiate update NVM, |
| 8512 | * which will force a write of the shadow (alt) RAM to |
| 8513 | * the NVM - thus storing the bandwidth values permanently. |
| 8514 | */ |
| 8515 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8516 | I40E_SR_NVM_CONTROL_WORD, |
| 8517 | 0x10, sizeof(nvm_word), |
| 8518 | &nvm_word, true, NULL); |
| 8519 | /* Save off last admin queue command status before releasing |
| 8520 | * the NVM |
| 8521 | */ |
| 8522 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8523 | i40e_release_nvm(&pf->hw); |
| 8524 | if (ret) |
| 8525 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8526 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8527 | i40e_stat_str(&pf->hw, ret), |
| 8528 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8529 | bw_commit_out: |
| 8530 | |
| 8531 | return ret; |
| 8532 | } |
| 8533 | |
| 8534 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8535 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8536 | * @pf: board private structure to initialize |
| 8537 | * |
| 8538 | * i40e_sw_init initializes the Adapter private data structure. |
| 8539 | * Fields are initialized based on PCI device information and |
| 8540 | * OS network device settings (MTU size). |
| 8541 | **/ |
| 8542 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8543 | { |
| 8544 | int err = 0; |
| 8545 | int size; |
| 8546 | |
| 8547 | pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, |
| 8548 | (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); |
| 8549 | if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { |
| 8550 | if (I40E_DEBUG_USER & debug) |
| 8551 | pf->hw.debug_mask = debug; |
| 8552 | pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), |
| 8553 | I40E_DEFAULT_MSG_ENABLE); |
| 8554 | } |
| 8555 | |
| 8556 | /* Set default capability flags */ |
| 8557 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8558 | I40E_FLAG_MSI_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8559 | I40E_FLAG_MSIX_ENABLED; |
| 8560 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8561 | /* Set default ITR */ |
| 8562 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8563 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8564 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8565 | /* Depending on PF configurations, it is possible that the RSS |
| 8566 | * maximum might end up larger than the available queues |
| 8567 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8568 | 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] | 8569 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8570 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8571 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8572 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8573 | if (pf->hw.func_caps.rss) { |
| 8574 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8575 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8576 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8577 | } |
| 8578 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8579 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8580 | 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] | 8581 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8582 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8583 | if (i40e_get_npar_bw_setting(pf)) |
| 8584 | dev_warn(&pf->pdev->dev, |
| 8585 | "Could not get NPAR bw settings\n"); |
| 8586 | else |
| 8587 | dev_info(&pf->pdev->dev, |
| 8588 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 8589 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8590 | } |
| 8591 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8592 | /* FW/NVM is not yet fixed in this regard */ |
| 8593 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8594 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8595 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8596 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8597 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8598 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8599 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8600 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8601 | else |
| 8602 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8603 | pf->fdir_pf_filter_count = |
| 8604 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8605 | pf->hw.fdir_shared_filter_count = |
| 8606 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8607 | } |
| 8608 | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8609 | if (i40e_is_mac_710(&pf->hw) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8610 | (((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] | 8611 | (pf->hw.aq.fw_maj_ver < 4))) { |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8612 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8613 | /* No DCB support for FW < v4.33 */ |
| 8614 | pf->flags |= I40E_FLAG_NO_DCB_SUPPORT; |
| 8615 | } |
| 8616 | |
| 8617 | /* Disable FW LLDP if FW < v4.3 */ |
| 8618 | if (i40e_is_mac_710(&pf->hw) && |
| 8619 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 8620 | (pf->hw.aq.fw_maj_ver < 4))) |
| 8621 | pf->flags |= I40E_FLAG_STOP_FW_LLDP; |
| 8622 | |
| 8623 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
| 8624 | if (i40e_is_mac_710(&pf->hw) && |
| 8625 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 8626 | (pf->hw.aq.fw_maj_ver >= 5))) |
| 8627 | pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8628 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8629 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8630 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8631 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 8632 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8633 | } |
| 8634 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8635 | if (pf->hw.func_caps.iwarp) { |
| 8636 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 8637 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 8638 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 8639 | } |
| 8640 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8641 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 8642 | i40e_init_pf_fcoe(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8643 | |
| 8644 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8645 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 8646 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8647 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 8648 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 8649 | pf->num_req_vfs = min_t(int, |
| 8650 | pf->hw.func_caps.num_vfs, |
| 8651 | I40E_MAX_VF_COUNT); |
| 8652 | } |
| 8653 | #endif /* CONFIG_PCI_IOV */ |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8654 | if (pf->hw.mac.type == I40E_MAC_X722) { |
| 8655 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE | |
| 8656 | I40E_FLAG_128_QP_RSS_CAPABLE | |
| 8657 | I40E_FLAG_HW_ATR_EVICT_CAPABLE | |
| 8658 | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE | |
| 8659 | I40E_FLAG_WB_ON_ITR_CAPABLE | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8660 | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
Jesse Brandeburg | 8e2cc0e | 2016-02-29 11:00:24 -0800 | [diff] [blame] | 8661 | I40E_FLAG_NO_PCI_LINK_CHECK | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8662 | I40E_FLAG_USE_SET_LLDP_MIB | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8663 | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8664 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 8665 | ((pf->hw.aq.api_maj_ver == 1) && |
| 8666 | (pf->hw.aq.api_min_ver > 4))) { |
| 8667 | /* Supported in FW API version higher than 1.4 */ |
| 8668 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 8669 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
| 8670 | } else { |
| 8671 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8672 | } |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8673 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8674 | pf->eeprom_version = 0xDEAD; |
| 8675 | pf->lan_veb = I40E_NO_VEB; |
| 8676 | pf->lan_vsi = I40E_NO_VSI; |
| 8677 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 8678 | /* By default FW has this off for performance reasons */ |
| 8679 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 8680 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8681 | /* set up queue assignment tracking */ |
| 8682 | size = sizeof(struct i40e_lump_tracking) |
| 8683 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 8684 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 8685 | if (!pf->qp_pile) { |
| 8686 | err = -ENOMEM; |
| 8687 | goto sw_init_done; |
| 8688 | } |
| 8689 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 8690 | pf->qp_pile->search_hint = 0; |
| 8691 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 8692 | pf->tx_timeout_recovery_level = 1; |
| 8693 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8694 | mutex_init(&pf->switch_mutex); |
| 8695 | |
Greg Rose | c668a12 | 2015-02-26 16:10:39 +0000 | [diff] [blame] | 8696 | /* If NPAR is enabled nudge the Tx scheduler */ |
| 8697 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) |
| 8698 | i40e_set_npar_bw_setting(pf); |
| 8699 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8700 | sw_init_done: |
| 8701 | return err; |
| 8702 | } |
| 8703 | |
| 8704 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8705 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 8706 | * @pf: board private structure to initialize |
| 8707 | * @features: the feature set that the stack is suggesting |
| 8708 | * |
| 8709 | * returns a bool to indicate if reset needs to happen |
| 8710 | **/ |
| 8711 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 8712 | { |
| 8713 | bool need_reset = false; |
| 8714 | |
| 8715 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 8716 | * the state changed, we need to reset. |
| 8717 | */ |
| 8718 | if (features & NETIF_F_NTUPLE) { |
| 8719 | /* Enable filters and mark for reset */ |
| 8720 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 8721 | need_reset = true; |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 8722 | /* enable FD_SB only if there is MSI-X vector */ |
| 8723 | if (pf->num_fdsb_msix > 0) |
| 8724 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8725 | } else { |
| 8726 | /* turn off filters, mark for reset and clear SW filter list */ |
| 8727 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8728 | need_reset = true; |
| 8729 | i40e_fdir_filter_exit(pf); |
| 8730 | } |
| 8731 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8732 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 8733 | /* reset fd counters */ |
| 8734 | pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0; |
| 8735 | pf->fdir_pf_active_filters = 0; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8736 | /* if ATR was auto disabled it can be re-enabled. */ |
| 8737 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 8738 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8739 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 8740 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 8741 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
| 8742 | } |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8743 | } |
| 8744 | return need_reset; |
| 8745 | } |
| 8746 | |
| 8747 | /** |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8748 | * i40e_clear_rss_lut - clear the rx hash lookup table |
| 8749 | * @vsi: the VSI being configured |
| 8750 | **/ |
| 8751 | static void i40e_clear_rss_lut(struct i40e_vsi *vsi) |
| 8752 | { |
| 8753 | struct i40e_pf *pf = vsi->back; |
| 8754 | struct i40e_hw *hw = &pf->hw; |
| 8755 | u16 vf_id = vsi->vf_id; |
| 8756 | u8 i; |
| 8757 | |
| 8758 | if (vsi->type == I40E_VSI_MAIN) { |
| 8759 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8760 | wr32(hw, I40E_PFQF_HLUT(i), 0); |
| 8761 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8762 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8763 | i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0); |
| 8764 | } else { |
| 8765 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8766 | } |
| 8767 | } |
| 8768 | |
| 8769 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8770 | * i40e_set_features - set the netdev feature flags |
| 8771 | * @netdev: ptr to the netdev being adjusted |
| 8772 | * @features: the feature set that the stack is suggesting |
| 8773 | **/ |
| 8774 | static int i40e_set_features(struct net_device *netdev, |
| 8775 | netdev_features_t features) |
| 8776 | { |
| 8777 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8778 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8779 | struct i40e_pf *pf = vsi->back; |
| 8780 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8781 | |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8782 | if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH)) |
| 8783 | i40e_pf_config_rss(pf); |
| 8784 | else if (!(features & NETIF_F_RXHASH) && |
| 8785 | netdev->features & NETIF_F_RXHASH) |
| 8786 | i40e_clear_rss_lut(vsi); |
| 8787 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8788 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8789 | i40e_vlan_stripping_enable(vsi); |
| 8790 | else |
| 8791 | i40e_vlan_stripping_disable(vsi); |
| 8792 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8793 | need_reset = i40e_set_ntuple(pf, features); |
| 8794 | |
| 8795 | if (need_reset) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8796 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8797 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8798 | return 0; |
| 8799 | } |
| 8800 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8801 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8802 | * 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] | 8803 | * @pf: board private structure |
| 8804 | * @port: The UDP port to look up |
| 8805 | * |
| 8806 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 8807 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8808 | 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] | 8809 | { |
| 8810 | u8 i; |
| 8811 | |
| 8812 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8813 | if (pf->udp_ports[i].index == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8814 | return i; |
| 8815 | } |
| 8816 | |
| 8817 | return i; |
| 8818 | } |
| 8819 | |
| 8820 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8821 | * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8822 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8823 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8824 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8825 | static void i40e_udp_tunnel_add(struct net_device *netdev, |
| 8826 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8827 | { |
| 8828 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8829 | struct i40e_vsi *vsi = np->vsi; |
| 8830 | struct i40e_pf *pf = vsi->back; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8831 | __be16 port = ti->port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8832 | u8 next_idx; |
| 8833 | u8 idx; |
| 8834 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8835 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8836 | |
| 8837 | /* Check if port already exists */ |
| 8838 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8839 | netdev_info(netdev, "port %d already offloaded\n", |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8840 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8841 | return; |
| 8842 | } |
| 8843 | |
| 8844 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8845 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8846 | |
| 8847 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8848 | netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n", |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8849 | ntohs(port)); |
| 8850 | return; |
| 8851 | } |
| 8852 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8853 | switch (ti->type) { |
| 8854 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8855 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 8856 | break; |
| 8857 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8858 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8859 | return; |
| 8860 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 8861 | break; |
| 8862 | default: |
| 8863 | return; |
| 8864 | } |
| 8865 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8866 | /* New port: add it and mark its index in the bitmap */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8867 | pf->udp_ports[next_idx].index = port; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8868 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8869 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8870 | } |
| 8871 | |
| 8872 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8873 | * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8874 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8875 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8876 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8877 | static void i40e_udp_tunnel_del(struct net_device *netdev, |
| 8878 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8879 | { |
| 8880 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8881 | struct i40e_vsi *vsi = np->vsi; |
| 8882 | struct i40e_pf *pf = vsi->back; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8883 | __be16 port = ti->port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8884 | u8 idx; |
| 8885 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8886 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8887 | |
| 8888 | /* Check if port already exists */ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8889 | if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS) |
| 8890 | goto not_found; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8891 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8892 | switch (ti->type) { |
| 8893 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8894 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN) |
| 8895 | goto not_found; |
| 8896 | break; |
| 8897 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8898 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE) |
| 8899 | goto not_found; |
| 8900 | break; |
| 8901 | default: |
| 8902 | goto not_found; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8903 | } |
| 8904 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8905 | /* if port exists, set it to 0 (mark for deletion) |
| 8906 | * and make it pending |
| 8907 | */ |
| 8908 | pf->udp_ports[idx].index = 0; |
| 8909 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8910 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8911 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8912 | return; |
| 8913 | not_found: |
| 8914 | netdev_warn(netdev, "UDP port %d was not found, not deleting\n", |
| 8915 | ntohs(port)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8916 | } |
| 8917 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8918 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 8919 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8920 | { |
| 8921 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8922 | struct i40e_pf *pf = np->vsi->back; |
| 8923 | struct i40e_hw *hw = &pf->hw; |
| 8924 | |
| 8925 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 8926 | return -EOPNOTSUPP; |
| 8927 | |
| 8928 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 8929 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 8930 | |
| 8931 | return 0; |
| 8932 | } |
| 8933 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 8934 | /** |
| 8935 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 8936 | * @ndm: the input from the stack |
| 8937 | * @tb: pointer to array of nladdr (unused) |
| 8938 | * @dev: the net device pointer |
| 8939 | * @addr: the MAC address entry being added |
| 8940 | * @flags: instructions from stack about fdb operation |
| 8941 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8942 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 8943 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8944 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8945 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8946 | { |
| 8947 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8948 | struct i40e_pf *pf = np->vsi->back; |
| 8949 | int err = 0; |
| 8950 | |
| 8951 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 8952 | return -EOPNOTSUPP; |
| 8953 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 8954 | if (vid) { |
| 8955 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 8956 | return -EINVAL; |
| 8957 | } |
| 8958 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8959 | /* Hardware does not support aging addresses so if a |
| 8960 | * ndm_state is given only allow permanent addresses |
| 8961 | */ |
| 8962 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 8963 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 8964 | return -EINVAL; |
| 8965 | } |
| 8966 | |
| 8967 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 8968 | err = dev_uc_add_excl(dev, addr); |
| 8969 | else if (is_multicast_ether_addr(addr)) |
| 8970 | err = dev_mc_add_excl(dev, addr); |
| 8971 | else |
| 8972 | err = -EINVAL; |
| 8973 | |
| 8974 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 8975 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 8976 | err = 0; |
| 8977 | |
| 8978 | return err; |
| 8979 | } |
| 8980 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8981 | /** |
| 8982 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 8983 | * @dev: the netdev being configured |
| 8984 | * @nlh: RTNL message |
| 8985 | * |
| 8986 | * Inserts a new hardware bridge if not already created and |
| 8987 | * enables the bridging mode requested (VEB or VEPA). If the |
| 8988 | * hardware bridge has already been inserted and the request |
| 8989 | * is to change the mode then that requires a PF reset to |
| 8990 | * allow rebuild of the components with required hardware |
| 8991 | * bridge mode enabled. |
| 8992 | **/ |
| 8993 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 8994 | struct nlmsghdr *nlh, |
| 8995 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8996 | { |
| 8997 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8998 | struct i40e_vsi *vsi = np->vsi; |
| 8999 | struct i40e_pf *pf = vsi->back; |
| 9000 | struct i40e_veb *veb = NULL; |
| 9001 | struct nlattr *attr, *br_spec; |
| 9002 | int i, rem; |
| 9003 | |
| 9004 | /* Only for PF VSI for now */ |
| 9005 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9006 | return -EOPNOTSUPP; |
| 9007 | |
| 9008 | /* Find the HW bridge for PF VSI */ |
| 9009 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9010 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9011 | veb = pf->veb[i]; |
| 9012 | } |
| 9013 | |
| 9014 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 9015 | |
| 9016 | nla_for_each_nested(attr, br_spec, rem) { |
| 9017 | __u16 mode; |
| 9018 | |
| 9019 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 9020 | continue; |
| 9021 | |
| 9022 | mode = nla_get_u16(attr); |
| 9023 | if ((mode != BRIDGE_MODE_VEPA) && |
| 9024 | (mode != BRIDGE_MODE_VEB)) |
| 9025 | return -EINVAL; |
| 9026 | |
| 9027 | /* Insert a new HW bridge */ |
| 9028 | if (!veb) { |
| 9029 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9030 | vsi->tc_config.enabled_tc); |
| 9031 | if (veb) { |
| 9032 | veb->bridge_mode = mode; |
| 9033 | i40e_config_bridge_mode(veb); |
| 9034 | } else { |
| 9035 | /* No Bridge HW offload available */ |
| 9036 | return -ENOENT; |
| 9037 | } |
| 9038 | break; |
| 9039 | } else if (mode != veb->bridge_mode) { |
| 9040 | /* Existing HW bridge but different mode needs reset */ |
| 9041 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9042 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 9043 | if (mode == BRIDGE_MODE_VEB) |
| 9044 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 9045 | else |
| 9046 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9047 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9048 | break; |
| 9049 | } |
| 9050 | } |
| 9051 | |
| 9052 | return 0; |
| 9053 | } |
| 9054 | |
| 9055 | /** |
| 9056 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 9057 | * @skb: skb buff |
| 9058 | * @pid: process id |
| 9059 | * @seq: RTNL message seq # |
| 9060 | * @dev: the netdev being configured |
| 9061 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 9062 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9063 | * |
| 9064 | * Return the mode in which the hardware bridge is operating in |
| 9065 | * i.e VEB or VEPA. |
| 9066 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9067 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 9068 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 9069 | u32 __always_unused filter_mask, |
| 9070 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9071 | { |
| 9072 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9073 | struct i40e_vsi *vsi = np->vsi; |
| 9074 | struct i40e_pf *pf = vsi->back; |
| 9075 | struct i40e_veb *veb = NULL; |
| 9076 | int i; |
| 9077 | |
| 9078 | /* Only for PF VSI for now */ |
| 9079 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9080 | return -EOPNOTSUPP; |
| 9081 | |
| 9082 | /* Find the HW bridge for the PF VSI */ |
| 9083 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9084 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9085 | veb = pf->veb[i]; |
| 9086 | } |
| 9087 | |
| 9088 | if (!veb) |
| 9089 | return 0; |
| 9090 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9091 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 9092 | nlflags, 0, 0, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9093 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9094 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9095 | /* Hardware supports L4 tunnel length of 128B (=2^7) which includes |
| 9096 | * inner mac plus all inner ethertypes. |
| 9097 | */ |
| 9098 | #define I40E_MAX_TUNNEL_HDR_LEN 128 |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9099 | /** |
| 9100 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 9101 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 9102 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9103 | * @features: Offload features that the stack believes apply |
| 9104 | **/ |
| 9105 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 9106 | struct net_device *dev, |
| 9107 | netdev_features_t features) |
| 9108 | { |
| 9109 | if (skb->encapsulation && |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9110 | ((skb_inner_network_header(skb) - skb_transport_header(skb)) > |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9111 | I40E_MAX_TUNNEL_HDR_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 9112 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9113 | |
| 9114 | return features; |
| 9115 | } |
| 9116 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 9117 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9118 | .ndo_open = i40e_open, |
| 9119 | .ndo_stop = i40e_close, |
| 9120 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 9121 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 9122 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 9123 | .ndo_validate_addr = eth_validate_addr, |
| 9124 | .ndo_set_mac_address = i40e_set_mac, |
| 9125 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 9126 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9127 | .ndo_tx_timeout = i40e_tx_timeout, |
| 9128 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 9129 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 9130 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9131 | .ndo_poll_controller = i40e_netpoll, |
| 9132 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9133 | .ndo_setup_tc = __i40e_setup_tc, |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9134 | #ifdef I40E_FCOE |
| 9135 | .ndo_fcoe_enable = i40e_fcoe_enable, |
| 9136 | .ndo_fcoe_disable = i40e_fcoe_disable, |
| 9137 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9138 | .ndo_set_features = i40e_set_features, |
| 9139 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 9140 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9141 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9142 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 9143 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 9144 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Anjali Singhai Jain | c3bbbd2 | 2016-04-01 03:56:07 -0700 | [diff] [blame] | 9145 | .ndo_set_vf_trust = i40e_ndo_set_vf_trust, |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9146 | .ndo_udp_tunnel_add = i40e_udp_tunnel_add, |
| 9147 | .ndo_udp_tunnel_del = i40e_udp_tunnel_del, |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9148 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9149 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9150 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9151 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 9152 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9153 | }; |
| 9154 | |
| 9155 | /** |
| 9156 | * i40e_config_netdev - Setup the netdev flags |
| 9157 | * @vsi: the VSI being configured |
| 9158 | * |
| 9159 | * Returns 0 on success, negative value on failure |
| 9160 | **/ |
| 9161 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 9162 | { |
| 9163 | struct i40e_pf *pf = vsi->back; |
| 9164 | struct i40e_hw *hw = &pf->hw; |
| 9165 | struct i40e_netdev_priv *np; |
| 9166 | struct net_device *netdev; |
| 9167 | u8 mac_addr[ETH_ALEN]; |
| 9168 | int etherdev_size; |
| 9169 | |
| 9170 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9171 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9172 | if (!netdev) |
| 9173 | return -ENOMEM; |
| 9174 | |
| 9175 | vsi->netdev = netdev; |
| 9176 | np = netdev_priv(netdev); |
| 9177 | np->vsi = vsi; |
| 9178 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9179 | netdev->hw_enc_features |= NETIF_F_SG | |
| 9180 | NETIF_F_IP_CSUM | |
| 9181 | NETIF_F_IPV6_CSUM | |
| 9182 | NETIF_F_HIGHDMA | |
| 9183 | NETIF_F_SOFT_FEATURES | |
| 9184 | NETIF_F_TSO | |
| 9185 | NETIF_F_TSO_ECN | |
| 9186 | NETIF_F_TSO6 | |
| 9187 | NETIF_F_GSO_GRE | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9188 | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 9189 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 9190 | NETIF_F_GSO_IPXIP6 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9191 | NETIF_F_GSO_UDP_TUNNEL | |
| 9192 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9193 | NETIF_F_GSO_PARTIAL | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9194 | NETIF_F_SCTP_CRC | |
| 9195 | NETIF_F_RXHASH | |
| 9196 | NETIF_F_RXCSUM | |
Jesse Brandeburg | 5afdaaa | 2015-12-10 11:38:50 -0800 | [diff] [blame] | 9197 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9198 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9199 | if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)) |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9200 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
| 9201 | |
| 9202 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9203 | |
| 9204 | /* record features VLANs can make use of */ |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9205 | netdev->vlan_features |= netdev->hw_enc_features | |
| 9206 | NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9207 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9208 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9209 | netdev->hw_features |= NETIF_F_NTUPLE; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9210 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9211 | netdev->hw_features |= netdev->hw_enc_features | |
| 9212 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9213 | NETIF_F_HW_VLAN_CTAG_RX; |
| 9214 | |
| 9215 | netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9216 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9217 | |
| 9218 | if (vsi->type == I40E_VSI_MAIN) { |
| 9219 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9220 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9221 | /* The following steps are necessary to prevent reception |
| 9222 | * of tagged packets - some older NVM configurations load a |
| 9223 | * default a MAC-VLAN filter that accepts any tagged packet |
| 9224 | * which must be replaced by a normal filter. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 9225 | */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9226 | i40e_rm_default_mac_filter(vsi, mac_addr); |
| 9227 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 9228 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, true); |
| 9229 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9230 | } else { |
| 9231 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 9232 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 9233 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9234 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9235 | |
| 9236 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9237 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9238 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9239 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9240 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9241 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9242 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9243 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9244 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9245 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9246 | /* Setup netdev TC information */ |
| 9247 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9248 | |
| 9249 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9250 | netdev->watchdog_timeo = 5 * HZ; |
| 9251 | i40e_set_ethtool_ops(netdev); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9252 | #ifdef I40E_FCOE |
| 9253 | i40e_fcoe_config_netdev(netdev, vsi); |
| 9254 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9255 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 9256 | /* MTU range: 68 - 9706 */ |
| 9257 | netdev->min_mtu = ETH_MIN_MTU; |
| 9258 | netdev->max_mtu = I40E_MAX_RXBUFFER - |
| 9259 | (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
| 9260 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9261 | return 0; |
| 9262 | } |
| 9263 | |
| 9264 | /** |
| 9265 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9266 | * @vsi: the VSI being removed |
| 9267 | * |
| 9268 | * Returns 0 on success, negative value on failure |
| 9269 | **/ |
| 9270 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9271 | { |
| 9272 | /* remove default VSI is not allowed */ |
| 9273 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9274 | return; |
| 9275 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9276 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9277 | } |
| 9278 | |
| 9279 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9280 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9281 | * @vsi: the VSI being queried |
| 9282 | * |
| 9283 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9284 | **/ |
| 9285 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9286 | { |
| 9287 | struct i40e_veb *veb; |
| 9288 | struct i40e_pf *pf = vsi->back; |
| 9289 | |
| 9290 | /* Uplink is not a bridge so default to VEB */ |
| 9291 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9292 | return 1; |
| 9293 | |
| 9294 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9295 | if (!veb) { |
| 9296 | dev_info(&pf->pdev->dev, |
| 9297 | "There is no veb associated with the bridge\n"); |
| 9298 | return -ENOENT; |
| 9299 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9300 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9301 | /* Uplink is a bridge in VEPA mode */ |
| 9302 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9303 | return 0; |
| 9304 | } else { |
| 9305 | /* Uplink is a bridge in VEB mode */ |
| 9306 | return 1; |
| 9307 | } |
| 9308 | |
| 9309 | /* VEPA is now default bridge, so return 0 */ |
| 9310 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9311 | } |
| 9312 | |
| 9313 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9314 | * i40e_add_vsi - Add a VSI to the switch |
| 9315 | * @vsi: the VSI being configured |
| 9316 | * |
| 9317 | * This initializes a VSI context depending on the VSI type to be added and |
| 9318 | * passes it down to the add_vsi aq command. |
| 9319 | **/ |
| 9320 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9321 | { |
| 9322 | int ret = -ENODEV; |
Kiran Patil | f6bd096 | 2016-06-20 09:10:34 -0700 | [diff] [blame] | 9323 | i40e_status aq_ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9324 | struct i40e_pf *pf = vsi->back; |
| 9325 | struct i40e_hw *hw = &pf->hw; |
| 9326 | struct i40e_vsi_context ctxt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9327 | struct i40e_mac_filter *f, *ftmp; |
| 9328 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9329 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9330 | int f_count = 0; |
| 9331 | |
| 9332 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9333 | switch (vsi->type) { |
| 9334 | case I40E_VSI_MAIN: |
| 9335 | /* The PF's main VSI is already setup as part of the |
| 9336 | * device initialization, so we'll not bother with |
| 9337 | * the add_vsi call, but we will retrieve the current |
| 9338 | * VSI context. |
| 9339 | */ |
| 9340 | ctxt.seid = pf->main_vsi_seid; |
| 9341 | ctxt.pf_num = pf->hw.pf_id; |
| 9342 | ctxt.vf_num = 0; |
| 9343 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9344 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9345 | if (ret) { |
| 9346 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9347 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9348 | i40e_stat_str(&pf->hw, ret), |
| 9349 | i40e_aq_str(&pf->hw, |
| 9350 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9351 | return -ENOENT; |
| 9352 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9353 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9354 | vsi->info.valid_sections = 0; |
| 9355 | |
| 9356 | vsi->seid = ctxt.seid; |
| 9357 | vsi->id = ctxt.vsi_number; |
| 9358 | |
| 9359 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9360 | |
| 9361 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9362 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9363 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9364 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9365 | ctxt.seid = pf->main_vsi_seid; |
| 9366 | ctxt.pf_num = pf->hw.pf_id; |
| 9367 | ctxt.vf_num = 0; |
| 9368 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9369 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9370 | if (ret) { |
| 9371 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9372 | "update vsi failed, err %s aq_err %s\n", |
| 9373 | i40e_stat_str(&pf->hw, ret), |
| 9374 | i40e_aq_str(&pf->hw, |
| 9375 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9376 | ret = -ENOENT; |
| 9377 | goto err; |
| 9378 | } |
| 9379 | /* update the local VSI info queue map */ |
| 9380 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9381 | vsi->info.valid_sections = 0; |
| 9382 | } else { |
| 9383 | /* Default/Main VSI is only enabled for TC0 |
| 9384 | * reconfigure it to enable all TCs that are |
| 9385 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9386 | * For MFP case the iSCSI PF would use this |
| 9387 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9388 | */ |
| 9389 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9390 | if (ret) { |
| 9391 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9392 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9393 | enabled_tc, |
| 9394 | i40e_stat_str(&pf->hw, ret), |
| 9395 | i40e_aq_str(&pf->hw, |
| 9396 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9397 | ret = -ENOENT; |
| 9398 | } |
| 9399 | } |
| 9400 | break; |
| 9401 | |
| 9402 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9403 | ctxt.pf_num = hw->pf_id; |
| 9404 | ctxt.vf_num = 0; |
| 9405 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9406 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9407 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9408 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9409 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9410 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9411 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9412 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9413 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9414 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9415 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9416 | break; |
| 9417 | |
| 9418 | case I40E_VSI_VMDQ2: |
| 9419 | ctxt.pf_num = hw->pf_id; |
| 9420 | ctxt.vf_num = 0; |
| 9421 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9422 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9423 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9424 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9425 | /* This VSI is connected to VEB so the switch_id |
| 9426 | * should be set to zero by default. |
| 9427 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9428 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9429 | ctxt.info.valid_sections |= |
| 9430 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9431 | ctxt.info.switch_id = |
| 9432 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9433 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9434 | |
| 9435 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9436 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9437 | break; |
| 9438 | |
| 9439 | case I40E_VSI_SRIOV: |
| 9440 | ctxt.pf_num = hw->pf_id; |
| 9441 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9442 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9443 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9444 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9445 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9446 | /* This VSI is connected to VEB so the switch_id |
| 9447 | * should be set to zero by default. |
| 9448 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9449 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9450 | ctxt.info.valid_sections |= |
| 9451 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9452 | ctxt.info.switch_id = |
| 9453 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9454 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9455 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9456 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9457 | ctxt.info.valid_sections |= |
| 9458 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 9459 | ctxt.info.queueing_opt_flags |= |
Ashish Shah | 4b28cdb | 2016-05-03 15:13:17 -0700 | [diff] [blame] | 9460 | (I40E_AQ_VSI_QUE_OPT_TCP_ENA | |
| 9461 | I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9462 | } |
| 9463 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9464 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9465 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9466 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9467 | ctxt.info.valid_sections |= |
| 9468 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9469 | ctxt.info.sec_flags |= |
| 9470 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9471 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9472 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9473 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9474 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9475 | break; |
| 9476 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9477 | #ifdef I40E_FCOE |
| 9478 | case I40E_VSI_FCOE: |
| 9479 | ret = i40e_fcoe_vsi_init(vsi, &ctxt); |
| 9480 | if (ret) { |
| 9481 | dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n"); |
| 9482 | return ret; |
| 9483 | } |
| 9484 | break; |
| 9485 | |
| 9486 | #endif /* I40E_FCOE */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9487 | case I40E_VSI_IWARP: |
| 9488 | /* send down message to iWARP */ |
| 9489 | break; |
| 9490 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9491 | default: |
| 9492 | return -ENODEV; |
| 9493 | } |
| 9494 | |
| 9495 | if (vsi->type != I40E_VSI_MAIN) { |
| 9496 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9497 | if (ret) { |
| 9498 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9499 | "add vsi failed, err %s aq_err %s\n", |
| 9500 | i40e_stat_str(&pf->hw, ret), |
| 9501 | i40e_aq_str(&pf->hw, |
| 9502 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9503 | ret = -ENOENT; |
| 9504 | goto err; |
| 9505 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9506 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9507 | vsi->info.valid_sections = 0; |
| 9508 | vsi->seid = ctxt.seid; |
| 9509 | vsi->id = ctxt.vsi_number; |
| 9510 | } |
Kiran Patil | f6bd096 | 2016-06-20 09:10:34 -0700 | [diff] [blame] | 9511 | /* Except FDIR VSI, for all othet VSI set the broadcast filter */ |
| 9512 | if (vsi->type != I40E_VSI_FDIR) { |
| 9513 | aq_ret = i40e_aq_set_vsi_broadcast(hw, vsi->seid, true, NULL); |
| 9514 | if (aq_ret) { |
| 9515 | ret = i40e_aq_rc_to_posix(aq_ret, |
| 9516 | hw->aq.asq_last_status); |
| 9517 | dev_info(&pf->pdev->dev, |
| 9518 | "set brdcast promisc failed, err %s, aq_err %s\n", |
| 9519 | i40e_stat_str(hw, aq_ret), |
| 9520 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 9521 | } |
| 9522 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9523 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9524 | vsi->active_filters = 0; |
| 9525 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9526 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9527 | /* If macvlan filters already exist, force them to get loaded */ |
| 9528 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9529 | f->state = I40E_FILTER_NEW; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9530 | f_count++; |
| 9531 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9532 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9533 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9534 | if (f_count) { |
| 9535 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 9536 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 9537 | } |
| 9538 | |
| 9539 | /* Update VSI BW information */ |
| 9540 | ret = i40e_vsi_get_bw_info(vsi); |
| 9541 | if (ret) { |
| 9542 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9543 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 9544 | i40e_stat_str(&pf->hw, ret), |
| 9545 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9546 | /* VSI is already added so not tearing that up */ |
| 9547 | ret = 0; |
| 9548 | } |
| 9549 | |
| 9550 | err: |
| 9551 | return ret; |
| 9552 | } |
| 9553 | |
| 9554 | /** |
| 9555 | * i40e_vsi_release - Delete a VSI and free its resources |
| 9556 | * @vsi: the VSI being removed |
| 9557 | * |
| 9558 | * Returns 0 on success or < 0 on error |
| 9559 | **/ |
| 9560 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 9561 | { |
| 9562 | struct i40e_mac_filter *f, *ftmp; |
| 9563 | struct i40e_veb *veb = NULL; |
| 9564 | struct i40e_pf *pf; |
| 9565 | u16 uplink_seid; |
| 9566 | int i, n; |
| 9567 | |
| 9568 | pf = vsi->back; |
| 9569 | |
| 9570 | /* release of a VEB-owner or last VSI is not allowed */ |
| 9571 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 9572 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 9573 | vsi->seid, vsi->uplink_seid); |
| 9574 | return -ENODEV; |
| 9575 | } |
| 9576 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 9577 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 9578 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 9579 | return -ENODEV; |
| 9580 | } |
| 9581 | |
| 9582 | uplink_seid = vsi->uplink_seid; |
| 9583 | if (vsi->type != I40E_VSI_SRIOV) { |
| 9584 | if (vsi->netdev_registered) { |
| 9585 | vsi->netdev_registered = false; |
| 9586 | if (vsi->netdev) { |
| 9587 | /* results in a call to i40e_close() */ |
| 9588 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9589 | } |
| 9590 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 9591 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9592 | } |
| 9593 | i40e_vsi_disable_irq(vsi); |
| 9594 | } |
| 9595 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9596 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9597 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
| 9598 | i40e_del_filter(vsi, f->macaddr, f->vlan, |
| 9599 | f->is_vf, f->is_netdev); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9600 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9601 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 9602 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9603 | |
| 9604 | i40e_vsi_delete(vsi); |
| 9605 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 9606 | if (vsi->netdev) { |
| 9607 | free_netdev(vsi->netdev); |
| 9608 | vsi->netdev = NULL; |
| 9609 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9610 | i40e_vsi_clear_rings(vsi); |
| 9611 | i40e_vsi_clear(vsi); |
| 9612 | |
| 9613 | /* If this was the last thing on the VEB, except for the |
| 9614 | * controlling VSI, remove the VEB, which puts the controlling |
| 9615 | * VSI onto the next level down in the switch. |
| 9616 | * |
| 9617 | * Well, okay, there's one more exception here: don't remove |
| 9618 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 9619 | * from up the network stack. |
| 9620 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9621 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9622 | if (pf->vsi[i] && |
| 9623 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 9624 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9625 | n++; /* count the VSIs */ |
| 9626 | } |
| 9627 | } |
| 9628 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9629 | if (!pf->veb[i]) |
| 9630 | continue; |
| 9631 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 9632 | n++; /* count the VEBs */ |
| 9633 | if (pf->veb[i]->seid == uplink_seid) |
| 9634 | veb = pf->veb[i]; |
| 9635 | } |
| 9636 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 9637 | i40e_veb_release(veb); |
| 9638 | |
| 9639 | return 0; |
| 9640 | } |
| 9641 | |
| 9642 | /** |
| 9643 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 9644 | * @vsi: ptr to the VSI |
| 9645 | * |
| 9646 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 9647 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 9648 | * newly allocated VSI. |
| 9649 | * |
| 9650 | * Returns 0 on success or negative on failure |
| 9651 | **/ |
| 9652 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 9653 | { |
| 9654 | int ret = -ENOENT; |
| 9655 | struct i40e_pf *pf = vsi->back; |
| 9656 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9657 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9658 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 9659 | vsi->seid); |
| 9660 | return -EEXIST; |
| 9661 | } |
| 9662 | |
| 9663 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 9664 | 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] | 9665 | vsi->seid, vsi->base_vector); |
| 9666 | return -EEXIST; |
| 9667 | } |
| 9668 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9669 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9670 | if (ret) { |
| 9671 | dev_info(&pf->pdev->dev, |
| 9672 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 9673 | vsi->num_q_vectors, vsi->seid, ret); |
| 9674 | vsi->num_q_vectors = 0; |
| 9675 | goto vector_setup_out; |
| 9676 | } |
| 9677 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 9678 | /* In Legacy mode, we do not have to get any other vector since we |
| 9679 | * piggyback on the misc/ICR0 for queue interrupts. |
| 9680 | */ |
| 9681 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9682 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9683 | if (vsi->num_q_vectors) |
| 9684 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 9685 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9686 | if (vsi->base_vector < 0) { |
| 9687 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9688 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 9689 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9690 | i40e_vsi_free_q_vectors(vsi); |
| 9691 | ret = -ENOENT; |
| 9692 | goto vector_setup_out; |
| 9693 | } |
| 9694 | |
| 9695 | vector_setup_out: |
| 9696 | return ret; |
| 9697 | } |
| 9698 | |
| 9699 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9700 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 9701 | * @vsi: pointer to the vsi. |
| 9702 | * |
| 9703 | * This re-allocates a vsi's queue resources. |
| 9704 | * |
| 9705 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 9706 | * on success, otherwise returns NULL on failure. |
| 9707 | **/ |
| 9708 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 9709 | { |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9710 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9711 | u8 enabled_tc; |
| 9712 | int ret; |
| 9713 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9714 | if (!vsi) |
| 9715 | return NULL; |
| 9716 | |
| 9717 | pf = vsi->back; |
| 9718 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9719 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9720 | i40e_vsi_clear_rings(vsi); |
| 9721 | |
| 9722 | i40e_vsi_free_arrays(vsi, false); |
| 9723 | i40e_set_num_rings_in_vsi(vsi); |
| 9724 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 9725 | if (ret) |
| 9726 | goto err_vsi; |
| 9727 | |
| 9728 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 9729 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9730 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9731 | "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] | 9732 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9733 | goto err_vsi; |
| 9734 | } |
| 9735 | vsi->base_queue = ret; |
| 9736 | |
| 9737 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 9738 | * layout configurations. |
| 9739 | */ |
| 9740 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9741 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9742 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9743 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9744 | if (vsi->type == I40E_VSI_MAIN) |
| 9745 | i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9746 | |
| 9747 | /* assign it some queues */ |
| 9748 | ret = i40e_alloc_rings(vsi); |
| 9749 | if (ret) |
| 9750 | goto err_rings; |
| 9751 | |
| 9752 | /* map all of the rings to the q_vectors */ |
| 9753 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9754 | return vsi; |
| 9755 | |
| 9756 | err_rings: |
| 9757 | i40e_vsi_free_q_vectors(vsi); |
| 9758 | if (vsi->netdev_registered) { |
| 9759 | vsi->netdev_registered = false; |
| 9760 | unregister_netdev(vsi->netdev); |
| 9761 | free_netdev(vsi->netdev); |
| 9762 | vsi->netdev = NULL; |
| 9763 | } |
| 9764 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9765 | err_vsi: |
| 9766 | i40e_vsi_clear(vsi); |
| 9767 | return NULL; |
| 9768 | } |
| 9769 | |
| 9770 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9771 | * i40e_vsi_setup - Set up a VSI by a given type |
| 9772 | * @pf: board private structure |
| 9773 | * @type: VSI type |
| 9774 | * @uplink_seid: the switch element to link to |
| 9775 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 9776 | * |
| 9777 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 9778 | * to the identified VEB. |
| 9779 | * |
| 9780 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 9781 | * success, otherwise returns NULL on failure. |
| 9782 | **/ |
| 9783 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 9784 | u16 uplink_seid, u32 param1) |
| 9785 | { |
| 9786 | struct i40e_vsi *vsi = NULL; |
| 9787 | struct i40e_veb *veb = NULL; |
| 9788 | int ret, i; |
| 9789 | int v_idx; |
| 9790 | |
| 9791 | /* The requested uplink_seid must be either |
| 9792 | * - the PF's port seid |
| 9793 | * no VEB is needed because this is the PF |
| 9794 | * or this is a Flow Director special case VSI |
| 9795 | * - seid of an existing VEB |
| 9796 | * - seid of a VSI that owns an existing VEB |
| 9797 | * - seid of a VSI that doesn't own a VEB |
| 9798 | * a new VEB is created and the VSI becomes the owner |
| 9799 | * - seid of the PF VSI, which is what creates the first VEB |
| 9800 | * this is a special case of the previous |
| 9801 | * |
| 9802 | * Find which uplink_seid we were given and create a new VEB if needed |
| 9803 | */ |
| 9804 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9805 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 9806 | veb = pf->veb[i]; |
| 9807 | break; |
| 9808 | } |
| 9809 | } |
| 9810 | |
| 9811 | if (!veb && uplink_seid != pf->mac_seid) { |
| 9812 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9813 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9814 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 9815 | vsi = pf->vsi[i]; |
| 9816 | break; |
| 9817 | } |
| 9818 | } |
| 9819 | if (!vsi) { |
| 9820 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 9821 | uplink_seid); |
| 9822 | return NULL; |
| 9823 | } |
| 9824 | |
| 9825 | if (vsi->uplink_seid == pf->mac_seid) |
| 9826 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 9827 | vsi->tc_config.enabled_tc); |
| 9828 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 9829 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9830 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9831 | if (veb) { |
| 9832 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 9833 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 9834 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9835 | return NULL; |
| 9836 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 9837 | /* We come up by default in VEPA mode if SRIOV is not |
| 9838 | * already enabled, in which case we can't force VEPA |
| 9839 | * mode. |
| 9840 | */ |
| 9841 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 9842 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 9843 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9844 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9845 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9846 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9847 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9848 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9849 | veb = pf->veb[i]; |
| 9850 | } |
| 9851 | if (!veb) { |
| 9852 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 9853 | return NULL; |
| 9854 | } |
| 9855 | |
| 9856 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 9857 | uplink_seid = veb->seid; |
| 9858 | } |
| 9859 | |
| 9860 | /* get vsi sw struct */ |
| 9861 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 9862 | if (v_idx < 0) |
| 9863 | goto err_alloc; |
| 9864 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9865 | if (!vsi) |
| 9866 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9867 | vsi->type = type; |
| 9868 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 9869 | |
| 9870 | if (type == I40E_VSI_MAIN) |
| 9871 | pf->lan_vsi = v_idx; |
| 9872 | else if (type == I40E_VSI_SRIOV) |
| 9873 | vsi->vf_id = param1; |
| 9874 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9875 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 9876 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9877 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9878 | dev_info(&pf->pdev->dev, |
| 9879 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 9880 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9881 | goto err_vsi; |
| 9882 | } |
| 9883 | vsi->base_queue = ret; |
| 9884 | |
| 9885 | /* get a VSI from the hardware */ |
| 9886 | vsi->uplink_seid = uplink_seid; |
| 9887 | ret = i40e_add_vsi(vsi); |
| 9888 | if (ret) |
| 9889 | goto err_vsi; |
| 9890 | |
| 9891 | switch (vsi->type) { |
| 9892 | /* setup the netdev if needed */ |
| 9893 | case I40E_VSI_MAIN: |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9894 | /* Apply relevant filters if a platform-specific mac |
| 9895 | * address was selected. |
| 9896 | */ |
| 9897 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 9898 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 9899 | if (ret) { |
| 9900 | dev_warn(&pf->pdev->dev, |
| 9901 | "could not set up macaddr; err %d\n", |
| 9902 | ret); |
| 9903 | } |
| 9904 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9905 | case I40E_VSI_VMDQ2: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9906 | case I40E_VSI_FCOE: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9907 | ret = i40e_config_netdev(vsi); |
| 9908 | if (ret) |
| 9909 | goto err_netdev; |
| 9910 | ret = register_netdev(vsi->netdev); |
| 9911 | if (ret) |
| 9912 | goto err_netdev; |
| 9913 | vsi->netdev_registered = true; |
| 9914 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9915 | #ifdef CONFIG_I40E_DCB |
| 9916 | /* Setup DCB netlink interface */ |
| 9917 | i40e_dcbnl_setup(vsi); |
| 9918 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9919 | /* fall through */ |
| 9920 | |
| 9921 | case I40E_VSI_FDIR: |
| 9922 | /* set up vectors and rings if needed */ |
| 9923 | ret = i40e_vsi_setup_vectors(vsi); |
| 9924 | if (ret) |
| 9925 | goto err_msix; |
| 9926 | |
| 9927 | ret = i40e_alloc_rings(vsi); |
| 9928 | if (ret) |
| 9929 | goto err_rings; |
| 9930 | |
| 9931 | /* map all of the rings to the q_vectors */ |
| 9932 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9933 | |
| 9934 | i40e_vsi_reset_stats(vsi); |
| 9935 | break; |
| 9936 | |
| 9937 | default: |
| 9938 | /* no netdev or rings for the other VSI types */ |
| 9939 | break; |
| 9940 | } |
| 9941 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9942 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
| 9943 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 9944 | ret = i40e_vsi_config_rss(vsi); |
| 9945 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9946 | return vsi; |
| 9947 | |
| 9948 | err_rings: |
| 9949 | i40e_vsi_free_q_vectors(vsi); |
| 9950 | err_msix: |
| 9951 | if (vsi->netdev_registered) { |
| 9952 | vsi->netdev_registered = false; |
| 9953 | unregister_netdev(vsi->netdev); |
| 9954 | free_netdev(vsi->netdev); |
| 9955 | vsi->netdev = NULL; |
| 9956 | } |
| 9957 | err_netdev: |
| 9958 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9959 | err_vsi: |
| 9960 | i40e_vsi_clear(vsi); |
| 9961 | err_alloc: |
| 9962 | return NULL; |
| 9963 | } |
| 9964 | |
| 9965 | /** |
| 9966 | * i40e_veb_get_bw_info - Query VEB BW information |
| 9967 | * @veb: the veb to query |
| 9968 | * |
| 9969 | * Query the Tx scheduler BW configuration data for given VEB |
| 9970 | **/ |
| 9971 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 9972 | { |
| 9973 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 9974 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 9975 | struct i40e_pf *pf = veb->pf; |
| 9976 | struct i40e_hw *hw = &pf->hw; |
| 9977 | u32 tc_bw_max; |
| 9978 | int ret = 0; |
| 9979 | int i; |
| 9980 | |
| 9981 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 9982 | &bw_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 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 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 9992 | &ets_data, NULL); |
| 9993 | if (ret) { |
| 9994 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9995 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 9996 | i40e_stat_str(&pf->hw, ret), |
| 9997 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9998 | goto out; |
| 9999 | } |
| 10000 | |
| 10001 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 10002 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 10003 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 10004 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10005 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 10006 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 10007 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 10008 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 10009 | veb->bw_tc_limit_credits[i] = |
| 10010 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 10011 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 10012 | } |
| 10013 | |
| 10014 | out: |
| 10015 | return ret; |
| 10016 | } |
| 10017 | |
| 10018 | /** |
| 10019 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 10020 | * @pf: board private structure |
| 10021 | * |
| 10022 | * On error: returns error code (negative) |
| 10023 | * On success: returns vsi index in PF (positive) |
| 10024 | **/ |
| 10025 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 10026 | { |
| 10027 | int ret = -ENOENT; |
| 10028 | struct i40e_veb *veb; |
| 10029 | int i; |
| 10030 | |
| 10031 | /* Need to protect the allocation of switch elements at the PF level */ |
| 10032 | mutex_lock(&pf->switch_mutex); |
| 10033 | |
| 10034 | /* VEB list may be fragmented if VEB creation/destruction has |
| 10035 | * been happening. We can afford to do a quick scan to look |
| 10036 | * for any free slots in the list. |
| 10037 | * |
| 10038 | * find next empty veb slot, looping back around if necessary |
| 10039 | */ |
| 10040 | i = 0; |
| 10041 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 10042 | i++; |
| 10043 | if (i >= I40E_MAX_VEB) { |
| 10044 | ret = -ENOMEM; |
| 10045 | goto err_alloc_veb; /* out of VEB slots! */ |
| 10046 | } |
| 10047 | |
| 10048 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 10049 | if (!veb) { |
| 10050 | ret = -ENOMEM; |
| 10051 | goto err_alloc_veb; |
| 10052 | } |
| 10053 | veb->pf = pf; |
| 10054 | veb->idx = i; |
| 10055 | veb->enabled_tc = 1; |
| 10056 | |
| 10057 | pf->veb[i] = veb; |
| 10058 | ret = i; |
| 10059 | err_alloc_veb: |
| 10060 | mutex_unlock(&pf->switch_mutex); |
| 10061 | return ret; |
| 10062 | } |
| 10063 | |
| 10064 | /** |
| 10065 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 10066 | * @branch: where to start deleting |
| 10067 | * |
| 10068 | * This uses recursion to find the tips of the branch to be |
| 10069 | * removed, deleting until we get back to and can delete this VEB. |
| 10070 | **/ |
| 10071 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 10072 | { |
| 10073 | struct i40e_pf *pf = branch->pf; |
| 10074 | u16 branch_seid = branch->seid; |
| 10075 | u16 veb_idx = branch->idx; |
| 10076 | int i; |
| 10077 | |
| 10078 | /* release any VEBs on this VEB - RECURSION */ |
| 10079 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10080 | if (!pf->veb[i]) |
| 10081 | continue; |
| 10082 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 10083 | i40e_switch_branch_release(pf->veb[i]); |
| 10084 | } |
| 10085 | |
| 10086 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 10087 | * |
| 10088 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 10089 | * the VEB itself, so don't use (*branch) after this loop. |
| 10090 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10091 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10092 | if (!pf->vsi[i]) |
| 10093 | continue; |
| 10094 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 10095 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 10096 | i40e_vsi_release(pf->vsi[i]); |
| 10097 | } |
| 10098 | } |
| 10099 | |
| 10100 | /* There's one corner case where the VEB might not have been |
| 10101 | * removed, so double check it here and remove it if needed. |
| 10102 | * This case happens if the veb was created from the debugfs |
| 10103 | * commands and no VSIs were added to it. |
| 10104 | */ |
| 10105 | if (pf->veb[veb_idx]) |
| 10106 | i40e_veb_release(pf->veb[veb_idx]); |
| 10107 | } |
| 10108 | |
| 10109 | /** |
| 10110 | * i40e_veb_clear - remove veb struct |
| 10111 | * @veb: the veb to remove |
| 10112 | **/ |
| 10113 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 10114 | { |
| 10115 | if (!veb) |
| 10116 | return; |
| 10117 | |
| 10118 | if (veb->pf) { |
| 10119 | struct i40e_pf *pf = veb->pf; |
| 10120 | |
| 10121 | mutex_lock(&pf->switch_mutex); |
| 10122 | if (pf->veb[veb->idx] == veb) |
| 10123 | pf->veb[veb->idx] = NULL; |
| 10124 | mutex_unlock(&pf->switch_mutex); |
| 10125 | } |
| 10126 | |
| 10127 | kfree(veb); |
| 10128 | } |
| 10129 | |
| 10130 | /** |
| 10131 | * i40e_veb_release - Delete a VEB and free its resources |
| 10132 | * @veb: the VEB being removed |
| 10133 | **/ |
| 10134 | void i40e_veb_release(struct i40e_veb *veb) |
| 10135 | { |
| 10136 | struct i40e_vsi *vsi = NULL; |
| 10137 | struct i40e_pf *pf; |
| 10138 | int i, n = 0; |
| 10139 | |
| 10140 | pf = veb->pf; |
| 10141 | |
| 10142 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10143 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10144 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 10145 | n++; |
| 10146 | vsi = pf->vsi[i]; |
| 10147 | } |
| 10148 | } |
| 10149 | if (n != 1) { |
| 10150 | dev_info(&pf->pdev->dev, |
| 10151 | "can't remove VEB %d with %d VSIs left\n", |
| 10152 | veb->seid, n); |
| 10153 | return; |
| 10154 | } |
| 10155 | |
| 10156 | /* move the remaining VSI to uplink veb */ |
| 10157 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10158 | if (veb->uplink_seid) { |
| 10159 | vsi->uplink_seid = veb->uplink_seid; |
| 10160 | if (veb->uplink_seid == pf->mac_seid) |
| 10161 | vsi->veb_idx = I40E_NO_VEB; |
| 10162 | else |
| 10163 | vsi->veb_idx = veb->veb_idx; |
| 10164 | } else { |
| 10165 | /* floating VEB */ |
| 10166 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10167 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10168 | } |
| 10169 | |
| 10170 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10171 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10172 | } |
| 10173 | |
| 10174 | /** |
| 10175 | * i40e_add_veb - create the VEB in the switch |
| 10176 | * @veb: the VEB to be instantiated |
| 10177 | * @vsi: the controlling VSI |
| 10178 | **/ |
| 10179 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10180 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10181 | struct i40e_pf *pf = veb->pf; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10182 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10183 | int ret; |
| 10184 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10185 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10186 | veb->enabled_tc, false, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10187 | &veb->seid, enable_stats, NULL); |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10188 | |
| 10189 | /* get a VEB from the hardware */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10190 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10191 | dev_info(&pf->pdev->dev, |
| 10192 | "couldn't add VEB, err %s aq_err %s\n", |
| 10193 | i40e_stat_str(&pf->hw, ret), |
| 10194 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10195 | return -EPERM; |
| 10196 | } |
| 10197 | |
| 10198 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10199 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10200 | &veb->stats_idx, NULL, NULL, NULL); |
| 10201 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10202 | dev_info(&pf->pdev->dev, |
| 10203 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10204 | i40e_stat_str(&pf->hw, ret), |
| 10205 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10206 | return -EPERM; |
| 10207 | } |
| 10208 | ret = i40e_veb_get_bw_info(veb); |
| 10209 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10210 | dev_info(&pf->pdev->dev, |
| 10211 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10212 | i40e_stat_str(&pf->hw, ret), |
| 10213 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10214 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10215 | return -ENOENT; |
| 10216 | } |
| 10217 | |
| 10218 | vsi->uplink_seid = veb->seid; |
| 10219 | vsi->veb_idx = veb->idx; |
| 10220 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10221 | |
| 10222 | return 0; |
| 10223 | } |
| 10224 | |
| 10225 | /** |
| 10226 | * i40e_veb_setup - Set up a VEB |
| 10227 | * @pf: board private structure |
| 10228 | * @flags: VEB setup flags |
| 10229 | * @uplink_seid: the switch element to link to |
| 10230 | * @vsi_seid: the initial VSI seid |
| 10231 | * @enabled_tc: Enabled TC bit-map |
| 10232 | * |
| 10233 | * This allocates the sw VEB structure and links it into the switch |
| 10234 | * It is possible and legal for this to be a duplicate of an already |
| 10235 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10236 | * to be zero, in order to create a floating VEB. |
| 10237 | * |
| 10238 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10239 | * success, otherwise returns NULL on failure. |
| 10240 | **/ |
| 10241 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10242 | u16 uplink_seid, u16 vsi_seid, |
| 10243 | u8 enabled_tc) |
| 10244 | { |
| 10245 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10246 | int vsi_idx, veb_idx; |
| 10247 | int ret; |
| 10248 | |
| 10249 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10250 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10251 | (uplink_seid + vsi_seid != 0)) { |
| 10252 | dev_info(&pf->pdev->dev, |
| 10253 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10254 | uplink_seid, vsi_seid); |
| 10255 | return NULL; |
| 10256 | } |
| 10257 | |
| 10258 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10259 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10260 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10261 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10262 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10263 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10264 | vsi_seid); |
| 10265 | return NULL; |
| 10266 | } |
| 10267 | |
| 10268 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10269 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10270 | if (pf->veb[veb_idx] && |
| 10271 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10272 | uplink_veb = pf->veb[veb_idx]; |
| 10273 | break; |
| 10274 | } |
| 10275 | } |
| 10276 | if (!uplink_veb) { |
| 10277 | dev_info(&pf->pdev->dev, |
| 10278 | "uplink seid %d not found\n", uplink_seid); |
| 10279 | return NULL; |
| 10280 | } |
| 10281 | } |
| 10282 | |
| 10283 | /* get veb sw struct */ |
| 10284 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10285 | if (veb_idx < 0) |
| 10286 | goto err_alloc; |
| 10287 | veb = pf->veb[veb_idx]; |
| 10288 | veb->flags = flags; |
| 10289 | veb->uplink_seid = uplink_seid; |
| 10290 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10291 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10292 | |
| 10293 | /* create the VEB in the switch */ |
| 10294 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10295 | if (ret) |
| 10296 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10297 | if (vsi_idx == pf->lan_vsi) |
| 10298 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10299 | |
| 10300 | return veb; |
| 10301 | |
| 10302 | err_veb: |
| 10303 | i40e_veb_clear(veb); |
| 10304 | err_alloc: |
| 10305 | return NULL; |
| 10306 | } |
| 10307 | |
| 10308 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10309 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10310 | * @pf: board private structure |
| 10311 | * @ele: element we are building info from |
| 10312 | * @num_reported: total number of elements |
| 10313 | * @printconfig: should we print the contents |
| 10314 | * |
| 10315 | * helper function to assist in extracting a few useful SEID values. |
| 10316 | **/ |
| 10317 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10318 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10319 | u16 num_reported, bool printconfig) |
| 10320 | { |
| 10321 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10322 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10323 | u8 element_type = ele->element_type; |
| 10324 | u16 seid = le16_to_cpu(ele->seid); |
| 10325 | |
| 10326 | if (printconfig) |
| 10327 | dev_info(&pf->pdev->dev, |
| 10328 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10329 | element_type, seid, uplink_seid, downlink_seid); |
| 10330 | |
| 10331 | switch (element_type) { |
| 10332 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10333 | pf->mac_seid = seid; |
| 10334 | break; |
| 10335 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10336 | /* Main VEB? */ |
| 10337 | if (uplink_seid != pf->mac_seid) |
| 10338 | break; |
| 10339 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10340 | int v; |
| 10341 | |
| 10342 | /* find existing or else empty VEB */ |
| 10343 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10344 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10345 | pf->lan_veb = v; |
| 10346 | break; |
| 10347 | } |
| 10348 | } |
| 10349 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10350 | v = i40e_veb_mem_alloc(pf); |
| 10351 | if (v < 0) |
| 10352 | break; |
| 10353 | pf->lan_veb = v; |
| 10354 | } |
| 10355 | } |
| 10356 | |
| 10357 | pf->veb[pf->lan_veb]->seid = seid; |
| 10358 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10359 | pf->veb[pf->lan_veb]->pf = pf; |
| 10360 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10361 | break; |
| 10362 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10363 | if (num_reported != 1) |
| 10364 | break; |
| 10365 | /* This is immediately after a reset so we can assume this is |
| 10366 | * the PF's VSI |
| 10367 | */ |
| 10368 | pf->mac_seid = uplink_seid; |
| 10369 | pf->pf_seid = downlink_seid; |
| 10370 | pf->main_vsi_seid = seid; |
| 10371 | if (printconfig) |
| 10372 | dev_info(&pf->pdev->dev, |
| 10373 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10374 | pf->pf_seid, pf->main_vsi_seid); |
| 10375 | break; |
| 10376 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10377 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10378 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10379 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10380 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10381 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10382 | /* ignore these for now */ |
| 10383 | break; |
| 10384 | default: |
| 10385 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10386 | element_type, seid); |
| 10387 | break; |
| 10388 | } |
| 10389 | } |
| 10390 | |
| 10391 | /** |
| 10392 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10393 | * @pf: board private structure |
| 10394 | * @printconfig: should we print the contents |
| 10395 | * |
| 10396 | * Get the current switch configuration from the device and |
| 10397 | * extract a few useful SEID values. |
| 10398 | **/ |
| 10399 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10400 | { |
| 10401 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10402 | u16 next_seid = 0; |
| 10403 | int ret = 0; |
| 10404 | u8 *aq_buf; |
| 10405 | int i; |
| 10406 | |
| 10407 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10408 | if (!aq_buf) |
| 10409 | return -ENOMEM; |
| 10410 | |
| 10411 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10412 | do { |
| 10413 | u16 num_reported, num_total; |
| 10414 | |
| 10415 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10416 | I40E_AQ_LARGE_BUF, |
| 10417 | &next_seid, NULL); |
| 10418 | if (ret) { |
| 10419 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10420 | "get switch config failed err %s aq_err %s\n", |
| 10421 | i40e_stat_str(&pf->hw, ret), |
| 10422 | i40e_aq_str(&pf->hw, |
| 10423 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10424 | kfree(aq_buf); |
| 10425 | return -ENOENT; |
| 10426 | } |
| 10427 | |
| 10428 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10429 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10430 | |
| 10431 | if (printconfig) |
| 10432 | dev_info(&pf->pdev->dev, |
| 10433 | "header: %d reported %d total\n", |
| 10434 | num_reported, num_total); |
| 10435 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10436 | for (i = 0; i < num_reported; i++) { |
| 10437 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10438 | &sw_config->element[i]; |
| 10439 | |
| 10440 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10441 | printconfig); |
| 10442 | } |
| 10443 | } while (next_seid != 0); |
| 10444 | |
| 10445 | kfree(aq_buf); |
| 10446 | return ret; |
| 10447 | } |
| 10448 | |
| 10449 | /** |
| 10450 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10451 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10452 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10453 | * |
| 10454 | * Returns 0 on success, negative value on failure |
| 10455 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10456 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10457 | { |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10458 | u16 flags = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10459 | int ret; |
| 10460 | |
| 10461 | /* find out what's out there already */ |
| 10462 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10463 | if (ret) { |
| 10464 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10465 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10466 | i40e_stat_str(&pf->hw, ret), |
| 10467 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10468 | return ret; |
| 10469 | } |
| 10470 | i40e_pf_reset_stats(pf); |
| 10471 | |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10472 | /* set the switch config bit for the whole device to |
| 10473 | * support limited promisc or true promisc |
| 10474 | * when user requests promisc. The default is limited |
| 10475 | * promisc. |
| 10476 | */ |
| 10477 | |
| 10478 | if ((pf->hw.pf_id == 0) && |
| 10479 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) |
| 10480 | flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10481 | |
| 10482 | if (pf->hw.pf_id == 0) { |
| 10483 | u16 valid_flags; |
| 10484 | |
| 10485 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10486 | ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, |
| 10487 | NULL); |
| 10488 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { |
| 10489 | dev_info(&pf->pdev->dev, |
| 10490 | "couldn't set switch config bits, err %s aq_err %s\n", |
| 10491 | i40e_stat_str(&pf->hw, ret), |
| 10492 | i40e_aq_str(&pf->hw, |
| 10493 | pf->hw.aq.asq_last_status)); |
| 10494 | /* not a fatal problem, just keep going */ |
| 10495 | } |
| 10496 | } |
| 10497 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10498 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10499 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10500 | struct i40e_vsi *vsi = NULL; |
| 10501 | u16 uplink_seid; |
| 10502 | |
| 10503 | /* Set up the PF VSI associated with the PF's main VSI |
| 10504 | * that is already in the HW switch |
| 10505 | */ |
| 10506 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10507 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10508 | else |
| 10509 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10510 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10511 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10512 | else if (reinit) |
| 10513 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10514 | if (!vsi) { |
| 10515 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10516 | i40e_fdir_teardown(pf); |
| 10517 | return -EAGAIN; |
| 10518 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10519 | } else { |
| 10520 | /* force a reset of TC and queue layout configurations */ |
| 10521 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10522 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10523 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10524 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10525 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10526 | } |
| 10527 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 10528 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10529 | i40e_fdir_sb_setup(pf); |
| 10530 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10531 | /* Setup static PF queue filter control settings */ |
| 10532 | ret = i40e_setup_pf_filter_control(pf); |
| 10533 | if (ret) { |
| 10534 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 10535 | ret); |
| 10536 | /* Failure here should not stop continuing other steps */ |
| 10537 | } |
| 10538 | |
| 10539 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 10540 | * the hash |
| 10541 | */ |
| 10542 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 10543 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10544 | |
| 10545 | /* fill in link information and enable LSE reporting */ |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 10546 | i40e_update_link_info(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10547 | i40e_link_event(pf); |
| 10548 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10549 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10550 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 10551 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10552 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10553 | i40e_ptp_init(pf); |
| 10554 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10555 | return ret; |
| 10556 | } |
| 10557 | |
| 10558 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10559 | * i40e_determine_queue_usage - Work out queue distribution |
| 10560 | * @pf: board private structure |
| 10561 | **/ |
| 10562 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 10563 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10564 | int queues_left; |
| 10565 | |
| 10566 | pf->num_lan_qps = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10567 | #ifdef I40E_FCOE |
| 10568 | pf->num_fcoe_qps = 0; |
| 10569 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10570 | |
| 10571 | /* Find the max queues to be put into basic use. We'll always be |
| 10572 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 10573 | * big RSS set. |
| 10574 | */ |
| 10575 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 10576 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10577 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10578 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10579 | /* one qp for PF, no queues for anything else */ |
| 10580 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10581 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10582 | |
| 10583 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10584 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10585 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10586 | #ifdef I40E_FCOE |
| 10587 | I40E_FLAG_FCOE_ENABLED | |
| 10588 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10589 | I40E_FLAG_FD_SB_ENABLED | |
| 10590 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10591 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 10592 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10593 | I40E_FLAG_SRIOV_ENABLED | |
| 10594 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10595 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 10596 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 10597 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10598 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10599 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10600 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10601 | queues_left -= pf->num_lan_qps; |
| 10602 | |
| 10603 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10604 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10605 | #ifdef I40E_FCOE |
| 10606 | I40E_FLAG_FCOE_ENABLED | |
| 10607 | #endif |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10608 | I40E_FLAG_FD_SB_ENABLED | |
| 10609 | I40E_FLAG_FD_ATR_ENABLED | |
| 10610 | I40E_FLAG_DCB_ENABLED | |
| 10611 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10612 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10613 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10614 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10615 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 10616 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | |
| 10617 | I40E_FLAG_DCB_ENABLED); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10618 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 10619 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 10620 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 10621 | num_online_cpus()); |
| 10622 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 10623 | pf->hw.func_caps.num_tx_qp); |
| 10624 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10625 | queues_left -= pf->num_lan_qps; |
| 10626 | } |
| 10627 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10628 | #ifdef I40E_FCOE |
| 10629 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 10630 | if (I40E_DEFAULT_FCOE <= queues_left) { |
| 10631 | pf->num_fcoe_qps = I40E_DEFAULT_FCOE; |
| 10632 | } else if (I40E_MINIMUM_FCOE <= queues_left) { |
| 10633 | pf->num_fcoe_qps = I40E_MINIMUM_FCOE; |
| 10634 | } else { |
| 10635 | pf->num_fcoe_qps = 0; |
| 10636 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 10637 | dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n"); |
| 10638 | } |
| 10639 | |
| 10640 | queues_left -= pf->num_fcoe_qps; |
| 10641 | } |
| 10642 | |
| 10643 | #endif |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10644 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10645 | if (queues_left > 1) { |
| 10646 | queues_left -= 1; /* save 1 queue for FD */ |
| 10647 | } else { |
| 10648 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 10649 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 10650 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10651 | } |
| 10652 | |
| 10653 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10654 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10655 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 10656 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10657 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 10658 | } |
| 10659 | |
| 10660 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 10661 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 10662 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 10663 | (queues_left / pf->num_vmdq_qps)); |
| 10664 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 10665 | } |
| 10666 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10667 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10668 | dev_dbg(&pf->pdev->dev, |
| 10669 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 10670 | pf->hw.func_caps.num_tx_qp, |
| 10671 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10672 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 10673 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 10674 | queues_left); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10675 | #ifdef I40E_FCOE |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10676 | 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] | 10677 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10678 | } |
| 10679 | |
| 10680 | /** |
| 10681 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 10682 | * @pf: PF to be setup |
| 10683 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10684 | * 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] | 10685 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 10686 | * based filter sizes required for them. It also enables Flow director, |
| 10687 | * ethertype and macvlan type filter settings for the pf. |
| 10688 | * |
| 10689 | * Returns 0 on success, negative on failure |
| 10690 | **/ |
| 10691 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 10692 | { |
| 10693 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 10694 | |
| 10695 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 10696 | |
| 10697 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10698 | 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] | 10699 | settings->enable_fdir = true; |
| 10700 | |
| 10701 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 10702 | settings->enable_ethtype = true; |
| 10703 | settings->enable_macvlan = true; |
| 10704 | |
| 10705 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 10706 | return -ENOENT; |
| 10707 | |
| 10708 | return 0; |
| 10709 | } |
| 10710 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10711 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10712 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10713 | static void i40e_print_features(struct i40e_pf *pf) |
| 10714 | { |
| 10715 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10716 | char *buf; |
| 10717 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10718 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10719 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 10720 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10721 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10722 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10723 | 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] | 10724 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10725 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10726 | #endif |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10727 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10728 | pf->hw.func_caps.num_vsis, |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10729 | pf->vsi[pf->lan_vsi]->num_queue_pairs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10730 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10731 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10732 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10733 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10734 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10735 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 10736 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10737 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10738 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10739 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10740 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10741 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10742 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10743 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10744 | #ifdef I40E_FCOE |
| 10745 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10746 | i += snprintf(&buf[i], REMAIN(i), " FCOE"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10747 | #endif |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10748 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10749 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10750 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10751 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10752 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10753 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 10754 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10755 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10756 | } |
| 10757 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10758 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10759 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
| 10760 | * |
| 10761 | * @pdev: PCI device information struct |
| 10762 | * @pf: board private structure |
| 10763 | * |
| 10764 | * Look up the MAC address in Open Firmware on systems that support it, |
| 10765 | * and use IDPROM on SPARC if no OF address is found. On return, the |
| 10766 | * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value |
| 10767 | * has been selected. |
| 10768 | **/ |
| 10769 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 10770 | { |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10771 | pf->flags &= ~I40E_FLAG_PF_MAC; |
Sowmini Varadhan | ba94272 | 2016-01-12 19:32:31 -0800 | [diff] [blame] | 10772 | if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10773 | pf->flags |= I40E_FLAG_PF_MAC; |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10774 | } |
| 10775 | |
| 10776 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10777 | * i40e_probe - Device initialization routine |
| 10778 | * @pdev: PCI device information struct |
| 10779 | * @ent: entry in i40e_pci_tbl |
| 10780 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10781 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 10782 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10783 | * and a hardware reset occur. |
| 10784 | * |
| 10785 | * Returns 0 on success, negative on failure |
| 10786 | **/ |
| 10787 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 10788 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 10789 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10790 | struct i40e_pf *pf; |
| 10791 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10792 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10793 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10794 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 10795 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10796 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10797 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10798 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10799 | |
| 10800 | err = pci_enable_device_mem(pdev); |
| 10801 | if (err) |
| 10802 | return err; |
| 10803 | |
| 10804 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10805 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10806 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 10807 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10808 | if (err) { |
| 10809 | dev_err(&pdev->dev, |
| 10810 | "DMA configuration failed: 0x%x\n", err); |
| 10811 | goto err_dma; |
| 10812 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10813 | } |
| 10814 | |
| 10815 | /* set up pci connections */ |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10816 | err = pci_request_mem_regions(pdev, i40e_driver_name); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10817 | if (err) { |
| 10818 | dev_info(&pdev->dev, |
| 10819 | "pci_request_selected_regions failed %d\n", err); |
| 10820 | goto err_pci_reg; |
| 10821 | } |
| 10822 | |
| 10823 | pci_enable_pcie_error_reporting(pdev); |
| 10824 | pci_set_master(pdev); |
| 10825 | |
| 10826 | /* Now that we have a PCI connection, we need to do the |
| 10827 | * low level device setup. This is primarily setting up |
| 10828 | * the Admin Queue structures and then querying for the |
| 10829 | * device's current profile information. |
| 10830 | */ |
| 10831 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 10832 | if (!pf) { |
| 10833 | err = -ENOMEM; |
| 10834 | goto err_pf_alloc; |
| 10835 | } |
| 10836 | pf->next_vsi = 0; |
| 10837 | pf->pdev = pdev; |
| 10838 | set_bit(__I40E_DOWN, &pf->state); |
| 10839 | |
| 10840 | hw = &pf->hw; |
| 10841 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10842 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10843 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 10844 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10845 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10846 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10847 | if (!hw->hw_addr) { |
| 10848 | err = -EIO; |
| 10849 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 10850 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10851 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10852 | goto err_ioremap; |
| 10853 | } |
| 10854 | hw->vendor_id = pdev->vendor; |
| 10855 | hw->device_id = pdev->device; |
| 10856 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 10857 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 10858 | hw->subsystem_device_id = pdev->subsystem_device; |
| 10859 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 10860 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10861 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10862 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 10863 | /* set up the locks for the AQ, do this only once in probe |
| 10864 | * and destroy them only once in remove |
| 10865 | */ |
| 10866 | mutex_init(&hw->aq.asq_mutex); |
| 10867 | mutex_init(&hw->aq.arq_mutex); |
| 10868 | |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 10869 | if (debug != -1) { |
| 10870 | pf->msg_enable = pf->hw.debug_mask; |
| 10871 | pf->msg_enable = debug; |
| 10872 | } |
| 10873 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10874 | /* do a special CORER for clearing PXE mode once at init */ |
| 10875 | if (hw->revision_id == 0 && |
| 10876 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 10877 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 10878 | i40e_flush(hw); |
| 10879 | msleep(200); |
| 10880 | pf->corer_count++; |
| 10881 | |
| 10882 | i40e_clear_pxe_mode(hw); |
| 10883 | } |
| 10884 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10885 | /* 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] | 10886 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10887 | err = i40e_pf_reset(hw); |
| 10888 | if (err) { |
| 10889 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 10890 | goto err_pf_reset; |
| 10891 | } |
| 10892 | pf->pfr_count++; |
| 10893 | |
| 10894 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 10895 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 10896 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10897 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10898 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10899 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 10900 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10901 | "%s-%s:misc", |
| 10902 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10903 | |
| 10904 | err = i40e_init_shared_code(hw); |
| 10905 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 10906 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 10907 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10908 | goto err_pf_reset; |
| 10909 | } |
| 10910 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10911 | /* set up a default setting for link flow control */ |
| 10912 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 10913 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10914 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 10915 | if (err) { |
| 10916 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 10917 | dev_info(&pdev->dev, |
| 10918 | "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"); |
| 10919 | else |
| 10920 | dev_info(&pdev->dev, |
| 10921 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 10922 | |
| 10923 | goto err_pf_reset; |
| 10924 | } |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10925 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10926 | /* provide nvm, fw, api versions */ |
| 10927 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 10928 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 10929 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 10930 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10931 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10932 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 10933 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10934 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10935 | "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"); |
| 10936 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 10937 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10938 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10939 | "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] | 10940 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 10941 | i40e_verify_eeprom(pf); |
| 10942 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 10943 | /* Rev 0 hardware was never productized */ |
| 10944 | if (hw->revision_id < 1) |
| 10945 | 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"); |
| 10946 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 10947 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10948 | err = i40e_get_capabilities(pf); |
| 10949 | if (err) |
| 10950 | goto err_adminq_setup; |
| 10951 | |
| 10952 | err = i40e_sw_init(pf); |
| 10953 | if (err) { |
| 10954 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 10955 | goto err_sw_init; |
| 10956 | } |
| 10957 | |
| 10958 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 10959 | hw->func_caps.num_rx_qp, |
| 10960 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 10961 | if (err) { |
| 10962 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 10963 | goto err_init_lan_hmc; |
| 10964 | } |
| 10965 | |
| 10966 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 10967 | if (err) { |
| 10968 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 10969 | err = -ENOENT; |
| 10970 | goto err_configure_lan_hmc; |
| 10971 | } |
| 10972 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10973 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 10974 | * Ignore error return codes because if it was already disabled via |
| 10975 | * hardware settings this will fail |
| 10976 | */ |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 10977 | if (pf->flags & I40E_FLAG_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10978 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 10979 | i40e_aq_stop_lldp(hw, true, NULL); |
| 10980 | } |
| 10981 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10982 | i40e_get_mac_addr(hw, hw->mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10983 | /* allow a platform config to override the HW addr */ |
| 10984 | i40e_get_platform_mac_addr(pdev, pf); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 10985 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10986 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 10987 | err = -EIO; |
| 10988 | goto err_mac_addr; |
| 10989 | } |
| 10990 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 10991 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10992 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 10993 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 10994 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10995 | #ifdef I40E_FCOE |
| 10996 | err = i40e_get_san_mac_addr(hw, hw->mac.san_addr); |
| 10997 | if (err) |
| 10998 | dev_info(&pdev->dev, |
| 10999 | "(non-fatal) SAN MAC retrieval failed: %d\n", err); |
| 11000 | if (!is_valid_ether_addr(hw->mac.san_addr)) { |
| 11001 | dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n", |
| 11002 | hw->mac.san_addr); |
| 11003 | ether_addr_copy(hw->mac.san_addr, hw->mac.addr); |
| 11004 | } |
| 11005 | dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr); |
| 11006 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11007 | |
| 11008 | pci_set_drvdata(pdev, pf); |
| 11009 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11010 | #ifdef CONFIG_I40E_DCB |
| 11011 | err = i40e_init_pf_dcb(pf); |
| 11012 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 11013 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 11014 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE & I40E_FLAG_DCB_ENABLED); |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 11015 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11016 | } |
| 11017 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11018 | |
| 11019 | /* set up periodic task facility */ |
| 11020 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 11021 | pf->service_timer_period = HZ; |
| 11022 | |
| 11023 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 11024 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 11025 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11026 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11027 | /* NVM bit on means WoL disabled for the port */ |
| 11028 | 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] | 11029 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11030 | pf->wol_en = false; |
| 11031 | else |
| 11032 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11033 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 11034 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11035 | /* set up the main switch operations */ |
| 11036 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 11037 | err = i40e_init_interrupt_scheme(pf); |
| 11038 | if (err) |
| 11039 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11040 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11041 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 11042 | * to us; HW supports far more and we share the remaining pool with |
| 11043 | * the other PFs. We allocate space for more than the guarantee with |
| 11044 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11045 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11046 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 11047 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 11048 | else |
| 11049 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 11050 | |
| 11051 | /* 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] | 11052 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 11053 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11054 | if (!pf->vsi) { |
| 11055 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11056 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11057 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11058 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 11059 | #ifdef CONFIG_PCI_IOV |
| 11060 | /* prep for VF support */ |
| 11061 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 11062 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11063 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 11064 | if (pci_num_vf(pdev)) |
| 11065 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 11066 | } |
| 11067 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11068 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11069 | if (err) { |
| 11070 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 11071 | goto err_vsis; |
| 11072 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11073 | |
| 11074 | /* Make sure flow control is set according to current settings */ |
| 11075 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 11076 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 11077 | dev_dbg(&pf->pdev->dev, |
| 11078 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 11079 | i40e_stat_str(hw, err), |
| 11080 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11081 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 11082 | dev_dbg(&pf->pdev->dev, |
| 11083 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 11084 | i40e_stat_str(hw, err), |
| 11085 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11086 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 11087 | dev_dbg(&pf->pdev->dev, |
| 11088 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 11089 | i40e_stat_str(hw, err), |
| 11090 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11091 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11092 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11093 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11094 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 11095 | i40e_vsi_open(pf->vsi[i]); |
| 11096 | break; |
| 11097 | } |
| 11098 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11099 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11100 | /* The driver only wants link up/down and module qualification |
| 11101 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11102 | */ |
| 11103 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11104 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 11105 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11106 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11107 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11108 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 11109 | i40e_stat_str(&pf->hw, err), |
| 11110 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11111 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11112 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 11113 | * of TSO, so that we avoid the MDD being fired and causing |
| 11114 | * a reset in the case of small MSS+TSO. |
| 11115 | */ |
| 11116 | val = rd32(hw, I40E_REG_MSS); |
| 11117 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 11118 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 11119 | val |= I40E_64BYTE_MSS; |
| 11120 | wr32(hw, I40E_REG_MSS, val); |
| 11121 | } |
| 11122 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 11123 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 11124 | msleep(75); |
| 11125 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 11126 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11127 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 11128 | i40e_stat_str(&pf->hw, err), |
| 11129 | i40e_aq_str(&pf->hw, |
| 11130 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 11131 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11132 | /* The main driver is (mostly) up and happy. We need to set this state |
| 11133 | * before setting up the misc vector or we get a race and the vector |
| 11134 | * ends up disabled forever. |
| 11135 | */ |
| 11136 | clear_bit(__I40E_DOWN, &pf->state); |
| 11137 | |
| 11138 | /* In case of MSIX we are going to setup the misc vector right here |
| 11139 | * to handle admin queue events etc. In case of legacy and MSI |
| 11140 | * the misc functionality and queue processing is combined in |
| 11141 | * the same vector and that gets setup at open. |
| 11142 | */ |
| 11143 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 11144 | err = i40e_setup_misc_vector(pf); |
| 11145 | if (err) { |
| 11146 | dev_info(&pdev->dev, |
| 11147 | "setup of misc vector failed: %d\n", err); |
| 11148 | goto err_vsis; |
| 11149 | } |
| 11150 | } |
| 11151 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11152 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11153 | /* prep for VF support */ |
| 11154 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11155 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11156 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11157 | /* disable link interrupts for VFs */ |
| 11158 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11159 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11160 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11161 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11162 | |
| 11163 | if (pci_num_vf(pdev)) { |
| 11164 | dev_info(&pdev->dev, |
| 11165 | "Active VFs found, allocating resources.\n"); |
| 11166 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11167 | if (err) |
| 11168 | dev_info(&pdev->dev, |
| 11169 | "Error %d allocating resources for existing VFs\n", |
| 11170 | err); |
| 11171 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11172 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11173 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11174 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11175 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11176 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11177 | pf->num_iwarp_msix, |
| 11178 | I40E_IWARP_IRQ_PILE_ID); |
| 11179 | if (pf->iwarp_base_vector < 0) { |
| 11180 | dev_info(&pdev->dev, |
| 11181 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 11182 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 11183 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 11184 | } |
| 11185 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11186 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11187 | i40e_dbg_pf_init(pf); |
| 11188 | |
| 11189 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11190 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11191 | |
| 11192 | /* since everything's happy, start the service_task timer */ |
| 11193 | mod_timer(&pf->service_timer, |
| 11194 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11195 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11196 | /* add this PF to client device list and launch a client service task */ |
| 11197 | err = i40e_lan_add_device(pf); |
| 11198 | if (err) |
| 11199 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 11200 | err); |
| 11201 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11202 | #ifdef I40E_FCOE |
| 11203 | /* create FCoE interface */ |
| 11204 | i40e_fcoe_vsi_setup(pf); |
| 11205 | |
| 11206 | #endif |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11207 | #define PCI_SPEED_SIZE 8 |
| 11208 | #define PCI_WIDTH_SIZE 8 |
| 11209 | /* Devices on the IOSF bus do not have this information |
| 11210 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11211 | * checking them. |
| 11212 | */ |
| 11213 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { |
| 11214 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11215 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11216 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11217 | /* Get the negotiated link width and speed from PCI config |
| 11218 | * space |
| 11219 | */ |
| 11220 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11221 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11222 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11223 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11224 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11225 | switch (hw->bus.speed) { |
| 11226 | case i40e_bus_speed_8000: |
| 11227 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11228 | case i40e_bus_speed_5000: |
| 11229 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11230 | case i40e_bus_speed_2500: |
| 11231 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11232 | default: |
| 11233 | break; |
| 11234 | } |
| 11235 | switch (hw->bus.width) { |
| 11236 | case i40e_bus_width_pcie_x8: |
| 11237 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11238 | case i40e_bus_width_pcie_x4: |
| 11239 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11240 | case i40e_bus_width_pcie_x2: |
| 11241 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11242 | case i40e_bus_width_pcie_x1: |
| 11243 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11244 | default: |
| 11245 | break; |
| 11246 | } |
| 11247 | |
| 11248 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11249 | speed, width); |
| 11250 | |
| 11251 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11252 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11253 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11254 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11255 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11256 | } |
| 11257 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11258 | /* get the requested speeds from the fw */ |
| 11259 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11260 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11261 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11262 | i40e_stat_str(&pf->hw, err), |
| 11263 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11264 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11265 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11266 | /* get the supported phy types from the fw */ |
| 11267 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11268 | if (err) |
| 11269 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11270 | i40e_stat_str(&pf->hw, err), |
| 11271 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 11272 | pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type); |
| 11273 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11274 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11275 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11276 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11277 | * PF/VF VSIs. |
| 11278 | * The FW can still send Flow control frames if enabled. |
| 11279 | */ |
| 11280 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11281 | pf->main_vsi_seid); |
| 11282 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 11283 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
| 11284 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
| 11285 | pf->flags |= I40E_FLAG_HAVE_10GBASET_PHY; |
| 11286 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11287 | /* print a string summarizing features */ |
| 11288 | i40e_print_features(pf); |
| 11289 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11290 | return 0; |
| 11291 | |
| 11292 | /* Unwind what we've done if something failed in the setup */ |
| 11293 | err_vsis: |
| 11294 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11295 | i40e_clear_interrupt_scheme(pf); |
| 11296 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11297 | err_switch_setup: |
| 11298 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11299 | del_timer_sync(&pf->service_timer); |
| 11300 | err_mac_addr: |
| 11301 | err_configure_lan_hmc: |
| 11302 | (void)i40e_shutdown_lan_hmc(hw); |
| 11303 | err_init_lan_hmc: |
| 11304 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11305 | err_sw_init: |
| 11306 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11307 | err_pf_reset: |
| 11308 | iounmap(hw->hw_addr); |
| 11309 | err_ioremap: |
| 11310 | kfree(pf); |
| 11311 | err_pf_alloc: |
| 11312 | pci_disable_pcie_error_reporting(pdev); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11313 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11314 | err_pci_reg: |
| 11315 | err_dma: |
| 11316 | pci_disable_device(pdev); |
| 11317 | return err; |
| 11318 | } |
| 11319 | |
| 11320 | /** |
| 11321 | * i40e_remove - Device removal routine |
| 11322 | * @pdev: PCI device information struct |
| 11323 | * |
| 11324 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11325 | * that is should release a PCI device. This could be caused by a |
| 11326 | * Hot-Plug event, or because the driver is going to be removed from |
| 11327 | * memory. |
| 11328 | **/ |
| 11329 | static void i40e_remove(struct pci_dev *pdev) |
| 11330 | { |
| 11331 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11332 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11333 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11334 | int i; |
| 11335 | |
| 11336 | i40e_dbg_pf_exit(pf); |
| 11337 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11338 | i40e_ptp_stop(pf); |
| 11339 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11340 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 11341 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 11342 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11343 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11344 | /* no more scheduling of any task */ |
Pandi Kumar Maharajan | a4618ec | 2016-02-18 09:19:25 -0800 | [diff] [blame] | 11345 | set_bit(__I40E_SUSPENDED, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11346 | set_bit(__I40E_DOWN, &pf->state); |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 11347 | if (pf->service_timer.data) |
| 11348 | del_timer_sync(&pf->service_timer); |
| 11349 | if (pf->service_task.func) |
| 11350 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11351 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11352 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11353 | i40e_free_vfs(pf); |
| 11354 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11355 | } |
| 11356 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11357 | i40e_fdir_teardown(pf); |
| 11358 | |
| 11359 | /* If there is a switch structure or any orphans, remove them. |
| 11360 | * This will leave only the PF's VSI remaining. |
| 11361 | */ |
| 11362 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11363 | if (!pf->veb[i]) |
| 11364 | continue; |
| 11365 | |
| 11366 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11367 | pf->veb[i]->uplink_seid == 0) |
| 11368 | i40e_switch_branch_release(pf->veb[i]); |
| 11369 | } |
| 11370 | |
| 11371 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11372 | * adminq and hmc. |
| 11373 | */ |
| 11374 | if (pf->vsi[pf->lan_vsi]) |
| 11375 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11376 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11377 | /* remove attached clients */ |
| 11378 | ret_code = i40e_lan_del_device(pf); |
| 11379 | if (ret_code) { |
| 11380 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 11381 | ret_code); |
| 11382 | } |
| 11383 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11384 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11385 | if (hw->hmc.hmc_obj) { |
| 11386 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11387 | if (ret_code) |
| 11388 | dev_warn(&pdev->dev, |
| 11389 | "Failed to destroy the HMC resources: %d\n", |
| 11390 | ret_code); |
| 11391 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11392 | |
| 11393 | /* shutdown the adminq */ |
Henry Tieman | ac9c5c6 | 2016-09-06 18:05:11 -0700 | [diff] [blame] | 11394 | i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11395 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11396 | /* destroy the locks only once, here */ |
| 11397 | mutex_destroy(&hw->aq.arq_mutex); |
| 11398 | mutex_destroy(&hw->aq.asq_mutex); |
| 11399 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11400 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11401 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11402 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11403 | if (pf->vsi[i]) { |
| 11404 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11405 | i40e_vsi_clear(pf->vsi[i]); |
| 11406 | pf->vsi[i] = NULL; |
| 11407 | } |
| 11408 | } |
| 11409 | |
| 11410 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11411 | kfree(pf->veb[i]); |
| 11412 | pf->veb[i] = NULL; |
| 11413 | } |
| 11414 | |
| 11415 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11416 | kfree(pf->vsi); |
| 11417 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11418 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11419 | kfree(pf); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11420 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11421 | |
| 11422 | pci_disable_pcie_error_reporting(pdev); |
| 11423 | pci_disable_device(pdev); |
| 11424 | } |
| 11425 | |
| 11426 | /** |
| 11427 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11428 | * @pdev: PCI device information struct |
| 11429 | * |
| 11430 | * Called to warn that something happened and the error handling steps |
| 11431 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11432 | * remediation. |
| 11433 | **/ |
| 11434 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11435 | enum pci_channel_state error) |
| 11436 | { |
| 11437 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11438 | |
| 11439 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11440 | |
Guilherme G Piccoli | edfc23ee | 2016-10-03 00:31:12 -0700 | [diff] [blame] | 11441 | if (!pf) { |
| 11442 | dev_info(&pdev->dev, |
| 11443 | "Cannot recover - error happened during device probe\n"); |
| 11444 | return PCI_ERS_RESULT_DISCONNECT; |
| 11445 | } |
| 11446 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11447 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11448 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11449 | rtnl_lock(); |
| 11450 | i40e_prep_for_reset(pf); |
| 11451 | rtnl_unlock(); |
| 11452 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11453 | |
| 11454 | /* Request a slot reset */ |
| 11455 | return PCI_ERS_RESULT_NEED_RESET; |
| 11456 | } |
| 11457 | |
| 11458 | /** |
| 11459 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11460 | * @pdev: PCI device information struct |
| 11461 | * |
| 11462 | * Called to find if the driver can work with the device now that |
| 11463 | * the pci slot has been reset. If a basic connection seems good |
| 11464 | * (registers are readable and have sane content) then return a |
| 11465 | * happy little PCI_ERS_RESULT_xxx. |
| 11466 | **/ |
| 11467 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11468 | { |
| 11469 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11470 | pci_ers_result_t result; |
| 11471 | int err; |
| 11472 | u32 reg; |
| 11473 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11474 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11475 | if (pci_enable_device_mem(pdev)) { |
| 11476 | dev_info(&pdev->dev, |
| 11477 | "Cannot re-enable PCI device after reset.\n"); |
| 11478 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11479 | } else { |
| 11480 | pci_set_master(pdev); |
| 11481 | pci_restore_state(pdev); |
| 11482 | pci_save_state(pdev); |
| 11483 | pci_wake_from_d3(pdev, false); |
| 11484 | |
| 11485 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11486 | if (reg == 0) |
| 11487 | result = PCI_ERS_RESULT_RECOVERED; |
| 11488 | else |
| 11489 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11490 | } |
| 11491 | |
| 11492 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11493 | if (err) { |
| 11494 | dev_info(&pdev->dev, |
| 11495 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11496 | err); |
| 11497 | /* non-fatal, continue */ |
| 11498 | } |
| 11499 | |
| 11500 | return result; |
| 11501 | } |
| 11502 | |
| 11503 | /** |
| 11504 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11505 | * @pdev: PCI device information struct |
| 11506 | * |
| 11507 | * Called to allow the driver to bring things back up after PCI error |
| 11508 | * and/or reset recovery has finished. |
| 11509 | **/ |
| 11510 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11511 | { |
| 11512 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11513 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11514 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11515 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 11516 | return; |
| 11517 | |
| 11518 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11519 | i40e_handle_reset_warning(pf); |
Vasily Averin | 4c4935a | 2015-07-08 15:04:26 +0300 | [diff] [blame] | 11520 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11521 | } |
| 11522 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11523 | /** |
| 11524 | * i40e_shutdown - PCI callback for shutting down |
| 11525 | * @pdev: PCI device information struct |
| 11526 | **/ |
| 11527 | static void i40e_shutdown(struct pci_dev *pdev) |
| 11528 | { |
| 11529 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11530 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11531 | |
| 11532 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11533 | set_bit(__I40E_DOWN, &pf->state); |
| 11534 | rtnl_lock(); |
| 11535 | i40e_prep_for_reset(pf); |
| 11536 | rtnl_unlock(); |
| 11537 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11538 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11539 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11540 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11541 | del_timer_sync(&pf->service_timer); |
| 11542 | cancel_work_sync(&pf->service_task); |
| 11543 | i40e_fdir_teardown(pf); |
| 11544 | |
| 11545 | rtnl_lock(); |
| 11546 | i40e_prep_for_reset(pf); |
| 11547 | rtnl_unlock(); |
| 11548 | |
| 11549 | wr32(hw, I40E_PFPM_APM, |
| 11550 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11551 | wr32(hw, I40E_PFPM_WUFC, |
| 11552 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11553 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 11554 | i40e_clear_interrupt_scheme(pf); |
| 11555 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11556 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11557 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11558 | pci_set_power_state(pdev, PCI_D3hot); |
| 11559 | } |
| 11560 | } |
| 11561 | |
| 11562 | #ifdef CONFIG_PM |
| 11563 | /** |
| 11564 | * i40e_suspend - PCI callback for moving to D3 |
| 11565 | * @pdev: PCI device information struct |
| 11566 | **/ |
| 11567 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11568 | { |
| 11569 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11570 | struct i40e_hw *hw = &pf->hw; |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11571 | int retval = 0; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11572 | |
| 11573 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11574 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 11575 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11576 | rtnl_lock(); |
| 11577 | i40e_prep_for_reset(pf); |
| 11578 | rtnl_unlock(); |
| 11579 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11580 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11581 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11582 | |
Greg Rose | b33d3b7 | 2016-05-16 10:26:37 -0700 | [diff] [blame] | 11583 | i40e_stop_misc_vector(pf); |
| 11584 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11585 | retval = pci_save_state(pdev); |
| 11586 | if (retval) |
| 11587 | return retval; |
| 11588 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11589 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11590 | pci_set_power_state(pdev, PCI_D3hot); |
| 11591 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11592 | return retval; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11593 | } |
| 11594 | |
| 11595 | /** |
| 11596 | * i40e_resume - PCI callback for waking up from D3 |
| 11597 | * @pdev: PCI device information struct |
| 11598 | **/ |
| 11599 | static int i40e_resume(struct pci_dev *pdev) |
| 11600 | { |
| 11601 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11602 | u32 err; |
| 11603 | |
| 11604 | pci_set_power_state(pdev, PCI_D0); |
| 11605 | pci_restore_state(pdev); |
| 11606 | /* pci_restore_state() clears dev->state_saves, so |
| 11607 | * call pci_save_state() again to restore it. |
| 11608 | */ |
| 11609 | pci_save_state(pdev); |
| 11610 | |
| 11611 | err = pci_enable_device_mem(pdev); |
| 11612 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11613 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11614 | return err; |
| 11615 | } |
| 11616 | pci_set_master(pdev); |
| 11617 | |
| 11618 | /* no wakeup events while running */ |
| 11619 | pci_wake_from_d3(pdev, false); |
| 11620 | |
| 11621 | /* handling the reset will rebuild the device state */ |
| 11622 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11623 | clear_bit(__I40E_DOWN, &pf->state); |
| 11624 | rtnl_lock(); |
| 11625 | i40e_reset_and_rebuild(pf, false); |
| 11626 | rtnl_unlock(); |
| 11627 | } |
| 11628 | |
| 11629 | return 0; |
| 11630 | } |
| 11631 | |
| 11632 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11633 | static const struct pci_error_handlers i40e_err_handler = { |
| 11634 | .error_detected = i40e_pci_error_detected, |
| 11635 | .slot_reset = i40e_pci_error_slot_reset, |
| 11636 | .resume = i40e_pci_error_resume, |
| 11637 | }; |
| 11638 | |
| 11639 | static struct pci_driver i40e_driver = { |
| 11640 | .name = i40e_driver_name, |
| 11641 | .id_table = i40e_pci_tbl, |
| 11642 | .probe = i40e_probe, |
| 11643 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11644 | #ifdef CONFIG_PM |
| 11645 | .suspend = i40e_suspend, |
| 11646 | .resume = i40e_resume, |
| 11647 | #endif |
| 11648 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11649 | .err_handler = &i40e_err_handler, |
| 11650 | .sriov_configure = i40e_pci_sriov_configure, |
| 11651 | }; |
| 11652 | |
| 11653 | /** |
| 11654 | * i40e_init_module - Driver registration routine |
| 11655 | * |
| 11656 | * i40e_init_module is the first routine called when the driver is |
| 11657 | * loaded. All it does is register with the PCI subsystem. |
| 11658 | **/ |
| 11659 | static int __init i40e_init_module(void) |
| 11660 | { |
| 11661 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 11662 | i40e_driver_string, i40e_driver_version_str); |
| 11663 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 11664 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11665 | /* we will see if single thread per module is enough for now, |
| 11666 | * it can't be any worse than using the system workqueue which |
| 11667 | * was already single threaded |
| 11668 | */ |
Jacob Keller | 6992a6c | 2016-08-04 11:37:01 -0700 | [diff] [blame] | 11669 | i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1, |
| 11670 | i40e_driver_name); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11671 | if (!i40e_wq) { |
| 11672 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 11673 | return -ENOMEM; |
| 11674 | } |
| 11675 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11676 | i40e_dbg_init(); |
| 11677 | return pci_register_driver(&i40e_driver); |
| 11678 | } |
| 11679 | module_init(i40e_init_module); |
| 11680 | |
| 11681 | /** |
| 11682 | * i40e_exit_module - Driver exit cleanup routine |
| 11683 | * |
| 11684 | * i40e_exit_module is called just before the driver is removed |
| 11685 | * from memory. |
| 11686 | **/ |
| 11687 | static void __exit i40e_exit_module(void) |
| 11688 | { |
| 11689 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11690 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11691 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11692 | } |
| 11693 | module_exit(i40e_exit_module); |