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 | cf465fe | 2016-09-27 11:28:54 -0700 | [diff] [blame] | 44 | #define DRV_VERSION_BUILD 21 |
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; |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 96 | module_param(debug, uint, 0); |
| 97 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 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 |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1148 | * |
| 1149 | * Returns ptr to the filter object or NULL |
| 1150 | **/ |
| 1151 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1152 | const u8 *macaddr, s16 vlan) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1153 | { |
| 1154 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1155 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1156 | |
| 1157 | if (!vsi || !macaddr) |
| 1158 | return NULL; |
| 1159 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1160 | key = i40e_addr_to_hkey(macaddr); |
| 1161 | hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1162 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1163 | (vlan == f->vlan)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1164 | return f; |
| 1165 | } |
| 1166 | return NULL; |
| 1167 | } |
| 1168 | |
| 1169 | /** |
| 1170 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1171 | * @vsi: the VSI to be searched |
| 1172 | * @macaddr: the MAC address we are searching for |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1173 | * |
| 1174 | * Returns the first filter with the provided MAC address or NULL if |
| 1175 | * MAC address was not found |
| 1176 | **/ |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1177 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1178 | { |
| 1179 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1180 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1181 | |
| 1182 | if (!vsi || !macaddr) |
| 1183 | return NULL; |
| 1184 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1185 | key = i40e_addr_to_hkey(macaddr); |
| 1186 | hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1187 | if ((ether_addr_equal(macaddr, f->macaddr))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1188 | return f; |
| 1189 | } |
| 1190 | return NULL; |
| 1191 | } |
| 1192 | |
| 1193 | /** |
| 1194 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1195 | * @vsi: the VSI to be searched |
| 1196 | * |
| 1197 | * Returns true if VSI is in vlan mode or false otherwise |
| 1198 | **/ |
| 1199 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1200 | { |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1201 | /* If we have a PVID, always operate in VLAN mode */ |
| 1202 | if (vsi->info.pvid) |
| 1203 | return true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1204 | |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1205 | /* We need to operate in VLAN mode whenever we have any filters with |
| 1206 | * a VLAN other than I40E_VLAN_ALL. We could check the table each |
| 1207 | * time, incurring search cost repeatedly. However, we can notice two |
| 1208 | * things: |
| 1209 | * |
| 1210 | * 1) the only place where we can gain a VLAN filter is in |
| 1211 | * i40e_add_filter. |
| 1212 | * |
| 1213 | * 2) the only place where filters are actually removed is in |
Jacob Keller | 0b7c8b5 | 2016-10-25 16:08:52 -0700 | [diff] [blame] | 1214 | * i40e_sync_filters_subtask. |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1215 | * |
| 1216 | * Thus, we can simply use a boolean value, has_vlan_filters which we |
| 1217 | * will set to true when we add a VLAN filter in i40e_add_filter. Then |
| 1218 | * we have to perform the full search after deleting filters in |
Jacob Keller | 0b7c8b5 | 2016-10-25 16:08:52 -0700 | [diff] [blame] | 1219 | * i40e_sync_filters_subtask, but we already have to search |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1220 | * filters here and can perform the check at the same time. This |
| 1221 | * results in avoiding embedding a loop for VLAN mode inside another |
| 1222 | * loop over all the filters, and should maintain correctness as noted |
| 1223 | * above. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1224 | */ |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1225 | return vsi->has_vlan_filter; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1229 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1230 | * @vsi: the VSI to be searched |
| 1231 | * @macaddr: the MAC address |
| 1232 | * @vlan: the vlan |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1233 | * |
| 1234 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1235 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1236 | * NOTE: This function is expected to be called with mac_filter_hash_lock |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1237 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1238 | **/ |
| 1239 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1240 | const u8 *macaddr, s16 vlan) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1241 | { |
| 1242 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1243 | u64 key; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1244 | |
| 1245 | if (!vsi || !macaddr) |
| 1246 | return NULL; |
| 1247 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1248 | f = i40e_find_filter(vsi, macaddr, vlan); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1249 | if (!f) { |
| 1250 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1251 | if (!f) |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1252 | return NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1253 | |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1254 | /* Update the boolean indicating if we need to function in |
| 1255 | * VLAN mode. |
| 1256 | */ |
| 1257 | if (vlan >= 0) |
| 1258 | vsi->has_vlan_filter = true; |
| 1259 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1260 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1261 | f->vlan = vlan; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1262 | /* If we're in overflow promisc mode, set the state directly |
| 1263 | * to failed, so we don't bother to try sending the filter |
| 1264 | * to the hardware. |
| 1265 | */ |
| 1266 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state)) |
| 1267 | f->state = I40E_FILTER_FAILED; |
| 1268 | else |
| 1269 | f->state = I40E_FILTER_NEW; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1270 | INIT_HLIST_NODE(&f->hlist); |
| 1271 | |
| 1272 | key = i40e_addr_to_hkey(macaddr); |
| 1273 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1274 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1275 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1276 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1277 | } |
| 1278 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1279 | /* If we're asked to add a filter that has been marked for removal, it |
| 1280 | * is safe to simply restore it to active state. __i40e_del_filter |
| 1281 | * will have simply deleted any filters which were previously marked |
| 1282 | * NEW or FAILED, so if it is currently marked REMOVE it must have |
| 1283 | * previously been ACTIVE. Since we haven't yet run the sync filters |
| 1284 | * task, just restore this filter to the ACTIVE state so that the |
| 1285 | * sync task leaves it in place |
| 1286 | */ |
| 1287 | if (f->state == I40E_FILTER_REMOVE) |
| 1288 | f->state = I40E_FILTER_ACTIVE; |
| 1289 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1290 | return f; |
| 1291 | } |
| 1292 | |
| 1293 | /** |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1294 | * __i40e_del_filter - Remove a specific filter from the VSI |
| 1295 | * @vsi: VSI to remove from |
| 1296 | * @f: the filter to remove from the list |
| 1297 | * |
| 1298 | * This function should be called instead of i40e_del_filter only if you know |
| 1299 | * the exact filter you will remove already, such as via i40e_find_filter or |
| 1300 | * i40e_find_mac. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1301 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1302 | * NOTE: This function is expected to be called with mac_filter_hash_lock |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1303 | * being held. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1304 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1305 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1306 | * instead of list_for_each_entry(). |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1307 | **/ |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1308 | static void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1309 | { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1310 | if (!f) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1311 | return; |
| 1312 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1313 | if ((f->state == I40E_FILTER_FAILED) || |
| 1314 | (f->state == I40E_FILTER_NEW)) { |
| 1315 | /* this one never got added by the FW. Just remove it, |
| 1316 | * no need to sync anything. |
| 1317 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1318 | hash_del(&f->hlist); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1319 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1320 | } else { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1321 | f->state = I40E_FILTER_REMOVE; |
| 1322 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1323 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | /** |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1328 | * i40e_del_filter - Remove a MAC/VLAN filter from the VSI |
| 1329 | * @vsi: the VSI to be searched |
| 1330 | * @macaddr: the MAC address |
| 1331 | * @vlan: the VLAN |
| 1332 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1333 | * NOTE: This function is expected to be called with mac_filter_hash_lock |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1334 | * being held. |
| 1335 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1336 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1337 | * instead of list_for_each_entry(). |
| 1338 | **/ |
| 1339 | void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan) |
| 1340 | { |
| 1341 | struct i40e_mac_filter *f; |
| 1342 | |
| 1343 | if (!vsi || !macaddr) |
| 1344 | return; |
| 1345 | |
| 1346 | f = i40e_find_filter(vsi, macaddr, vlan); |
| 1347 | __i40e_del_filter(vsi, f); |
| 1348 | } |
| 1349 | |
| 1350 | /** |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1351 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1352 | * @vsi: the VSI to be searched |
| 1353 | * @macaddr: the mac address to be filtered |
| 1354 | * |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1355 | * Goes through all the macvlan filters and adds a macvlan filter for each |
| 1356 | * unique vlan that already exists. If a PVID has been assigned, instead only |
| 1357 | * add the macaddr to that VLAN. |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1358 | * |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1359 | * Returns last filter added on success, else NULL |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1360 | **/ |
| 1361 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, |
| 1362 | const u8 *macaddr) |
| 1363 | { |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1364 | struct i40e_mac_filter *f, *add = NULL; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1365 | struct hlist_node *h; |
| 1366 | int bkt; |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1367 | |
| 1368 | if (vsi->info.pvid) |
| 1369 | return i40e_add_filter(vsi, macaddr, |
| 1370 | le16_to_cpu(vsi->info.pvid)); |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1371 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1372 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 1373 | if (f->state == I40E_FILTER_REMOVE) |
| 1374 | continue; |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1375 | add = i40e_add_filter(vsi, macaddr, f->vlan); |
| 1376 | if (!add) |
| 1377 | return NULL; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1380 | return add; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | /** |
| 1384 | * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS |
| 1385 | * @vsi: the VSI to be searched |
| 1386 | * @macaddr: the mac address to be removed |
| 1387 | * |
| 1388 | * Removes a given MAC address from a VSI, regardless of VLAN |
| 1389 | * |
| 1390 | * Returns 0 for success, or error |
| 1391 | **/ |
| 1392 | int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, const u8 *macaddr) |
| 1393 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1394 | struct i40e_mac_filter *f; |
| 1395 | struct hlist_node *h; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1396 | bool found = false; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1397 | int bkt; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1398 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1399 | WARN(!spin_is_locked(&vsi->mac_filter_hash_lock), |
| 1400 | "Missing mac_filter_hash_lock\n"); |
| 1401 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1402 | if (ether_addr_equal(macaddr, f->macaddr)) { |
| 1403 | __i40e_del_filter(vsi, f); |
| 1404 | found = true; |
| 1405 | } |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1406 | } |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1407 | |
| 1408 | if (found) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1409 | return 0; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1410 | else |
| 1411 | return -ENOENT; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1415 | * i40e_set_mac - NDO callback to set mac address |
| 1416 | * @netdev: network interface device structure |
| 1417 | * @p: pointer to an address structure |
| 1418 | * |
| 1419 | * Returns 0 on success, negative on failure |
| 1420 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1421 | #ifdef I40E_FCOE |
| 1422 | int i40e_set_mac(struct net_device *netdev, void *p) |
| 1423 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1424 | static int i40e_set_mac(struct net_device *netdev, void *p) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1425 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1426 | { |
| 1427 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1428 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1429 | struct i40e_pf *pf = vsi->back; |
| 1430 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1431 | struct sockaddr *addr = p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1432 | |
| 1433 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1434 | return -EADDRNOTAVAIL; |
| 1435 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1436 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1437 | netdev_info(netdev, "already using mac address %pM\n", |
| 1438 | addr->sa_data); |
| 1439 | return 0; |
| 1440 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1441 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1442 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1443 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1444 | return -EADDRNOTAVAIL; |
| 1445 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1446 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1447 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1448 | hw->mac.addr); |
| 1449 | else |
| 1450 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1451 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1452 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1453 | i40e_del_mac_all_vlan(vsi, netdev->dev_addr); |
| 1454 | i40e_put_mac_in_vlan(vsi, addr->sa_data); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1455 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1456 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1457 | if (vsi->type == I40E_VSI_MAIN) { |
| 1458 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1459 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1460 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1461 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1462 | addr->sa_data, NULL); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1463 | if (ret) |
| 1464 | netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n", |
| 1465 | i40e_stat_str(hw, ret), |
| 1466 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1469 | /* schedule our worker thread which will take care of |
| 1470 | * applying the new filter changes |
| 1471 | */ |
| 1472 | i40e_service_event_schedule(vsi->back); |
| 1473 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | /** |
| 1477 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1478 | * @vsi: the VSI being setup |
| 1479 | * @ctxt: VSI context structure |
| 1480 | * @enabled_tc: Enabled TCs bitmap |
| 1481 | * @is_add: True if called before Add VSI |
| 1482 | * |
| 1483 | * Setup VSI queue mapping for enabled traffic classes. |
| 1484 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1485 | #ifdef I40E_FCOE |
| 1486 | void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1487 | struct i40e_vsi_context *ctxt, |
| 1488 | u8 enabled_tc, |
| 1489 | bool is_add) |
| 1490 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1491 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1492 | struct i40e_vsi_context *ctxt, |
| 1493 | u8 enabled_tc, |
| 1494 | bool is_add) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1495 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1496 | { |
| 1497 | struct i40e_pf *pf = vsi->back; |
| 1498 | u16 sections = 0; |
| 1499 | u8 netdev_tc = 0; |
| 1500 | u16 numtc = 0; |
| 1501 | u16 qcount; |
| 1502 | u8 offset; |
| 1503 | u16 qmap; |
| 1504 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1505 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1506 | |
| 1507 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1508 | offset = 0; |
| 1509 | |
| 1510 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1511 | /* Find numtc from enabled TC bitmap */ |
| 1512 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1513 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1514 | numtc++; |
| 1515 | } |
| 1516 | if (!numtc) { |
| 1517 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1518 | numtc = 1; |
| 1519 | } |
| 1520 | } else { |
| 1521 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1522 | numtc = 1; |
| 1523 | } |
| 1524 | |
| 1525 | vsi->tc_config.numtc = numtc; |
| 1526 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1527 | /* Number of queues per enabled TC */ |
Catherine Sullivan | 7d64402 | 2016-05-16 10:26:41 -0700 | [diff] [blame] | 1528 | qcount = vsi->alloc_queue_pairs; |
| 1529 | |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1530 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1531 | 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] | 1532 | |
| 1533 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1534 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1535 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1536 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1537 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1538 | int pow, num_qps; |
| 1539 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1540 | switch (vsi->type) { |
| 1541 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1542 | qcount = min_t(int, pf->alloc_rss_size, |
| 1543 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1544 | break; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1545 | #ifdef I40E_FCOE |
| 1546 | case I40E_VSI_FCOE: |
| 1547 | qcount = num_tc_qps; |
| 1548 | break; |
| 1549 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1550 | case I40E_VSI_FDIR: |
| 1551 | case I40E_VSI_SRIOV: |
| 1552 | case I40E_VSI_VMDQ2: |
| 1553 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1554 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1555 | WARN_ON(i != 0); |
| 1556 | break; |
| 1557 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1558 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1559 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1560 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1561 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1562 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1563 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1564 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1565 | pow++; |
| 1566 | num_qps >>= 1; |
| 1567 | } |
| 1568 | |
| 1569 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1570 | qmap = |
| 1571 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1572 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1573 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1574 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1575 | } else { |
| 1576 | /* TC is not enabled so set the offset to |
| 1577 | * default queue and allocate one queue |
| 1578 | * for the given TC. |
| 1579 | */ |
| 1580 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1581 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1582 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1583 | |
| 1584 | qmap = 0; |
| 1585 | } |
| 1586 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1587 | } |
| 1588 | |
| 1589 | /* Set actual Tx/Rx queue pairs */ |
| 1590 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1591 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1592 | if (vsi->req_queue_pairs > 0) |
| 1593 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1594 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1595 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1596 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1597 | |
| 1598 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1599 | if (is_add) { |
| 1600 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1601 | |
| 1602 | ctxt->info.up_enable_bits = enabled_tc; |
| 1603 | } |
| 1604 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1605 | ctxt->info.mapping_flags |= |
| 1606 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1607 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1608 | ctxt->info.queue_mapping[i] = |
| 1609 | cpu_to_le16(vsi->base_queue + i); |
| 1610 | } else { |
| 1611 | ctxt->info.mapping_flags |= |
| 1612 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1613 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1614 | } |
| 1615 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1616 | } |
| 1617 | |
| 1618 | /** |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1619 | * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address |
| 1620 | * @netdev: the netdevice |
| 1621 | * @addr: address to add |
| 1622 | * |
| 1623 | * Called by __dev_(mc|uc)_sync when an address needs to be added. We call |
| 1624 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1625 | */ |
| 1626 | static int i40e_addr_sync(struct net_device *netdev, const u8 *addr) |
| 1627 | { |
| 1628 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1629 | struct i40e_vsi *vsi = np->vsi; |
| 1630 | struct i40e_mac_filter *f; |
| 1631 | |
| 1632 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1633 | f = i40e_put_mac_in_vlan(vsi, addr); |
| 1634 | else |
| 1635 | f = i40e_add_filter(vsi, addr, I40E_VLAN_ANY); |
| 1636 | |
| 1637 | if (f) |
| 1638 | return 0; |
| 1639 | else |
| 1640 | return -ENOMEM; |
| 1641 | } |
| 1642 | |
| 1643 | /** |
| 1644 | * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address |
| 1645 | * @netdev: the netdevice |
| 1646 | * @addr: address to add |
| 1647 | * |
| 1648 | * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call |
| 1649 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1650 | */ |
| 1651 | static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr) |
| 1652 | { |
| 1653 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1654 | struct i40e_vsi *vsi = np->vsi; |
| 1655 | |
| 1656 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1657 | i40e_del_mac_all_vlan(vsi, addr); |
| 1658 | else |
| 1659 | i40e_del_filter(vsi, addr, I40E_VLAN_ANY); |
| 1660 | |
| 1661 | return 0; |
| 1662 | } |
| 1663 | |
| 1664 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1665 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1666 | * @netdev: network interface device structure |
| 1667 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1668 | #ifdef I40E_FCOE |
| 1669 | void i40e_set_rx_mode(struct net_device *netdev) |
| 1670 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1671 | static void i40e_set_rx_mode(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1672 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1673 | { |
| 1674 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1675 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1676 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1677 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1678 | |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1679 | __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
| 1680 | __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1681 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1682 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1683 | |
| 1684 | /* check for other flag changes */ |
| 1685 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1686 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1687 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1688 | } |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1689 | |
| 1690 | /* schedule our worker thread which will take care of |
| 1691 | * applying the new filter changes |
| 1692 | */ |
| 1693 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | /** |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 1697 | * i40e_undo_filter_entries - Undo the changes made to MAC filter entries |
| 1698 | * @vsi: Pointer to VSI struct |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1699 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1700 | * those entries needs to be undone. |
| 1701 | * |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 1702 | * MAC filter entries from list were slated to be sent to firmware, either for |
| 1703 | * addition or deletion. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1704 | **/ |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 1705 | static void i40e_undo_filter_entries(struct i40e_vsi *vsi, |
| 1706 | struct hlist_head *from) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1707 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1708 | struct i40e_mac_filter *f; |
| 1709 | struct hlist_node *h; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1710 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1711 | hlist_for_each_entry_safe(f, h, from, hlist) { |
| 1712 | u64 key = i40e_addr_to_hkey(f->macaddr); |
| 1713 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1714 | /* Move the element back into MAC filter list*/ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1715 | hlist_del(&f->hlist); |
| 1716 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | /** |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1721 | * i40e_update_filter_state - Update filter state based on return data |
| 1722 | * from firmware |
| 1723 | * @count: Number of filters added |
| 1724 | * @add_list: return data from fw |
| 1725 | * @head: pointer to first filter in current batch |
| 1726 | * @aq_err: status from fw |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1727 | * |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1728 | * MAC filter entries from list were slated to be added to device. Returns |
| 1729 | * number of successful filters. Note that 0 does NOT mean success! |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1730 | **/ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1731 | static int |
| 1732 | i40e_update_filter_state(int count, |
| 1733 | struct i40e_aqc_add_macvlan_element_data *add_list, |
| 1734 | struct i40e_mac_filter *add_head, int aq_err) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1735 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1736 | int retval = 0; |
| 1737 | int i; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1738 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1739 | |
| 1740 | if (!aq_err) { |
| 1741 | retval = count; |
| 1742 | /* Everything's good, mark all filters active. */ |
| 1743 | for (i = 0; i < count ; i++) { |
| 1744 | add_head->state = I40E_FILTER_ACTIVE; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1745 | add_head = hlist_entry(add_head->hlist.next, |
| 1746 | typeof(struct i40e_mac_filter), |
| 1747 | hlist); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1748 | } |
| 1749 | } else if (aq_err == I40E_AQ_RC_ENOSPC) { |
| 1750 | /* Device ran out of filter space. Check the return value |
| 1751 | * for each filter to see which ones are active. |
| 1752 | */ |
| 1753 | for (i = 0; i < count ; i++) { |
| 1754 | if (add_list[i].match_method == |
| 1755 | I40E_AQC_MM_ERR_NO_RES) { |
| 1756 | add_head->state = I40E_FILTER_FAILED; |
| 1757 | } else { |
| 1758 | add_head->state = I40E_FILTER_ACTIVE; |
| 1759 | retval++; |
| 1760 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1761 | add_head = hlist_entry(add_head->hlist.next, |
| 1762 | typeof(struct i40e_mac_filter), |
| 1763 | hlist); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1764 | } |
| 1765 | } else { |
| 1766 | /* Some other horrible thing happened, fail all filters */ |
| 1767 | retval = 0; |
| 1768 | for (i = 0; i < count ; i++) { |
| 1769 | add_head->state = I40E_FILTER_FAILED; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1770 | add_head = hlist_entry(add_head->hlist.next, |
| 1771 | typeof(struct i40e_mac_filter), |
| 1772 | hlist); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1773 | } |
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 | return retval; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | /** |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 1779 | * i40e_aqc_del_filters - Request firmware to delete a set of filters |
| 1780 | * @vsi: ptr to the VSI |
| 1781 | * @vsi_name: name to display in messages |
| 1782 | * @list: the list of filters to send to firmware |
| 1783 | * @num_del: the number of filters to delete |
| 1784 | * @retval: Set to -EIO on failure to delete |
| 1785 | * |
| 1786 | * Send a request to firmware via AdminQ to delete a set of filters. Uses |
| 1787 | * *retval instead of a return value so that success does not force ret_val to |
| 1788 | * be set to 0. This ensures that a sequence of calls to this function |
| 1789 | * preserve the previous value of *retval on successful delete. |
| 1790 | */ |
| 1791 | static |
| 1792 | void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 1793 | struct i40e_aqc_remove_macvlan_element_data *list, |
| 1794 | int num_del, int *retval) |
| 1795 | { |
| 1796 | struct i40e_hw *hw = &vsi->back->hw; |
| 1797 | i40e_status aq_ret; |
| 1798 | int aq_err; |
| 1799 | |
| 1800 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL); |
| 1801 | aq_err = hw->aq.asq_last_status; |
| 1802 | |
| 1803 | /* Explicitly ignore and do not report when firmware returns ENOENT */ |
| 1804 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { |
| 1805 | *retval = -EIO; |
| 1806 | dev_info(&vsi->back->pdev->dev, |
| 1807 | "ignoring delete macvlan error on %s, err %s, aq_err %s\n", |
| 1808 | vsi_name, i40e_stat_str(hw, aq_ret), |
| 1809 | i40e_aq_str(hw, aq_err)); |
| 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | /** |
| 1814 | * i40e_aqc_add_filters - Request firmware to add a set of filters |
| 1815 | * @vsi: ptr to the VSI |
| 1816 | * @vsi_name: name to display in messages |
| 1817 | * @list: the list of filters to send to firmware |
| 1818 | * @add_head: Position in the add hlist |
| 1819 | * @num_add: the number of filters to add |
| 1820 | * @promisc_change: set to true on exit if promiscuous mode was forced on |
| 1821 | * |
| 1822 | * Send a request to firmware via AdminQ to add a chunk of filters. Will set |
| 1823 | * promisc_changed to true if the firmware has run out of space for more |
| 1824 | * filters. |
| 1825 | */ |
| 1826 | static |
| 1827 | void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 1828 | struct i40e_aqc_add_macvlan_element_data *list, |
| 1829 | struct i40e_mac_filter *add_head, |
| 1830 | int num_add, bool *promisc_changed) |
| 1831 | { |
| 1832 | struct i40e_hw *hw = &vsi->back->hw; |
| 1833 | i40e_status aq_ret; |
| 1834 | int aq_err, fcnt; |
| 1835 | |
| 1836 | aq_ret = i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL); |
| 1837 | aq_err = hw->aq.asq_last_status; |
| 1838 | fcnt = i40e_update_filter_state(num_add, list, add_head, aq_ret); |
| 1839 | vsi->active_filters += fcnt; |
| 1840 | |
| 1841 | if (fcnt != num_add) { |
| 1842 | *promisc_changed = true; |
| 1843 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 1844 | vsi->promisc_threshold = (vsi->active_filters * 3) / 4; |
| 1845 | dev_warn(&vsi->back->pdev->dev, |
| 1846 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", |
| 1847 | i40e_aq_str(hw, aq_err), |
| 1848 | vsi_name); |
| 1849 | } |
| 1850 | } |
| 1851 | |
| 1852 | /** |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame^] | 1853 | * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags |
| 1854 | * @vsi: pointer to the VSI |
| 1855 | * @f: filter data |
| 1856 | * |
| 1857 | * This function sets or clears the promiscuous broadcast flags for VLAN |
| 1858 | * filters in order to properly receive broadcast frames. Assumes that only |
| 1859 | * broadcast filters are passed. |
| 1860 | **/ |
| 1861 | static |
| 1862 | void i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name, |
| 1863 | struct i40e_mac_filter *f) |
| 1864 | { |
| 1865 | bool enable = f->state == I40E_FILTER_NEW; |
| 1866 | struct i40e_hw *hw = &vsi->back->hw; |
| 1867 | i40e_status aq_ret; |
| 1868 | |
| 1869 | if (f->vlan == I40E_VLAN_ANY) { |
| 1870 | aq_ret = i40e_aq_set_vsi_broadcast(hw, |
| 1871 | vsi->seid, |
| 1872 | enable, |
| 1873 | NULL); |
| 1874 | } else { |
| 1875 | aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw, |
| 1876 | vsi->seid, |
| 1877 | enable, |
| 1878 | f->vlan, |
| 1879 | NULL); |
| 1880 | } |
| 1881 | |
| 1882 | if (aq_ret) { |
| 1883 | dev_warn(&vsi->back->pdev->dev, |
| 1884 | "Error %s setting broadcast promiscuous mode on %s\n", |
| 1885 | i40e_aq_str(hw, hw->aq.asq_last_status), |
| 1886 | vsi_name); |
| 1887 | f->state = I40E_FILTER_FAILED; |
| 1888 | } else if (enable) { |
| 1889 | f->state = I40E_FILTER_ACTIVE; |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1894 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1895 | * @vsi: ptr to the VSI |
| 1896 | * |
| 1897 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1898 | * |
| 1899 | * Returns 0 or error value |
| 1900 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 1901 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1902 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1903 | struct hlist_head tmp_add_list, tmp_del_list; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1904 | struct i40e_mac_filter *f, *add_head = NULL; |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1905 | struct i40e_hw *hw = &vsi->back->hw; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1906 | unsigned int vlan_any_filters = 0; |
| 1907 | unsigned int non_vlan_filters = 0; |
| 1908 | unsigned int vlan_filters = 0; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1909 | bool promisc_changed = false; |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1910 | char vsi_name[16] = "PF"; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1911 | int filter_list_len = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1912 | i40e_status aq_ret = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1913 | u32 changed_flags = 0; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1914 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1915 | struct i40e_pf *pf; |
| 1916 | int num_add = 0; |
| 1917 | int num_del = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1918 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1919 | u16 cmd_flags; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1920 | int list_size; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1921 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1922 | |
| 1923 | /* empty array typed pointers, kcalloc later */ |
| 1924 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1925 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1926 | |
| 1927 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1928 | usleep_range(1000, 2000); |
| 1929 | pf = vsi->back; |
| 1930 | |
| 1931 | if (vsi->netdev) { |
| 1932 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1933 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1934 | } |
| 1935 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1936 | INIT_HLIST_HEAD(&tmp_add_list); |
| 1937 | INIT_HLIST_HEAD(&tmp_del_list); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1938 | |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1939 | if (vsi->type == I40E_VSI_SRIOV) |
| 1940 | snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id); |
| 1941 | else if (vsi->type != I40E_VSI_MAIN) |
| 1942 | snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid); |
| 1943 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1944 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1945 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1946 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1947 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1948 | /* Create a list of filters to delete. */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1949 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1950 | if (f->state == I40E_FILTER_REMOVE) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1951 | /* Move the element into temporary del_list */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1952 | hash_del(&f->hlist); |
| 1953 | hlist_add_head(&f->hlist, &tmp_del_list); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1954 | vsi->active_filters--; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1955 | |
| 1956 | /* Avoid counting removed filters */ |
| 1957 | continue; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1958 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1959 | if (f->state == I40E_FILTER_NEW) { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1960 | hash_del(&f->hlist); |
| 1961 | hlist_add_head(&f->hlist, &tmp_add_list); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1962 | } |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1963 | |
| 1964 | /* Count the number of each type of filter we have |
| 1965 | * remaining, ignoring any filters we're about to |
| 1966 | * delete. |
| 1967 | */ |
| 1968 | if (f->vlan > 0) |
| 1969 | vlan_filters++; |
| 1970 | else if (!f->vlan) |
| 1971 | non_vlan_filters++; |
| 1972 | else |
| 1973 | vlan_any_filters++; |
| 1974 | } |
| 1975 | |
| 1976 | /* We should never have VLAN=-1 filters at the same time as we |
| 1977 | * have either VLAN=0 or VLAN>0 filters, so warn about this |
| 1978 | * case here to help catch any issues. |
| 1979 | */ |
| 1980 | WARN_ON(vlan_any_filters && (vlan_filters + non_vlan_filters)); |
| 1981 | |
| 1982 | /* If we only have VLAN=0 filters remaining, and don't have |
| 1983 | * any other VLAN filters, we need to convert these VLAN=0 |
| 1984 | * filters into VLAN=-1 (I40E_VLAN_ANY) so that we operate |
| 1985 | * correctly in non-VLAN mode and receive all traffic tagged |
| 1986 | * or untagged. |
| 1987 | */ |
| 1988 | if (non_vlan_filters && !vlan_filters) { |
| 1989 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, |
| 1990 | hlist) { |
| 1991 | /* Only replace VLAN=0 filters */ |
| 1992 | if (f->vlan) |
| 1993 | continue; |
| 1994 | |
| 1995 | /* Allocate a replacement element */ |
| 1996 | add_head = kzalloc(sizeof(*add_head), |
| 1997 | GFP_KERNEL); |
| 1998 | if (!add_head) |
| 1999 | goto err_no_memory_locked; |
| 2000 | |
| 2001 | /* Copy the filter, with new state and VLAN */ |
| 2002 | *add_head = *f; |
| 2003 | add_head->state = I40E_FILTER_NEW; |
| 2004 | add_head->vlan = I40E_VLAN_ANY; |
| 2005 | |
| 2006 | /* Move the replacement to the add list */ |
| 2007 | INIT_HLIST_NODE(&add_head->hlist); |
| 2008 | hlist_add_head(&add_head->hlist, |
| 2009 | &tmp_add_list); |
| 2010 | |
| 2011 | /* Move the original to the delete list */ |
| 2012 | f->state = I40E_FILTER_REMOVE; |
| 2013 | hash_del(&f->hlist); |
| 2014 | hlist_add_head(&f->hlist, &tmp_del_list); |
| 2015 | vsi->active_filters--; |
| 2016 | } |
| 2017 | |
| 2018 | /* Also update any filters on the tmp_add list */ |
| 2019 | hlist_for_each_entry(f, &tmp_add_list, hlist) { |
| 2020 | if (!f->vlan) |
| 2021 | f->vlan = I40E_VLAN_ANY; |
| 2022 | } |
| 2023 | add_head = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2024 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2025 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | /* Now process 'del_list' outside the lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2029 | if (!hlist_empty(&tmp_del_list)) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2030 | filter_list_len = hw->aq.asq_buf_size / |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2031 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2032 | list_size = filter_list_len * |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2033 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2034 | del_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2035 | if (!del_list) |
| 2036 | goto err_no_memory; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2037 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2038 | hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2039 | cmd_flags = 0; |
| 2040 | |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame^] | 2041 | /* handle broadcast filters by updating the broadcast |
| 2042 | * promiscuous flag instead of deleting a MAC filter. |
| 2043 | */ |
| 2044 | if (is_broadcast_ether_addr(f->macaddr)) { |
| 2045 | i40e_aqc_broadcast_filter(vsi, vsi_name, f); |
| 2046 | |
| 2047 | hlist_del(&f->hlist); |
| 2048 | kfree(f); |
| 2049 | continue; |
| 2050 | } |
| 2051 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2052 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2053 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2054 | if (f->vlan == I40E_VLAN_ANY) { |
| 2055 | del_list[num_del].vlan_tag = 0; |
Alan Brady | a6cb914 | 2016-09-06 18:05:07 -0700 | [diff] [blame] | 2056 | cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2057 | } else { |
| 2058 | del_list[num_del].vlan_tag = |
| 2059 | cpu_to_le16((u16)(f->vlan)); |
| 2060 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2061 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2062 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 2063 | del_list[num_del].flags = cmd_flags; |
| 2064 | num_del++; |
| 2065 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2066 | /* flush a full buffer */ |
| 2067 | if (num_del == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2068 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2069 | num_del, &retval); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2070 | memset(del_list, 0, list_size); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2071 | num_del = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2072 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2073 | /* Release memory for MAC filter entries which were |
| 2074 | * synced up with HW. |
| 2075 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2076 | hlist_del(&f->hlist); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2077 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2078 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2079 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2080 | if (num_del) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2081 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2082 | num_del, &retval); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | kfree(del_list); |
| 2086 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2087 | } |
| 2088 | |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 2089 | /* After finishing notifying firmware of the deleted filters, update |
| 2090 | * the cached value of vsi->has_vlan_filter. Note that we are safe to |
| 2091 | * use just !!vlan_filters here because if we only have VLAN=0 (that |
| 2092 | * is, non_vlan_filters) these will all be converted to VLAN=-1 in the |
| 2093 | * logic above already so this value would still be correct. |
| 2094 | */ |
| 2095 | vsi->has_vlan_filter = !!vlan_filters; |
| 2096 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2097 | if (!hlist_empty(&tmp_add_list)) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2098 | /* Do all the adds now. */ |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2099 | filter_list_len = hw->aq.asq_buf_size / |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2100 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2101 | list_size = filter_list_len * |
| 2102 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
| 2103 | add_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2104 | if (!add_list) |
| 2105 | goto err_no_memory; |
| 2106 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2107 | num_add = 0; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame^] | 2108 | hlist_for_each_entry_safe(f, h, &tmp_add_list, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2109 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2110 | &vsi->state)) { |
| 2111 | f->state = I40E_FILTER_FAILED; |
| 2112 | continue; |
| 2113 | } |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame^] | 2114 | |
| 2115 | /* handle broadcast filters by updating the broadcast |
| 2116 | * promiscuous flag instead of adding a MAC filter. |
| 2117 | */ |
| 2118 | if (is_broadcast_ether_addr(f->macaddr)) { |
| 2119 | u64 key = i40e_addr_to_hkey(f->macaddr); |
| 2120 | i40e_aqc_broadcast_filter(vsi, vsi_name, f); |
| 2121 | |
| 2122 | hlist_del(&f->hlist); |
| 2123 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
| 2124 | continue; |
| 2125 | } |
| 2126 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2127 | /* add to add array */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2128 | if (num_add == 0) |
| 2129 | add_head = f; |
| 2130 | cmd_flags = 0; |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2131 | ether_addr_copy(add_list[num_add].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2132 | if (f->vlan == I40E_VLAN_ANY) { |
| 2133 | add_list[num_add].vlan_tag = 0; |
| 2134 | cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; |
| 2135 | } else { |
| 2136 | add_list[num_add].vlan_tag = |
| 2137 | cpu_to_le16((u16)(f->vlan)); |
| 2138 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2139 | add_list[num_add].queue_number = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2140 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2141 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2142 | num_add++; |
| 2143 | |
| 2144 | /* flush a full buffer */ |
| 2145 | if (num_add == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2146 | i40e_aqc_add_filters(vsi, vsi_name, add_list, |
| 2147 | add_head, num_add, |
| 2148 | &promisc_changed); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2149 | memset(add_list, 0, list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2150 | num_add = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2151 | } |
| 2152 | } |
| 2153 | if (num_add) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame] | 2154 | i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head, |
| 2155 | num_add, &promisc_changed); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2156 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2157 | /* Now move all of the filters from the temp add list back to |
| 2158 | * the VSI's list. |
| 2159 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2160 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2161 | hlist_for_each_entry_safe(f, h, &tmp_add_list, hlist) { |
| 2162 | u64 key = i40e_addr_to_hkey(f->macaddr); |
| 2163 | |
| 2164 | hlist_del(&f->hlist); |
| 2165 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2166 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2167 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2168 | kfree(add_list); |
| 2169 | add_list = NULL; |
| 2170 | } |
| 2171 | |
| 2172 | /* Check to see if we can drop out of overflow promiscuous mode. */ |
| 2173 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) && |
| 2174 | (vsi->active_filters < vsi->promisc_threshold)) { |
| 2175 | int failed_count = 0; |
| 2176 | /* See if we have any failed filters. We can't drop out of |
| 2177 | * promiscuous until these have all been deleted. |
| 2178 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2179 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2180 | hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2181 | if (f->state == I40E_FILTER_FAILED) |
| 2182 | failed_count++; |
| 2183 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2184 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2185 | if (!failed_count) { |
| 2186 | dev_info(&pf->pdev->dev, |
| 2187 | "filter logjam cleared on %s, leaving overflow promiscuous mode\n", |
| 2188 | vsi_name); |
| 2189 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2190 | promisc_changed = true; |
| 2191 | vsi->promisc_threshold = 0; |
| 2192 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2195 | /* if the VF is not trusted do not do promisc */ |
| 2196 | if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) { |
| 2197 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2198 | goto out; |
| 2199 | } |
| 2200 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2201 | /* check for changes in promiscuous modes */ |
| 2202 | if (changed_flags & IFF_ALLMULTI) { |
| 2203 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2204 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2205 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2206 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2207 | vsi->seid, |
| 2208 | cur_multipromisc, |
| 2209 | NULL); |
| 2210 | if (aq_ret) { |
| 2211 | retval = i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2212 | hw->aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2213 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2214 | "set multi promisc failed on %s, err %s aq_err %s\n", |
| 2215 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2216 | i40e_stat_str(hw, aq_ret), |
| 2217 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2218 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2219 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2220 | if ((changed_flags & IFF_PROMISC) || |
| 2221 | (promisc_changed && |
| 2222 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2223 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2224 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2225 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 2226 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2227 | &vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2228 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2229 | (pf->lan_veb != I40E_NO_VEB) && |
| 2230 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2231 | /* set defport ON for Main VSI instead of true promisc |
| 2232 | * this way we will get all unicast/multicast and VLAN |
| 2233 | * promisc behavior but will not get VF or VMDq traffic |
| 2234 | * replicated on the Main VSI. |
| 2235 | */ |
| 2236 | if (pf->cur_promisc != cur_promisc) { |
| 2237 | pf->cur_promisc = cur_promisc; |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2238 | if (cur_promisc) |
| 2239 | aq_ret = |
| 2240 | i40e_aq_set_default_vsi(hw, |
| 2241 | vsi->seid, |
| 2242 | NULL); |
| 2243 | else |
| 2244 | aq_ret = |
| 2245 | i40e_aq_clear_default_vsi(hw, |
| 2246 | vsi->seid, |
| 2247 | NULL); |
| 2248 | if (aq_ret) { |
| 2249 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2250 | hw->aq.asq_last_status); |
| 2251 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2252 | "Set default VSI failed on %s, err %s, aq_err %s\n", |
| 2253 | vsi_name, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2254 | i40e_stat_str(hw, aq_ret), |
| 2255 | i40e_aq_str(hw, |
| 2256 | hw->aq.asq_last_status)); |
| 2257 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2258 | } |
| 2259 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2260 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2261 | hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2262 | vsi->seid, |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 2263 | cur_promisc, NULL, |
| 2264 | true); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2265 | if (aq_ret) { |
| 2266 | retval = |
| 2267 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2268 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2269 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2270 | "set unicast promisc failed on %s, err %s, aq_err %s\n", |
| 2271 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2272 | i40e_stat_str(hw, aq_ret), |
| 2273 | i40e_aq_str(hw, |
| 2274 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2275 | } |
| 2276 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2277 | hw, |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2278 | vsi->seid, |
| 2279 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2280 | if (aq_ret) { |
| 2281 | retval = |
| 2282 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2283 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2284 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2285 | "set multicast promisc failed on %s, err %s, aq_err %s\n", |
| 2286 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2287 | i40e_stat_str(hw, aq_ret), |
| 2288 | i40e_aq_str(hw, |
| 2289 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2290 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2291 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2292 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2293 | vsi->seid, |
| 2294 | cur_promisc, NULL); |
| 2295 | if (aq_ret) { |
| 2296 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2297 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2298 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2299 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2300 | i40e_stat_str(hw, aq_ret), |
| 2301 | i40e_aq_str(hw, |
| 2302 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2303 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2304 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2305 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2306 | /* if something went wrong then set the changed flag so we try again */ |
| 2307 | if (retval) |
| 2308 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2309 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2310 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2311 | return retval; |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2312 | |
| 2313 | err_no_memory: |
| 2314 | /* Restore elements on the temporary add and delete lists */ |
| 2315 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2316 | err_no_memory_locked: |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2317 | i40e_undo_filter_entries(vsi, &tmp_del_list); |
| 2318 | i40e_undo_filter_entries(vsi, &tmp_add_list); |
| 2319 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 2320 | |
| 2321 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2322 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
| 2323 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | /** |
| 2327 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2328 | * @pf: board private structure |
| 2329 | **/ |
| 2330 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2331 | { |
| 2332 | int v; |
| 2333 | |
| 2334 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2335 | return; |
| 2336 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2337 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2338 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2339 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2340 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2341 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2342 | |
| 2343 | if (ret) { |
| 2344 | /* come back and try again later */ |
| 2345 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2346 | break; |
| 2347 | } |
| 2348 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2349 | } |
| 2350 | } |
| 2351 | |
| 2352 | /** |
| 2353 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2354 | * @netdev: network interface device structure |
| 2355 | * @new_mtu: new value for maximum frame size |
| 2356 | * |
| 2357 | * Returns 0 on success, negative on failure |
| 2358 | **/ |
| 2359 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2360 | { |
| 2361 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2362 | struct i40e_vsi *vsi = np->vsi; |
| 2363 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2364 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2365 | netdev->mtu, new_mtu); |
| 2366 | netdev->mtu = new_mtu; |
| 2367 | if (netif_running(netdev)) |
| 2368 | i40e_vsi_reinit_locked(vsi); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 2369 | i40e_notify_client_of_l2_param_changes(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2370 | return 0; |
| 2371 | } |
| 2372 | |
| 2373 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2374 | * i40e_ioctl - Access the hwtstamp interface |
| 2375 | * @netdev: network interface device structure |
| 2376 | * @ifr: interface request data |
| 2377 | * @cmd: ioctl command |
| 2378 | **/ |
| 2379 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2380 | { |
| 2381 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2382 | struct i40e_pf *pf = np->vsi->back; |
| 2383 | |
| 2384 | switch (cmd) { |
| 2385 | case SIOCGHWTSTAMP: |
| 2386 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2387 | case SIOCSHWTSTAMP: |
| 2388 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2389 | default: |
| 2390 | return -EOPNOTSUPP; |
| 2391 | } |
| 2392 | } |
| 2393 | |
| 2394 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2395 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2396 | * @vsi: the vsi being adjusted |
| 2397 | **/ |
| 2398 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2399 | { |
| 2400 | struct i40e_vsi_context ctxt; |
| 2401 | i40e_status ret; |
| 2402 | |
| 2403 | if ((vsi->info.valid_sections & |
| 2404 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2405 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2406 | return; /* already enabled */ |
| 2407 | |
| 2408 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2409 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2410 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2411 | |
| 2412 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2413 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2414 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2415 | if (ret) { |
| 2416 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2417 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2418 | i40e_stat_str(&vsi->back->hw, ret), |
| 2419 | i40e_aq_str(&vsi->back->hw, |
| 2420 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2421 | } |
| 2422 | } |
| 2423 | |
| 2424 | /** |
| 2425 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2426 | * @vsi: the vsi being adjusted |
| 2427 | **/ |
| 2428 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2429 | { |
| 2430 | struct i40e_vsi_context ctxt; |
| 2431 | i40e_status ret; |
| 2432 | |
| 2433 | if ((vsi->info.valid_sections & |
| 2434 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2435 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2436 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2437 | return; /* already disabled */ |
| 2438 | |
| 2439 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2440 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2441 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2442 | |
| 2443 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2444 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2445 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2446 | if (ret) { |
| 2447 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2448 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2449 | i40e_stat_str(&vsi->back->hw, ret), |
| 2450 | i40e_aq_str(&vsi->back->hw, |
| 2451 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2452 | } |
| 2453 | } |
| 2454 | |
| 2455 | /** |
| 2456 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2457 | * @netdev: network interface to be adjusted |
| 2458 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2459 | **/ |
| 2460 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2461 | { |
| 2462 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2463 | struct i40e_vsi *vsi = np->vsi; |
| 2464 | |
| 2465 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2466 | i40e_vlan_stripping_enable(vsi); |
| 2467 | else |
| 2468 | i40e_vlan_stripping_disable(vsi); |
| 2469 | } |
| 2470 | |
| 2471 | /** |
| 2472 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 2473 | * @vsi: the vsi being configured |
| 2474 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 2475 | **/ |
| 2476 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2477 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2478 | struct i40e_mac_filter *f, *add_f, *del_f; |
| 2479 | struct hlist_node *h; |
| 2480 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2481 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2482 | /* Locked once because all functions invoked below iterates list*/ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2483 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2484 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2485 | if (vsi->netdev) { |
| 2486 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2487 | if (!add_f) { |
| 2488 | dev_info(&vsi->back->pdev->dev, |
| 2489 | "Could not add vlan filter %d for %pM\n", |
| 2490 | vid, vsi->netdev->dev_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2491 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2492 | return -ENOMEM; |
| 2493 | } |
| 2494 | } |
| 2495 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2496 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 2497 | if (f->state == I40E_FILTER_REMOVE) |
| 2498 | continue; |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2499 | add_f = i40e_add_filter(vsi, f->macaddr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2500 | if (!add_f) { |
| 2501 | dev_info(&vsi->back->pdev->dev, |
| 2502 | "Could not add vlan filter %d for %pM\n", |
| 2503 | vid, f->macaddr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2504 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2505 | return -ENOMEM; |
| 2506 | } |
| 2507 | } |
| 2508 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2509 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 2510 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 2511 | * with 0, so we now accept untagged and specified tagged traffic |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2512 | * (and not all tags along with untagged) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2513 | */ |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 2514 | if (vid > 0 && vsi->netdev) { |
| 2515 | del_f = i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 2516 | I40E_VLAN_ANY); |
| 2517 | if (del_f) { |
| 2518 | __i40e_del_filter(vsi, del_f); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2519 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2520 | if (!add_f) { |
| 2521 | dev_info(&vsi->back->pdev->dev, |
| 2522 | "Could not add filter 0 for %pM\n", |
| 2523 | vsi->netdev->dev_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2524 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2525 | return -ENOMEM; |
| 2526 | } |
| 2527 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2528 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2529 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2530 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
| 2531 | if (vid > 0 && !vsi->info.pvid) { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2532 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 2533 | if (f->state == I40E_FILTER_REMOVE) |
| 2534 | continue; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 2535 | del_f = i40e_find_filter(vsi, f->macaddr, |
| 2536 | I40E_VLAN_ANY); |
| 2537 | if (!del_f) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2538 | continue; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 2539 | __i40e_del_filter(vsi, del_f); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2540 | add_f = i40e_add_filter(vsi, f->macaddr, 0); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2541 | if (!add_f) { |
| 2542 | dev_info(&vsi->back->pdev->dev, |
| 2543 | "Could not add filter 0 for %pM\n", |
| 2544 | f->macaddr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2545 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2546 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2547 | } |
| 2548 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2549 | } |
| 2550 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2551 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2552 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2553 | /* schedule our worker thread which will take care of |
| 2554 | * applying the new filter changes |
| 2555 | */ |
| 2556 | i40e_service_event_schedule(vsi->back); |
| 2557 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | /** |
| 2561 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 2562 | * @vsi: the vsi being configured |
| 2563 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
| 2564 | **/ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 2565 | void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2566 | { |
| 2567 | struct net_device *netdev = vsi->netdev; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2568 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2569 | struct hlist_node *h; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2570 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2571 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2572 | /* Locked once because all functions invoked below iterates list */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2573 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2574 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2575 | if (vsi->netdev) |
| 2576 | i40e_del_filter(vsi, netdev->dev_addr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2577 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2578 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 2579 | if (f->vlan == vid) |
| 2580 | __i40e_del_filter(vsi, f); |
| 2581 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2582 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2583 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2584 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2585 | /* schedule our worker thread which will take care of |
| 2586 | * applying the new filter changes |
| 2587 | */ |
| 2588 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | /** |
| 2592 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2593 | * @netdev: network interface to be adjusted |
| 2594 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2595 | * |
| 2596 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2597 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2598 | #ifdef I40E_FCOE |
| 2599 | int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2600 | __always_unused __be16 proto, u16 vid) |
| 2601 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2602 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2603 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2604 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2605 | { |
| 2606 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2607 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2608 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2609 | |
Jacob Keller | 6a112785 | 2016-10-25 16:08:49 -0700 | [diff] [blame] | 2610 | if (vid >= VLAN_N_VID) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2611 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2612 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2613 | /* If the network stack called us with vid = 0 then |
| 2614 | * it is asking to receive priority tagged packets with |
| 2615 | * vlan id 0. Our HW receives them by default when configured |
| 2616 | * to receive untagged packets so there is no need to add an |
| 2617 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2618 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2619 | if (vid) |
| 2620 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2621 | |
Jacob Keller | 6a112785 | 2016-10-25 16:08:49 -0700 | [diff] [blame] | 2622 | if (!ret) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2623 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2624 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2625 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | /** |
| 2629 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2630 | * @netdev: network interface to be adjusted |
| 2631 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2632 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2633 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2634 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2635 | #ifdef I40E_FCOE |
| 2636 | int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2637 | __always_unused __be16 proto, u16 vid) |
| 2638 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2639 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2640 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2641 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2642 | { |
| 2643 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2644 | struct i40e_vsi *vsi = np->vsi; |
| 2645 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2646 | /* return code is ignored as there is nothing a user |
| 2647 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2648 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2649 | */ |
| 2650 | i40e_vsi_kill_vlan(vsi, vid); |
| 2651 | |
| 2652 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2653 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2654 | return 0; |
| 2655 | } |
| 2656 | |
| 2657 | /** |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 2658 | * i40e_macaddr_init - explicitly write the mac address filters |
| 2659 | * |
| 2660 | * @vsi: pointer to the vsi |
| 2661 | * @macaddr: the MAC address |
| 2662 | * |
| 2663 | * This is needed when the macaddr has been obtained by other |
| 2664 | * means than the default, e.g., from Open Firmware or IDPROM. |
| 2665 | * Returns 0 on success, negative on failure |
| 2666 | **/ |
| 2667 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) |
| 2668 | { |
| 2669 | int ret; |
| 2670 | struct i40e_aqc_add_macvlan_element_data element; |
| 2671 | |
| 2672 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 2673 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 2674 | macaddr, NULL); |
| 2675 | if (ret) { |
| 2676 | dev_info(&vsi->back->pdev->dev, |
| 2677 | "Addr change for VSI failed: %d\n", ret); |
| 2678 | return -EADDRNOTAVAIL; |
| 2679 | } |
| 2680 | |
| 2681 | memset(&element, 0, sizeof(element)); |
| 2682 | ether_addr_copy(element.mac_addr, macaddr); |
| 2683 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 2684 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); |
| 2685 | if (ret) { |
| 2686 | dev_info(&vsi->back->pdev->dev, |
| 2687 | "add filter failed err %s aq_err %s\n", |
| 2688 | i40e_stat_str(&vsi->back->hw, ret), |
| 2689 | i40e_aq_str(&vsi->back->hw, |
| 2690 | vsi->back->hw.aq.asq_last_status)); |
| 2691 | } |
| 2692 | return ret; |
| 2693 | } |
| 2694 | |
| 2695 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2696 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2697 | * @vsi: the vsi being brought back up |
| 2698 | **/ |
| 2699 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2700 | { |
| 2701 | u16 vid; |
| 2702 | |
| 2703 | if (!vsi->netdev) |
| 2704 | return; |
| 2705 | |
| 2706 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2707 | |
| 2708 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2709 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2710 | vid); |
| 2711 | } |
| 2712 | |
| 2713 | /** |
| 2714 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2715 | * @vsi: the vsi being adjusted |
| 2716 | * @vid: the vlan id to set as a PVID |
| 2717 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2718 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2719 | { |
| 2720 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2721 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2722 | |
| 2723 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2724 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2725 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2726 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2727 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2728 | |
| 2729 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2730 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2731 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2732 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2733 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2734 | "add pvid failed, err %s aq_err %s\n", |
| 2735 | i40e_stat_str(&vsi->back->hw, ret), |
| 2736 | i40e_aq_str(&vsi->back->hw, |
| 2737 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2738 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2741 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | /** |
| 2745 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2746 | * @vsi: the vsi being adjusted |
| 2747 | * |
| 2748 | * Just use the vlan_rx_register() service to put it back to normal |
| 2749 | **/ |
| 2750 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2751 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2752 | i40e_vlan_stripping_disable(vsi); |
| 2753 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2754 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | /** |
| 2758 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2759 | * @vsi: ptr to the VSI |
| 2760 | * |
| 2761 | * If this function returns with an error, then it's possible one or |
| 2762 | * more of the rings is populated (while the rest are not). It is the |
| 2763 | * callers duty to clean those orphaned rings. |
| 2764 | * |
| 2765 | * Return 0 on success, negative on failure |
| 2766 | **/ |
| 2767 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2768 | { |
| 2769 | int i, err = 0; |
| 2770 | |
| 2771 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2772 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2773 | |
| 2774 | return err; |
| 2775 | } |
| 2776 | |
| 2777 | /** |
| 2778 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2779 | * @vsi: ptr to the VSI |
| 2780 | * |
| 2781 | * Free VSI's transmit software resources |
| 2782 | **/ |
| 2783 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2784 | { |
| 2785 | int i; |
| 2786 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2787 | if (!vsi->tx_rings) |
| 2788 | return; |
| 2789 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2790 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2791 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2792 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2793 | } |
| 2794 | |
| 2795 | /** |
| 2796 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2797 | * @vsi: ptr to the VSI |
| 2798 | * |
| 2799 | * If this function returns with an error, then it's possible one or |
| 2800 | * more of the rings is populated (while the rest are not). It is the |
| 2801 | * callers duty to clean those orphaned rings. |
| 2802 | * |
| 2803 | * Return 0 on success, negative on failure |
| 2804 | **/ |
| 2805 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2806 | { |
| 2807 | int i, err = 0; |
| 2808 | |
| 2809 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2810 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2811 | #ifdef I40E_FCOE |
| 2812 | i40e_fcoe_setup_ddp_resources(vsi); |
| 2813 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2814 | return err; |
| 2815 | } |
| 2816 | |
| 2817 | /** |
| 2818 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2819 | * @vsi: ptr to the VSI |
| 2820 | * |
| 2821 | * Free all receive software resources |
| 2822 | **/ |
| 2823 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2824 | { |
| 2825 | int i; |
| 2826 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2827 | if (!vsi->rx_rings) |
| 2828 | return; |
| 2829 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2830 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2831 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2832 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2833 | #ifdef I40E_FCOE |
| 2834 | i40e_fcoe_free_ddp_resources(vsi); |
| 2835 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2839 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2840 | * @ring: The Tx ring to configure |
| 2841 | * |
| 2842 | * This enables/disables XPS for a given Tx descriptor ring |
| 2843 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2844 | **/ |
| 2845 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2846 | { |
| 2847 | struct i40e_vsi *vsi = ring->vsi; |
| 2848 | cpumask_var_t mask; |
| 2849 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2850 | if (!ring->q_vector || !ring->netdev) |
| 2851 | return; |
| 2852 | |
| 2853 | /* Single TC mode enable XPS */ |
| 2854 | if (vsi->tc_config.numtc <= 1) { |
| 2855 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2856 | netif_set_xps_queue(ring->netdev, |
| 2857 | &ring->q_vector->affinity_mask, |
| 2858 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2859 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2860 | /* Disable XPS to allow selection based on TC */ |
| 2861 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2862 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2863 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2864 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2865 | |
| 2866 | /* schedule our worker thread which will take care of |
| 2867 | * applying the new filter changes |
| 2868 | */ |
| 2869 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2873 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2874 | * @ring: The Tx ring to configure |
| 2875 | * |
| 2876 | * Configure the Tx descriptor ring in the HMC context. |
| 2877 | **/ |
| 2878 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2879 | { |
| 2880 | struct i40e_vsi *vsi = ring->vsi; |
| 2881 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2882 | struct i40e_hw *hw = &vsi->back->hw; |
| 2883 | struct i40e_hmc_obj_txq tx_ctx; |
| 2884 | i40e_status err = 0; |
| 2885 | u32 qtx_ctl = 0; |
| 2886 | |
| 2887 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2888 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2889 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2890 | ring->atr_count = 0; |
| 2891 | } else { |
| 2892 | ring->atr_sample_rate = 0; |
| 2893 | } |
| 2894 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2895 | /* configure XPS */ |
| 2896 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2897 | |
| 2898 | /* clear the context structure first */ |
| 2899 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2900 | |
| 2901 | tx_ctx.new_context = 1; |
| 2902 | tx_ctx.base = (ring->dma / 128); |
| 2903 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2904 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2905 | I40E_FLAG_FD_ATR_ENABLED)); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2906 | #ifdef I40E_FCOE |
| 2907 | tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2908 | #endif |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2909 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2910 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2911 | if (vsi->type != I40E_VSI_FDIR) |
| 2912 | tx_ctx.head_wb_ena = 1; |
| 2913 | tx_ctx.head_wb_addr = ring->dma + |
| 2914 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2915 | |
| 2916 | /* As part of VSI creation/update, FW allocates certain |
| 2917 | * Tx arbitration queue sets for each TC enabled for |
| 2918 | * the VSI. The FW returns the handles to these queue |
| 2919 | * sets as part of the response buffer to Add VSI, |
| 2920 | * Update VSI, etc. AQ commands. It is expected that |
| 2921 | * these queue set handles be associated with the Tx |
| 2922 | * queues by the driver as part of the TX queue context |
| 2923 | * initialization. This has to be done regardless of |
| 2924 | * DCB as by default everything is mapped to TC0. |
| 2925 | */ |
| 2926 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2927 | tx_ctx.rdylist_act = 0; |
| 2928 | |
| 2929 | /* clear the context in the HMC */ |
| 2930 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2931 | if (err) { |
| 2932 | dev_info(&vsi->back->pdev->dev, |
| 2933 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2934 | ring->queue_index, pf_q, err); |
| 2935 | return -ENOMEM; |
| 2936 | } |
| 2937 | |
| 2938 | /* set the context in the HMC */ |
| 2939 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2940 | if (err) { |
| 2941 | dev_info(&vsi->back->pdev->dev, |
| 2942 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2943 | ring->queue_index, pf_q, err); |
| 2944 | return -ENOMEM; |
| 2945 | } |
| 2946 | |
| 2947 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2948 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2949 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2950 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2951 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2952 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2953 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2954 | } |
| 2955 | |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2956 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2957 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2958 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2959 | i40e_flush(hw); |
| 2960 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2961 | /* cache tail off for easier writes later */ |
| 2962 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2963 | |
| 2964 | return 0; |
| 2965 | } |
| 2966 | |
| 2967 | /** |
| 2968 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2969 | * @ring: The Rx ring to configure |
| 2970 | * |
| 2971 | * Configure the Rx descriptor ring in the HMC context. |
| 2972 | **/ |
| 2973 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2974 | { |
| 2975 | struct i40e_vsi *vsi = ring->vsi; |
| 2976 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2977 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2978 | struct i40e_hw *hw = &vsi->back->hw; |
| 2979 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2980 | i40e_status err = 0; |
| 2981 | |
| 2982 | ring->state = 0; |
| 2983 | |
| 2984 | /* clear the context structure first */ |
| 2985 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2986 | |
| 2987 | ring->rx_buf_len = vsi->rx_buf_len; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2988 | |
| 2989 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2990 | |
| 2991 | rx_ctx.base = (ring->dma / 128); |
| 2992 | rx_ctx.qlen = ring->count; |
| 2993 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 2994 | /* use 32 byte descriptors */ |
| 2995 | rx_ctx.dsize = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2996 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 2997 | /* descriptor type is always zero |
| 2998 | * rx_ctx.dtype = 0; |
| 2999 | */ |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 3000 | rx_ctx.hsplit_0 = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3001 | |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 3002 | 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] | 3003 | if (hw->revision_id == 0) |
| 3004 | rx_ctx.lrxqthresh = 0; |
| 3005 | else |
| 3006 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3007 | rx_ctx.crcstrip = 1; |
| 3008 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 3009 | /* this controls whether VLAN is stripped from inner headers */ |
| 3010 | rx_ctx.showiv = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3011 | #ifdef I40E_FCOE |
| 3012 | rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 3013 | #endif |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 3014 | /* set the prefena field to 1 because the manual says to */ |
| 3015 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3016 | |
| 3017 | /* clear the context in the HMC */ |
| 3018 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 3019 | if (err) { |
| 3020 | dev_info(&vsi->back->pdev->dev, |
| 3021 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 3022 | ring->queue_index, pf_q, err); |
| 3023 | return -ENOMEM; |
| 3024 | } |
| 3025 | |
| 3026 | /* set the context in the HMC */ |
| 3027 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 3028 | if (err) { |
| 3029 | dev_info(&vsi->back->pdev->dev, |
| 3030 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 3031 | ring->queue_index, pf_q, err); |
| 3032 | return -ENOMEM; |
| 3033 | } |
| 3034 | |
| 3035 | /* cache tail for quicker writes, and clear the reg before use */ |
| 3036 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 3037 | writel(0, ring->tail); |
| 3038 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 3039 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3040 | |
| 3041 | return 0; |
| 3042 | } |
| 3043 | |
| 3044 | /** |
| 3045 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 3046 | * @vsi: VSI structure describing this set of rings and resources |
| 3047 | * |
| 3048 | * Configure the Tx VSI for operation. |
| 3049 | **/ |
| 3050 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 3051 | { |
| 3052 | int err = 0; |
| 3053 | u16 i; |
| 3054 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3055 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 3056 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3057 | |
| 3058 | return err; |
| 3059 | } |
| 3060 | |
| 3061 | /** |
| 3062 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 3063 | * @vsi: the VSI being configured |
| 3064 | * |
| 3065 | * Configure the Rx VSI for operation. |
| 3066 | **/ |
| 3067 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 3068 | { |
| 3069 | int err = 0; |
| 3070 | u16 i; |
| 3071 | |
| 3072 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 3073 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 3074 | + ETH_FCS_LEN + VLAN_HLEN; |
| 3075 | else |
| 3076 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 3077 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 3078 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3079 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3080 | #ifdef I40E_FCOE |
| 3081 | /* setup rx buffer for FCoE */ |
| 3082 | if ((vsi->type == I40E_VSI_FCOE) && |
| 3083 | (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) { |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3084 | vsi->rx_buf_len = I40E_RXBUFFER_3072; |
| 3085 | vsi->max_frame = I40E_RXBUFFER_3072; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3089 | /* round up for the chip's needs */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3090 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3091 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3092 | |
| 3093 | /* set up individual rings */ |
| 3094 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3095 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3096 | |
| 3097 | return err; |
| 3098 | } |
| 3099 | |
| 3100 | /** |
| 3101 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3102 | * @vsi: ptr to the VSI |
| 3103 | **/ |
| 3104 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3105 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3106 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3107 | u16 qoffset, qcount; |
| 3108 | int i, n; |
| 3109 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3110 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3111 | /* Reset the TC information */ |
| 3112 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3113 | rx_ring = vsi->rx_rings[i]; |
| 3114 | tx_ring = vsi->tx_rings[i]; |
| 3115 | rx_ring->dcb_tc = 0; |
| 3116 | tx_ring->dcb_tc = 0; |
| 3117 | } |
| 3118 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3119 | |
| 3120 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3121 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3122 | continue; |
| 3123 | |
| 3124 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3125 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3126 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3127 | rx_ring = vsi->rx_rings[i]; |
| 3128 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3129 | rx_ring->dcb_tc = n; |
| 3130 | tx_ring->dcb_tc = n; |
| 3131 | } |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | /** |
| 3136 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3137 | * @vsi: ptr to the VSI |
| 3138 | **/ |
| 3139 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3140 | { |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 3141 | struct i40e_pf *pf = vsi->back; |
| 3142 | int err; |
| 3143 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3144 | if (vsi->netdev) |
| 3145 | i40e_set_rx_mode(vsi->netdev); |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 3146 | |
| 3147 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 3148 | err = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 3149 | if (err) { |
| 3150 | dev_warn(&pf->pdev->dev, |
| 3151 | "could not set up macaddr; err %d\n", err); |
| 3152 | } |
| 3153 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3157 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3158 | * @vsi: Pointer to the targeted VSI |
| 3159 | * |
| 3160 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3161 | * filters were saved. |
| 3162 | **/ |
| 3163 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3164 | { |
| 3165 | struct i40e_fdir_filter *filter; |
| 3166 | struct i40e_pf *pf = vsi->back; |
| 3167 | struct hlist_node *node; |
| 3168 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3169 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3170 | return; |
| 3171 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3172 | hlist_for_each_entry_safe(filter, node, |
| 3173 | &pf->fdir_filter_list, fdir_node) { |
| 3174 | i40e_add_del_fdir(vsi, filter, true); |
| 3175 | } |
| 3176 | } |
| 3177 | |
| 3178 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3179 | * i40e_vsi_configure - Set up the VSI for action |
| 3180 | * @vsi: the VSI being configured |
| 3181 | **/ |
| 3182 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3183 | { |
| 3184 | int err; |
| 3185 | |
| 3186 | i40e_set_vsi_rx_mode(vsi); |
| 3187 | i40e_restore_vlan(vsi); |
| 3188 | i40e_vsi_config_dcb_rings(vsi); |
| 3189 | err = i40e_vsi_configure_tx(vsi); |
| 3190 | if (!err) |
| 3191 | err = i40e_vsi_configure_rx(vsi); |
| 3192 | |
| 3193 | return err; |
| 3194 | } |
| 3195 | |
| 3196 | /** |
| 3197 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3198 | * @vsi: the VSI being configured |
| 3199 | **/ |
| 3200 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3201 | { |
| 3202 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3203 | struct i40e_hw *hw = &pf->hw; |
| 3204 | u16 vector; |
| 3205 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3206 | u32 qp; |
| 3207 | |
| 3208 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3209 | * and PFINT_LNKLSTn registers, e.g.: |
| 3210 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3211 | */ |
| 3212 | qp = vsi->base_queue; |
| 3213 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3214 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3215 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3216 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3217 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3218 | 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] | 3219 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3220 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3221 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3222 | 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] | 3223 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3224 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3225 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3226 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
| 3227 | INTRL_USEC_TO_REG(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3228 | |
| 3229 | /* Linked list for the queuepairs assigned to this vector */ |
| 3230 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3231 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3232 | u32 val; |
| 3233 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3234 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3235 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3236 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3237 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 3238 | (I40E_QUEUE_TYPE_TX |
| 3239 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 3240 | |
| 3241 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3242 | |
| 3243 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3244 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3245 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3246 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 3247 | (I40E_QUEUE_TYPE_RX |
| 3248 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3249 | |
| 3250 | /* Terminate the linked list */ |
| 3251 | if (q == (q_vector->num_ringpairs - 1)) |
| 3252 | val |= (I40E_QUEUE_END_OF_LIST |
| 3253 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3254 | |
| 3255 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3256 | qp++; |
| 3257 | } |
| 3258 | } |
| 3259 | |
| 3260 | i40e_flush(hw); |
| 3261 | } |
| 3262 | |
| 3263 | /** |
| 3264 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3265 | * @hw: ptr to the hardware info |
| 3266 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3267 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3268 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3269 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3270 | u32 val; |
| 3271 | |
| 3272 | /* clear things first */ |
| 3273 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3274 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3275 | |
| 3276 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3277 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3278 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3279 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3280 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3281 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3282 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3283 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3284 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3285 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3286 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3287 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3288 | if (pf->flags & I40E_FLAG_PTP) |
| 3289 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3290 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3291 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3292 | |
| 3293 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3294 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3295 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3296 | |
| 3297 | /* OTHER_ITR_IDX = 0 */ |
| 3298 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3299 | } |
| 3300 | |
| 3301 | /** |
| 3302 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3303 | * @vsi: the VSI being configured |
| 3304 | **/ |
| 3305 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3306 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3307 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3308 | struct i40e_pf *pf = vsi->back; |
| 3309 | struct i40e_hw *hw = &pf->hw; |
| 3310 | u32 val; |
| 3311 | |
| 3312 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3313 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3314 | 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] | 3315 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3316 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3317 | 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] | 3318 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3319 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3320 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3321 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3322 | |
| 3323 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3324 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3325 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3326 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3327 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3328 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3329 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3330 | |
| 3331 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3332 | |
| 3333 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3334 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3335 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3336 | |
| 3337 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3338 | i40e_flush(hw); |
| 3339 | } |
| 3340 | |
| 3341 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3342 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3343 | * @pf: board private structure |
| 3344 | **/ |
| 3345 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3346 | { |
| 3347 | struct i40e_hw *hw = &pf->hw; |
| 3348 | |
| 3349 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3350 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3351 | i40e_flush(hw); |
| 3352 | } |
| 3353 | |
| 3354 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3355 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3356 | * @pf: board private structure |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3357 | * @clearpba: true when all pending interrupt events should be cleared |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3358 | **/ |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3359 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3360 | { |
| 3361 | struct i40e_hw *hw = &pf->hw; |
| 3362 | u32 val; |
| 3363 | |
| 3364 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3365 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3366 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3367 | |
| 3368 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3369 | i40e_flush(hw); |
| 3370 | } |
| 3371 | |
| 3372 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3373 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3374 | * @irq: interrupt number |
| 3375 | * @data: pointer to a q_vector |
| 3376 | **/ |
| 3377 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3378 | { |
| 3379 | struct i40e_q_vector *q_vector = data; |
| 3380 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3381 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3382 | return IRQ_HANDLED; |
| 3383 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3384 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3385 | |
| 3386 | return IRQ_HANDLED; |
| 3387 | } |
| 3388 | |
| 3389 | /** |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3390 | * i40e_irq_affinity_notify - Callback for affinity changes |
| 3391 | * @notify: context as to what irq was changed |
| 3392 | * @mask: the new affinity mask |
| 3393 | * |
| 3394 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3395 | * so that we may register to receive changes to the irq affinity masks. |
| 3396 | **/ |
| 3397 | static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify, |
| 3398 | const cpumask_t *mask) |
| 3399 | { |
| 3400 | struct i40e_q_vector *q_vector = |
| 3401 | container_of(notify, struct i40e_q_vector, affinity_notify); |
| 3402 | |
| 3403 | q_vector->affinity_mask = *mask; |
| 3404 | } |
| 3405 | |
| 3406 | /** |
| 3407 | * i40e_irq_affinity_release - Callback for affinity notifier release |
| 3408 | * @ref: internal core kernel usage |
| 3409 | * |
| 3410 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3411 | * to inform the current notification subscriber that they will no longer |
| 3412 | * receive notifications. |
| 3413 | **/ |
| 3414 | static void i40e_irq_affinity_release(struct kref *ref) {} |
| 3415 | |
| 3416 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3417 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3418 | * @vsi: the VSI being configured |
| 3419 | * @basename: name for the vector |
| 3420 | * |
| 3421 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3422 | **/ |
| 3423 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3424 | { |
| 3425 | int q_vectors = vsi->num_q_vectors; |
| 3426 | struct i40e_pf *pf = vsi->back; |
| 3427 | int base = vsi->base_vector; |
| 3428 | int rx_int_idx = 0; |
| 3429 | int tx_int_idx = 0; |
| 3430 | int vector, err; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3431 | int irq_num; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3432 | |
| 3433 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3434 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3435 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3436 | irq_num = pf->msix_entries[base + vector].vector; |
| 3437 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3438 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3439 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3440 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3441 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3442 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3443 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3444 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3445 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3446 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3447 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3448 | } else { |
| 3449 | /* skip this unused q_vector */ |
| 3450 | continue; |
| 3451 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3452 | err = request_irq(irq_num, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3453 | vsi->irq_handler, |
| 3454 | 0, |
| 3455 | q_vector->name, |
| 3456 | q_vector); |
| 3457 | if (err) { |
| 3458 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3459 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3460 | goto free_queue_irqs; |
| 3461 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3462 | |
| 3463 | /* register for affinity change notifications */ |
| 3464 | q_vector->affinity_notify.notify = i40e_irq_affinity_notify; |
| 3465 | q_vector->affinity_notify.release = i40e_irq_affinity_release; |
| 3466 | irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3467 | /* assign the mask for this irq */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3468 | irq_set_affinity_hint(irq_num, &q_vector->affinity_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3469 | } |
| 3470 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3471 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3472 | return 0; |
| 3473 | |
| 3474 | free_queue_irqs: |
| 3475 | while (vector) { |
| 3476 | vector--; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3477 | irq_num = pf->msix_entries[base + vector].vector; |
| 3478 | irq_set_affinity_notifier(irq_num, NULL); |
| 3479 | irq_set_affinity_hint(irq_num, NULL); |
| 3480 | free_irq(irq_num, &vsi->q_vectors[vector]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3481 | } |
| 3482 | return err; |
| 3483 | } |
| 3484 | |
| 3485 | /** |
| 3486 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3487 | * @vsi: the VSI being un-configured |
| 3488 | **/ |
| 3489 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3490 | { |
| 3491 | struct i40e_pf *pf = vsi->back; |
| 3492 | struct i40e_hw *hw = &pf->hw; |
| 3493 | int base = vsi->base_vector; |
| 3494 | int i; |
| 3495 | |
| 3496 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3497 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3498 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3499 | } |
| 3500 | |
| 3501 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3502 | for (i = vsi->base_vector; |
| 3503 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3504 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3505 | |
| 3506 | i40e_flush(hw); |
| 3507 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3508 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3509 | } else { |
| 3510 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3511 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3512 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3513 | i40e_flush(hw); |
| 3514 | synchronize_irq(pf->pdev->irq); |
| 3515 | } |
| 3516 | } |
| 3517 | |
| 3518 | /** |
| 3519 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3520 | * @vsi: the VSI being configured |
| 3521 | **/ |
| 3522 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3523 | { |
| 3524 | struct i40e_pf *pf = vsi->back; |
| 3525 | int i; |
| 3526 | |
| 3527 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3528 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3529 | i40e_irq_dynamic_enable(vsi, i); |
| 3530 | } else { |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3531 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3532 | } |
| 3533 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3534 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3535 | return 0; |
| 3536 | } |
| 3537 | |
| 3538 | /** |
| 3539 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3540 | * @pf: board private structure |
| 3541 | **/ |
| 3542 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3543 | { |
| 3544 | /* Disable ICR 0 */ |
| 3545 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3546 | i40e_flush(&pf->hw); |
| 3547 | } |
| 3548 | |
| 3549 | /** |
| 3550 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3551 | * @irq: interrupt number |
| 3552 | * @data: pointer to a q_vector |
| 3553 | * |
| 3554 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3555 | * with both queue and non-queue interrupts. This is also used in |
| 3556 | * MSIX mode to handle the non-queue interrupts. |
| 3557 | **/ |
| 3558 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3559 | { |
| 3560 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3561 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3562 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3563 | u32 icr0, icr0_remaining; |
| 3564 | u32 val, ena_mask; |
| 3565 | |
| 3566 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3567 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3568 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3569 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3570 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3571 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3572 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3573 | /* if interrupt but no bits showing, must be SWINT */ |
| 3574 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3575 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3576 | pf->sw_int_count++; |
| 3577 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3578 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 3579 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
| 3580 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3581 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3582 | dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
| 3583 | } |
| 3584 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3585 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3586 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3587 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3588 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3589 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3590 | /* We do not have a way to disarm Queue causes while leaving |
| 3591 | * interrupt enabled for all other causes, ideally |
| 3592 | * interrupt should be disabled while we are in NAPI but |
| 3593 | * this is not a performance path and napi_schedule() |
| 3594 | * can deal with rescheduling. |
| 3595 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3596 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3597 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3601 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3602 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3603 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3604 | } |
| 3605 | |
| 3606 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3607 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3608 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3609 | } |
| 3610 | |
| 3611 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3612 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3613 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3614 | } |
| 3615 | |
| 3616 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3617 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3618 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3619 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3620 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3621 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3622 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3623 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3624 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3625 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3626 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3627 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3628 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3629 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3630 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3631 | } |
| 3632 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3633 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3634 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3635 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3636 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3637 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3638 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3639 | } |
| 3640 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3641 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3642 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3643 | |
| 3644 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3645 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3646 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3647 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3648 | } |
| 3649 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3650 | /* If a critical error is pending we have no choice but to reset the |
| 3651 | * device. |
| 3652 | * Report and mask out any remaining unexpected interrupts. |
| 3653 | */ |
| 3654 | icr0_remaining = icr0 & ena_mask; |
| 3655 | if (icr0_remaining) { |
| 3656 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3657 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3658 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3659 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3660 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3661 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3662 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3663 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3664 | } |
| 3665 | ena_mask &= ~icr0_remaining; |
| 3666 | } |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3667 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3668 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3669 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3670 | /* re-enable interrupt causes */ |
| 3671 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3672 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3673 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3674 | i40e_irq_dynamic_enable_icr0(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3675 | } |
| 3676 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3677 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3681 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3682 | * @tx_ring: tx ring to clean |
| 3683 | * @budget: how many cleans we're allowed |
| 3684 | * |
| 3685 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3686 | **/ |
| 3687 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3688 | { |
| 3689 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3690 | u16 i = tx_ring->next_to_clean; |
| 3691 | struct i40e_tx_buffer *tx_buf; |
| 3692 | struct i40e_tx_desc *tx_desc; |
| 3693 | |
| 3694 | tx_buf = &tx_ring->tx_bi[i]; |
| 3695 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3696 | i -= tx_ring->count; |
| 3697 | |
| 3698 | do { |
| 3699 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3700 | |
| 3701 | /* if next_to_watch is not set then there is no work pending */ |
| 3702 | if (!eop_desc) |
| 3703 | break; |
| 3704 | |
| 3705 | /* prevent any other reads prior to eop_desc */ |
| 3706 | read_barrier_depends(); |
| 3707 | |
| 3708 | /* if the descriptor isn't done, no work yet to do */ |
| 3709 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3710 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3711 | break; |
| 3712 | |
| 3713 | /* clear next_to_watch to prevent false hangs */ |
| 3714 | tx_buf->next_to_watch = NULL; |
| 3715 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3716 | tx_desc->buffer_addr = 0; |
| 3717 | tx_desc->cmd_type_offset_bsz = 0; |
| 3718 | /* move past filter desc */ |
| 3719 | tx_buf++; |
| 3720 | tx_desc++; |
| 3721 | i++; |
| 3722 | if (unlikely(!i)) { |
| 3723 | i -= tx_ring->count; |
| 3724 | tx_buf = tx_ring->tx_bi; |
| 3725 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3726 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3727 | /* unmap skb header data */ |
| 3728 | dma_unmap_single(tx_ring->dev, |
| 3729 | dma_unmap_addr(tx_buf, dma), |
| 3730 | dma_unmap_len(tx_buf, len), |
| 3731 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3732 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3733 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3734 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3735 | tx_buf->raw_buf = NULL; |
| 3736 | tx_buf->tx_flags = 0; |
| 3737 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3738 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3739 | tx_desc->buffer_addr = 0; |
| 3740 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3741 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3742 | /* 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] | 3743 | tx_buf++; |
| 3744 | tx_desc++; |
| 3745 | i++; |
| 3746 | if (unlikely(!i)) { |
| 3747 | i -= tx_ring->count; |
| 3748 | tx_buf = tx_ring->tx_bi; |
| 3749 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3750 | } |
| 3751 | |
| 3752 | /* update budget accounting */ |
| 3753 | budget--; |
| 3754 | } while (likely(budget)); |
| 3755 | |
| 3756 | i += tx_ring->count; |
| 3757 | tx_ring->next_to_clean = i; |
| 3758 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3759 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3760 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3761 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3762 | return budget > 0; |
| 3763 | } |
| 3764 | |
| 3765 | /** |
| 3766 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3767 | * @irq: interrupt number |
| 3768 | * @data: pointer to a q_vector |
| 3769 | **/ |
| 3770 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3771 | { |
| 3772 | struct i40e_q_vector *q_vector = data; |
| 3773 | struct i40e_vsi *vsi; |
| 3774 | |
| 3775 | if (!q_vector->tx.ring) |
| 3776 | return IRQ_HANDLED; |
| 3777 | |
| 3778 | vsi = q_vector->tx.ring->vsi; |
| 3779 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3780 | |
| 3781 | return IRQ_HANDLED; |
| 3782 | } |
| 3783 | |
| 3784 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3785 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3786 | * @vsi: the VSI being configured |
| 3787 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3788 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3789 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3790 | 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] | 3791 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3792 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3793 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3794 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3795 | |
| 3796 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3797 | tx_ring->next = q_vector->tx.ring; |
| 3798 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3799 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3800 | |
| 3801 | rx_ring->q_vector = q_vector; |
| 3802 | rx_ring->next = q_vector->rx.ring; |
| 3803 | q_vector->rx.ring = rx_ring; |
| 3804 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3805 | } |
| 3806 | |
| 3807 | /** |
| 3808 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3809 | * @vsi: the VSI being configured |
| 3810 | * |
| 3811 | * This function maps descriptor rings to the queue-specific vectors |
| 3812 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3813 | * one vector per queue pair, but on a constrained vector budget, we |
| 3814 | * group the queue pairs as "efficiently" as possible. |
| 3815 | **/ |
| 3816 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3817 | { |
| 3818 | int qp_remaining = vsi->num_queue_pairs; |
| 3819 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3820 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3821 | int v_start = 0; |
| 3822 | int qp_idx = 0; |
| 3823 | |
| 3824 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3825 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3826 | * It is also important to go through all the vectors available to be |
| 3827 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3828 | * are cleared. This is especially important when decreasing the |
| 3829 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3830 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3831 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3832 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3833 | |
| 3834 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3835 | |
| 3836 | q_vector->num_ringpairs = num_ringpairs; |
| 3837 | |
| 3838 | q_vector->rx.count = 0; |
| 3839 | q_vector->tx.count = 0; |
| 3840 | q_vector->rx.ring = NULL; |
| 3841 | q_vector->tx.ring = NULL; |
| 3842 | |
| 3843 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3844 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3845 | qp_idx++; |
| 3846 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3847 | } |
| 3848 | } |
| 3849 | } |
| 3850 | |
| 3851 | /** |
| 3852 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3853 | * @vsi: the VSI being configured |
| 3854 | * @basename: name for the vector |
| 3855 | **/ |
| 3856 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3857 | { |
| 3858 | struct i40e_pf *pf = vsi->back; |
| 3859 | int err; |
| 3860 | |
| 3861 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3862 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3863 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3864 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3865 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3866 | else |
| 3867 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3868 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3869 | |
| 3870 | if (err) |
| 3871 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3872 | |
| 3873 | return err; |
| 3874 | } |
| 3875 | |
| 3876 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3877 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3878 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3879 | * @netdev: network interface device structure |
| 3880 | * |
| 3881 | * This is used by netconsole to send skbs without having to re-enable |
| 3882 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3883 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3884 | #ifdef I40E_FCOE |
| 3885 | void i40e_netpoll(struct net_device *netdev) |
| 3886 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3887 | static void i40e_netpoll(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3888 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3889 | { |
| 3890 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3891 | struct i40e_vsi *vsi = np->vsi; |
| 3892 | struct i40e_pf *pf = vsi->back; |
| 3893 | int i; |
| 3894 | |
| 3895 | /* if interface is down do nothing */ |
| 3896 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3897 | return; |
| 3898 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3899 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3900 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3901 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3902 | } else { |
| 3903 | i40e_intr(pf->pdev->irq, netdev); |
| 3904 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3905 | } |
| 3906 | #endif |
| 3907 | |
| 3908 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3909 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3910 | * @pf: the PF being configured |
| 3911 | * @pf_q: the PF queue |
| 3912 | * @enable: enable or disable state of the queue |
| 3913 | * |
| 3914 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3915 | * enabled or disabled state. |
| 3916 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3917 | * multiple retries; else will return 0 in case of success. |
| 3918 | **/ |
| 3919 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3920 | { |
| 3921 | int i; |
| 3922 | u32 tx_reg; |
| 3923 | |
| 3924 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3925 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3926 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3927 | break; |
| 3928 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3929 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3930 | } |
| 3931 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3932 | return -ETIMEDOUT; |
| 3933 | |
| 3934 | return 0; |
| 3935 | } |
| 3936 | |
| 3937 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3938 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3939 | * @vsi: the VSI being configured |
| 3940 | * @enable: start or stop the rings |
| 3941 | **/ |
| 3942 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3943 | { |
| 3944 | struct i40e_pf *pf = vsi->back; |
| 3945 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3946 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3947 | u32 tx_reg; |
| 3948 | |
| 3949 | pf_q = vsi->base_queue; |
| 3950 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3951 | |
| 3952 | /* warn the TX unit of coming changes */ |
| 3953 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3954 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3955 | usleep_range(10, 20); |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3956 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3957 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3958 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3959 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3960 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3961 | break; |
| 3962 | usleep_range(1000, 2000); |
| 3963 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3964 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3965 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3966 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3967 | |
| 3968 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3969 | if (enable) { |
| 3970 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3971 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3972 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3973 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3974 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3975 | |
| 3976 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 3977 | /* No waiting for the Tx queue to disable */ |
| 3978 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3979 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3980 | |
| 3981 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3982 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 3983 | if (ret) { |
| 3984 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3985 | "VSI seid %d Tx ring %d %sable timeout\n", |
| 3986 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3987 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3988 | } |
| 3989 | } |
| 3990 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3991 | if (hw->revision_id == 0) |
| 3992 | mdelay(50); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3993 | return ret; |
| 3994 | } |
| 3995 | |
| 3996 | /** |
| 3997 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 3998 | * @pf: the PF being configured |
| 3999 | * @pf_q: the PF queue |
| 4000 | * @enable: enable or disable state of the queue |
| 4001 | * |
| 4002 | * This routine will wait for the given Rx queue of the PF to reach the |
| 4003 | * enabled or disabled state. |
| 4004 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 4005 | * multiple retries; else will return 0 in case of success. |
| 4006 | **/ |
| 4007 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 4008 | { |
| 4009 | int i; |
| 4010 | u32 rx_reg; |
| 4011 | |
| 4012 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 4013 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 4014 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 4015 | break; |
| 4016 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 4017 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4018 | } |
| 4019 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 4020 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 4021 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4022 | return 0; |
| 4023 | } |
| 4024 | |
| 4025 | /** |
| 4026 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 4027 | * @vsi: the VSI being configured |
| 4028 | * @enable: start or stop the rings |
| 4029 | **/ |
| 4030 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 4031 | { |
| 4032 | struct i40e_pf *pf = vsi->back; |
| 4033 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4034 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4035 | u32 rx_reg; |
| 4036 | |
| 4037 | pf_q = vsi->base_queue; |
| 4038 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4039 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4040 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4041 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 4042 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 4043 | break; |
| 4044 | usleep_range(1000, 2000); |
| 4045 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4046 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 4047 | /* Skip if the queue is already in the requested state */ |
| 4048 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 4049 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4050 | |
| 4051 | /* turn on/off the queue */ |
| 4052 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4053 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4054 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4055 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4056 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4057 | /* No waiting for the Tx queue to disable */ |
| 4058 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 4059 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4060 | |
| 4061 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4062 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 4063 | if (ret) { |
| 4064 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4065 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 4066 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4067 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4068 | } |
| 4069 | } |
| 4070 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4071 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4072 | } |
| 4073 | |
| 4074 | /** |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4075 | * i40e_vsi_start_rings - Start a VSI's rings |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4076 | * @vsi: the VSI being configured |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4077 | **/ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4078 | int i40e_vsi_start_rings(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4079 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 4080 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4081 | |
| 4082 | /* do rx first for enable and last for disable */ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4083 | ret = i40e_vsi_control_rx(vsi, true); |
| 4084 | if (ret) |
| 4085 | return ret; |
| 4086 | ret = i40e_vsi_control_tx(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4087 | |
| 4088 | return ret; |
| 4089 | } |
| 4090 | |
| 4091 | /** |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 4092 | * i40e_vsi_stop_rings - Stop a VSI's rings |
| 4093 | * @vsi: the VSI being configured |
| 4094 | **/ |
| 4095 | void i40e_vsi_stop_rings(struct i40e_vsi *vsi) |
| 4096 | { |
| 4097 | /* do rx first for enable and last for disable |
| 4098 | * Ignore return value, we need to shutdown whatever we can |
| 4099 | */ |
| 4100 | i40e_vsi_control_tx(vsi, false); |
| 4101 | i40e_vsi_control_rx(vsi, false); |
| 4102 | } |
| 4103 | |
| 4104 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4105 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 4106 | * @vsi: the VSI being configured |
| 4107 | **/ |
| 4108 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 4109 | { |
| 4110 | struct i40e_pf *pf = vsi->back; |
| 4111 | struct i40e_hw *hw = &pf->hw; |
| 4112 | int base = vsi->base_vector; |
| 4113 | u32 val, qp; |
| 4114 | int i; |
| 4115 | |
| 4116 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4117 | if (!vsi->q_vectors) |
| 4118 | return; |
| 4119 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 4120 | if (!vsi->irqs_ready) |
| 4121 | return; |
| 4122 | |
| 4123 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4124 | for (i = 0; i < vsi->num_q_vectors; i++) { |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4125 | int irq_num; |
| 4126 | u16 vector; |
| 4127 | |
| 4128 | vector = i + base; |
| 4129 | irq_num = pf->msix_entries[vector].vector; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4130 | |
| 4131 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 4132 | if (!vsi->q_vectors[i] || |
| 4133 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4134 | continue; |
| 4135 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4136 | /* clear the affinity notifier in the IRQ descriptor */ |
| 4137 | irq_set_affinity_notifier(irq_num, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4138 | /* clear the affinity_mask in the IRQ descriptor */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4139 | irq_set_affinity_hint(irq_num, NULL); |
| 4140 | synchronize_irq(irq_num); |
| 4141 | free_irq(irq_num, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4142 | |
| 4143 | /* Tear down the interrupt queue link list |
| 4144 | * |
| 4145 | * We know that they come in pairs and always |
| 4146 | * the Rx first, then the Tx. To clear the |
| 4147 | * link list, stick the EOL value into the |
| 4148 | * next_q field of the registers. |
| 4149 | */ |
| 4150 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4151 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4152 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4153 | val |= I40E_QUEUE_END_OF_LIST |
| 4154 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4155 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4156 | |
| 4157 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4158 | u32 next; |
| 4159 | |
| 4160 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4161 | |
| 4162 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4163 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4164 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4165 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4166 | |
| 4167 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4168 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4169 | |
| 4170 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4171 | |
| 4172 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4173 | |
| 4174 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4175 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4176 | |
| 4177 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4178 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4179 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4180 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4181 | |
| 4182 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4183 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4184 | |
| 4185 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4186 | qp = next; |
| 4187 | } |
| 4188 | } |
| 4189 | } else { |
| 4190 | free_irq(pf->pdev->irq, pf); |
| 4191 | |
| 4192 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4193 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4194 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4195 | val |= I40E_QUEUE_END_OF_LIST |
| 4196 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4197 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4198 | |
| 4199 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4200 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4201 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4202 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4203 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4204 | |
| 4205 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4206 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4207 | |
| 4208 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4209 | |
| 4210 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4211 | |
| 4212 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4213 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4214 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4215 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4216 | |
| 4217 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4218 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4219 | |
| 4220 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4221 | } |
| 4222 | } |
| 4223 | |
| 4224 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4225 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4226 | * @vsi: the VSI being configured |
| 4227 | * @v_idx: Index of vector to be freed |
| 4228 | * |
| 4229 | * This function frees the memory allocated to the q_vector. In addition if |
| 4230 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4231 | * to freeing the q_vector. |
| 4232 | **/ |
| 4233 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4234 | { |
| 4235 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4236 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4237 | |
| 4238 | if (!q_vector) |
| 4239 | return; |
| 4240 | |
| 4241 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4242 | i40e_for_each_ring(ring, q_vector->tx) |
| 4243 | ring->q_vector = NULL; |
| 4244 | |
| 4245 | i40e_for_each_ring(ring, q_vector->rx) |
| 4246 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4247 | |
| 4248 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4249 | if (vsi->netdev) |
| 4250 | netif_napi_del(&q_vector->napi); |
| 4251 | |
| 4252 | vsi->q_vectors[v_idx] = NULL; |
| 4253 | |
| 4254 | kfree_rcu(q_vector, rcu); |
| 4255 | } |
| 4256 | |
| 4257 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4258 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4259 | * @vsi: the VSI being un-configured |
| 4260 | * |
| 4261 | * This frees the memory allocated to the q_vectors and |
| 4262 | * deletes references to the NAPI struct. |
| 4263 | **/ |
| 4264 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4265 | { |
| 4266 | int v_idx; |
| 4267 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4268 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4269 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | /** |
| 4273 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4274 | * @pf: board private structure |
| 4275 | **/ |
| 4276 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4277 | { |
| 4278 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4279 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4280 | pci_disable_msix(pf->pdev); |
| 4281 | kfree(pf->msix_entries); |
| 4282 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4283 | kfree(pf->irq_pile); |
| 4284 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4285 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4286 | pci_disable_msi(pf->pdev); |
| 4287 | } |
| 4288 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4289 | } |
| 4290 | |
| 4291 | /** |
| 4292 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4293 | * @pf: board private structure |
| 4294 | * |
| 4295 | * We go through and clear interrupt specific resources and reset the structure |
| 4296 | * to pre-load conditions |
| 4297 | **/ |
| 4298 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4299 | { |
| 4300 | int i; |
| 4301 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4302 | i40e_stop_misc_vector(pf); |
Shannon Nelson | 6927839 | 2016-03-10 14:59:43 -0800 | [diff] [blame] | 4303 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4304 | synchronize_irq(pf->msix_entries[0].vector); |
| 4305 | free_irq(pf->msix_entries[0].vector, pf); |
| 4306 | } |
| 4307 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4308 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4309 | I40E_IWARP_IRQ_PILE_ID); |
| 4310 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4311 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4312 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4313 | if (pf->vsi[i]) |
| 4314 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4315 | i40e_reset_interrupt_capability(pf); |
| 4316 | } |
| 4317 | |
| 4318 | /** |
| 4319 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4320 | * @vsi: the VSI being configured |
| 4321 | **/ |
| 4322 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4323 | { |
| 4324 | int q_idx; |
| 4325 | |
| 4326 | if (!vsi->netdev) |
| 4327 | return; |
| 4328 | |
| 4329 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4330 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4331 | } |
| 4332 | |
| 4333 | /** |
| 4334 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4335 | * @vsi: the VSI being configured |
| 4336 | **/ |
| 4337 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4338 | { |
| 4339 | int q_idx; |
| 4340 | |
| 4341 | if (!vsi->netdev) |
| 4342 | return; |
| 4343 | |
| 4344 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4345 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4349 | * i40e_vsi_close - Shut down a VSI |
| 4350 | * @vsi: the vsi to be quelled |
| 4351 | **/ |
| 4352 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4353 | { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4354 | bool reset = false; |
| 4355 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4356 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4357 | i40e_down(vsi); |
| 4358 | i40e_vsi_free_irq(vsi); |
| 4359 | i40e_vsi_free_tx_resources(vsi); |
| 4360 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4361 | vsi->current_netdev_flags = 0; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4362 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4363 | reset = true; |
| 4364 | i40e_notify_client_of_netdev_close(vsi, reset); |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4365 | } |
| 4366 | |
| 4367 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4368 | * i40e_quiesce_vsi - Pause a given VSI |
| 4369 | * @vsi: the VSI being paused |
| 4370 | **/ |
| 4371 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4372 | { |
| 4373 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4374 | return; |
| 4375 | |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4376 | /* No need to disable FCoE VSI when Tx suspended */ |
| 4377 | if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) && |
| 4378 | vsi->type == I40E_VSI_FCOE) { |
| 4379 | dev_dbg(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4380 | "VSI seid %d skipping FCoE VSI disable\n", vsi->seid); |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4381 | return; |
| 4382 | } |
| 4383 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4384 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4385 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4386 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4387 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4388 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | /** |
| 4392 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4393 | * @vsi: the VSI being resumed |
| 4394 | **/ |
| 4395 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4396 | { |
| 4397 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 4398 | return; |
| 4399 | |
| 4400 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4401 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4402 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4403 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4404 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | /** |
| 4408 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4409 | * @pf: the PF |
| 4410 | **/ |
| 4411 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4412 | { |
| 4413 | int v; |
| 4414 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4415 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4416 | if (pf->vsi[v]) |
| 4417 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4418 | } |
| 4419 | } |
| 4420 | |
| 4421 | /** |
| 4422 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4423 | * @pf: the PF |
| 4424 | **/ |
| 4425 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4426 | { |
| 4427 | int v; |
| 4428 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4429 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4430 | if (pf->vsi[v]) |
| 4431 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4432 | } |
| 4433 | } |
| 4434 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4435 | #ifdef CONFIG_I40E_DCB |
| 4436 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4437 | * 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] | 4438 | * @vsi: the VSI being configured |
| 4439 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4440 | * This function waits for the given VSI's queues to be disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4441 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4442 | static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4443 | { |
| 4444 | struct i40e_pf *pf = vsi->back; |
| 4445 | int i, pf_q, ret; |
| 4446 | |
| 4447 | pf_q = vsi->base_queue; |
| 4448 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4449 | /* Check and wait for the disable status of the queue */ |
| 4450 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4451 | if (ret) { |
| 4452 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4453 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4454 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4455 | return ret; |
| 4456 | } |
| 4457 | } |
| 4458 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4459 | pf_q = vsi->base_queue; |
| 4460 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4461 | /* Check and wait for the disable status of the queue */ |
| 4462 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4463 | if (ret) { |
| 4464 | dev_info(&pf->pdev->dev, |
| 4465 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4466 | vsi->seid, pf_q); |
| 4467 | return ret; |
| 4468 | } |
| 4469 | } |
| 4470 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4471 | return 0; |
| 4472 | } |
| 4473 | |
| 4474 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4475 | * 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] | 4476 | * @pf: the PF |
| 4477 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4478 | * 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] | 4479 | * VSIs that are managed by this PF. |
| 4480 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4481 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4482 | { |
| 4483 | int v, ret = 0; |
| 4484 | |
| 4485 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4486 | /* No need to wait for FCoE VSI queues */ |
| 4487 | if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4488 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4489 | if (ret) |
| 4490 | break; |
| 4491 | } |
| 4492 | } |
| 4493 | |
| 4494 | return ret; |
| 4495 | } |
| 4496 | |
| 4497 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4498 | |
| 4499 | /** |
| 4500 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4501 | * @q_idx: TX queue number |
| 4502 | * @vsi: Pointer to VSI struct |
| 4503 | * |
| 4504 | * This function checks specified queue for given VSI. Detects hung condition. |
| 4505 | * Sets hung bit since it is two step process. Before next run of service task |
| 4506 | * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not, |
| 4507 | * hung condition remain unchanged and during subsequent run, this function |
| 4508 | * issues SW interrupt to recover from hung condition. |
| 4509 | **/ |
| 4510 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4511 | { |
| 4512 | struct i40e_ring *tx_ring = NULL; |
| 4513 | struct i40e_pf *pf; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4514 | u32 head, val, tx_pending_hw; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4515 | int i; |
| 4516 | |
| 4517 | pf = vsi->back; |
| 4518 | |
| 4519 | /* now that we have an index, find the tx_ring struct */ |
| 4520 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4521 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4522 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4523 | tx_ring = vsi->tx_rings[i]; |
| 4524 | break; |
| 4525 | } |
| 4526 | } |
| 4527 | } |
| 4528 | |
| 4529 | if (!tx_ring) |
| 4530 | return; |
| 4531 | |
| 4532 | /* Read interrupt register */ |
| 4533 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4534 | val = rd32(&pf->hw, |
| 4535 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4536 | tx_ring->vsi->base_vector - 1)); |
| 4537 | else |
| 4538 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4539 | |
| 4540 | head = i40e_get_head(tx_ring); |
| 4541 | |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4542 | tx_pending_hw = i40e_get_tx_pending(tx_ring, false); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4543 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4544 | /* HW is done executing descriptors, updated HEAD write back, |
| 4545 | * but SW hasn't processed those descriptors. If interrupt is |
| 4546 | * not generated from this point ON, it could result into |
| 4547 | * dev_watchdog detecting timeout on those netdev_queue, |
| 4548 | * hence proactively trigger SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4549 | */ |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4550 | if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4551 | /* NAPI Poll didn't run and clear since it was set */ |
| 4552 | if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4553 | &tx_ring->q_vector->hung_detected)) { |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4554 | 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", |
| 4555 | vsi->seid, q_idx, tx_pending_hw, |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4556 | tx_ring->next_to_clean, head, |
| 4557 | tx_ring->next_to_use, |
| 4558 | readl(tx_ring->tail)); |
| 4559 | netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n", |
| 4560 | vsi->seid, q_idx, val); |
| 4561 | i40e_force_wb(vsi, tx_ring->q_vector); |
| 4562 | } else { |
| 4563 | /* First Chance - detected possible hung */ |
| 4564 | set_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4565 | &tx_ring->q_vector->hung_detected); |
| 4566 | } |
| 4567 | } |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4568 | |
| 4569 | /* This is the case where we have interrupts missing, |
| 4570 | * so the tx_pending in HW will most likely be 0, but we |
| 4571 | * will have tx_pending in SW since the WB happened but the |
| 4572 | * interrupt got lost. |
| 4573 | */ |
| 4574 | if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) && |
| 4575 | (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
| 4576 | if (napi_reschedule(&tx_ring->q_vector->napi)) |
| 4577 | tx_ring->tx_stats.tx_lost_interrupt++; |
| 4578 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4579 | } |
| 4580 | |
| 4581 | /** |
| 4582 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4583 | * @pf: pointer to PF struct |
| 4584 | * |
| 4585 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4586 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4587 | * SW interrupt. |
| 4588 | **/ |
| 4589 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4590 | { |
| 4591 | struct net_device *netdev; |
| 4592 | struct i40e_vsi *vsi; |
| 4593 | int i; |
| 4594 | |
| 4595 | /* Only for LAN VSI */ |
| 4596 | vsi = pf->vsi[pf->lan_vsi]; |
| 4597 | |
| 4598 | if (!vsi) |
| 4599 | return; |
| 4600 | |
| 4601 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
| 4602 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 4603 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4604 | return; |
| 4605 | |
| 4606 | /* Make sure type is MAIN VSI */ |
| 4607 | if (vsi->type != I40E_VSI_MAIN) |
| 4608 | return; |
| 4609 | |
| 4610 | netdev = vsi->netdev; |
| 4611 | if (!netdev) |
| 4612 | return; |
| 4613 | |
| 4614 | /* Bail out if netif_carrier is not OK */ |
| 4615 | if (!netif_carrier_ok(netdev)) |
| 4616 | return; |
| 4617 | |
| 4618 | /* Go thru' TX queues for netdev */ |
| 4619 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4620 | struct netdev_queue *q; |
| 4621 | |
| 4622 | q = netdev_get_tx_queue(netdev, i); |
| 4623 | if (q) |
| 4624 | i40e_detect_recover_hung_queue(i, vsi); |
| 4625 | } |
| 4626 | } |
| 4627 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4628 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4629 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4630 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4631 | * |
| 4632 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4633 | * and LAN TC. |
| 4634 | **/ |
| 4635 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4636 | { |
| 4637 | struct i40e_dcb_app_priority_table app; |
| 4638 | struct i40e_hw *hw = &pf->hw; |
| 4639 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4640 | u8 tc, i; |
| 4641 | /* Get the iSCSI APP TLV */ |
| 4642 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4643 | |
| 4644 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4645 | app = dcbcfg->app[i]; |
| 4646 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4647 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4648 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4649 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4650 | break; |
| 4651 | } |
| 4652 | } |
| 4653 | |
| 4654 | return enabled_tc; |
| 4655 | } |
| 4656 | |
| 4657 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4658 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4659 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4660 | * |
| 4661 | * Return the number of TCs from given DCBx configuration |
| 4662 | **/ |
| 4663 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4664 | { |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4665 | int i, tc_unused = 0; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4666 | u8 num_tc = 0; |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4667 | u8 ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4668 | |
| 4669 | /* Scan the ETS Config Priority Table to find |
| 4670 | * traffic class enabled for a given priority |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4671 | * and create a bitmask of enabled TCs |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4672 | */ |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4673 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) |
| 4674 | num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]); |
| 4675 | |
| 4676 | /* Now scan the bitmask to check for |
| 4677 | * contiguous TCs starting with TC0 |
| 4678 | */ |
| 4679 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4680 | if (num_tc & BIT(i)) { |
| 4681 | if (!tc_unused) { |
| 4682 | ret++; |
| 4683 | } else { |
| 4684 | pr_err("Non-contiguous TC - Disabling DCB\n"); |
| 4685 | return 1; |
| 4686 | } |
| 4687 | } else { |
| 4688 | tc_unused = 1; |
| 4689 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4690 | } |
| 4691 | |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4692 | /* There is always at least TC0 */ |
| 4693 | if (!ret) |
| 4694 | ret = 1; |
| 4695 | |
| 4696 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | /** |
| 4700 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4701 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4702 | * |
| 4703 | * Query the current DCB configuration and return the number of |
| 4704 | * traffic classes enabled from the given DCBX config |
| 4705 | **/ |
| 4706 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4707 | { |
| 4708 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4709 | u8 enabled_tc = 1; |
| 4710 | u8 i; |
| 4711 | |
| 4712 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4713 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4714 | |
| 4715 | return enabled_tc; |
| 4716 | } |
| 4717 | |
| 4718 | /** |
| 4719 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4720 | * @pf: PF being queried |
| 4721 | * |
| 4722 | * Return number of traffic classes enabled for the given PF |
| 4723 | **/ |
| 4724 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4725 | { |
| 4726 | struct i40e_hw *hw = &pf->hw; |
Dave Ertman | 52a08ca | 2016-07-27 12:02:34 -0700 | [diff] [blame] | 4727 | u8 i, enabled_tc = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4728 | u8 num_tc = 0; |
| 4729 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4730 | |
| 4731 | /* If DCB is not enabled then always in single TC */ |
| 4732 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4733 | return 1; |
| 4734 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4735 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4736 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4737 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4738 | |
| 4739 | /* MFP mode return count of enabled TCs for this PF */ |
| 4740 | if (pf->hw.func_caps.iscsi) |
| 4741 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4742 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4743 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4744 | |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4745 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4746 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4747 | num_tc++; |
| 4748 | } |
| 4749 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4753 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4754 | * @pf: PF being queried |
| 4755 | * |
| 4756 | * Return a bitmap for enabled traffic classes for this PF. |
| 4757 | **/ |
| 4758 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4759 | { |
| 4760 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4761 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4762 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4763 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4764 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4765 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4766 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4767 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4768 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4769 | if (pf->hw.func_caps.iscsi) |
| 4770 | return i40e_get_iscsi_tc_map(pf); |
| 4771 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4772 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4773 | } |
| 4774 | |
| 4775 | /** |
| 4776 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4777 | * @vsi: the VSI being queried |
| 4778 | * |
| 4779 | * Returns 0 on success, negative value on failure |
| 4780 | **/ |
| 4781 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4782 | { |
| 4783 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4784 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4785 | struct i40e_pf *pf = vsi->back; |
| 4786 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4787 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4788 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4789 | int i; |
| 4790 | |
| 4791 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4792 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4793 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4794 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4795 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4796 | i40e_stat_str(&pf->hw, ret), |
| 4797 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4798 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4802 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4803 | NULL); |
| 4804 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4805 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4806 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4807 | i40e_stat_str(&pf->hw, ret), |
| 4808 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4809 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4810 | } |
| 4811 | |
| 4812 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4813 | dev_info(&pf->pdev->dev, |
| 4814 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4815 | bw_config.tc_valid_bits, |
| 4816 | bw_ets_config.tc_valid_bits); |
| 4817 | /* Still continuing */ |
| 4818 | } |
| 4819 | |
| 4820 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4821 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4822 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4823 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4824 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4825 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4826 | vsi->bw_ets_limit_credits[i] = |
| 4827 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4828 | /* 3 bits out of 4 for each TC */ |
| 4829 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4830 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4831 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4832 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4833 | } |
| 4834 | |
| 4835 | /** |
| 4836 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4837 | * @vsi: the VSI being configured |
| 4838 | * @enabled_tc: TC bitmap |
| 4839 | * @bw_credits: BW shared credits per TC |
| 4840 | * |
| 4841 | * Returns 0 on success, negative value on failure |
| 4842 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4843 | 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] | 4844 | u8 *bw_share) |
| 4845 | { |
| 4846 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4847 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4848 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4849 | |
| 4850 | bw_data.tc_valid_bits = enabled_tc; |
| 4851 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4852 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4853 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4854 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4855 | NULL); |
| 4856 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4857 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4858 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4859 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4860 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4861 | } |
| 4862 | |
| 4863 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4864 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4865 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4866 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4867 | } |
| 4868 | |
| 4869 | /** |
| 4870 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4871 | * @vsi: the VSI being configured |
| 4872 | * @enabled_tc: TC map to be enabled |
| 4873 | * |
| 4874 | **/ |
| 4875 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4876 | { |
| 4877 | struct net_device *netdev = vsi->netdev; |
| 4878 | struct i40e_pf *pf = vsi->back; |
| 4879 | struct i40e_hw *hw = &pf->hw; |
| 4880 | u8 netdev_tc = 0; |
| 4881 | int i; |
| 4882 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4883 | |
| 4884 | if (!netdev) |
| 4885 | return; |
| 4886 | |
| 4887 | if (!enabled_tc) { |
| 4888 | netdev_reset_tc(netdev); |
| 4889 | return; |
| 4890 | } |
| 4891 | |
| 4892 | /* Set up actual enabled TCs on the VSI */ |
| 4893 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 4894 | return; |
| 4895 | |
| 4896 | /* set per TC queues for the VSI */ |
| 4897 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4898 | /* Only set TC queues for enabled tcs |
| 4899 | * |
| 4900 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 4901 | * enabled_tc bitmap would be 0x00001001; the driver |
| 4902 | * will set the numtc for netdev as 2 that will be |
| 4903 | * referenced by the netdev layer as TC 0 and 1. |
| 4904 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4905 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4906 | netdev_set_tc_queue(netdev, |
| 4907 | vsi->tc_config.tc_info[i].netdev_tc, |
| 4908 | vsi->tc_config.tc_info[i].qcount, |
| 4909 | vsi->tc_config.tc_info[i].qoffset); |
| 4910 | } |
| 4911 | |
| 4912 | /* Assign UP2TC map for the VSI */ |
| 4913 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4914 | /* Get the actual TC# for the UP */ |
| 4915 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4916 | /* Get the mapped netdev TC# for the UP */ |
| 4917 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 4918 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 4919 | } |
| 4920 | } |
| 4921 | |
| 4922 | /** |
| 4923 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 4924 | * @vsi: the VSI being configured |
| 4925 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 4926 | **/ |
| 4927 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 4928 | struct i40e_vsi_context *ctxt) |
| 4929 | { |
| 4930 | /* copy just the sections touched not the entire info |
| 4931 | * since not all sections are valid as returned by |
| 4932 | * update vsi params |
| 4933 | */ |
| 4934 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 4935 | memcpy(&vsi->info.queue_mapping, |
| 4936 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 4937 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 4938 | sizeof(vsi->info.tc_mapping)); |
| 4939 | } |
| 4940 | |
| 4941 | /** |
| 4942 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 4943 | * @vsi: VSI to be configured |
| 4944 | * @enabled_tc: TC bitmap |
| 4945 | * |
| 4946 | * This configures a particular VSI for TCs that are mapped to the |
| 4947 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 4948 | * VSIs to configure TC for a particular VSI. |
| 4949 | * |
| 4950 | * NOTE: |
| 4951 | * It is expected that the VSI queues have been quisced before calling |
| 4952 | * this function. |
| 4953 | **/ |
| 4954 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4955 | { |
| 4956 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 4957 | struct i40e_vsi_context ctxt; |
| 4958 | int ret = 0; |
| 4959 | int i; |
| 4960 | |
| 4961 | /* Check if enabled_tc is same as existing or new TCs */ |
| 4962 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 4963 | return ret; |
| 4964 | |
| 4965 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 4966 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4967 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4968 | bw_share[i] = 1; |
| 4969 | } |
| 4970 | |
| 4971 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 4972 | if (ret) { |
| 4973 | dev_info(&vsi->back->pdev->dev, |
| 4974 | "Failed configuring TC map %d for VSI %d\n", |
| 4975 | enabled_tc, vsi->seid); |
| 4976 | goto out; |
| 4977 | } |
| 4978 | |
| 4979 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 4980 | ctxt.seid = vsi->seid; |
| 4981 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 4982 | ctxt.vf_num = 0; |
| 4983 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 4984 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4985 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 4986 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4987 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 4988 | ctxt.info.valid_sections |= |
| 4989 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 4990 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 4991 | } |
| 4992 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4993 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 4994 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 4995 | if (ret) { |
| 4996 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4997 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 4998 | i40e_stat_str(&vsi->back->hw, ret), |
| 4999 | i40e_aq_str(&vsi->back->hw, |
| 5000 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5001 | goto out; |
| 5002 | } |
| 5003 | /* update the local VSI info with updated queue map */ |
| 5004 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 5005 | vsi->info.valid_sections = 0; |
| 5006 | |
| 5007 | /* Update current VSI BW information */ |
| 5008 | ret = i40e_vsi_get_bw_info(vsi); |
| 5009 | if (ret) { |
| 5010 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5011 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 5012 | i40e_stat_str(&vsi->back->hw, ret), |
| 5013 | i40e_aq_str(&vsi->back->hw, |
| 5014 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5015 | goto out; |
| 5016 | } |
| 5017 | |
| 5018 | /* Update the netdev TC setup */ |
| 5019 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 5020 | out: |
| 5021 | return ret; |
| 5022 | } |
| 5023 | |
| 5024 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5025 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 5026 | * @veb: given VEB |
| 5027 | * @enabled_tc: TC bitmap |
| 5028 | * |
| 5029 | * Configures given TC bitmap for VEB (switching) element |
| 5030 | **/ |
| 5031 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 5032 | { |
| 5033 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 5034 | struct i40e_pf *pf = veb->pf; |
| 5035 | int ret = 0; |
| 5036 | int i; |
| 5037 | |
| 5038 | /* No TCs or already enabled TCs just return */ |
| 5039 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 5040 | return ret; |
| 5041 | |
| 5042 | bw_data.tc_valid_bits = enabled_tc; |
| 5043 | /* bw_data.absolute_credits is not set (relative) */ |
| 5044 | |
| 5045 | /* Enable ETS TCs with equal BW Share for now */ |
| 5046 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5047 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5048 | bw_data.tc_bw_share_credits[i] = 1; |
| 5049 | } |
| 5050 | |
| 5051 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 5052 | &bw_data, NULL); |
| 5053 | if (ret) { |
| 5054 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5055 | "VEB bw config failed, err %s aq_err %s\n", |
| 5056 | i40e_stat_str(&pf->hw, ret), |
| 5057 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5058 | goto out; |
| 5059 | } |
| 5060 | |
| 5061 | /* Update the BW information */ |
| 5062 | ret = i40e_veb_get_bw_info(veb); |
| 5063 | if (ret) { |
| 5064 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5065 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 5066 | i40e_stat_str(&pf->hw, ret), |
| 5067 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5068 | } |
| 5069 | |
| 5070 | out: |
| 5071 | return ret; |
| 5072 | } |
| 5073 | |
| 5074 | #ifdef CONFIG_I40E_DCB |
| 5075 | /** |
| 5076 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 5077 | * @pf: PF struct |
| 5078 | * |
| 5079 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 5080 | * the caller would've quiesce all the VSIs before calling |
| 5081 | * this function |
| 5082 | **/ |
| 5083 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 5084 | { |
| 5085 | u8 tc_map = 0; |
| 5086 | int ret; |
| 5087 | u8 v; |
| 5088 | |
| 5089 | /* Enable the TCs available on PF to all VEBs */ |
| 5090 | tc_map = i40e_pf_get_tc_map(pf); |
| 5091 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 5092 | if (!pf->veb[v]) |
| 5093 | continue; |
| 5094 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 5095 | if (ret) { |
| 5096 | dev_info(&pf->pdev->dev, |
| 5097 | "Failed configuring TC for VEB seid=%d\n", |
| 5098 | pf->veb[v]->seid); |
| 5099 | /* Will try to configure as many components */ |
| 5100 | } |
| 5101 | } |
| 5102 | |
| 5103 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5104 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5105 | if (!pf->vsi[v]) |
| 5106 | continue; |
| 5107 | |
| 5108 | /* - Enable all TCs for the LAN VSI |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5109 | #ifdef I40E_FCOE |
| 5110 | * - For FCoE VSI only enable the TC configured |
| 5111 | * as per the APP TLV |
| 5112 | #endif |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5113 | * - For all others keep them at TC0 for now |
| 5114 | */ |
| 5115 | if (v == pf->lan_vsi) |
| 5116 | tc_map = i40e_pf_get_tc_map(pf); |
| 5117 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5118 | tc_map = I40E_DEFAULT_TRAFFIC_CLASS; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5119 | #ifdef I40E_FCOE |
| 5120 | if (pf->vsi[v]->type == I40E_VSI_FCOE) |
| 5121 | tc_map = i40e_get_fcoe_tc_map(pf); |
| 5122 | #endif /* #ifdef I40E_FCOE */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5123 | |
| 5124 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 5125 | if (ret) { |
| 5126 | dev_info(&pf->pdev->dev, |
| 5127 | "Failed configuring TC for VSI seid=%d\n", |
| 5128 | pf->vsi[v]->seid); |
| 5129 | /* Will try to configure as many components */ |
| 5130 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 5131 | /* Re-configure VSI vectors based on updated TC map */ |
| 5132 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5133 | if (pf->vsi[v]->netdev) |
| 5134 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 5135 | } |
| 5136 | } |
| 5137 | } |
| 5138 | |
| 5139 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5140 | * i40e_resume_port_tx - Resume port Tx |
| 5141 | * @pf: PF struct |
| 5142 | * |
| 5143 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 5144 | * resume. |
| 5145 | **/ |
| 5146 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 5147 | { |
| 5148 | struct i40e_hw *hw = &pf->hw; |
| 5149 | int ret; |
| 5150 | |
| 5151 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 5152 | if (ret) { |
| 5153 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5154 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 5155 | i40e_stat_str(&pf->hw, ret), |
| 5156 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5157 | /* Schedule PF reset to recover */ |
| 5158 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5159 | i40e_service_event_schedule(pf); |
| 5160 | } |
| 5161 | |
| 5162 | return ret; |
| 5163 | } |
| 5164 | |
| 5165 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5166 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 5167 | * @pf: PF being configured |
| 5168 | * |
| 5169 | * Query the current DCB configuration and cache it |
| 5170 | * in the hardware structure |
| 5171 | **/ |
| 5172 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 5173 | { |
| 5174 | struct i40e_hw *hw = &pf->hw; |
| 5175 | int err = 0; |
| 5176 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5177 | /* 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] | 5178 | if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5179 | goto out; |
| 5180 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5181 | /* Get the initial DCB configuration */ |
| 5182 | err = i40e_init_dcb(hw); |
| 5183 | if (!err) { |
| 5184 | /* Device/Function is not DCBX capable */ |
| 5185 | if ((!hw->func_caps.dcb) || |
| 5186 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5187 | dev_info(&pf->pdev->dev, |
| 5188 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 5189 | |
| 5190 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 5191 | goto out; |
| 5192 | |
| 5193 | } else { |
| 5194 | /* When status is not DISABLED then DCBX in FW */ |
| 5195 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5196 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5197 | |
| 5198 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5199 | /* Enable DCB tagging only when more than one TC |
| 5200 | * or explicitly disable if only one TC |
| 5201 | */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5202 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5203 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5204 | else |
| 5205 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5206 | dev_dbg(&pf->pdev->dev, |
| 5207 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5208 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5209 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5210 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5211 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5212 | i40e_stat_str(&pf->hw, err), |
| 5213 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5214 | } |
| 5215 | |
| 5216 | out: |
| 5217 | return err; |
| 5218 | } |
| 5219 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5220 | #define SPEED_SIZE 14 |
| 5221 | #define FC_SIZE 8 |
| 5222 | /** |
| 5223 | * i40e_print_link_message - print link up or down |
| 5224 | * @vsi: the VSI for which link needs a message |
| 5225 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5226 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5227 | { |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5228 | char *speed = "Unknown"; |
| 5229 | char *fc = "Unknown"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5230 | |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5231 | if (vsi->current_isup == isup) |
| 5232 | return; |
| 5233 | vsi->current_isup = isup; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5234 | if (!isup) { |
| 5235 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5236 | return; |
| 5237 | } |
| 5238 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5239 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5240 | * least 10GB |
| 5241 | */ |
| 5242 | if (vsi->back->hw.func_caps.npar_enable && |
| 5243 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5244 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5245 | netdev_warn(vsi->netdev, |
| 5246 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5247 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5248 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5249 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5250 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5251 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5252 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5253 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5254 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5255 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5256 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5257 | break; |
| 5258 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5259 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5260 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5261 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5262 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5263 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5264 | default: |
| 5265 | break; |
| 5266 | } |
| 5267 | |
| 5268 | switch (vsi->back->hw.fc.current_mode) { |
| 5269 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5270 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5271 | break; |
| 5272 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5273 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5274 | break; |
| 5275 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5276 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5277 | break; |
| 5278 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5279 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5280 | break; |
| 5281 | } |
| 5282 | |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5283 | 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] | 5284 | speed, fc); |
| 5285 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5286 | |
| 5287 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5288 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5289 | * @vsi: the VSI being configured |
| 5290 | **/ |
| 5291 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5292 | { |
| 5293 | struct i40e_pf *pf = vsi->back; |
| 5294 | int err; |
| 5295 | |
| 5296 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5297 | i40e_vsi_configure_msix(vsi); |
| 5298 | else |
| 5299 | i40e_configure_msi_and_legacy(vsi); |
| 5300 | |
| 5301 | /* start rings */ |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 5302 | err = i40e_vsi_start_rings(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5303 | if (err) |
| 5304 | return err; |
| 5305 | |
| 5306 | clear_bit(__I40E_DOWN, &vsi->state); |
| 5307 | i40e_napi_enable_all(vsi); |
| 5308 | i40e_vsi_enable_irq(vsi); |
| 5309 | |
| 5310 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5311 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5312 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5313 | netif_tx_start_all_queues(vsi->netdev); |
| 5314 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5315 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5316 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5317 | /* need to check for qualified module here*/ |
| 5318 | if ((pf->hw.phy.link_info.link_info & |
| 5319 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5320 | (!(pf->hw.phy.link_info.an_info & |
| 5321 | I40E_AQ_QUALIFIED_MODULE))) |
| 5322 | netdev_err(vsi->netdev, |
| 5323 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5324 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5325 | |
| 5326 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5327 | if (vsi->type == I40E_VSI_FDIR) { |
| 5328 | /* reset fd counters */ |
| 5329 | pf->fd_add_err = pf->fd_atr_cnt = 0; |
| 5330 | if (pf->fd_tcp_rule > 0) { |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 5331 | pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5332 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5333 | 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] | 5334 | pf->fd_tcp_rule = 0; |
| 5335 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5336 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5337 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5338 | |
| 5339 | /* On the next run of the service_task, notify any clients of the new |
| 5340 | * opened netdev |
| 5341 | */ |
| 5342 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5343 | i40e_service_event_schedule(pf); |
| 5344 | |
| 5345 | return 0; |
| 5346 | } |
| 5347 | |
| 5348 | /** |
| 5349 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5350 | * @vsi: the VSI being configured |
| 5351 | * |
| 5352 | * Rebuild the ring structs after some configuration |
| 5353 | * has changed, e.g. MTU size. |
| 5354 | **/ |
| 5355 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5356 | { |
| 5357 | struct i40e_pf *pf = vsi->back; |
| 5358 | |
| 5359 | WARN_ON(in_interrupt()); |
| 5360 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5361 | usleep_range(1000, 2000); |
| 5362 | i40e_down(vsi); |
| 5363 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5364 | i40e_up(vsi); |
| 5365 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 5366 | } |
| 5367 | |
| 5368 | /** |
| 5369 | * i40e_up - Bring the connection back up after being down |
| 5370 | * @vsi: the VSI being configured |
| 5371 | **/ |
| 5372 | int i40e_up(struct i40e_vsi *vsi) |
| 5373 | { |
| 5374 | int err; |
| 5375 | |
| 5376 | err = i40e_vsi_configure(vsi); |
| 5377 | if (!err) |
| 5378 | err = i40e_up_complete(vsi); |
| 5379 | |
| 5380 | return err; |
| 5381 | } |
| 5382 | |
| 5383 | /** |
| 5384 | * i40e_down - Shutdown the connection processing |
| 5385 | * @vsi: the VSI being stopped |
| 5386 | **/ |
| 5387 | void i40e_down(struct i40e_vsi *vsi) |
| 5388 | { |
| 5389 | int i; |
| 5390 | |
| 5391 | /* It is assumed that the caller of this function |
| 5392 | * sets the vsi->state __I40E_DOWN bit. |
| 5393 | */ |
| 5394 | if (vsi->netdev) { |
| 5395 | netif_carrier_off(vsi->netdev); |
| 5396 | netif_tx_disable(vsi->netdev); |
| 5397 | } |
| 5398 | i40e_vsi_disable_irq(vsi); |
Filip Sadowski | 3aa7b74 | 2016-10-11 15:26:58 -0700 | [diff] [blame] | 5399 | i40e_vsi_stop_rings(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5400 | i40e_napi_disable_all(vsi); |
| 5401 | |
| 5402 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5403 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 5404 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5405 | } |
Catherine Sullivan | f980d44 | 2016-05-16 10:26:34 -0700 | [diff] [blame] | 5406 | |
| 5407 | i40e_notify_client_of_netdev_close(vsi, false); |
| 5408 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5409 | } |
| 5410 | |
| 5411 | /** |
| 5412 | * i40e_setup_tc - configure multiple traffic classes |
| 5413 | * @netdev: net device to configure |
| 5414 | * @tc: number of traffic classes to enable |
| 5415 | **/ |
| 5416 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5417 | { |
| 5418 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5419 | struct i40e_vsi *vsi = np->vsi; |
| 5420 | struct i40e_pf *pf = vsi->back; |
| 5421 | u8 enabled_tc = 0; |
| 5422 | int ret = -EINVAL; |
| 5423 | int i; |
| 5424 | |
| 5425 | /* Check if DCB enabled to continue */ |
| 5426 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5427 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5428 | goto exit; |
| 5429 | } |
| 5430 | |
| 5431 | /* Check if MFP enabled */ |
| 5432 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5433 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5434 | goto exit; |
| 5435 | } |
| 5436 | |
| 5437 | /* Check whether tc count is within enabled limit */ |
| 5438 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5439 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5440 | goto exit; |
| 5441 | } |
| 5442 | |
| 5443 | /* Generate TC map for number of tc requested */ |
| 5444 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5445 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5446 | |
| 5447 | /* Requesting same TC configuration as already enabled */ |
| 5448 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5449 | return 0; |
| 5450 | |
| 5451 | /* Quiesce VSI queues */ |
| 5452 | i40e_quiesce_vsi(vsi); |
| 5453 | |
| 5454 | /* Configure VSI for enabled TCs */ |
| 5455 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5456 | if (ret) { |
| 5457 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5458 | vsi->seid); |
| 5459 | goto exit; |
| 5460 | } |
| 5461 | |
| 5462 | /* Unquiesce VSI */ |
| 5463 | i40e_unquiesce_vsi(vsi); |
| 5464 | |
| 5465 | exit: |
| 5466 | return ret; |
| 5467 | } |
| 5468 | |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5469 | #ifdef I40E_FCOE |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5470 | int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5471 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5472 | #else |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5473 | static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5474 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5475 | #endif |
| 5476 | { |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5477 | if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5478 | return -EINVAL; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5479 | return i40e_setup_tc(netdev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5480 | } |
| 5481 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5482 | /** |
| 5483 | * i40e_open - Called when a network interface is made active |
| 5484 | * @netdev: network interface device structure |
| 5485 | * |
| 5486 | * The open entry point is called when a network interface is made |
| 5487 | * active by the system (IFF_UP). At this point all resources needed |
| 5488 | * for transmit and receive operations are allocated, the interrupt |
| 5489 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5490 | * enabled, and the stack is notified that the interface is ready. |
| 5491 | * |
| 5492 | * Returns 0 on success, negative value on failure |
| 5493 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5494 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5495 | { |
| 5496 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5497 | struct i40e_vsi *vsi = np->vsi; |
| 5498 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5499 | int err; |
| 5500 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5501 | /* disallow open during test or if eeprom is broken */ |
| 5502 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 5503 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5504 | return -EBUSY; |
| 5505 | |
| 5506 | netif_carrier_off(netdev); |
| 5507 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5508 | err = i40e_vsi_open(vsi); |
| 5509 | if (err) |
| 5510 | return err; |
| 5511 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5512 | /* configure global TSO hardware offload settings */ |
| 5513 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5514 | TCP_FLAG_FIN) >> 16); |
| 5515 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5516 | TCP_FLAG_FIN | |
| 5517 | TCP_FLAG_CWR) >> 16); |
| 5518 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5519 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 5520 | udp_tunnel_get_rx_info(netdev); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5521 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5522 | return 0; |
| 5523 | } |
| 5524 | |
| 5525 | /** |
| 5526 | * i40e_vsi_open - |
| 5527 | * @vsi: the VSI to open |
| 5528 | * |
| 5529 | * Finish initialization of the VSI. |
| 5530 | * |
| 5531 | * Returns 0 on success, negative value on failure |
| 5532 | **/ |
| 5533 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5534 | { |
| 5535 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5536 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5537 | int err; |
| 5538 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5539 | /* allocate descriptors */ |
| 5540 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5541 | if (err) |
| 5542 | goto err_setup_tx; |
| 5543 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5544 | if (err) |
| 5545 | goto err_setup_rx; |
| 5546 | |
| 5547 | err = i40e_vsi_configure(vsi); |
| 5548 | if (err) |
| 5549 | goto err_setup_rx; |
| 5550 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5551 | if (vsi->netdev) { |
| 5552 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5553 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5554 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5555 | if (err) |
| 5556 | goto err_setup_rx; |
| 5557 | |
| 5558 | /* Notify the stack of the actual queue counts. */ |
| 5559 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5560 | vsi->num_queue_pairs); |
| 5561 | if (err) |
| 5562 | goto err_set_queues; |
| 5563 | |
| 5564 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5565 | vsi->num_queue_pairs); |
| 5566 | if (err) |
| 5567 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5568 | |
| 5569 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5570 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5571 | dev_driver_string(&pf->pdev->dev), |
| 5572 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5573 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5574 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5575 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5576 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5577 | goto err_setup_rx; |
| 5578 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5579 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5580 | err = i40e_up_complete(vsi); |
| 5581 | if (err) |
| 5582 | goto err_up_complete; |
| 5583 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5584 | return 0; |
| 5585 | |
| 5586 | err_up_complete: |
| 5587 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5588 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5589 | i40e_vsi_free_irq(vsi); |
| 5590 | err_setup_rx: |
| 5591 | i40e_vsi_free_rx_resources(vsi); |
| 5592 | err_setup_tx: |
| 5593 | i40e_vsi_free_tx_resources(vsi); |
| 5594 | if (vsi == pf->vsi[pf->lan_vsi]) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5595 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5596 | |
| 5597 | return err; |
| 5598 | } |
| 5599 | |
| 5600 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5601 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5602 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5603 | * |
| 5604 | * This function destroys the hlist where all the Flow Director |
| 5605 | * filters were saved. |
| 5606 | **/ |
| 5607 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5608 | { |
| 5609 | struct i40e_fdir_filter *filter; |
| 5610 | struct hlist_node *node2; |
| 5611 | |
| 5612 | hlist_for_each_entry_safe(filter, node2, |
| 5613 | &pf->fdir_filter_list, fdir_node) { |
| 5614 | hlist_del(&filter->fdir_node); |
| 5615 | kfree(filter); |
| 5616 | } |
| 5617 | pf->fdir_pf_active_filters = 0; |
| 5618 | } |
| 5619 | |
| 5620 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5621 | * i40e_close - Disables a network interface |
| 5622 | * @netdev: network interface device structure |
| 5623 | * |
| 5624 | * The close entry point is called when an interface is de-activated |
| 5625 | * by the OS. The hardware is still under the driver's control, but |
| 5626 | * this netdev interface is disabled. |
| 5627 | * |
| 5628 | * Returns 0, this is not allowed to fail |
| 5629 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5630 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5631 | { |
| 5632 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5633 | struct i40e_vsi *vsi = np->vsi; |
| 5634 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5635 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5636 | |
| 5637 | return 0; |
| 5638 | } |
| 5639 | |
| 5640 | /** |
| 5641 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5642 | * @pf: board private structure |
| 5643 | * @reset_flags: which reset is requested |
| 5644 | * |
| 5645 | * The essential difference in resets is that the PF Reset |
| 5646 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5647 | * firmware, and doesn't bother the other PFs on the chip. |
| 5648 | **/ |
| 5649 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5650 | { |
| 5651 | u32 val; |
| 5652 | |
| 5653 | WARN_ON(in_interrupt()); |
| 5654 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5655 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5656 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5657 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5658 | |
| 5659 | /* Request a Global Reset |
| 5660 | * |
| 5661 | * This will start the chip's countdown to the actual full |
| 5662 | * chip reset event, and a warning interrupt to be sent |
| 5663 | * to all PFs, including the requestor. Our handler |
| 5664 | * for the warning interrupt will deal with the shutdown |
| 5665 | * and recovery of the switch setup. |
| 5666 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5667 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5668 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5669 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5670 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5671 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5672 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5673 | |
| 5674 | /* Request a Core Reset |
| 5675 | * |
| 5676 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5677 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5678 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5679 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5680 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5681 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5682 | i40e_flush(&pf->hw); |
| 5683 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5684 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5685 | |
| 5686 | /* Request a PF Reset |
| 5687 | * |
| 5688 | * Resets only the PF-specific registers |
| 5689 | * |
| 5690 | * This goes directly to the tear-down and rebuild of |
| 5691 | * the switch, since we need to do all the recovery as |
| 5692 | * for the Core Reset. |
| 5693 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5694 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5695 | i40e_handle_reset_warning(pf); |
| 5696 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5697 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5698 | int v; |
| 5699 | |
| 5700 | /* Find the VSI(s) that requested a re-init */ |
| 5701 | dev_info(&pf->pdev->dev, |
| 5702 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5703 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5704 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5705 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5706 | if (vsi != NULL && |
| 5707 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5708 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5709 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5710 | } |
| 5711 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5712 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5713 | int v; |
| 5714 | |
| 5715 | /* Find the VSI(s) that needs to be brought down */ |
| 5716 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5717 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5718 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5719 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5720 | if (vsi != NULL && |
| 5721 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5722 | set_bit(__I40E_DOWN, &vsi->state); |
| 5723 | i40e_down(vsi); |
| 5724 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5725 | } |
| 5726 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5727 | } else { |
| 5728 | dev_info(&pf->pdev->dev, |
| 5729 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5730 | } |
| 5731 | } |
| 5732 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5733 | #ifdef CONFIG_I40E_DCB |
| 5734 | /** |
| 5735 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5736 | * @pf: board private structure |
| 5737 | * @old_cfg: current DCB config |
| 5738 | * @new_cfg: new DCB config |
| 5739 | **/ |
| 5740 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5741 | struct i40e_dcbx_config *old_cfg, |
| 5742 | struct i40e_dcbx_config *new_cfg) |
| 5743 | { |
| 5744 | bool need_reconfig = false; |
| 5745 | |
| 5746 | /* Check if ETS configuration has changed */ |
| 5747 | if (memcmp(&new_cfg->etscfg, |
| 5748 | &old_cfg->etscfg, |
| 5749 | sizeof(new_cfg->etscfg))) { |
| 5750 | /* If Priority Table has changed reconfig is needed */ |
| 5751 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5752 | &old_cfg->etscfg.prioritytable, |
| 5753 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5754 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5755 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5756 | } |
| 5757 | |
| 5758 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5759 | &old_cfg->etscfg.tcbwtable, |
| 5760 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5761 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5762 | |
| 5763 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5764 | &old_cfg->etscfg.tsatable, |
| 5765 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5766 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5767 | } |
| 5768 | |
| 5769 | /* Check if PFC configuration has changed */ |
| 5770 | if (memcmp(&new_cfg->pfc, |
| 5771 | &old_cfg->pfc, |
| 5772 | sizeof(new_cfg->pfc))) { |
| 5773 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5774 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5775 | } |
| 5776 | |
| 5777 | /* Check if APP Table has changed */ |
| 5778 | if (memcmp(&new_cfg->app, |
| 5779 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5780 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5781 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5782 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5783 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5784 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5785 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5786 | return need_reconfig; |
| 5787 | } |
| 5788 | |
| 5789 | /** |
| 5790 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5791 | * @pf: board private structure |
| 5792 | * @e: event info posted on ARQ |
| 5793 | **/ |
| 5794 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5795 | struct i40e_arq_event_info *e) |
| 5796 | { |
| 5797 | struct i40e_aqc_lldp_get_mib *mib = |
| 5798 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5799 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5800 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5801 | bool need_reconfig = false; |
| 5802 | int ret = 0; |
| 5803 | u8 type; |
| 5804 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5805 | /* Not DCB capable or capability disabled */ |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5806 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5807 | return ret; |
| 5808 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5809 | /* Ignore if event is not for Nearest Bridge */ |
| 5810 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5811 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5812 | 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] | 5813 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5814 | return ret; |
| 5815 | |
| 5816 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5817 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5818 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5819 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5820 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5821 | /* Update the remote cached instance and return */ |
| 5822 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5823 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5824 | &hw->remote_dcbx_config); |
| 5825 | goto exit; |
| 5826 | } |
| 5827 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5828 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5829 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5830 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5831 | /* Reset the old DCBx configuration data */ |
| 5832 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5833 | /* Get updated DCBX data from firmware */ |
| 5834 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5835 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5836 | dev_info(&pf->pdev->dev, |
| 5837 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 5838 | i40e_stat_str(&pf->hw, ret), |
| 5839 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5840 | goto exit; |
| 5841 | } |
| 5842 | |
| 5843 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5844 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5845 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5846 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5847 | goto exit; |
| 5848 | } |
| 5849 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5850 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5851 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5852 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5853 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5854 | |
| 5855 | if (!need_reconfig) |
| 5856 | goto exit; |
| 5857 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5858 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5859 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5860 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5861 | else |
| 5862 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5863 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5864 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5865 | /* Reconfiguration needed quiesce all VSIs */ |
| 5866 | i40e_pf_quiesce_all_vsi(pf); |
| 5867 | |
| 5868 | /* Changes in configuration update VEB/VSI */ |
| 5869 | i40e_dcb_reconfigure(pf); |
| 5870 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5871 | ret = i40e_resume_port_tx(pf); |
| 5872 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5873 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5874 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5875 | if (ret) |
| 5876 | goto exit; |
| 5877 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 5878 | /* Wait for the PF's queues to be disabled */ |
| 5879 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5880 | if (ret) { |
| 5881 | /* Schedule PF reset to recover */ |
| 5882 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5883 | i40e_service_event_schedule(pf); |
| 5884 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5885 | i40e_pf_unquiesce_all_vsi(pf); |
Neerav Parikh | 85a1aab | 2016-06-07 09:14:55 -0700 | [diff] [blame] | 5886 | /* Notify the client for the DCB changes */ |
| 5887 | i40e_notify_client_of_l2_param_changes(pf->vsi[pf->lan_vsi]); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5888 | } |
| 5889 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5890 | exit: |
| 5891 | return ret; |
| 5892 | } |
| 5893 | #endif /* CONFIG_I40E_DCB */ |
| 5894 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5895 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5896 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 5897 | * @pf: board private structure |
| 5898 | * @reset_flags: which reset is requested |
| 5899 | * |
| 5900 | **/ |
| 5901 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 5902 | { |
| 5903 | rtnl_lock(); |
| 5904 | i40e_do_reset(pf, reset_flags); |
| 5905 | rtnl_unlock(); |
| 5906 | } |
| 5907 | |
| 5908 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5909 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 5910 | * @pf: board private structure |
| 5911 | * @e: event info posted on ARQ |
| 5912 | * |
| 5913 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 5914 | * and VF queues |
| 5915 | **/ |
| 5916 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 5917 | struct i40e_arq_event_info *e) |
| 5918 | { |
| 5919 | struct i40e_aqc_lan_overflow *data = |
| 5920 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 5921 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 5922 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 5923 | struct i40e_hw *hw = &pf->hw; |
| 5924 | struct i40e_vf *vf; |
| 5925 | u16 vf_id; |
| 5926 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5927 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 5928 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5929 | |
| 5930 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 5931 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 5932 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 5933 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 5934 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 5935 | vf_id -= hw->func_caps.vf_base_id; |
| 5936 | vf = &pf->vf[vf_id]; |
| 5937 | i40e_vc_notify_vf_reset(vf); |
| 5938 | /* Allow VF to process pending reset notification */ |
| 5939 | msleep(20); |
| 5940 | i40e_reset_vf(vf, false); |
| 5941 | } |
| 5942 | } |
| 5943 | |
| 5944 | /** |
| 5945 | * i40e_service_event_complete - Finish up the service event |
| 5946 | * @pf: board private structure |
| 5947 | **/ |
| 5948 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 5949 | { |
Shannon Nelson | b875f99 | 2015-10-21 19:47:03 -0400 | [diff] [blame] | 5950 | WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5951 | |
| 5952 | /* flush memory to make sure state is correct before next watchog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5953 | smp_mb__before_atomic(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5954 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 5955 | } |
| 5956 | |
| 5957 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5958 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 5959 | * @pf: board private structure |
| 5960 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5961 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5962 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5963 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5964 | |
| 5965 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5966 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 5967 | return fcnt_prog; |
| 5968 | } |
| 5969 | |
| 5970 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5971 | * 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] | 5972 | * @pf: board private structure |
| 5973 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5974 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5975 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5976 | u32 val, fcnt_prog; |
| 5977 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5978 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5979 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 5980 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 5981 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 5982 | return fcnt_prog; |
| 5983 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5984 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5985 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5986 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 5987 | * @pf: board private structure |
| 5988 | **/ |
| 5989 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 5990 | { |
| 5991 | u32 val, fcnt_prog; |
| 5992 | |
| 5993 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 5994 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 5995 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 5996 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 5997 | return fcnt_prog; |
| 5998 | } |
| 5999 | |
| 6000 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6001 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 6002 | * @pf: board private structure |
| 6003 | **/ |
| 6004 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 6005 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6006 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6007 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6008 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6009 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6010 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 6011 | return; |
| 6012 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6013 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 6014 | * to re-enable |
| 6015 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6016 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 6017 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6018 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 6019 | (pf->fd_add_err == 0) || |
| 6020 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6021 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 6022 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 6023 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 6024 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6025 | 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] | 6026 | } |
| 6027 | } |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6028 | |
| 6029 | /* Wait for some more space to be available to turn on ATR. We also |
| 6030 | * must check that no existing ntuple rules for TCP are in effect |
| 6031 | */ |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6032 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 6033 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6034 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 6035 | (pf->fd_tcp_rule == 0)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6036 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 6037 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 6038 | 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] | 6039 | } |
| 6040 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 6041 | |
| 6042 | /* if hw had a problem adding a filter, delete it */ |
| 6043 | if (pf->fd_inv > 0) { |
| 6044 | hlist_for_each_entry_safe(filter, node, |
| 6045 | &pf->fdir_filter_list, fdir_node) { |
| 6046 | if (filter->fd_id == pf->fd_inv) { |
| 6047 | hlist_del(&filter->fdir_node); |
| 6048 | kfree(filter); |
| 6049 | pf->fdir_pf_active_filters--; |
| 6050 | } |
| 6051 | } |
| 6052 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6053 | } |
| 6054 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6055 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6056 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6057 | /** |
| 6058 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 6059 | * @pf: board private structure |
| 6060 | **/ |
| 6061 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 6062 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6063 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6064 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6065 | bool disable_atr = false; |
| 6066 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6067 | int reg; |
| 6068 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6069 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 6070 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 6071 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6072 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6073 | /* If the flush is happening too quick and we have mostly SB rules we |
| 6074 | * should not re-enable ATR for some time. |
| 6075 | */ |
| 6076 | min_flush_time = pf->fd_flush_timestamp + |
| 6077 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 6078 | 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] | 6079 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6080 | if (!(time_after(jiffies, min_flush_time)) && |
| 6081 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 6082 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6083 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 6084 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6085 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6086 | |
| 6087 | pf->fd_flush_timestamp = jiffies; |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 6088 | pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6089 | /* flush all filters */ |
| 6090 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 6091 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 6092 | i40e_flush(&pf->hw); |
| 6093 | pf->fd_flush_cnt++; |
| 6094 | pf->fd_add_err = 0; |
| 6095 | do { |
| 6096 | /* Check FD flush status every 5-6msec */ |
| 6097 | usleep_range(5000, 6000); |
| 6098 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 6099 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 6100 | break; |
| 6101 | } while (flush_wait_retry--); |
| 6102 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 6103 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 6104 | } else { |
| 6105 | /* replay sideband filters */ |
| 6106 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
| 6107 | if (!disable_atr) |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 6108 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6109 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
| 6110 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6111 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 6112 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6113 | } |
| 6114 | |
| 6115 | /** |
| 6116 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 6117 | * @pf: board private structure |
| 6118 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6119 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6120 | { |
| 6121 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 6122 | } |
| 6123 | |
| 6124 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 6125 | * being applied really fast; before we see the first |
| 6126 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 6127 | * reacting will make sure we don't cause flush too often. |
| 6128 | */ |
| 6129 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 6130 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6131 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6132 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 6133 | * @pf: board private structure |
| 6134 | **/ |
| 6135 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 6136 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6137 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6138 | /* if interface is down do nothing */ |
| 6139 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 6140 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6141 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6142 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6143 | i40e_fdir_flush_and_replay(pf); |
| 6144 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6145 | i40e_fdir_check_and_reenable(pf); |
| 6146 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6147 | } |
| 6148 | |
| 6149 | /** |
| 6150 | * i40e_vsi_link_event - notify VSI of a link event |
| 6151 | * @vsi: vsi to be notified |
| 6152 | * @link_up: link up or down |
| 6153 | **/ |
| 6154 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 6155 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 6156 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6157 | return; |
| 6158 | |
| 6159 | switch (vsi->type) { |
| 6160 | case I40E_VSI_MAIN: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6161 | #ifdef I40E_FCOE |
| 6162 | case I40E_VSI_FCOE: |
| 6163 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6164 | if (!vsi->netdev || !vsi->netdev_registered) |
| 6165 | break; |
| 6166 | |
| 6167 | if (link_up) { |
| 6168 | netif_carrier_on(vsi->netdev); |
| 6169 | netif_tx_wake_all_queues(vsi->netdev); |
| 6170 | } else { |
| 6171 | netif_carrier_off(vsi->netdev); |
| 6172 | netif_tx_stop_all_queues(vsi->netdev); |
| 6173 | } |
| 6174 | break; |
| 6175 | |
| 6176 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6177 | case I40E_VSI_VMDQ2: |
| 6178 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6179 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6180 | case I40E_VSI_MIRROR: |
| 6181 | default: |
| 6182 | /* there is no notification for other VSIs */ |
| 6183 | break; |
| 6184 | } |
| 6185 | } |
| 6186 | |
| 6187 | /** |
| 6188 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6189 | * @veb: veb to be notified |
| 6190 | * @link_up: link up or down |
| 6191 | **/ |
| 6192 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6193 | { |
| 6194 | struct i40e_pf *pf; |
| 6195 | int i; |
| 6196 | |
| 6197 | if (!veb || !veb->pf) |
| 6198 | return; |
| 6199 | pf = veb->pf; |
| 6200 | |
| 6201 | /* depth first... */ |
| 6202 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6203 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6204 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6205 | |
| 6206 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6207 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6208 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6209 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6210 | } |
| 6211 | |
| 6212 | /** |
| 6213 | * i40e_link_event - Update netif_carrier status |
| 6214 | * @pf: board private structure |
| 6215 | **/ |
| 6216 | static void i40e_link_event(struct i40e_pf *pf) |
| 6217 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6218 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6219 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6220 | i40e_status status; |
| 6221 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6222 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6223 | /* save off old link status information */ |
| 6224 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6225 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6226 | /* set this to force the get_link_status call to refresh state */ |
| 6227 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6228 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6229 | 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] | 6230 | |
| 6231 | status = i40e_get_link_status(&pf->hw, &new_link); |
| 6232 | if (status) { |
| 6233 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6234 | status); |
| 6235 | return; |
| 6236 | } |
| 6237 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6238 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6239 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6240 | |
| 6241 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6242 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6243 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 6244 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6245 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6246 | |
| 6247 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 6248 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6249 | |
| 6250 | /* Notify the base of the switch tree connected to |
| 6251 | * the link. Floating VEBs are not notified. |
| 6252 | */ |
| 6253 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6254 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6255 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6256 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6257 | |
| 6258 | if (pf->vf) |
| 6259 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6260 | |
| 6261 | if (pf->flags & I40E_FLAG_PTP) |
| 6262 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6263 | } |
| 6264 | |
| 6265 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6266 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6267 | * @pf: board private structure |
| 6268 | **/ |
| 6269 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6270 | { |
| 6271 | int i; |
| 6272 | |
| 6273 | /* if interface is down do nothing */ |
| 6274 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 6275 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6276 | return; |
| 6277 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6278 | /* make sure we don't do these things too often */ |
| 6279 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6280 | pf->service_timer_period))) |
| 6281 | return; |
| 6282 | pf->service_timer_previous = jiffies; |
| 6283 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6284 | if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) |
| 6285 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6286 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6287 | /* Update the stats for active netdevs so the network stack |
| 6288 | * can look at updated numbers whenever it cares to |
| 6289 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6290 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6291 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6292 | i40e_update_stats(pf->vsi[i]); |
| 6293 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6294 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6295 | /* Update the stats for the active switching components */ |
| 6296 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6297 | if (pf->veb[i]) |
| 6298 | i40e_update_veb_stats(pf->veb[i]); |
| 6299 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6300 | |
| 6301 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6302 | } |
| 6303 | |
| 6304 | /** |
| 6305 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6306 | * @pf: board private structure |
| 6307 | **/ |
| 6308 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6309 | { |
| 6310 | u32 reset_flags = 0; |
| 6311 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6312 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6313 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6314 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6315 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 6316 | } |
| 6317 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6318 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6319 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6320 | } |
| 6321 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6322 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6323 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 6324 | } |
| 6325 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6326 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6327 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 6328 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6329 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6330 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6331 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 6332 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6333 | |
| 6334 | /* If there's a recovery already waiting, it takes |
| 6335 | * precedence before starting a new reset sequence. |
| 6336 | */ |
| 6337 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 6338 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6339 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6340 | } |
| 6341 | |
| 6342 | /* If we're already down or resetting, just bail */ |
| 6343 | if (reset_flags && |
| 6344 | !test_bit(__I40E_DOWN, &pf->state) && |
| 6345 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6346 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6347 | |
| 6348 | unlock: |
| 6349 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6350 | } |
| 6351 | |
| 6352 | /** |
| 6353 | * i40e_handle_link_event - Handle link event |
| 6354 | * @pf: board private structure |
| 6355 | * @e: event info posted on ARQ |
| 6356 | **/ |
| 6357 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6358 | struct i40e_arq_event_info *e) |
| 6359 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6360 | struct i40e_aqc_get_link_status *status = |
| 6361 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6362 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6363 | /* Do a new status request to re-enable LSE reporting |
| 6364 | * and load new status information into the hw struct |
| 6365 | * This completely ignores any state information |
| 6366 | * in the ARQ event info, instead choosing to always |
| 6367 | * issue the AQ update link status command. |
| 6368 | */ |
| 6369 | i40e_link_event(pf); |
| 6370 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6371 | /* check for unqualified module, if link is down */ |
| 6372 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6373 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6374 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6375 | dev_err(&pf->pdev->dev, |
| 6376 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6377 | } |
| 6378 | |
| 6379 | /** |
| 6380 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6381 | * @pf: board private structure |
| 6382 | **/ |
| 6383 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6384 | { |
| 6385 | struct i40e_arq_event_info event; |
| 6386 | struct i40e_hw *hw = &pf->hw; |
| 6387 | u16 pending, i = 0; |
| 6388 | i40e_status ret; |
| 6389 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6390 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6391 | u32 val; |
| 6392 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6393 | /* Do not run clean AQ when PF reset fails */ |
| 6394 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 6395 | return; |
| 6396 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6397 | /* check for error indications */ |
| 6398 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6399 | oldval = val; |
| 6400 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6401 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6402 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6403 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6404 | } |
| 6405 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6406 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6407 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6408 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6409 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6410 | } |
| 6411 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6412 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6413 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6414 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6415 | } |
| 6416 | if (oldval != val) |
| 6417 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6418 | |
| 6419 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6420 | oldval = val; |
| 6421 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6422 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6423 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6424 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6425 | } |
| 6426 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6427 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6428 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6429 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6430 | } |
| 6431 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6432 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6433 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6434 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6435 | } |
| 6436 | if (oldval != val) |
| 6437 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6438 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6439 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6440 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6441 | if (!event.msg_buf) |
| 6442 | return; |
| 6443 | |
| 6444 | do { |
| 6445 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6446 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6447 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6448 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6449 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6450 | break; |
| 6451 | } |
| 6452 | |
| 6453 | opcode = le16_to_cpu(event.desc.opcode); |
| 6454 | switch (opcode) { |
| 6455 | |
| 6456 | case i40e_aqc_opc_get_link_status: |
| 6457 | i40e_handle_link_event(pf, &event); |
| 6458 | break; |
| 6459 | case i40e_aqc_opc_send_msg_to_pf: |
| 6460 | ret = i40e_vc_process_vf_msg(pf, |
| 6461 | le16_to_cpu(event.desc.retval), |
| 6462 | le32_to_cpu(event.desc.cookie_high), |
| 6463 | le32_to_cpu(event.desc.cookie_low), |
| 6464 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6465 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6466 | break; |
| 6467 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6468 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6469 | #ifdef CONFIG_I40E_DCB |
| 6470 | rtnl_lock(); |
| 6471 | ret = i40e_handle_lldp_event(pf, &event); |
| 6472 | rtnl_unlock(); |
| 6473 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6474 | break; |
| 6475 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6476 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6477 | i40e_handle_lan_overflow_event(pf, &event); |
| 6478 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6479 | case i40e_aqc_opc_send_msg_to_peer: |
| 6480 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6481 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6482 | case i40e_aqc_opc_nvm_erase: |
| 6483 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6484 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 6485 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 6486 | "ARQ NVM operation 0x%04x completed\n", |
| 6487 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6488 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6489 | default: |
| 6490 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 6491 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6492 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6493 | break; |
| 6494 | } |
| 6495 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 6496 | |
| 6497 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 6498 | /* re-enable Admin queue interrupt cause */ |
| 6499 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6500 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6501 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6502 | i40e_flush(hw); |
| 6503 | |
| 6504 | kfree(event.msg_buf); |
| 6505 | } |
| 6506 | |
| 6507 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6508 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6509 | * @pf: board private structure |
| 6510 | **/ |
| 6511 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6512 | { |
| 6513 | int err; |
| 6514 | |
| 6515 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6516 | if (err) { |
| 6517 | /* retry in case of garbage read */ |
| 6518 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6519 | if (err) { |
| 6520 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6521 | err); |
| 6522 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6523 | } |
| 6524 | } |
| 6525 | |
| 6526 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 6527 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 6528 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6529 | } |
| 6530 | } |
| 6531 | |
| 6532 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6533 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6534 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6535 | * |
| 6536 | * enable switch loop back or die - no point in a return value |
| 6537 | **/ |
| 6538 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6539 | { |
| 6540 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6541 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6542 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6543 | |
| 6544 | ctxt.seid = pf->main_vsi_seid; |
| 6545 | ctxt.pf_num = pf->hw.pf_id; |
| 6546 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6547 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6548 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6549 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6550 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6551 | i40e_stat_str(&pf->hw, ret), |
| 6552 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6553 | return; |
| 6554 | } |
| 6555 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6556 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6557 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6558 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6559 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6560 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6561 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6562 | "update vsi switch failed, err %s aq_err %s\n", |
| 6563 | i40e_stat_str(&pf->hw, ret), |
| 6564 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | /** |
| 6569 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6570 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6571 | * |
| 6572 | * disable switch loop back or die - no point in a return value |
| 6573 | **/ |
| 6574 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6575 | { |
| 6576 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6577 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6578 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6579 | |
| 6580 | ctxt.seid = pf->main_vsi_seid; |
| 6581 | ctxt.pf_num = pf->hw.pf_id; |
| 6582 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6583 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6584 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6585 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6586 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6587 | i40e_stat_str(&pf->hw, ret), |
| 6588 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6589 | return; |
| 6590 | } |
| 6591 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6592 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6593 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6594 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6595 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6596 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6597 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6598 | "update vsi switch failed, err %s aq_err %s\n", |
| 6599 | i40e_stat_str(&pf->hw, ret), |
| 6600 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6601 | } |
| 6602 | } |
| 6603 | |
| 6604 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6605 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6606 | * @veb: pointer to the bridge instance |
| 6607 | * |
| 6608 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6609 | * specified HW bridge instance. It is expected this function is called |
| 6610 | * when a new HW bridge is instantiated. |
| 6611 | **/ |
| 6612 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6613 | { |
| 6614 | struct i40e_pf *pf = veb->pf; |
| 6615 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6616 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6617 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6618 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6619 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6620 | i40e_disable_pf_switch_lb(pf); |
| 6621 | else |
| 6622 | i40e_enable_pf_switch_lb(pf); |
| 6623 | } |
| 6624 | |
| 6625 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6626 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6627 | * @veb: pointer to the VEB instance |
| 6628 | * |
| 6629 | * This is a recursive function that first builds the attached VSIs then |
| 6630 | * recurses in to build the next layer of VEB. We track the connections |
| 6631 | * through our own index numbers because the seid's from the HW could |
| 6632 | * change across the reset. |
| 6633 | **/ |
| 6634 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6635 | { |
| 6636 | struct i40e_vsi *ctl_vsi = NULL; |
| 6637 | struct i40e_pf *pf = veb->pf; |
| 6638 | int v, veb_idx; |
| 6639 | int ret; |
| 6640 | |
| 6641 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6642 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6643 | if (pf->vsi[v] && |
| 6644 | pf->vsi[v]->veb_idx == veb->idx && |
| 6645 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6646 | ctl_vsi = pf->vsi[v]; |
| 6647 | break; |
| 6648 | } |
| 6649 | } |
| 6650 | if (!ctl_vsi) { |
| 6651 | dev_info(&pf->pdev->dev, |
| 6652 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6653 | ret = -ENOENT; |
| 6654 | goto end_reconstitute; |
| 6655 | } |
| 6656 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6657 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6658 | ret = i40e_add_vsi(ctl_vsi); |
| 6659 | if (ret) { |
| 6660 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6661 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6662 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6663 | goto end_reconstitute; |
| 6664 | } |
| 6665 | i40e_vsi_reset_stats(ctl_vsi); |
| 6666 | |
| 6667 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6668 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6669 | if (ret) |
| 6670 | goto end_reconstitute; |
| 6671 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6672 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6673 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6674 | else |
| 6675 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6676 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6677 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6678 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6679 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6680 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6681 | continue; |
| 6682 | |
| 6683 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6684 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6685 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6686 | vsi->uplink_seid = veb->seid; |
| 6687 | ret = i40e_add_vsi(vsi); |
| 6688 | if (ret) { |
| 6689 | dev_info(&pf->pdev->dev, |
| 6690 | "rebuild of vsi_idx %d failed: %d\n", |
| 6691 | v, ret); |
| 6692 | goto end_reconstitute; |
| 6693 | } |
| 6694 | i40e_vsi_reset_stats(vsi); |
| 6695 | } |
| 6696 | } |
| 6697 | |
| 6698 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6699 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6700 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6701 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6702 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6703 | if (ret) |
| 6704 | break; |
| 6705 | } |
| 6706 | } |
| 6707 | |
| 6708 | end_reconstitute: |
| 6709 | return ret; |
| 6710 | } |
| 6711 | |
| 6712 | /** |
| 6713 | * i40e_get_capabilities - get info about the HW |
| 6714 | * @pf: the PF struct |
| 6715 | **/ |
| 6716 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6717 | { |
| 6718 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6719 | u16 data_size; |
| 6720 | int buf_len; |
| 6721 | int err; |
| 6722 | |
| 6723 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6724 | do { |
| 6725 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6726 | if (!cap_buf) |
| 6727 | return -ENOMEM; |
| 6728 | |
| 6729 | /* this loads the data into the hw struct for us */ |
| 6730 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6731 | &data_size, |
| 6732 | i40e_aqc_opc_list_func_capabilities, |
| 6733 | NULL); |
| 6734 | /* data loaded, buffer no longer needed */ |
| 6735 | kfree(cap_buf); |
| 6736 | |
| 6737 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6738 | /* retry with a larger buffer */ |
| 6739 | buf_len = data_size; |
| 6740 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6741 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6742 | "capability discovery failed, err %s aq_err %s\n", |
| 6743 | i40e_stat_str(&pf->hw, err), |
| 6744 | i40e_aq_str(&pf->hw, |
| 6745 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6746 | return -ENODEV; |
| 6747 | } |
| 6748 | } while (err); |
| 6749 | |
| 6750 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6751 | dev_info(&pf->pdev->dev, |
| 6752 | "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", |
| 6753 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6754 | pf->hw.func_caps.num_msix_vectors, |
| 6755 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6756 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6757 | pf->hw.func_caps.fd_filters_best_effort, |
| 6758 | pf->hw.func_caps.num_tx_qp, |
| 6759 | pf->hw.func_caps.num_vsis); |
| 6760 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6761 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6762 | + pf->hw.func_caps.num_vfs) |
| 6763 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6764 | dev_info(&pf->pdev->dev, |
| 6765 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6766 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6767 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6768 | } |
| 6769 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6770 | return 0; |
| 6771 | } |
| 6772 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6773 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6774 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6775 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6776 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6777 | * @pf: board private structure |
| 6778 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6779 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6780 | { |
| 6781 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6782 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6783 | /* quick workaround for an NVM issue that leaves a critical register |
| 6784 | * uninitialized |
| 6785 | */ |
| 6786 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6787 | static const u32 hkey[] = { |
| 6788 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6789 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6790 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6791 | 0x95b3a76d}; |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6792 | int i; |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6793 | |
| 6794 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6795 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6796 | } |
| 6797 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6798 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6799 | return; |
| 6800 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6801 | /* find existing VSI and see if it needs configuring */ |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6802 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6803 | |
| 6804 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6805 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6806 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6807 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6808 | if (!vsi) { |
| 6809 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6810 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6811 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6812 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6813 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6814 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6815 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6816 | } |
| 6817 | |
| 6818 | /** |
| 6819 | * i40e_fdir_teardown - release the Flow Director resources |
| 6820 | * @pf: board private structure |
| 6821 | **/ |
| 6822 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6823 | { |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6824 | struct i40e_vsi *vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6825 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6826 | i40e_fdir_filter_exit(pf); |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 6827 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
| 6828 | if (vsi) |
| 6829 | i40e_vsi_release(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6830 | } |
| 6831 | |
| 6832 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6833 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6834 | * @pf: board private structure |
| 6835 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6836 | * 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] | 6837 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6838 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6839 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6840 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6841 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6842 | u32 v; |
| 6843 | |
| 6844 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6845 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6846 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 6847 | if (i40e_check_asq_alive(&pf->hw)) |
| 6848 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6849 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6850 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6851 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6852 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6853 | i40e_pf_quiesce_all_vsi(pf); |
| 6854 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6855 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6856 | if (pf->vsi[v]) |
| 6857 | pf->vsi[v]->seid = 0; |
| 6858 | } |
| 6859 | |
| 6860 | i40e_shutdown_adminq(&pf->hw); |
| 6861 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6862 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6863 | if (hw->hmc.hmc_obj) { |
| 6864 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6865 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6866 | dev_warn(&pf->pdev->dev, |
| 6867 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6868 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6869 | } |
| 6870 | |
| 6871 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6872 | * i40e_send_version - update firmware with driver version |
| 6873 | * @pf: PF struct |
| 6874 | */ |
| 6875 | static void i40e_send_version(struct i40e_pf *pf) |
| 6876 | { |
| 6877 | struct i40e_driver_version dv; |
| 6878 | |
| 6879 | dv.major_version = DRV_VERSION_MAJOR; |
| 6880 | dv.minor_version = DRV_VERSION_MINOR; |
| 6881 | dv.build_version = DRV_VERSION_BUILD; |
| 6882 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 6883 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6884 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 6885 | } |
| 6886 | |
| 6887 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 6888 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6889 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6890 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6891 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6892 | 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] | 6893 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6894 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6895 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6896 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6897 | u32 val; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6898 | u32 v; |
| 6899 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6900 | /* Now we wait for GRST to settle out. |
| 6901 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 6902 | * because the reset will make them disappear. |
| 6903 | */ |
| 6904 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6905 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6906 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6907 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 6908 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6909 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6910 | pf->pfr_count++; |
| 6911 | |
| 6912 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6913 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6914 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6915 | |
| 6916 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 6917 | ret = i40e_init_adminq(&pf->hw); |
| 6918 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6919 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 6920 | i40e_stat_str(&pf->hw, ret), |
| 6921 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6922 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6923 | } |
| 6924 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6925 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 6926 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6927 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6928 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 6929 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6930 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6931 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6932 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6933 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6934 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 6935 | hw->func_caps.num_rx_qp, |
| 6936 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 6937 | if (ret) { |
| 6938 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 6939 | goto end_core_reset; |
| 6940 | } |
| 6941 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 6942 | if (ret) { |
| 6943 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 6944 | goto end_core_reset; |
| 6945 | } |
| 6946 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6947 | #ifdef CONFIG_I40E_DCB |
| 6948 | ret = i40e_init_pf_dcb(pf); |
| 6949 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6950 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 6951 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 6952 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6953 | } |
| 6954 | #endif /* CONFIG_I40E_DCB */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6955 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 6956 | i40e_init_pf_fcoe(pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6957 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6958 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6959 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6960 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6961 | if (ret) |
| 6962 | goto end_core_reset; |
| 6963 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6964 | /* The driver only wants link up/down and module qualification |
| 6965 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6966 | */ |
| 6967 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6968 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 6969 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6970 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6971 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6972 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 6973 | i40e_stat_str(&pf->hw, ret), |
| 6974 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6975 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6976 | /* make sure our flow control settings are restored */ |
| 6977 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 6978 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 6979 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 6980 | i40e_stat_str(&pf->hw, ret), |
| 6981 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6982 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6983 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 6984 | * They are still in our local switch element arrays, so only |
| 6985 | * need to rebuild the switch model in the HW. |
| 6986 | * |
| 6987 | * If there were VEBs but the reconstitution failed, we'll try |
| 6988 | * try to recover minimal use by getting the basic PF VSI working. |
| 6989 | */ |
| 6990 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6991 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6992 | /* find the one VEB connected to the MAC, and find orphans */ |
| 6993 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6994 | if (!pf->veb[v]) |
| 6995 | continue; |
| 6996 | |
| 6997 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 6998 | pf->veb[v]->uplink_seid == 0) { |
| 6999 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 7000 | |
| 7001 | if (!ret) |
| 7002 | continue; |
| 7003 | |
| 7004 | /* If Main VEB failed, we're in deep doodoo, |
| 7005 | * so give up rebuilding the switch and set up |
| 7006 | * for minimal rebuild of PF VSI. |
| 7007 | * If orphan failed, we'll report the error |
| 7008 | * but try to keep going. |
| 7009 | */ |
| 7010 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 7011 | dev_info(&pf->pdev->dev, |
| 7012 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 7013 | ret); |
| 7014 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 7015 | = pf->mac_seid; |
| 7016 | break; |
| 7017 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 7018 | dev_info(&pf->pdev->dev, |
| 7019 | "rebuild of orphan VEB failed: %d\n", |
| 7020 | ret); |
| 7021 | } |
| 7022 | } |
| 7023 | } |
| 7024 | } |
| 7025 | |
| 7026 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 7027 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7028 | /* no VEB, so rebuild only the Main VSI */ |
| 7029 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 7030 | if (ret) { |
| 7031 | dev_info(&pf->pdev->dev, |
| 7032 | "rebuild of Main VSI failed: %d\n", ret); |
| 7033 | goto end_core_reset; |
| 7034 | } |
| 7035 | } |
| 7036 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 7037 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 7038 | * of TSO, so that we avoid the MDD being fired and causing |
| 7039 | * a reset in the case of small MSS+TSO. |
| 7040 | */ |
| 7041 | #define I40E_REG_MSS 0x000E64DC |
| 7042 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 7043 | #define I40E_64BYTE_MSS 0x400000 |
| 7044 | val = rd32(hw, I40E_REG_MSS); |
| 7045 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 7046 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 7047 | val |= I40E_64BYTE_MSS; |
| 7048 | wr32(hw, I40E_REG_MSS, val); |
| 7049 | } |
| 7050 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 7051 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 7052 | msleep(75); |
| 7053 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 7054 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7055 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 7056 | i40e_stat_str(&pf->hw, ret), |
| 7057 | i40e_aq_str(&pf->hw, |
| 7058 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7059 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7060 | /* reinit the misc interrupt */ |
| 7061 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7062 | ret = i40e_setup_misc_vector(pf); |
| 7063 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 7064 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 7065 | * transmitted. By doing so we stop a malicious VF from sending out |
| 7066 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 7067 | * PF/VF VSIs. |
| 7068 | * The FW can still send Flow control frames if enabled. |
| 7069 | */ |
| 7070 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 7071 | pf->main_vsi_seid); |
| 7072 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7073 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 7074 | i40e_pf_unquiesce_all_vsi(pf); |
| 7075 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 7076 | if (pf->num_alloc_vfs) { |
| 7077 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 7078 | i40e_reset_vf(&pf->vf[v], true); |
| 7079 | } |
| 7080 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7081 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 7082 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7083 | |
| 7084 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7085 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 7086 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7087 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 7088 | } |
| 7089 | |
| 7090 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7091 | * 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] | 7092 | * @pf: board private structure |
| 7093 | * |
| 7094 | * Close up the VFs and other things in prep for a Core Reset, |
| 7095 | * then get ready to rebuild the world. |
| 7096 | **/ |
| 7097 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 7098 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 7099 | i40e_prep_for_reset(pf); |
| 7100 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7101 | } |
| 7102 | |
| 7103 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7104 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7105 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7106 | * |
| 7107 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 7108 | **/ |
| 7109 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 7110 | { |
| 7111 | struct i40e_hw *hw = &pf->hw; |
| 7112 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7113 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7114 | struct i40e_vf *vf; |
| 7115 | u32 reg; |
| 7116 | int i; |
| 7117 | |
| 7118 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 7119 | return; |
| 7120 | |
| 7121 | /* find what triggered the MDD event */ |
| 7122 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 7123 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7124 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 7125 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7126 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7127 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7128 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7129 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7130 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 7131 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 7132 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7133 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7134 | 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] | 7135 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7136 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 7137 | mdd_detected = true; |
| 7138 | } |
| 7139 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 7140 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7141 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 7142 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7143 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7144 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7145 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 7146 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 7147 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7148 | if (netif_msg_rx_err(pf)) |
| 7149 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 7150 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7151 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 7152 | mdd_detected = true; |
| 7153 | } |
| 7154 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7155 | if (mdd_detected) { |
| 7156 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 7157 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 7158 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7159 | 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] | 7160 | pf_mdd_detected = true; |
| 7161 | } |
| 7162 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 7163 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 7164 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7165 | 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] | 7166 | pf_mdd_detected = true; |
| 7167 | } |
| 7168 | /* Queue belongs to the PF, initiate a reset */ |
| 7169 | if (pf_mdd_detected) { |
| 7170 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 7171 | i40e_service_event_schedule(pf); |
| 7172 | } |
| 7173 | } |
| 7174 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7175 | /* see if one of the VFs needs its hand slapped */ |
| 7176 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7177 | vf = &(pf->vf[i]); |
| 7178 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7179 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7180 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7181 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7182 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7183 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7184 | } |
| 7185 | |
| 7186 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7187 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7188 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7189 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7190 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7191 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7192 | } |
| 7193 | |
| 7194 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7195 | dev_info(&pf->pdev->dev, |
| 7196 | "Too many MDD events on VF %d, disabled\n", i); |
| 7197 | dev_info(&pf->pdev->dev, |
| 7198 | "Use PF Control I/F to re-enable the VF\n"); |
| 7199 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 7200 | } |
| 7201 | } |
| 7202 | |
| 7203 | /* re-enable mdd interrupt cause */ |
| 7204 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 7205 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7206 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7207 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7208 | i40e_flush(hw); |
| 7209 | } |
| 7210 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7211 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7212 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7213 | * @pf: board private structure |
| 7214 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7215 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7216 | { |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7217 | struct i40e_hw *hw = &pf->hw; |
| 7218 | i40e_status ret; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7219 | __be16 port; |
| 7220 | int i; |
| 7221 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7222 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7223 | return; |
| 7224 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7225 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7226 | |
| 7227 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7228 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7229 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
| 7230 | port = pf->udp_ports[i].index; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7231 | if (port) |
Carolyn Wyborny | b3f5c7b | 2016-08-24 11:33:51 -0700 | [diff] [blame] | 7232 | ret = i40e_aq_add_udp_tunnel(hw, port, |
| 7233 | pf->udp_ports[i].type, |
| 7234 | NULL, NULL); |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7235 | else |
| 7236 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7237 | |
| 7238 | if (ret) { |
Carolyn Wyborny | 730a8f8 | 2016-02-17 16:12:16 -0800 | [diff] [blame] | 7239 | dev_dbg(&pf->pdev->dev, |
| 7240 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 7241 | pf->udp_ports[i].type ? "vxlan" : "geneve", |
| 7242 | port ? "add" : "delete", |
| 7243 | ntohs(port), i, |
| 7244 | i40e_stat_str(&pf->hw, ret), |
| 7245 | i40e_aq_str(&pf->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7246 | pf->hw.aq.asq_last_status)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7247 | pf->udp_ports[i].index = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7248 | } |
| 7249 | } |
| 7250 | } |
| 7251 | } |
| 7252 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7253 | /** |
| 7254 | * i40e_service_task - Run the driver's async subtasks |
| 7255 | * @work: pointer to work_struct containing our data |
| 7256 | **/ |
| 7257 | static void i40e_service_task(struct work_struct *work) |
| 7258 | { |
| 7259 | struct i40e_pf *pf = container_of(work, |
| 7260 | struct i40e_pf, |
| 7261 | service_task); |
| 7262 | unsigned long start_time = jiffies; |
| 7263 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7264 | /* don't bother with service tasks if a reset is in progress */ |
| 7265 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7266 | i40e_service_event_complete(pf); |
| 7267 | return; |
| 7268 | } |
| 7269 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7270 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 7271 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7272 | i40e_reset_subtask(pf); |
| 7273 | i40e_handle_mdd_event(pf); |
| 7274 | i40e_vc_process_vflr_event(pf); |
| 7275 | i40e_watchdog_subtask(pf); |
| 7276 | i40e_fdir_reinit_subtask(pf); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7277 | i40e_client_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7278 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7279 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7280 | i40e_clean_adminq_subtask(pf); |
| 7281 | |
| 7282 | i40e_service_event_complete(pf); |
| 7283 | |
| 7284 | /* If the tasks have taken longer than one timer cycle or there |
| 7285 | * is more work to be done, reschedule the service task now |
| 7286 | * rather than wait for the timer to tick again. |
| 7287 | */ |
| 7288 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 7289 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 7290 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 7291 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 7292 | i40e_service_event_schedule(pf); |
| 7293 | } |
| 7294 | |
| 7295 | /** |
| 7296 | * i40e_service_timer - timer callback |
| 7297 | * @data: pointer to PF struct |
| 7298 | **/ |
| 7299 | static void i40e_service_timer(unsigned long data) |
| 7300 | { |
| 7301 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7302 | |
| 7303 | mod_timer(&pf->service_timer, |
| 7304 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7305 | i40e_service_event_schedule(pf); |
| 7306 | } |
| 7307 | |
| 7308 | /** |
| 7309 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7310 | * @vsi: the VSI being configured |
| 7311 | **/ |
| 7312 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7313 | { |
| 7314 | struct i40e_pf *pf = vsi->back; |
| 7315 | |
| 7316 | switch (vsi->type) { |
| 7317 | case I40E_VSI_MAIN: |
| 7318 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7319 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7320 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7321 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7322 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7323 | else |
| 7324 | vsi->num_q_vectors = 1; |
| 7325 | |
| 7326 | break; |
| 7327 | |
| 7328 | case I40E_VSI_FDIR: |
| 7329 | vsi->alloc_queue_pairs = 1; |
| 7330 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7331 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7332 | vsi->num_q_vectors = pf->num_fdsb_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7333 | break; |
| 7334 | |
| 7335 | case I40E_VSI_VMDQ2: |
| 7336 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7337 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7338 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7339 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7340 | break; |
| 7341 | |
| 7342 | case I40E_VSI_SRIOV: |
| 7343 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7344 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7345 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7346 | break; |
| 7347 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7348 | #ifdef I40E_FCOE |
| 7349 | case I40E_VSI_FCOE: |
| 7350 | vsi->alloc_queue_pairs = pf->num_fcoe_qps; |
| 7351 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7352 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7353 | vsi->num_q_vectors = pf->num_fcoe_msix; |
| 7354 | break; |
| 7355 | |
| 7356 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7357 | default: |
| 7358 | WARN_ON(1); |
| 7359 | return -ENODATA; |
| 7360 | } |
| 7361 | |
| 7362 | return 0; |
| 7363 | } |
| 7364 | |
| 7365 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7366 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7367 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7368 | * @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] | 7369 | * |
| 7370 | * On error: returns error code (negative) |
| 7371 | * On success: returns 0 |
| 7372 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7373 | 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] | 7374 | { |
| 7375 | int size; |
| 7376 | int ret = 0; |
| 7377 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7378 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7379 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 7380 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7381 | if (!vsi->tx_rings) |
| 7382 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7383 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 7384 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7385 | if (alloc_qvectors) { |
| 7386 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7387 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7388 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7389 | if (!vsi->q_vectors) { |
| 7390 | ret = -ENOMEM; |
| 7391 | goto err_vectors; |
| 7392 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7393 | } |
| 7394 | return ret; |
| 7395 | |
| 7396 | err_vectors: |
| 7397 | kfree(vsi->tx_rings); |
| 7398 | return ret; |
| 7399 | } |
| 7400 | |
| 7401 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7402 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7403 | * @pf: board private structure |
| 7404 | * @type: type of VSI |
| 7405 | * |
| 7406 | * On error: returns error code (negative) |
| 7407 | * On success: returns vsi index in PF (positive) |
| 7408 | **/ |
| 7409 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7410 | { |
| 7411 | int ret = -ENODEV; |
| 7412 | struct i40e_vsi *vsi; |
| 7413 | int vsi_idx; |
| 7414 | int i; |
| 7415 | |
| 7416 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7417 | mutex_lock(&pf->switch_mutex); |
| 7418 | |
| 7419 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7420 | * been happening. We can afford to do a quick scan to look |
| 7421 | * for any free VSIs in the list. |
| 7422 | * |
| 7423 | * find next empty vsi slot, looping back around if necessary |
| 7424 | */ |
| 7425 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7426 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7427 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7428 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7429 | i = 0; |
| 7430 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7431 | i++; |
| 7432 | } |
| 7433 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7434 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7435 | vsi_idx = i; /* Found one! */ |
| 7436 | } else { |
| 7437 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7438 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7439 | } |
| 7440 | pf->next_vsi = ++i; |
| 7441 | |
| 7442 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7443 | if (!vsi) { |
| 7444 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7445 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7446 | } |
| 7447 | vsi->type = type; |
| 7448 | vsi->back = pf; |
| 7449 | set_bit(__I40E_DOWN, &vsi->state); |
| 7450 | vsi->flags = 0; |
| 7451 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7452 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7453 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7454 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7455 | vsi->netdev_registered = false; |
| 7456 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 7457 | hash_init(vsi->mac_filter_hash); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7458 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7459 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7460 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7461 | if (ret) |
| 7462 | goto err_rings; |
| 7463 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7464 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7465 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7466 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7467 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7468 | /* Setup default MSIX irq handler for VSI */ |
| 7469 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7470 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7471 | /* Initialize VSI lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 7472 | spin_lock_init(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7473 | pf->vsi[vsi_idx] = vsi; |
| 7474 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7475 | goto unlock_pf; |
| 7476 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7477 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7478 | pf->next_vsi = i - 1; |
| 7479 | kfree(vsi); |
| 7480 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7481 | mutex_unlock(&pf->switch_mutex); |
| 7482 | return ret; |
| 7483 | } |
| 7484 | |
| 7485 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7486 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7487 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7488 | * @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] | 7489 | * |
| 7490 | * On error: returns error code (negative) |
| 7491 | * On success: returns 0 |
| 7492 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7493 | 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] | 7494 | { |
| 7495 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7496 | if (free_qvectors) { |
| 7497 | kfree(vsi->q_vectors); |
| 7498 | vsi->q_vectors = NULL; |
| 7499 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7500 | kfree(vsi->tx_rings); |
| 7501 | vsi->tx_rings = NULL; |
| 7502 | vsi->rx_rings = NULL; |
| 7503 | } |
| 7504 | |
| 7505 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7506 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7507 | * and lookup table |
| 7508 | * @vsi: Pointer to VSI structure |
| 7509 | */ |
| 7510 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7511 | { |
| 7512 | if (!vsi) |
| 7513 | return; |
| 7514 | |
| 7515 | kfree(vsi->rss_hkey_user); |
| 7516 | vsi->rss_hkey_user = NULL; |
| 7517 | |
| 7518 | kfree(vsi->rss_lut_user); |
| 7519 | vsi->rss_lut_user = NULL; |
| 7520 | } |
| 7521 | |
| 7522 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7523 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7524 | * @vsi: the VSI being un-configured |
| 7525 | **/ |
| 7526 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7527 | { |
| 7528 | struct i40e_pf *pf; |
| 7529 | |
| 7530 | if (!vsi) |
| 7531 | return 0; |
| 7532 | |
| 7533 | if (!vsi->back) |
| 7534 | goto free_vsi; |
| 7535 | pf = vsi->back; |
| 7536 | |
| 7537 | mutex_lock(&pf->switch_mutex); |
| 7538 | if (!pf->vsi[vsi->idx]) { |
| 7539 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7540 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7541 | goto unlock_vsi; |
| 7542 | } |
| 7543 | |
| 7544 | if (pf->vsi[vsi->idx] != vsi) { |
| 7545 | dev_err(&pf->pdev->dev, |
| 7546 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7547 | pf->vsi[vsi->idx]->idx, |
| 7548 | pf->vsi[vsi->idx], |
| 7549 | pf->vsi[vsi->idx]->type, |
| 7550 | vsi->idx, vsi, vsi->type); |
| 7551 | goto unlock_vsi; |
| 7552 | } |
| 7553 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7554 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7555 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7556 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7557 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7558 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7559 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7560 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7561 | pf->vsi[vsi->idx] = NULL; |
| 7562 | if (vsi->idx < pf->next_vsi) |
| 7563 | pf->next_vsi = vsi->idx; |
| 7564 | |
| 7565 | unlock_vsi: |
| 7566 | mutex_unlock(&pf->switch_mutex); |
| 7567 | free_vsi: |
| 7568 | kfree(vsi); |
| 7569 | |
| 7570 | return 0; |
| 7571 | } |
| 7572 | |
| 7573 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7574 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7575 | * @vsi: the VSI being cleaned |
| 7576 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7577 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7578 | { |
| 7579 | int i; |
| 7580 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7581 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7582 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7583 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7584 | vsi->tx_rings[i] = NULL; |
| 7585 | vsi->rx_rings[i] = NULL; |
| 7586 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7587 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7588 | } |
| 7589 | |
| 7590 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7591 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7592 | * @vsi: the VSI being configured |
| 7593 | **/ |
| 7594 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7595 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7596 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7597 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7598 | int i; |
| 7599 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7600 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7601 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7602 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7603 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7604 | if (!tx_ring) |
| 7605 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7606 | |
| 7607 | tx_ring->queue_index = i; |
| 7608 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7609 | tx_ring->ring_active = false; |
| 7610 | tx_ring->vsi = vsi; |
| 7611 | tx_ring->netdev = vsi->netdev; |
| 7612 | tx_ring->dev = &pf->pdev->dev; |
| 7613 | tx_ring->count = vsi->num_desc; |
| 7614 | tx_ring->size = 0; |
| 7615 | tx_ring->dcb_tc = 0; |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 7616 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 7617 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7618 | tx_ring->tx_itr_setting = pf->tx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7619 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7620 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7621 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7622 | rx_ring->queue_index = i; |
| 7623 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7624 | rx_ring->ring_active = false; |
| 7625 | rx_ring->vsi = vsi; |
| 7626 | rx_ring->netdev = vsi->netdev; |
| 7627 | rx_ring->dev = &pf->pdev->dev; |
| 7628 | rx_ring->count = vsi->num_desc; |
| 7629 | rx_ring->size = 0; |
| 7630 | rx_ring->dcb_tc = 0; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7631 | rx_ring->rx_itr_setting = pf->rx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7632 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7633 | } |
| 7634 | |
| 7635 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7636 | |
| 7637 | err_out: |
| 7638 | i40e_vsi_clear_rings(vsi); |
| 7639 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7640 | } |
| 7641 | |
| 7642 | /** |
| 7643 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7644 | * @pf: board private structure |
| 7645 | * @vectors: the number of MSI-X vectors to request |
| 7646 | * |
| 7647 | * Returns the number of vectors reserved, or error |
| 7648 | **/ |
| 7649 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7650 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7651 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7652 | I40E_MIN_MSIX, vectors); |
| 7653 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7654 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7655 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7656 | vectors = 0; |
| 7657 | } |
| 7658 | |
| 7659 | return vectors; |
| 7660 | } |
| 7661 | |
| 7662 | /** |
| 7663 | * i40e_init_msix - Setup the MSIX capability |
| 7664 | * @pf: board private structure |
| 7665 | * |
| 7666 | * Work with the OS to set up the MSIX vectors needed. |
| 7667 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7668 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7669 | **/ |
| 7670 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7671 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7672 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7673 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7674 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7675 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7676 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7677 | |
| 7678 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7679 | return -ENODEV; |
| 7680 | |
| 7681 | /* The number of vectors we'll request will be comprised of: |
| 7682 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7683 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7684 | * - Queues being used for RSS. |
| 7685 | * We don't need as many as max_rss_size vectors. |
| 7686 | * use rss_size instead in the calculation since that |
| 7687 | * is governed by number of cpus in the system. |
| 7688 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7689 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7690 | * - The CPU count within the NUMA node if iWARP is enabled |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7691 | #ifdef I40E_FCOE |
| 7692 | * - The number of FCOE qps. |
| 7693 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7694 | * Once we count this up, try the request. |
| 7695 | * |
| 7696 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7697 | * and try again. If that still fails, we punt. |
| 7698 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7699 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7700 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7701 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7702 | /* reserve one vector for miscellaneous handler */ |
| 7703 | if (vectors_left) { |
| 7704 | v_budget++; |
| 7705 | vectors_left--; |
| 7706 | } |
| 7707 | |
| 7708 | /* reserve vectors for the main PF traffic queues */ |
| 7709 | pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left); |
| 7710 | vectors_left -= pf->num_lan_msix; |
| 7711 | v_budget += pf->num_lan_msix; |
| 7712 | |
| 7713 | /* reserve one vector for sideband flow director */ |
| 7714 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7715 | if (vectors_left) { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7716 | pf->num_fdsb_msix = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7717 | v_budget++; |
| 7718 | vectors_left--; |
| 7719 | } else { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7720 | pf->num_fdsb_msix = 0; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7721 | } |
| 7722 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7723 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7724 | #ifdef I40E_FCOE |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7725 | /* can we reserve enough for FCoE? */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7726 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7727 | if (!vectors_left) |
| 7728 | pf->num_fcoe_msix = 0; |
| 7729 | else if (vectors_left >= pf->num_fcoe_qps) |
| 7730 | pf->num_fcoe_msix = pf->num_fcoe_qps; |
| 7731 | else |
| 7732 | pf->num_fcoe_msix = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7733 | v_budget += pf->num_fcoe_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7734 | vectors_left -= pf->num_fcoe_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7735 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7736 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7737 | #endif |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7738 | /* can we reserve enough for iWARP? */ |
| 7739 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7740 | iwarp_requested = pf->num_iwarp_msix; |
| 7741 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7742 | if (!vectors_left) |
| 7743 | pf->num_iwarp_msix = 0; |
| 7744 | else if (vectors_left < pf->num_iwarp_msix) |
| 7745 | pf->num_iwarp_msix = 1; |
| 7746 | v_budget += pf->num_iwarp_msix; |
| 7747 | vectors_left -= pf->num_iwarp_msix; |
| 7748 | } |
| 7749 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7750 | /* any vectors left over go for VMDq support */ |
| 7751 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7752 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7753 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7754 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 7755 | if (!vectors_left) { |
| 7756 | pf->num_vmdq_msix = 0; |
| 7757 | pf->num_vmdq_qps = 0; |
| 7758 | } else { |
| 7759 | /* if we're short on vectors for what's desired, we limit |
| 7760 | * the queues per vmdq. If this is still more than are |
| 7761 | * available, the user will need to change the number of |
| 7762 | * queues/vectors used by the PF later with the ethtool |
| 7763 | * channels command |
| 7764 | */ |
| 7765 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7766 | pf->num_vmdq_qps = 1; |
| 7767 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7768 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 7769 | v_budget += vmdq_vecs; |
| 7770 | vectors_left -= vmdq_vecs; |
| 7771 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7772 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7773 | |
| 7774 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7775 | GFP_KERNEL); |
| 7776 | if (!pf->msix_entries) |
| 7777 | return -ENOMEM; |
| 7778 | |
| 7779 | for (i = 0; i < v_budget; i++) |
| 7780 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7781 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7782 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7783 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7784 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7785 | kfree(pf->msix_entries); |
| 7786 | pf->msix_entries = NULL; |
Guilherme G Piccoli | 4c95aa5 | 2016-09-22 10:03:58 -0300 | [diff] [blame] | 7787 | pci_disable_msix(pf->pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7788 | return -ENODEV; |
| 7789 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7790 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7791 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7792 | pf->num_vmdq_vsis = 0; |
| 7793 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7794 | pf->num_lan_qps = 1; |
| 7795 | pf->num_lan_msix = 1; |
| 7796 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7797 | } else if (!vectors_left) { |
| 7798 | /* If we have limited resources, we will start with no vectors |
| 7799 | * for the special features and then allocate vectors to some |
| 7800 | * of these features based on the policy and at the end disable |
| 7801 | * the features that did not get any vectors. |
| 7802 | */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7803 | int vec; |
| 7804 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7805 | dev_info(&pf->pdev->dev, |
| 7806 | "MSI-X vector limit reached, attempting to redistribute vectors\n"); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7807 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7808 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7809 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7810 | /* Scale vector usage down */ |
| 7811 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7812 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7813 | pf->num_vmdq_qps = 1; |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7814 | #ifdef I40E_FCOE |
| 7815 | pf->num_fcoe_qps = 0; |
| 7816 | pf->num_fcoe_msix = 0; |
| 7817 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7818 | |
| 7819 | /* partition out the remaining vectors */ |
| 7820 | switch (vec) { |
| 7821 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7822 | pf->num_lan_msix = 1; |
| 7823 | break; |
| 7824 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7825 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7826 | pf->num_lan_msix = 1; |
| 7827 | pf->num_iwarp_msix = 1; |
| 7828 | } else { |
| 7829 | pf->num_lan_msix = 2; |
| 7830 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7831 | #ifdef I40E_FCOE |
| 7832 | /* give one vector to FCoE */ |
| 7833 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7834 | pf->num_lan_msix = 1; |
| 7835 | pf->num_fcoe_msix = 1; |
| 7836 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7837 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7838 | break; |
| 7839 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7840 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7841 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 7842 | iwarp_requested); |
| 7843 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 7844 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7845 | } else { |
| 7846 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 7847 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7848 | } |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 7849 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7850 | pf->num_fdsb_msix = 1; |
| 7851 | vec--; |
| 7852 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7853 | pf->num_lan_msix = min_t(int, |
| 7854 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 7855 | pf->num_lan_msix); |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7856 | pf->num_lan_qps = pf->num_lan_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7857 | #ifdef I40E_FCOE |
| 7858 | /* give one vector to FCoE */ |
| 7859 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7860 | pf->num_fcoe_msix = 1; |
| 7861 | vec--; |
| 7862 | } |
| 7863 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7864 | break; |
| 7865 | } |
| 7866 | } |
| 7867 | |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 7868 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 7869 | (pf->num_fdsb_msix == 0)) { |
| 7870 | dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n"); |
| 7871 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7872 | } |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7873 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7874 | (pf->num_vmdq_msix == 0)) { |
| 7875 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 7876 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 7877 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7878 | |
| 7879 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 7880 | (pf->num_iwarp_msix == 0)) { |
| 7881 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 7882 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 7883 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7884 | #ifdef I40E_FCOE |
| 7885 | |
| 7886 | if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { |
| 7887 | dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n"); |
| 7888 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 7889 | } |
| 7890 | #endif |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7891 | i40e_debug(&pf->hw, I40E_DEBUG_INIT, |
| 7892 | "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n", |
| 7893 | pf->num_lan_msix, |
| 7894 | pf->num_vmdq_msix * pf->num_vmdq_vsis, |
| 7895 | pf->num_fdsb_msix, |
| 7896 | pf->num_iwarp_msix); |
| 7897 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7898 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7899 | } |
| 7900 | |
| 7901 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7902 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7903 | * @vsi: the VSI being configured |
| 7904 | * @v_idx: index of the vector in the vsi struct |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7905 | * @cpu: cpu to be used on affinity_mask |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7906 | * |
| 7907 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 7908 | **/ |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7909 | 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] | 7910 | { |
| 7911 | struct i40e_q_vector *q_vector; |
| 7912 | |
| 7913 | /* allocate q_vector */ |
| 7914 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 7915 | if (!q_vector) |
| 7916 | return -ENOMEM; |
| 7917 | |
| 7918 | q_vector->vsi = vsi; |
| 7919 | q_vector->v_idx = v_idx; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7920 | cpumask_set_cpu(cpu, &q_vector->affinity_mask); |
| 7921 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7922 | if (vsi->netdev) |
| 7923 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 7924 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7925 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 7926 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 7927 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 7928 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7929 | /* tie q_vector and vsi together */ |
| 7930 | vsi->q_vectors[v_idx] = q_vector; |
| 7931 | |
| 7932 | return 0; |
| 7933 | } |
| 7934 | |
| 7935 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7936 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7937 | * @vsi: the VSI being configured |
| 7938 | * |
| 7939 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 7940 | * return -ENOMEM. |
| 7941 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7942 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7943 | { |
| 7944 | struct i40e_pf *pf = vsi->back; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7945 | int err, v_idx, num_q_vectors, current_cpu; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7946 | |
| 7947 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 7948 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7949 | num_q_vectors = vsi->num_q_vectors; |
| 7950 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 7951 | num_q_vectors = 1; |
| 7952 | else |
| 7953 | return -EINVAL; |
| 7954 | |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7955 | current_cpu = cpumask_first(cpu_online_mask); |
| 7956 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7957 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7958 | err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7959 | if (err) |
| 7960 | goto err_out; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7961 | current_cpu = cpumask_next(current_cpu, cpu_online_mask); |
| 7962 | if (unlikely(current_cpu >= nr_cpu_ids)) |
| 7963 | current_cpu = cpumask_first(cpu_online_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7964 | } |
| 7965 | |
| 7966 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7967 | |
| 7968 | err_out: |
| 7969 | while (v_idx--) |
| 7970 | i40e_free_q_vector(vsi, v_idx); |
| 7971 | |
| 7972 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7973 | } |
| 7974 | |
| 7975 | /** |
| 7976 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 7977 | * @pf: board private structure to initialize |
| 7978 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7979 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7980 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7981 | int vectors = 0; |
| 7982 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7983 | |
| 7984 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7985 | vectors = i40e_init_msix(pf); |
| 7986 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7987 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7988 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7989 | #ifdef I40E_FCOE |
| 7990 | I40E_FLAG_FCOE_ENABLED | |
| 7991 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7992 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7993 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 7994 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7995 | I40E_FLAG_SRIOV_ENABLED | |
| 7996 | I40E_FLAG_FD_SB_ENABLED | |
| 7997 | I40E_FLAG_FD_ATR_ENABLED | |
| 7998 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7999 | |
| 8000 | /* rework the queue expectations without MSIX */ |
| 8001 | i40e_determine_queue_usage(pf); |
| 8002 | } |
| 8003 | } |
| 8004 | |
| 8005 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 8006 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8007 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8008 | vectors = pci_enable_msi(pf->pdev); |
| 8009 | if (vectors < 0) { |
| 8010 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 8011 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8012 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 8013 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8014 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8015 | } |
| 8016 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 8017 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8018 | 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] | 8019 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8020 | /* set up vector assignment tracking */ |
| 8021 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 8022 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8023 | if (!pf->irq_pile) { |
| 8024 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 8025 | return -ENOMEM; |
| 8026 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8027 | pf->irq_pile->num_entries = vectors; |
| 8028 | pf->irq_pile->search_hint = 0; |
| 8029 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 8030 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 8031 | (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] | 8032 | |
| 8033 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8034 | } |
| 8035 | |
| 8036 | /** |
| 8037 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 8038 | * @pf: board private structure |
| 8039 | * |
| 8040 | * This sets up the handler for MSIX 0, which is used to manage the |
| 8041 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 8042 | * when in MSI or Legacy interrupt mode. |
| 8043 | **/ |
| 8044 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 8045 | { |
| 8046 | struct i40e_hw *hw = &pf->hw; |
| 8047 | int err = 0; |
| 8048 | |
| 8049 | /* Only request the irq if this is the first time through, and |
| 8050 | * not when we're rebuilding after a Reset |
| 8051 | */ |
| 8052 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 8053 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8054 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8055 | if (err) { |
| 8056 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8057 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8058 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8059 | return -EFAULT; |
| 8060 | } |
| 8061 | } |
| 8062 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 8063 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8064 | |
| 8065 | /* associate no queues to the misc vector */ |
| 8066 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 8067 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 8068 | |
| 8069 | i40e_flush(hw); |
| 8070 | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 8071 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8072 | |
| 8073 | return err; |
| 8074 | } |
| 8075 | |
| 8076 | /** |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8077 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 8078 | * @vsi: vsi structure |
| 8079 | * @seed: RSS hash seed |
| 8080 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8081 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8082 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8083 | { |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8084 | struct i40e_pf *pf = vsi->back; |
| 8085 | struct i40e_hw *hw = &pf->hw; |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8086 | int ret = 0; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8087 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8088 | if (seed) { |
| 8089 | struct i40e_aqc_get_set_rss_key_data *seed_dw = |
| 8090 | (struct i40e_aqc_get_set_rss_key_data *)seed; |
| 8091 | ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw); |
| 8092 | if (ret) { |
| 8093 | dev_info(&pf->pdev->dev, |
| 8094 | "Cannot set RSS key, err %s aq_err %s\n", |
| 8095 | i40e_stat_str(hw, ret), |
| 8096 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8097 | return ret; |
| 8098 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8099 | } |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8100 | if (lut) { |
| 8101 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8102 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8103 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8104 | if (ret) { |
| 8105 | dev_info(&pf->pdev->dev, |
| 8106 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 8107 | i40e_stat_str(hw, ret), |
| 8108 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8109 | return ret; |
| 8110 | } |
| 8111 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8112 | return ret; |
| 8113 | } |
| 8114 | |
| 8115 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8116 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 8117 | * @vsi: Pointer to vsi structure |
| 8118 | * @seed: Buffter to store the hash keys |
| 8119 | * @lut: Buffer to store the lookup table entries |
| 8120 | * @lut_size: Size of buffer to store the lookup table entries |
| 8121 | * |
| 8122 | * Return 0 on success, negative on failure |
| 8123 | */ |
| 8124 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8125 | u8 *lut, u16 lut_size) |
| 8126 | { |
| 8127 | struct i40e_pf *pf = vsi->back; |
| 8128 | struct i40e_hw *hw = &pf->hw; |
| 8129 | int ret = 0; |
| 8130 | |
| 8131 | if (seed) { |
| 8132 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 8133 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 8134 | if (ret) { |
| 8135 | dev_info(&pf->pdev->dev, |
| 8136 | "Cannot get RSS key, err %s aq_err %s\n", |
| 8137 | i40e_stat_str(&pf->hw, ret), |
| 8138 | i40e_aq_str(&pf->hw, |
| 8139 | pf->hw.aq.asq_last_status)); |
| 8140 | return ret; |
| 8141 | } |
| 8142 | } |
| 8143 | |
| 8144 | if (lut) { |
| 8145 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 8146 | |
| 8147 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8148 | if (ret) { |
| 8149 | dev_info(&pf->pdev->dev, |
| 8150 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 8151 | i40e_stat_str(&pf->hw, ret), |
| 8152 | i40e_aq_str(&pf->hw, |
| 8153 | pf->hw.aq.asq_last_status)); |
| 8154 | return ret; |
| 8155 | } |
| 8156 | } |
| 8157 | |
| 8158 | return ret; |
| 8159 | } |
| 8160 | |
| 8161 | /** |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8162 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 8163 | * @vsi: VSI structure |
| 8164 | **/ |
| 8165 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 8166 | { |
| 8167 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 8168 | struct i40e_pf *pf = vsi->back; |
| 8169 | u8 *lut; |
| 8170 | int ret; |
| 8171 | |
| 8172 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) |
| 8173 | return 0; |
| 8174 | |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8175 | if (!vsi->rss_size) |
| 8176 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8177 | vsi->num_queue_pairs); |
| 8178 | if (!vsi->rss_size) |
| 8179 | return -EINVAL; |
| 8180 | |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8181 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8182 | if (!lut) |
| 8183 | return -ENOMEM; |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8184 | /* Use the user configured hash keys and lookup table if there is one, |
| 8185 | * otherwise use default |
| 8186 | */ |
| 8187 | if (vsi->rss_lut_user) |
| 8188 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8189 | else |
| 8190 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
| 8191 | if (vsi->rss_hkey_user) |
| 8192 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8193 | else |
| 8194 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8195 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 8196 | kfree(lut); |
| 8197 | |
| 8198 | return ret; |
| 8199 | } |
| 8200 | |
| 8201 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8202 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8203 | * @vsi: Pointer to vsi structure |
| 8204 | * @seed: RSS hash seed |
| 8205 | * @lut: Lookup table |
| 8206 | * @lut_size: Lookup table size |
| 8207 | * |
| 8208 | * Returns 0 on success, negative on failure |
| 8209 | **/ |
| 8210 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8211 | const u8 *lut, u16 lut_size) |
| 8212 | { |
| 8213 | struct i40e_pf *pf = vsi->back; |
| 8214 | struct i40e_hw *hw = &pf->hw; |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8215 | u16 vf_id = vsi->vf_id; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8216 | u8 i; |
| 8217 | |
| 8218 | /* Fill out hash function seed */ |
| 8219 | if (seed) { |
| 8220 | u32 *seed_dw = (u32 *)seed; |
| 8221 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8222 | if (vsi->type == I40E_VSI_MAIN) { |
| 8223 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 8224 | i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), |
| 8225 | seed_dw[i]); |
| 8226 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8227 | for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++) |
| 8228 | i40e_write_rx_ctl(hw, |
| 8229 | I40E_VFQF_HKEY1(i, vf_id), |
| 8230 | seed_dw[i]); |
| 8231 | } else { |
| 8232 | dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n"); |
| 8233 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8234 | } |
| 8235 | |
| 8236 | if (lut) { |
| 8237 | u32 *lut_dw = (u32 *)lut; |
| 8238 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8239 | if (vsi->type == I40E_VSI_MAIN) { |
| 8240 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8241 | return -EINVAL; |
| 8242 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8243 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8244 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8245 | if (lut_size != I40E_VF_HLUT_ARRAY_SIZE) |
| 8246 | return -EINVAL; |
| 8247 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8248 | i40e_write_rx_ctl(hw, |
| 8249 | I40E_VFQF_HLUT1(i, vf_id), |
| 8250 | lut_dw[i]); |
| 8251 | } else { |
| 8252 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8253 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8254 | } |
| 8255 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8256 | |
| 8257 | return 0; |
| 8258 | } |
| 8259 | |
| 8260 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8261 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8262 | * @vsi: Pointer to VSI structure |
| 8263 | * @seed: Buffer to store the keys |
| 8264 | * @lut: Buffer to store the lookup table entries |
| 8265 | * @lut_size: Size of buffer to store the lookup table entries |
| 8266 | * |
| 8267 | * Returns 0 on success, negative on failure |
| 8268 | */ |
| 8269 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8270 | u8 *lut, u16 lut_size) |
| 8271 | { |
| 8272 | struct i40e_pf *pf = vsi->back; |
| 8273 | struct i40e_hw *hw = &pf->hw; |
| 8274 | u16 i; |
| 8275 | |
| 8276 | if (seed) { |
| 8277 | u32 *seed_dw = (u32 *)seed; |
| 8278 | |
| 8279 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8280 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8281 | } |
| 8282 | if (lut) { |
| 8283 | u32 *lut_dw = (u32 *)lut; |
| 8284 | |
| 8285 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8286 | return -EINVAL; |
| 8287 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8288 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8289 | } |
| 8290 | |
| 8291 | return 0; |
| 8292 | } |
| 8293 | |
| 8294 | /** |
| 8295 | * i40e_config_rss - Configure RSS keys and lut |
| 8296 | * @vsi: Pointer to VSI structure |
| 8297 | * @seed: RSS hash seed |
| 8298 | * @lut: Lookup table |
| 8299 | * @lut_size: Lookup table size |
| 8300 | * |
| 8301 | * Returns 0 on success, negative on failure |
| 8302 | */ |
| 8303 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8304 | { |
| 8305 | struct i40e_pf *pf = vsi->back; |
| 8306 | |
| 8307 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8308 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8309 | else |
| 8310 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8311 | } |
| 8312 | |
| 8313 | /** |
| 8314 | * i40e_get_rss - Get RSS keys and lut |
| 8315 | * @vsi: Pointer to VSI structure |
| 8316 | * @seed: Buffer to store the keys |
| 8317 | * @lut: Buffer to store the lookup table entries |
| 8318 | * lut_size: Size of buffer to store the lookup table entries |
| 8319 | * |
| 8320 | * Returns 0 on success, negative on failure |
| 8321 | */ |
| 8322 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8323 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8324 | struct i40e_pf *pf = vsi->back; |
| 8325 | |
| 8326 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8327 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8328 | else |
| 8329 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8330 | } |
| 8331 | |
| 8332 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8333 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8334 | * @pf: Pointer to board private structure |
| 8335 | * @lut: Lookup table |
| 8336 | * @rss_table_size: Lookup table size |
| 8337 | * @rss_size: Range of queue number for hashing |
| 8338 | */ |
Alan Brady | f158235 | 2016-08-24 11:33:46 -0700 | [diff] [blame] | 8339 | void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8340 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8341 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8342 | u16 i; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8343 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8344 | for (i = 0; i < rss_table_size; i++) |
| 8345 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8346 | } |
| 8347 | |
| 8348 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8349 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8350 | * @pf: board private structure |
| 8351 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8352 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8353 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8354 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8355 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8356 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8357 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8358 | u32 reg_val; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8359 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8360 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8361 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8362 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8363 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 8364 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8365 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8366 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8367 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8368 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8369 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8370 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8371 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8372 | reg_val = (pf->rss_table_size == 512) ? |
| 8373 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8374 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8375 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8376 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8377 | /* Determine the RSS size of the VSI */ |
| 8378 | if (!vsi->rss_size) |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8379 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8380 | vsi->num_queue_pairs); |
Mitch Williams | a4fa59c | 2016-09-12 14:18:43 -0700 | [diff] [blame] | 8381 | if (!vsi->rss_size) |
| 8382 | return -EINVAL; |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8383 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8384 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8385 | if (!lut) |
| 8386 | return -ENOMEM; |
| 8387 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8388 | /* Use user configured lut if there is one, otherwise use default */ |
| 8389 | if (vsi->rss_lut_user) |
| 8390 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8391 | else |
| 8392 | 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] | 8393 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8394 | /* Use user configured hash key if there is one, otherwise |
| 8395 | * use default. |
| 8396 | */ |
| 8397 | if (vsi->rss_hkey_user) |
| 8398 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8399 | else |
| 8400 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8401 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8402 | kfree(lut); |
| 8403 | |
| 8404 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8405 | } |
| 8406 | |
| 8407 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8408 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8409 | * @pf: board private structure |
| 8410 | * @queue_count: the requested queue count for rss. |
| 8411 | * |
| 8412 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8413 | * count which may be different from the requested queue count. |
| 8414 | **/ |
| 8415 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8416 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8417 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8418 | int new_rss_size; |
| 8419 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8420 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8421 | return 0; |
| 8422 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8423 | 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] | 8424 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8425 | if (queue_count != vsi->num_queue_pairs) { |
| 8426 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8427 | i40e_prep_for_reset(pf); |
| 8428 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8429 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8430 | |
| 8431 | i40e_reset_and_rebuild(pf, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8432 | |
| 8433 | /* Discard the user configured hash keys and lut, if less |
| 8434 | * queues are enabled. |
| 8435 | */ |
| 8436 | if (queue_count < vsi->rss_size) { |
| 8437 | i40e_clear_rss_config_user(vsi); |
| 8438 | dev_dbg(&pf->pdev->dev, |
| 8439 | "discard user configured hash keys and lut\n"); |
| 8440 | } |
| 8441 | |
| 8442 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8443 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8444 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8445 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8446 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8447 | } |
Lihong Yang | 1281505 | 2016-09-27 11:28:48 -0700 | [diff] [blame] | 8448 | dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n", |
| 8449 | vsi->req_queue_pairs, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8450 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8451 | } |
| 8452 | |
| 8453 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8454 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 8455 | * @pf: board private structure |
| 8456 | **/ |
| 8457 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 8458 | { |
| 8459 | i40e_status status; |
| 8460 | bool min_valid, max_valid; |
| 8461 | u32 max_bw, min_bw; |
| 8462 | |
| 8463 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8464 | &min_valid, &max_valid); |
| 8465 | |
| 8466 | if (!status) { |
| 8467 | if (min_valid) |
| 8468 | pf->npar_min_bw = min_bw; |
| 8469 | if (max_valid) |
| 8470 | pf->npar_max_bw = max_bw; |
| 8471 | } |
| 8472 | |
| 8473 | return status; |
| 8474 | } |
| 8475 | |
| 8476 | /** |
| 8477 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 8478 | * @pf: board private structure |
| 8479 | **/ |
| 8480 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 8481 | { |
| 8482 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8483 | i40e_status status; |
| 8484 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8485 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8486 | 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] | 8487 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8488 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 8489 | |
| 8490 | /* Set the new bandwidths */ |
| 8491 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8492 | |
| 8493 | return status; |
| 8494 | } |
| 8495 | |
| 8496 | /** |
| 8497 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 8498 | * @pf: board private structure |
| 8499 | **/ |
| 8500 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 8501 | { |
| 8502 | /* Commit temporary BW setting to permanent NVM image */ |
| 8503 | enum i40e_admin_queue_err last_aq_status; |
| 8504 | i40e_status ret; |
| 8505 | u16 nvm_word; |
| 8506 | |
| 8507 | if (pf->hw.partition_id != 1) { |
| 8508 | dev_info(&pf->pdev->dev, |
| 8509 | "Commit BW only works on partition 1! This is partition %d", |
| 8510 | pf->hw.partition_id); |
| 8511 | ret = I40E_NOT_SUPPORTED; |
| 8512 | goto bw_commit_out; |
| 8513 | } |
| 8514 | |
| 8515 | /* Acquire NVM for read access */ |
| 8516 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8517 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8518 | if (ret) { |
| 8519 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8520 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8521 | i40e_stat_str(&pf->hw, ret), |
| 8522 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8523 | goto bw_commit_out; |
| 8524 | } |
| 8525 | |
| 8526 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8527 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8528 | I40E_SR_NVM_CONTROL_WORD, |
| 8529 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8530 | false, NULL); |
| 8531 | /* Save off last admin queue command status before releasing |
| 8532 | * the NVM |
| 8533 | */ |
| 8534 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8535 | i40e_release_nvm(&pf->hw); |
| 8536 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8537 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8538 | i40e_stat_str(&pf->hw, ret), |
| 8539 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8540 | goto bw_commit_out; |
| 8541 | } |
| 8542 | |
| 8543 | /* Wait a bit for NVM release to complete */ |
| 8544 | msleep(50); |
| 8545 | |
| 8546 | /* Acquire NVM for write access */ |
| 8547 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8548 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8549 | if (ret) { |
| 8550 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8551 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8552 | i40e_stat_str(&pf->hw, ret), |
| 8553 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8554 | goto bw_commit_out; |
| 8555 | } |
| 8556 | /* Write it back out unchanged to initiate update NVM, |
| 8557 | * which will force a write of the shadow (alt) RAM to |
| 8558 | * the NVM - thus storing the bandwidth values permanently. |
| 8559 | */ |
| 8560 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8561 | I40E_SR_NVM_CONTROL_WORD, |
| 8562 | 0x10, sizeof(nvm_word), |
| 8563 | &nvm_word, true, NULL); |
| 8564 | /* Save off last admin queue command status before releasing |
| 8565 | * the NVM |
| 8566 | */ |
| 8567 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8568 | i40e_release_nvm(&pf->hw); |
| 8569 | if (ret) |
| 8570 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8571 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8572 | i40e_stat_str(&pf->hw, ret), |
| 8573 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8574 | bw_commit_out: |
| 8575 | |
| 8576 | return ret; |
| 8577 | } |
| 8578 | |
| 8579 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8580 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8581 | * @pf: board private structure to initialize |
| 8582 | * |
| 8583 | * i40e_sw_init initializes the Adapter private data structure. |
| 8584 | * Fields are initialized based on PCI device information and |
| 8585 | * OS network device settings (MTU size). |
| 8586 | **/ |
| 8587 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8588 | { |
| 8589 | int err = 0; |
| 8590 | int size; |
| 8591 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8592 | /* Set default capability flags */ |
| 8593 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8594 | I40E_FLAG_MSI_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8595 | I40E_FLAG_MSIX_ENABLED; |
| 8596 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8597 | /* Set default ITR */ |
| 8598 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8599 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8600 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8601 | /* Depending on PF configurations, it is possible that the RSS |
| 8602 | * maximum might end up larger than the available queues |
| 8603 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8604 | 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] | 8605 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8606 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8607 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8608 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8609 | if (pf->hw.func_caps.rss) { |
| 8610 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8611 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8612 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8613 | } |
| 8614 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8615 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8616 | 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] | 8617 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8618 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8619 | if (i40e_get_npar_bw_setting(pf)) |
| 8620 | dev_warn(&pf->pdev->dev, |
| 8621 | "Could not get NPAR bw settings\n"); |
| 8622 | else |
| 8623 | dev_info(&pf->pdev->dev, |
| 8624 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 8625 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8626 | } |
| 8627 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8628 | /* FW/NVM is not yet fixed in this regard */ |
| 8629 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8630 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8631 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8632 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8633 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8634 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8635 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8636 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8637 | else |
| 8638 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8639 | pf->fdir_pf_filter_count = |
| 8640 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8641 | pf->hw.fdir_shared_filter_count = |
| 8642 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8643 | } |
| 8644 | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8645 | if (i40e_is_mac_710(&pf->hw) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8646 | (((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] | 8647 | (pf->hw.aq.fw_maj_ver < 4))) { |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8648 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8649 | /* No DCB support for FW < v4.33 */ |
| 8650 | pf->flags |= I40E_FLAG_NO_DCB_SUPPORT; |
| 8651 | } |
| 8652 | |
| 8653 | /* Disable FW LLDP if FW < v4.3 */ |
| 8654 | if (i40e_is_mac_710(&pf->hw) && |
| 8655 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 8656 | (pf->hw.aq.fw_maj_ver < 4))) |
| 8657 | pf->flags |= I40E_FLAG_STOP_FW_LLDP; |
| 8658 | |
| 8659 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
| 8660 | if (i40e_is_mac_710(&pf->hw) && |
| 8661 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 8662 | (pf->hw.aq.fw_maj_ver >= 5))) |
| 8663 | pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8664 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8665 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8666 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8667 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 8668 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8669 | } |
| 8670 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8671 | if (pf->hw.func_caps.iwarp) { |
| 8672 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 8673 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 8674 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 8675 | } |
| 8676 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8677 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 8678 | i40e_init_pf_fcoe(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8679 | |
| 8680 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8681 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 8682 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8683 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 8684 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 8685 | pf->num_req_vfs = min_t(int, |
| 8686 | pf->hw.func_caps.num_vfs, |
| 8687 | I40E_MAX_VF_COUNT); |
| 8688 | } |
| 8689 | #endif /* CONFIG_PCI_IOV */ |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8690 | if (pf->hw.mac.type == I40E_MAC_X722) { |
| 8691 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE | |
| 8692 | I40E_FLAG_128_QP_RSS_CAPABLE | |
| 8693 | I40E_FLAG_HW_ATR_EVICT_CAPABLE | |
| 8694 | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE | |
| 8695 | I40E_FLAG_WB_ON_ITR_CAPABLE | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8696 | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
Jesse Brandeburg | 8e2cc0e | 2016-02-29 11:00:24 -0800 | [diff] [blame] | 8697 | I40E_FLAG_NO_PCI_LINK_CHECK | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8698 | I40E_FLAG_USE_SET_LLDP_MIB | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8699 | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8700 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 8701 | ((pf->hw.aq.api_maj_ver == 1) && |
| 8702 | (pf->hw.aq.api_min_ver > 4))) { |
| 8703 | /* Supported in FW API version higher than 1.4 */ |
| 8704 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 8705 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
| 8706 | } else { |
| 8707 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8708 | } |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8709 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8710 | pf->eeprom_version = 0xDEAD; |
| 8711 | pf->lan_veb = I40E_NO_VEB; |
| 8712 | pf->lan_vsi = I40E_NO_VSI; |
| 8713 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 8714 | /* By default FW has this off for performance reasons */ |
| 8715 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 8716 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8717 | /* set up queue assignment tracking */ |
| 8718 | size = sizeof(struct i40e_lump_tracking) |
| 8719 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 8720 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 8721 | if (!pf->qp_pile) { |
| 8722 | err = -ENOMEM; |
| 8723 | goto sw_init_done; |
| 8724 | } |
| 8725 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 8726 | pf->qp_pile->search_hint = 0; |
| 8727 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 8728 | pf->tx_timeout_recovery_level = 1; |
| 8729 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8730 | mutex_init(&pf->switch_mutex); |
| 8731 | |
Greg Rose | c668a12 | 2015-02-26 16:10:39 +0000 | [diff] [blame] | 8732 | /* If NPAR is enabled nudge the Tx scheduler */ |
| 8733 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) |
| 8734 | i40e_set_npar_bw_setting(pf); |
| 8735 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8736 | sw_init_done: |
| 8737 | return err; |
| 8738 | } |
| 8739 | |
| 8740 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8741 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 8742 | * @pf: board private structure to initialize |
| 8743 | * @features: the feature set that the stack is suggesting |
| 8744 | * |
| 8745 | * returns a bool to indicate if reset needs to happen |
| 8746 | **/ |
| 8747 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 8748 | { |
| 8749 | bool need_reset = false; |
| 8750 | |
| 8751 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 8752 | * the state changed, we need to reset. |
| 8753 | */ |
| 8754 | if (features & NETIF_F_NTUPLE) { |
| 8755 | /* Enable filters and mark for reset */ |
| 8756 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 8757 | need_reset = true; |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 8758 | /* enable FD_SB only if there is MSI-X vector */ |
| 8759 | if (pf->num_fdsb_msix > 0) |
| 8760 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8761 | } else { |
| 8762 | /* turn off filters, mark for reset and clear SW filter list */ |
| 8763 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8764 | need_reset = true; |
| 8765 | i40e_fdir_filter_exit(pf); |
| 8766 | } |
| 8767 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8768 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 8769 | /* reset fd counters */ |
| 8770 | pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0; |
| 8771 | pf->fdir_pf_active_filters = 0; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8772 | /* if ATR was auto disabled it can be re-enabled. */ |
| 8773 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 8774 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8775 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 8776 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 8777 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
| 8778 | } |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8779 | } |
| 8780 | return need_reset; |
| 8781 | } |
| 8782 | |
| 8783 | /** |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8784 | * i40e_clear_rss_lut - clear the rx hash lookup table |
| 8785 | * @vsi: the VSI being configured |
| 8786 | **/ |
| 8787 | static void i40e_clear_rss_lut(struct i40e_vsi *vsi) |
| 8788 | { |
| 8789 | struct i40e_pf *pf = vsi->back; |
| 8790 | struct i40e_hw *hw = &pf->hw; |
| 8791 | u16 vf_id = vsi->vf_id; |
| 8792 | u8 i; |
| 8793 | |
| 8794 | if (vsi->type == I40E_VSI_MAIN) { |
| 8795 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8796 | wr32(hw, I40E_PFQF_HLUT(i), 0); |
| 8797 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8798 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8799 | i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0); |
| 8800 | } else { |
| 8801 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8802 | } |
| 8803 | } |
| 8804 | |
| 8805 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8806 | * i40e_set_features - set the netdev feature flags |
| 8807 | * @netdev: ptr to the netdev being adjusted |
| 8808 | * @features: the feature set that the stack is suggesting |
| 8809 | **/ |
| 8810 | static int i40e_set_features(struct net_device *netdev, |
| 8811 | netdev_features_t features) |
| 8812 | { |
| 8813 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8814 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8815 | struct i40e_pf *pf = vsi->back; |
| 8816 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8817 | |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8818 | if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH)) |
| 8819 | i40e_pf_config_rss(pf); |
| 8820 | else if (!(features & NETIF_F_RXHASH) && |
| 8821 | netdev->features & NETIF_F_RXHASH) |
| 8822 | i40e_clear_rss_lut(vsi); |
| 8823 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8824 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8825 | i40e_vlan_stripping_enable(vsi); |
| 8826 | else |
| 8827 | i40e_vlan_stripping_disable(vsi); |
| 8828 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8829 | need_reset = i40e_set_ntuple(pf, features); |
| 8830 | |
| 8831 | if (need_reset) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8832 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8833 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8834 | return 0; |
| 8835 | } |
| 8836 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8837 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8838 | * 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] | 8839 | * @pf: board private structure |
| 8840 | * @port: The UDP port to look up |
| 8841 | * |
| 8842 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 8843 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8844 | 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] | 8845 | { |
| 8846 | u8 i; |
| 8847 | |
| 8848 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8849 | if (pf->udp_ports[i].index == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8850 | return i; |
| 8851 | } |
| 8852 | |
| 8853 | return i; |
| 8854 | } |
| 8855 | |
| 8856 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8857 | * 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] | 8858 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8859 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8860 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8861 | static void i40e_udp_tunnel_add(struct net_device *netdev, |
| 8862 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8863 | { |
| 8864 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8865 | struct i40e_vsi *vsi = np->vsi; |
| 8866 | struct i40e_pf *pf = vsi->back; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8867 | __be16 port = ti->port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8868 | u8 next_idx; |
| 8869 | u8 idx; |
| 8870 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8871 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8872 | |
| 8873 | /* Check if port already exists */ |
| 8874 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8875 | netdev_info(netdev, "port %d already offloaded\n", |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8876 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8877 | return; |
| 8878 | } |
| 8879 | |
| 8880 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8881 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8882 | |
| 8883 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8884 | 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] | 8885 | ntohs(port)); |
| 8886 | return; |
| 8887 | } |
| 8888 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8889 | switch (ti->type) { |
| 8890 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8891 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 8892 | break; |
| 8893 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8894 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8895 | return; |
| 8896 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 8897 | break; |
| 8898 | default: |
| 8899 | return; |
| 8900 | } |
| 8901 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8902 | /* New port: add it and mark its index in the bitmap */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8903 | pf->udp_ports[next_idx].index = port; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8904 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8905 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8906 | } |
| 8907 | |
| 8908 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8909 | * 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] | 8910 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8911 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8912 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8913 | static void i40e_udp_tunnel_del(struct net_device *netdev, |
| 8914 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8915 | { |
| 8916 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8917 | struct i40e_vsi *vsi = np->vsi; |
| 8918 | struct i40e_pf *pf = vsi->back; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8919 | __be16 port = ti->port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8920 | u8 idx; |
| 8921 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8922 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8923 | |
| 8924 | /* Check if port already exists */ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8925 | if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS) |
| 8926 | goto not_found; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8927 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8928 | switch (ti->type) { |
| 8929 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8930 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN) |
| 8931 | goto not_found; |
| 8932 | break; |
| 8933 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8934 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE) |
| 8935 | goto not_found; |
| 8936 | break; |
| 8937 | default: |
| 8938 | goto not_found; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8939 | } |
| 8940 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8941 | /* if port exists, set it to 0 (mark for deletion) |
| 8942 | * and make it pending |
| 8943 | */ |
| 8944 | pf->udp_ports[idx].index = 0; |
| 8945 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8946 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8947 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8948 | return; |
| 8949 | not_found: |
| 8950 | netdev_warn(netdev, "UDP port %d was not found, not deleting\n", |
| 8951 | ntohs(port)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8952 | } |
| 8953 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8954 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 8955 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8956 | { |
| 8957 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8958 | struct i40e_pf *pf = np->vsi->back; |
| 8959 | struct i40e_hw *hw = &pf->hw; |
| 8960 | |
| 8961 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 8962 | return -EOPNOTSUPP; |
| 8963 | |
| 8964 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 8965 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 8966 | |
| 8967 | return 0; |
| 8968 | } |
| 8969 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 8970 | /** |
| 8971 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 8972 | * @ndm: the input from the stack |
| 8973 | * @tb: pointer to array of nladdr (unused) |
| 8974 | * @dev: the net device pointer |
| 8975 | * @addr: the MAC address entry being added |
| 8976 | * @flags: instructions from stack about fdb operation |
| 8977 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8978 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 8979 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8980 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8981 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8982 | { |
| 8983 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8984 | struct i40e_pf *pf = np->vsi->back; |
| 8985 | int err = 0; |
| 8986 | |
| 8987 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 8988 | return -EOPNOTSUPP; |
| 8989 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 8990 | if (vid) { |
| 8991 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 8992 | return -EINVAL; |
| 8993 | } |
| 8994 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8995 | /* Hardware does not support aging addresses so if a |
| 8996 | * ndm_state is given only allow permanent addresses |
| 8997 | */ |
| 8998 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 8999 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 9000 | return -EINVAL; |
| 9001 | } |
| 9002 | |
| 9003 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 9004 | err = dev_uc_add_excl(dev, addr); |
| 9005 | else if (is_multicast_ether_addr(addr)) |
| 9006 | err = dev_mc_add_excl(dev, addr); |
| 9007 | else |
| 9008 | err = -EINVAL; |
| 9009 | |
| 9010 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 9011 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 9012 | err = 0; |
| 9013 | |
| 9014 | return err; |
| 9015 | } |
| 9016 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9017 | /** |
| 9018 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 9019 | * @dev: the netdev being configured |
| 9020 | * @nlh: RTNL message |
| 9021 | * |
| 9022 | * Inserts a new hardware bridge if not already created and |
| 9023 | * enables the bridging mode requested (VEB or VEPA). If the |
| 9024 | * hardware bridge has already been inserted and the request |
| 9025 | * is to change the mode then that requires a PF reset to |
| 9026 | * allow rebuild of the components with required hardware |
| 9027 | * bridge mode enabled. |
| 9028 | **/ |
| 9029 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 9030 | struct nlmsghdr *nlh, |
| 9031 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9032 | { |
| 9033 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9034 | struct i40e_vsi *vsi = np->vsi; |
| 9035 | struct i40e_pf *pf = vsi->back; |
| 9036 | struct i40e_veb *veb = NULL; |
| 9037 | struct nlattr *attr, *br_spec; |
| 9038 | int i, rem; |
| 9039 | |
| 9040 | /* Only for PF VSI for now */ |
| 9041 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9042 | return -EOPNOTSUPP; |
| 9043 | |
| 9044 | /* Find the HW bridge for PF VSI */ |
| 9045 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9046 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9047 | veb = pf->veb[i]; |
| 9048 | } |
| 9049 | |
| 9050 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 9051 | |
| 9052 | nla_for_each_nested(attr, br_spec, rem) { |
| 9053 | __u16 mode; |
| 9054 | |
| 9055 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 9056 | continue; |
| 9057 | |
| 9058 | mode = nla_get_u16(attr); |
| 9059 | if ((mode != BRIDGE_MODE_VEPA) && |
| 9060 | (mode != BRIDGE_MODE_VEB)) |
| 9061 | return -EINVAL; |
| 9062 | |
| 9063 | /* Insert a new HW bridge */ |
| 9064 | if (!veb) { |
| 9065 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9066 | vsi->tc_config.enabled_tc); |
| 9067 | if (veb) { |
| 9068 | veb->bridge_mode = mode; |
| 9069 | i40e_config_bridge_mode(veb); |
| 9070 | } else { |
| 9071 | /* No Bridge HW offload available */ |
| 9072 | return -ENOENT; |
| 9073 | } |
| 9074 | break; |
| 9075 | } else if (mode != veb->bridge_mode) { |
| 9076 | /* Existing HW bridge but different mode needs reset */ |
| 9077 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9078 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 9079 | if (mode == BRIDGE_MODE_VEB) |
| 9080 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 9081 | else |
| 9082 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9083 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9084 | break; |
| 9085 | } |
| 9086 | } |
| 9087 | |
| 9088 | return 0; |
| 9089 | } |
| 9090 | |
| 9091 | /** |
| 9092 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 9093 | * @skb: skb buff |
| 9094 | * @pid: process id |
| 9095 | * @seq: RTNL message seq # |
| 9096 | * @dev: the netdev being configured |
| 9097 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 9098 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9099 | * |
| 9100 | * Return the mode in which the hardware bridge is operating in |
| 9101 | * i.e VEB or VEPA. |
| 9102 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9103 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 9104 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 9105 | u32 __always_unused filter_mask, |
| 9106 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9107 | { |
| 9108 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9109 | struct i40e_vsi *vsi = np->vsi; |
| 9110 | struct i40e_pf *pf = vsi->back; |
| 9111 | struct i40e_veb *veb = NULL; |
| 9112 | int i; |
| 9113 | |
| 9114 | /* Only for PF VSI for now */ |
| 9115 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9116 | return -EOPNOTSUPP; |
| 9117 | |
| 9118 | /* Find the HW bridge for the PF VSI */ |
| 9119 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9120 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9121 | veb = pf->veb[i]; |
| 9122 | } |
| 9123 | |
| 9124 | if (!veb) |
| 9125 | return 0; |
| 9126 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9127 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Huaibin Wang | 599b076 | 2016-09-26 09:51:18 +0200 | [diff] [blame] | 9128 | 0, 0, nlflags, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9129 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9130 | |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9131 | /** |
| 9132 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 9133 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 9134 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9135 | * @features: Offload features that the stack believes apply |
| 9136 | **/ |
| 9137 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 9138 | struct net_device *dev, |
| 9139 | netdev_features_t features) |
| 9140 | { |
Alexander Duyck | f114dca | 2016-10-25 16:08:46 -0700 | [diff] [blame] | 9141 | size_t len; |
| 9142 | |
| 9143 | /* No point in doing any of this if neither checksum nor GSO are |
| 9144 | * being requested for this frame. We can rule out both by just |
| 9145 | * checking for CHECKSUM_PARTIAL |
| 9146 | */ |
| 9147 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 9148 | return features; |
| 9149 | |
| 9150 | /* We cannot support GSO if the MSS is going to be less than |
| 9151 | * 64 bytes. If it is then we need to drop support for GSO. |
| 9152 | */ |
| 9153 | if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64)) |
| 9154 | features &= ~NETIF_F_GSO_MASK; |
| 9155 | |
| 9156 | /* MACLEN can support at most 63 words */ |
| 9157 | len = skb_network_header(skb) - skb->data; |
| 9158 | if (len & ~(63 * 2)) |
| 9159 | goto out_err; |
| 9160 | |
| 9161 | /* IPLEN and EIPLEN can support at most 127 dwords */ |
| 9162 | len = skb_transport_header(skb) - skb_network_header(skb); |
| 9163 | if (len & ~(127 * 4)) |
| 9164 | goto out_err; |
| 9165 | |
| 9166 | if (skb->encapsulation) { |
| 9167 | /* L4TUNLEN can support 127 words */ |
| 9168 | len = skb_inner_network_header(skb) - skb_transport_header(skb); |
| 9169 | if (len & ~(127 * 2)) |
| 9170 | goto out_err; |
| 9171 | |
| 9172 | /* IPLEN can support at most 127 dwords */ |
| 9173 | len = skb_inner_transport_header(skb) - |
| 9174 | skb_inner_network_header(skb); |
| 9175 | if (len & ~(127 * 4)) |
| 9176 | goto out_err; |
| 9177 | } |
| 9178 | |
| 9179 | /* No need to validate L4LEN as TCP is the only protocol with a |
| 9180 | * a flexible value and we support all possible values supported |
| 9181 | * by TCP, which is at most 15 dwords |
| 9182 | */ |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9183 | |
| 9184 | return features; |
Alexander Duyck | f114dca | 2016-10-25 16:08:46 -0700 | [diff] [blame] | 9185 | out_err: |
| 9186 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9187 | } |
| 9188 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 9189 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9190 | .ndo_open = i40e_open, |
| 9191 | .ndo_stop = i40e_close, |
| 9192 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 9193 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 9194 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 9195 | .ndo_validate_addr = eth_validate_addr, |
| 9196 | .ndo_set_mac_address = i40e_set_mac, |
| 9197 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 9198 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9199 | .ndo_tx_timeout = i40e_tx_timeout, |
| 9200 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 9201 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 9202 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9203 | .ndo_poll_controller = i40e_netpoll, |
| 9204 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9205 | .ndo_setup_tc = __i40e_setup_tc, |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9206 | #ifdef I40E_FCOE |
| 9207 | .ndo_fcoe_enable = i40e_fcoe_enable, |
| 9208 | .ndo_fcoe_disable = i40e_fcoe_disable, |
| 9209 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9210 | .ndo_set_features = i40e_set_features, |
| 9211 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 9212 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9213 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9214 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 9215 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 9216 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Anjali Singhai Jain | c3bbbd2 | 2016-04-01 03:56:07 -0700 | [diff] [blame] | 9217 | .ndo_set_vf_trust = i40e_ndo_set_vf_trust, |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9218 | .ndo_udp_tunnel_add = i40e_udp_tunnel_add, |
| 9219 | .ndo_udp_tunnel_del = i40e_udp_tunnel_del, |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9220 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9221 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9222 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9223 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 9224 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9225 | }; |
| 9226 | |
| 9227 | /** |
| 9228 | * i40e_config_netdev - Setup the netdev flags |
| 9229 | * @vsi: the VSI being configured |
| 9230 | * |
| 9231 | * Returns 0 on success, negative value on failure |
| 9232 | **/ |
| 9233 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 9234 | { |
| 9235 | struct i40e_pf *pf = vsi->back; |
| 9236 | struct i40e_hw *hw = &pf->hw; |
| 9237 | struct i40e_netdev_priv *np; |
| 9238 | struct net_device *netdev; |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame^] | 9239 | u8 broadcast[ETH_ALEN]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9240 | u8 mac_addr[ETH_ALEN]; |
| 9241 | int etherdev_size; |
| 9242 | |
| 9243 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9244 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9245 | if (!netdev) |
| 9246 | return -ENOMEM; |
| 9247 | |
| 9248 | vsi->netdev = netdev; |
| 9249 | np = netdev_priv(netdev); |
| 9250 | np->vsi = vsi; |
| 9251 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9252 | netdev->hw_enc_features |= NETIF_F_SG | |
| 9253 | NETIF_F_IP_CSUM | |
| 9254 | NETIF_F_IPV6_CSUM | |
| 9255 | NETIF_F_HIGHDMA | |
| 9256 | NETIF_F_SOFT_FEATURES | |
| 9257 | NETIF_F_TSO | |
| 9258 | NETIF_F_TSO_ECN | |
| 9259 | NETIF_F_TSO6 | |
| 9260 | NETIF_F_GSO_GRE | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9261 | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 9262 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 9263 | NETIF_F_GSO_IPXIP6 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9264 | NETIF_F_GSO_UDP_TUNNEL | |
| 9265 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9266 | NETIF_F_GSO_PARTIAL | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9267 | NETIF_F_SCTP_CRC | |
| 9268 | NETIF_F_RXHASH | |
| 9269 | NETIF_F_RXCSUM | |
Jesse Brandeburg | 5afdaaa | 2015-12-10 11:38:50 -0800 | [diff] [blame] | 9270 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9271 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9272 | if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)) |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9273 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
| 9274 | |
| 9275 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9276 | |
| 9277 | /* record features VLANs can make use of */ |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9278 | netdev->vlan_features |= netdev->hw_enc_features | |
| 9279 | NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9280 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9281 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9282 | netdev->hw_features |= NETIF_F_NTUPLE; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9283 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9284 | netdev->hw_features |= netdev->hw_enc_features | |
| 9285 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9286 | NETIF_F_HW_VLAN_CTAG_RX; |
| 9287 | |
| 9288 | netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9289 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9290 | |
| 9291 | if (vsi->type == I40E_VSI_MAIN) { |
| 9292 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9293 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9294 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 9295 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9296 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9297 | } else { |
| 9298 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 9299 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 9300 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9301 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9302 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9303 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 9304 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9305 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9306 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9307 | |
Jacob Keller | 435c084 | 2016-11-08 13:05:10 -0800 | [diff] [blame^] | 9308 | /* Add the broadcast filter so that we initially will receive |
| 9309 | * broadcast packets. Note that when a new VLAN is first added the |
| 9310 | * driver will convert all filters marked I40E_VLAN_ANY into VLAN |
| 9311 | * specific filters as part of transitioning into "vlan" operation. |
| 9312 | * When more VLANs are added, the driver will copy each existing MAC |
| 9313 | * filter and add it for the new VLAN. |
| 9314 | * |
| 9315 | * Broadcast filters are handled specially by |
| 9316 | * i40e_sync_filters_subtask, as the driver must to set the broadcast |
| 9317 | * promiscuous bit instead of adding this directly as a MAC/VLAN |
| 9318 | * filter. The subtask will update the correct broadcast promiscuous |
| 9319 | * bits as VLANs become active or inactive. |
| 9320 | */ |
| 9321 | eth_broadcast_addr(broadcast); |
| 9322 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 9323 | i40e_add_filter(vsi, broadcast, I40E_VLAN_ANY); |
| 9324 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 9325 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9326 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9327 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9328 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9329 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9330 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9331 | /* Setup netdev TC information */ |
| 9332 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9333 | |
| 9334 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9335 | netdev->watchdog_timeo = 5 * HZ; |
| 9336 | i40e_set_ethtool_ops(netdev); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9337 | #ifdef I40E_FCOE |
| 9338 | i40e_fcoe_config_netdev(netdev, vsi); |
| 9339 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9340 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 9341 | /* MTU range: 68 - 9706 */ |
| 9342 | netdev->min_mtu = ETH_MIN_MTU; |
| 9343 | netdev->max_mtu = I40E_MAX_RXBUFFER - |
| 9344 | (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
| 9345 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9346 | return 0; |
| 9347 | } |
| 9348 | |
| 9349 | /** |
| 9350 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9351 | * @vsi: the VSI being removed |
| 9352 | * |
| 9353 | * Returns 0 on success, negative value on failure |
| 9354 | **/ |
| 9355 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9356 | { |
| 9357 | /* remove default VSI is not allowed */ |
| 9358 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9359 | return; |
| 9360 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9361 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9362 | } |
| 9363 | |
| 9364 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9365 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9366 | * @vsi: the VSI being queried |
| 9367 | * |
| 9368 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9369 | **/ |
| 9370 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9371 | { |
| 9372 | struct i40e_veb *veb; |
| 9373 | struct i40e_pf *pf = vsi->back; |
| 9374 | |
| 9375 | /* Uplink is not a bridge so default to VEB */ |
| 9376 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9377 | return 1; |
| 9378 | |
| 9379 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9380 | if (!veb) { |
| 9381 | dev_info(&pf->pdev->dev, |
| 9382 | "There is no veb associated with the bridge\n"); |
| 9383 | return -ENOENT; |
| 9384 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9385 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9386 | /* Uplink is a bridge in VEPA mode */ |
| 9387 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9388 | return 0; |
| 9389 | } else { |
| 9390 | /* Uplink is a bridge in VEB mode */ |
| 9391 | return 1; |
| 9392 | } |
| 9393 | |
| 9394 | /* VEPA is now default bridge, so return 0 */ |
| 9395 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9396 | } |
| 9397 | |
| 9398 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9399 | * i40e_add_vsi - Add a VSI to the switch |
| 9400 | * @vsi: the VSI being configured |
| 9401 | * |
| 9402 | * This initializes a VSI context depending on the VSI type to be added and |
| 9403 | * passes it down to the add_vsi aq command. |
| 9404 | **/ |
| 9405 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9406 | { |
| 9407 | int ret = -ENODEV; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9408 | struct i40e_pf *pf = vsi->back; |
| 9409 | struct i40e_hw *hw = &pf->hw; |
| 9410 | struct i40e_vsi_context ctxt; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9411 | struct i40e_mac_filter *f; |
| 9412 | struct hlist_node *h; |
| 9413 | int bkt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9414 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9415 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9416 | int f_count = 0; |
| 9417 | |
| 9418 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9419 | switch (vsi->type) { |
| 9420 | case I40E_VSI_MAIN: |
| 9421 | /* The PF's main VSI is already setup as part of the |
| 9422 | * device initialization, so we'll not bother with |
| 9423 | * the add_vsi call, but we will retrieve the current |
| 9424 | * VSI context. |
| 9425 | */ |
| 9426 | ctxt.seid = pf->main_vsi_seid; |
| 9427 | ctxt.pf_num = pf->hw.pf_id; |
| 9428 | ctxt.vf_num = 0; |
| 9429 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9430 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9431 | if (ret) { |
| 9432 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9433 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9434 | i40e_stat_str(&pf->hw, ret), |
| 9435 | i40e_aq_str(&pf->hw, |
| 9436 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9437 | return -ENOENT; |
| 9438 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9439 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9440 | vsi->info.valid_sections = 0; |
| 9441 | |
| 9442 | vsi->seid = ctxt.seid; |
| 9443 | vsi->id = ctxt.vsi_number; |
| 9444 | |
| 9445 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9446 | |
| 9447 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9448 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9449 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9450 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9451 | ctxt.seid = pf->main_vsi_seid; |
| 9452 | ctxt.pf_num = pf->hw.pf_id; |
| 9453 | ctxt.vf_num = 0; |
| 9454 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9455 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9456 | if (ret) { |
| 9457 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9458 | "update vsi failed, err %s aq_err %s\n", |
| 9459 | i40e_stat_str(&pf->hw, ret), |
| 9460 | i40e_aq_str(&pf->hw, |
| 9461 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9462 | ret = -ENOENT; |
| 9463 | goto err; |
| 9464 | } |
| 9465 | /* update the local VSI info queue map */ |
| 9466 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9467 | vsi->info.valid_sections = 0; |
| 9468 | } else { |
| 9469 | /* Default/Main VSI is only enabled for TC0 |
| 9470 | * reconfigure it to enable all TCs that are |
| 9471 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9472 | * For MFP case the iSCSI PF would use this |
| 9473 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9474 | */ |
| 9475 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9476 | if (ret) { |
| 9477 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9478 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9479 | enabled_tc, |
| 9480 | i40e_stat_str(&pf->hw, ret), |
| 9481 | i40e_aq_str(&pf->hw, |
| 9482 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9483 | ret = -ENOENT; |
| 9484 | } |
| 9485 | } |
| 9486 | break; |
| 9487 | |
| 9488 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9489 | ctxt.pf_num = hw->pf_id; |
| 9490 | ctxt.vf_num = 0; |
| 9491 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9492 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9493 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9494 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9495 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9496 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9497 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9498 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9499 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9500 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9501 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9502 | break; |
| 9503 | |
| 9504 | case I40E_VSI_VMDQ2: |
| 9505 | ctxt.pf_num = hw->pf_id; |
| 9506 | ctxt.vf_num = 0; |
| 9507 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9508 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9509 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9510 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9511 | /* This VSI is connected to VEB so the switch_id |
| 9512 | * should be set to zero by default. |
| 9513 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9514 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9515 | ctxt.info.valid_sections |= |
| 9516 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9517 | ctxt.info.switch_id = |
| 9518 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9519 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9520 | |
| 9521 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9522 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9523 | break; |
| 9524 | |
| 9525 | case I40E_VSI_SRIOV: |
| 9526 | ctxt.pf_num = hw->pf_id; |
| 9527 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9528 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9529 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9530 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9531 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9532 | /* This VSI is connected to VEB so the switch_id |
| 9533 | * should be set to zero by default. |
| 9534 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9535 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9536 | ctxt.info.valid_sections |= |
| 9537 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9538 | ctxt.info.switch_id = |
| 9539 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9540 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9541 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9542 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9543 | ctxt.info.valid_sections |= |
| 9544 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 9545 | ctxt.info.queueing_opt_flags |= |
Ashish Shah | 4b28cdb | 2016-05-03 15:13:17 -0700 | [diff] [blame] | 9546 | (I40E_AQ_VSI_QUE_OPT_TCP_ENA | |
| 9547 | I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9548 | } |
| 9549 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9550 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9551 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9552 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9553 | ctxt.info.valid_sections |= |
| 9554 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9555 | ctxt.info.sec_flags |= |
| 9556 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9557 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9558 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9559 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9560 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9561 | break; |
| 9562 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9563 | #ifdef I40E_FCOE |
| 9564 | case I40E_VSI_FCOE: |
| 9565 | ret = i40e_fcoe_vsi_init(vsi, &ctxt); |
| 9566 | if (ret) { |
| 9567 | dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n"); |
| 9568 | return ret; |
| 9569 | } |
| 9570 | break; |
| 9571 | |
| 9572 | #endif /* I40E_FCOE */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9573 | case I40E_VSI_IWARP: |
| 9574 | /* send down message to iWARP */ |
| 9575 | break; |
| 9576 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9577 | default: |
| 9578 | return -ENODEV; |
| 9579 | } |
| 9580 | |
| 9581 | if (vsi->type != I40E_VSI_MAIN) { |
| 9582 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9583 | if (ret) { |
| 9584 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9585 | "add vsi failed, err %s aq_err %s\n", |
| 9586 | i40e_stat_str(&pf->hw, ret), |
| 9587 | i40e_aq_str(&pf->hw, |
| 9588 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9589 | ret = -ENOENT; |
| 9590 | goto err; |
| 9591 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9592 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9593 | vsi->info.valid_sections = 0; |
| 9594 | vsi->seid = ctxt.seid; |
| 9595 | vsi->id = ctxt.vsi_number; |
| 9596 | } |
| 9597 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9598 | vsi->active_filters = 0; |
| 9599 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9600 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9601 | /* If macvlan filters already exist, force them to get loaded */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9602 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9603 | f->state = I40E_FILTER_NEW; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9604 | f_count++; |
| 9605 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9606 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9607 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9608 | if (f_count) { |
| 9609 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 9610 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 9611 | } |
| 9612 | |
| 9613 | /* Update VSI BW information */ |
| 9614 | ret = i40e_vsi_get_bw_info(vsi); |
| 9615 | if (ret) { |
| 9616 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9617 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 9618 | i40e_stat_str(&pf->hw, ret), |
| 9619 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9620 | /* VSI is already added so not tearing that up */ |
| 9621 | ret = 0; |
| 9622 | } |
| 9623 | |
| 9624 | err: |
| 9625 | return ret; |
| 9626 | } |
| 9627 | |
| 9628 | /** |
| 9629 | * i40e_vsi_release - Delete a VSI and free its resources |
| 9630 | * @vsi: the VSI being removed |
| 9631 | * |
| 9632 | * Returns 0 on success or < 0 on error |
| 9633 | **/ |
| 9634 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 9635 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9636 | struct i40e_mac_filter *f; |
| 9637 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9638 | struct i40e_veb *veb = NULL; |
| 9639 | struct i40e_pf *pf; |
| 9640 | u16 uplink_seid; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9641 | int i, n, bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9642 | |
| 9643 | pf = vsi->back; |
| 9644 | |
| 9645 | /* release of a VEB-owner or last VSI is not allowed */ |
| 9646 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 9647 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 9648 | vsi->seid, vsi->uplink_seid); |
| 9649 | return -ENODEV; |
| 9650 | } |
| 9651 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 9652 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 9653 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 9654 | return -ENODEV; |
| 9655 | } |
| 9656 | |
| 9657 | uplink_seid = vsi->uplink_seid; |
| 9658 | if (vsi->type != I40E_VSI_SRIOV) { |
| 9659 | if (vsi->netdev_registered) { |
| 9660 | vsi->netdev_registered = false; |
| 9661 | if (vsi->netdev) { |
| 9662 | /* results in a call to i40e_close() */ |
| 9663 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9664 | } |
| 9665 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 9666 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9667 | } |
| 9668 | i40e_vsi_disable_irq(vsi); |
| 9669 | } |
| 9670 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9671 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 9672 | |
| 9673 | /* clear the sync flag on all filters */ |
| 9674 | if (vsi->netdev) { |
| 9675 | __dev_uc_unsync(vsi->netdev, NULL); |
| 9676 | __dev_mc_unsync(vsi->netdev, NULL); |
| 9677 | } |
| 9678 | |
| 9679 | /* make sure any remaining filters are marked for deletion */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9680 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 9681 | __i40e_del_filter(vsi, f); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 9682 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9683 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9684 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 9685 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9686 | |
| 9687 | i40e_vsi_delete(vsi); |
| 9688 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 9689 | if (vsi->netdev) { |
| 9690 | free_netdev(vsi->netdev); |
| 9691 | vsi->netdev = NULL; |
| 9692 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9693 | i40e_vsi_clear_rings(vsi); |
| 9694 | i40e_vsi_clear(vsi); |
| 9695 | |
| 9696 | /* If this was the last thing on the VEB, except for the |
| 9697 | * controlling VSI, remove the VEB, which puts the controlling |
| 9698 | * VSI onto the next level down in the switch. |
| 9699 | * |
| 9700 | * Well, okay, there's one more exception here: don't remove |
| 9701 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 9702 | * from up the network stack. |
| 9703 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9704 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9705 | if (pf->vsi[i] && |
| 9706 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 9707 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9708 | n++; /* count the VSIs */ |
| 9709 | } |
| 9710 | } |
| 9711 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9712 | if (!pf->veb[i]) |
| 9713 | continue; |
| 9714 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 9715 | n++; /* count the VEBs */ |
| 9716 | if (pf->veb[i]->seid == uplink_seid) |
| 9717 | veb = pf->veb[i]; |
| 9718 | } |
| 9719 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 9720 | i40e_veb_release(veb); |
| 9721 | |
| 9722 | return 0; |
| 9723 | } |
| 9724 | |
| 9725 | /** |
| 9726 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 9727 | * @vsi: ptr to the VSI |
| 9728 | * |
| 9729 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 9730 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 9731 | * newly allocated VSI. |
| 9732 | * |
| 9733 | * Returns 0 on success or negative on failure |
| 9734 | **/ |
| 9735 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 9736 | { |
| 9737 | int ret = -ENOENT; |
| 9738 | struct i40e_pf *pf = vsi->back; |
| 9739 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9740 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9741 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 9742 | vsi->seid); |
| 9743 | return -EEXIST; |
| 9744 | } |
| 9745 | |
| 9746 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 9747 | 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] | 9748 | vsi->seid, vsi->base_vector); |
| 9749 | return -EEXIST; |
| 9750 | } |
| 9751 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9752 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9753 | if (ret) { |
| 9754 | dev_info(&pf->pdev->dev, |
| 9755 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 9756 | vsi->num_q_vectors, vsi->seid, ret); |
| 9757 | vsi->num_q_vectors = 0; |
| 9758 | goto vector_setup_out; |
| 9759 | } |
| 9760 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 9761 | /* In Legacy mode, we do not have to get any other vector since we |
| 9762 | * piggyback on the misc/ICR0 for queue interrupts. |
| 9763 | */ |
| 9764 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9765 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9766 | if (vsi->num_q_vectors) |
| 9767 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 9768 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9769 | if (vsi->base_vector < 0) { |
| 9770 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9771 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 9772 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9773 | i40e_vsi_free_q_vectors(vsi); |
| 9774 | ret = -ENOENT; |
| 9775 | goto vector_setup_out; |
| 9776 | } |
| 9777 | |
| 9778 | vector_setup_out: |
| 9779 | return ret; |
| 9780 | } |
| 9781 | |
| 9782 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9783 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 9784 | * @vsi: pointer to the vsi. |
| 9785 | * |
| 9786 | * This re-allocates a vsi's queue resources. |
| 9787 | * |
| 9788 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 9789 | * on success, otherwise returns NULL on failure. |
| 9790 | **/ |
| 9791 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 9792 | { |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9793 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9794 | u8 enabled_tc; |
| 9795 | int ret; |
| 9796 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9797 | if (!vsi) |
| 9798 | return NULL; |
| 9799 | |
| 9800 | pf = vsi->back; |
| 9801 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9802 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9803 | i40e_vsi_clear_rings(vsi); |
| 9804 | |
| 9805 | i40e_vsi_free_arrays(vsi, false); |
| 9806 | i40e_set_num_rings_in_vsi(vsi); |
| 9807 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 9808 | if (ret) |
| 9809 | goto err_vsi; |
| 9810 | |
| 9811 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 9812 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9813 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9814 | "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] | 9815 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9816 | goto err_vsi; |
| 9817 | } |
| 9818 | vsi->base_queue = ret; |
| 9819 | |
| 9820 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 9821 | * layout configurations. |
| 9822 | */ |
| 9823 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9824 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9825 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9826 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 9827 | |
| 9828 | /* assign it some queues */ |
| 9829 | ret = i40e_alloc_rings(vsi); |
| 9830 | if (ret) |
| 9831 | goto err_rings; |
| 9832 | |
| 9833 | /* map all of the rings to the q_vectors */ |
| 9834 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9835 | return vsi; |
| 9836 | |
| 9837 | err_rings: |
| 9838 | i40e_vsi_free_q_vectors(vsi); |
| 9839 | if (vsi->netdev_registered) { |
| 9840 | vsi->netdev_registered = false; |
| 9841 | unregister_netdev(vsi->netdev); |
| 9842 | free_netdev(vsi->netdev); |
| 9843 | vsi->netdev = NULL; |
| 9844 | } |
| 9845 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9846 | err_vsi: |
| 9847 | i40e_vsi_clear(vsi); |
| 9848 | return NULL; |
| 9849 | } |
| 9850 | |
| 9851 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9852 | * i40e_vsi_setup - Set up a VSI by a given type |
| 9853 | * @pf: board private structure |
| 9854 | * @type: VSI type |
| 9855 | * @uplink_seid: the switch element to link to |
| 9856 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 9857 | * |
| 9858 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 9859 | * to the identified VEB. |
| 9860 | * |
| 9861 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 9862 | * success, otherwise returns NULL on failure. |
| 9863 | **/ |
| 9864 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 9865 | u16 uplink_seid, u32 param1) |
| 9866 | { |
| 9867 | struct i40e_vsi *vsi = NULL; |
| 9868 | struct i40e_veb *veb = NULL; |
| 9869 | int ret, i; |
| 9870 | int v_idx; |
| 9871 | |
| 9872 | /* The requested uplink_seid must be either |
| 9873 | * - the PF's port seid |
| 9874 | * no VEB is needed because this is the PF |
| 9875 | * or this is a Flow Director special case VSI |
| 9876 | * - seid of an existing VEB |
| 9877 | * - seid of a VSI that owns an existing VEB |
| 9878 | * - seid of a VSI that doesn't own a VEB |
| 9879 | * a new VEB is created and the VSI becomes the owner |
| 9880 | * - seid of the PF VSI, which is what creates the first VEB |
| 9881 | * this is a special case of the previous |
| 9882 | * |
| 9883 | * Find which uplink_seid we were given and create a new VEB if needed |
| 9884 | */ |
| 9885 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9886 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 9887 | veb = pf->veb[i]; |
| 9888 | break; |
| 9889 | } |
| 9890 | } |
| 9891 | |
| 9892 | if (!veb && uplink_seid != pf->mac_seid) { |
| 9893 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9894 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9895 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 9896 | vsi = pf->vsi[i]; |
| 9897 | break; |
| 9898 | } |
| 9899 | } |
| 9900 | if (!vsi) { |
| 9901 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 9902 | uplink_seid); |
| 9903 | return NULL; |
| 9904 | } |
| 9905 | |
| 9906 | if (vsi->uplink_seid == pf->mac_seid) |
| 9907 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 9908 | vsi->tc_config.enabled_tc); |
| 9909 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 9910 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9911 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9912 | if (veb) { |
| 9913 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 9914 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 9915 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9916 | return NULL; |
| 9917 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 9918 | /* We come up by default in VEPA mode if SRIOV is not |
| 9919 | * already enabled, in which case we can't force VEPA |
| 9920 | * mode. |
| 9921 | */ |
| 9922 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 9923 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 9924 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9925 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9926 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9927 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9928 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9929 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9930 | veb = pf->veb[i]; |
| 9931 | } |
| 9932 | if (!veb) { |
| 9933 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 9934 | return NULL; |
| 9935 | } |
| 9936 | |
| 9937 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 9938 | uplink_seid = veb->seid; |
| 9939 | } |
| 9940 | |
| 9941 | /* get vsi sw struct */ |
| 9942 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 9943 | if (v_idx < 0) |
| 9944 | goto err_alloc; |
| 9945 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9946 | if (!vsi) |
| 9947 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9948 | vsi->type = type; |
| 9949 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 9950 | |
| 9951 | if (type == I40E_VSI_MAIN) |
| 9952 | pf->lan_vsi = v_idx; |
| 9953 | else if (type == I40E_VSI_SRIOV) |
| 9954 | vsi->vf_id = param1; |
| 9955 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9956 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 9957 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9958 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9959 | dev_info(&pf->pdev->dev, |
| 9960 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 9961 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9962 | goto err_vsi; |
| 9963 | } |
| 9964 | vsi->base_queue = ret; |
| 9965 | |
| 9966 | /* get a VSI from the hardware */ |
| 9967 | vsi->uplink_seid = uplink_seid; |
| 9968 | ret = i40e_add_vsi(vsi); |
| 9969 | if (ret) |
| 9970 | goto err_vsi; |
| 9971 | |
| 9972 | switch (vsi->type) { |
| 9973 | /* setup the netdev if needed */ |
| 9974 | case I40E_VSI_MAIN: |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9975 | /* Apply relevant filters if a platform-specific mac |
| 9976 | * address was selected. |
| 9977 | */ |
| 9978 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 9979 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 9980 | if (ret) { |
| 9981 | dev_warn(&pf->pdev->dev, |
| 9982 | "could not set up macaddr; err %d\n", |
| 9983 | ret); |
| 9984 | } |
| 9985 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9986 | case I40E_VSI_VMDQ2: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9987 | case I40E_VSI_FCOE: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9988 | ret = i40e_config_netdev(vsi); |
| 9989 | if (ret) |
| 9990 | goto err_netdev; |
| 9991 | ret = register_netdev(vsi->netdev); |
| 9992 | if (ret) |
| 9993 | goto err_netdev; |
| 9994 | vsi->netdev_registered = true; |
| 9995 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9996 | #ifdef CONFIG_I40E_DCB |
| 9997 | /* Setup DCB netlink interface */ |
| 9998 | i40e_dcbnl_setup(vsi); |
| 9999 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10000 | /* fall through */ |
| 10001 | |
| 10002 | case I40E_VSI_FDIR: |
| 10003 | /* set up vectors and rings if needed */ |
| 10004 | ret = i40e_vsi_setup_vectors(vsi); |
| 10005 | if (ret) |
| 10006 | goto err_msix; |
| 10007 | |
| 10008 | ret = i40e_alloc_rings(vsi); |
| 10009 | if (ret) |
| 10010 | goto err_rings; |
| 10011 | |
| 10012 | /* map all of the rings to the q_vectors */ |
| 10013 | i40e_vsi_map_rings_to_vectors(vsi); |
| 10014 | |
| 10015 | i40e_vsi_reset_stats(vsi); |
| 10016 | break; |
| 10017 | |
| 10018 | default: |
| 10019 | /* no netdev or rings for the other VSI types */ |
| 10020 | break; |
| 10021 | } |
| 10022 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 10023 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
| 10024 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 10025 | ret = i40e_vsi_config_rss(vsi); |
| 10026 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10027 | return vsi; |
| 10028 | |
| 10029 | err_rings: |
| 10030 | i40e_vsi_free_q_vectors(vsi); |
| 10031 | err_msix: |
| 10032 | if (vsi->netdev_registered) { |
| 10033 | vsi->netdev_registered = false; |
| 10034 | unregister_netdev(vsi->netdev); |
| 10035 | free_netdev(vsi->netdev); |
| 10036 | vsi->netdev = NULL; |
| 10037 | } |
| 10038 | err_netdev: |
| 10039 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 10040 | err_vsi: |
| 10041 | i40e_vsi_clear(vsi); |
| 10042 | err_alloc: |
| 10043 | return NULL; |
| 10044 | } |
| 10045 | |
| 10046 | /** |
| 10047 | * i40e_veb_get_bw_info - Query VEB BW information |
| 10048 | * @veb: the veb to query |
| 10049 | * |
| 10050 | * Query the Tx scheduler BW configuration data for given VEB |
| 10051 | **/ |
| 10052 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 10053 | { |
| 10054 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 10055 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 10056 | struct i40e_pf *pf = veb->pf; |
| 10057 | struct i40e_hw *hw = &pf->hw; |
| 10058 | u32 tc_bw_max; |
| 10059 | int ret = 0; |
| 10060 | int i; |
| 10061 | |
| 10062 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 10063 | &bw_data, NULL); |
| 10064 | if (ret) { |
| 10065 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10066 | "query veb bw config failed, err %s aq_err %s\n", |
| 10067 | i40e_stat_str(&pf->hw, ret), |
| 10068 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10069 | goto out; |
| 10070 | } |
| 10071 | |
| 10072 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 10073 | &ets_data, NULL); |
| 10074 | if (ret) { |
| 10075 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10076 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 10077 | i40e_stat_str(&pf->hw, ret), |
| 10078 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10079 | goto out; |
| 10080 | } |
| 10081 | |
| 10082 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 10083 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 10084 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 10085 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10086 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 10087 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 10088 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 10089 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 10090 | veb->bw_tc_limit_credits[i] = |
| 10091 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 10092 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 10093 | } |
| 10094 | |
| 10095 | out: |
| 10096 | return ret; |
| 10097 | } |
| 10098 | |
| 10099 | /** |
| 10100 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 10101 | * @pf: board private structure |
| 10102 | * |
| 10103 | * On error: returns error code (negative) |
| 10104 | * On success: returns vsi index in PF (positive) |
| 10105 | **/ |
| 10106 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 10107 | { |
| 10108 | int ret = -ENOENT; |
| 10109 | struct i40e_veb *veb; |
| 10110 | int i; |
| 10111 | |
| 10112 | /* Need to protect the allocation of switch elements at the PF level */ |
| 10113 | mutex_lock(&pf->switch_mutex); |
| 10114 | |
| 10115 | /* VEB list may be fragmented if VEB creation/destruction has |
| 10116 | * been happening. We can afford to do a quick scan to look |
| 10117 | * for any free slots in the list. |
| 10118 | * |
| 10119 | * find next empty veb slot, looping back around if necessary |
| 10120 | */ |
| 10121 | i = 0; |
| 10122 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 10123 | i++; |
| 10124 | if (i >= I40E_MAX_VEB) { |
| 10125 | ret = -ENOMEM; |
| 10126 | goto err_alloc_veb; /* out of VEB slots! */ |
| 10127 | } |
| 10128 | |
| 10129 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 10130 | if (!veb) { |
| 10131 | ret = -ENOMEM; |
| 10132 | goto err_alloc_veb; |
| 10133 | } |
| 10134 | veb->pf = pf; |
| 10135 | veb->idx = i; |
| 10136 | veb->enabled_tc = 1; |
| 10137 | |
| 10138 | pf->veb[i] = veb; |
| 10139 | ret = i; |
| 10140 | err_alloc_veb: |
| 10141 | mutex_unlock(&pf->switch_mutex); |
| 10142 | return ret; |
| 10143 | } |
| 10144 | |
| 10145 | /** |
| 10146 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 10147 | * @branch: where to start deleting |
| 10148 | * |
| 10149 | * This uses recursion to find the tips of the branch to be |
| 10150 | * removed, deleting until we get back to and can delete this VEB. |
| 10151 | **/ |
| 10152 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 10153 | { |
| 10154 | struct i40e_pf *pf = branch->pf; |
| 10155 | u16 branch_seid = branch->seid; |
| 10156 | u16 veb_idx = branch->idx; |
| 10157 | int i; |
| 10158 | |
| 10159 | /* release any VEBs on this VEB - RECURSION */ |
| 10160 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10161 | if (!pf->veb[i]) |
| 10162 | continue; |
| 10163 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 10164 | i40e_switch_branch_release(pf->veb[i]); |
| 10165 | } |
| 10166 | |
| 10167 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 10168 | * |
| 10169 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 10170 | * the VEB itself, so don't use (*branch) after this loop. |
| 10171 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10172 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10173 | if (!pf->vsi[i]) |
| 10174 | continue; |
| 10175 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 10176 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 10177 | i40e_vsi_release(pf->vsi[i]); |
| 10178 | } |
| 10179 | } |
| 10180 | |
| 10181 | /* There's one corner case where the VEB might not have been |
| 10182 | * removed, so double check it here and remove it if needed. |
| 10183 | * This case happens if the veb was created from the debugfs |
| 10184 | * commands and no VSIs were added to it. |
| 10185 | */ |
| 10186 | if (pf->veb[veb_idx]) |
| 10187 | i40e_veb_release(pf->veb[veb_idx]); |
| 10188 | } |
| 10189 | |
| 10190 | /** |
| 10191 | * i40e_veb_clear - remove veb struct |
| 10192 | * @veb: the veb to remove |
| 10193 | **/ |
| 10194 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 10195 | { |
| 10196 | if (!veb) |
| 10197 | return; |
| 10198 | |
| 10199 | if (veb->pf) { |
| 10200 | struct i40e_pf *pf = veb->pf; |
| 10201 | |
| 10202 | mutex_lock(&pf->switch_mutex); |
| 10203 | if (pf->veb[veb->idx] == veb) |
| 10204 | pf->veb[veb->idx] = NULL; |
| 10205 | mutex_unlock(&pf->switch_mutex); |
| 10206 | } |
| 10207 | |
| 10208 | kfree(veb); |
| 10209 | } |
| 10210 | |
| 10211 | /** |
| 10212 | * i40e_veb_release - Delete a VEB and free its resources |
| 10213 | * @veb: the VEB being removed |
| 10214 | **/ |
| 10215 | void i40e_veb_release(struct i40e_veb *veb) |
| 10216 | { |
| 10217 | struct i40e_vsi *vsi = NULL; |
| 10218 | struct i40e_pf *pf; |
| 10219 | int i, n = 0; |
| 10220 | |
| 10221 | pf = veb->pf; |
| 10222 | |
| 10223 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10224 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10225 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 10226 | n++; |
| 10227 | vsi = pf->vsi[i]; |
| 10228 | } |
| 10229 | } |
| 10230 | if (n != 1) { |
| 10231 | dev_info(&pf->pdev->dev, |
| 10232 | "can't remove VEB %d with %d VSIs left\n", |
| 10233 | veb->seid, n); |
| 10234 | return; |
| 10235 | } |
| 10236 | |
| 10237 | /* move the remaining VSI to uplink veb */ |
| 10238 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10239 | if (veb->uplink_seid) { |
| 10240 | vsi->uplink_seid = veb->uplink_seid; |
| 10241 | if (veb->uplink_seid == pf->mac_seid) |
| 10242 | vsi->veb_idx = I40E_NO_VEB; |
| 10243 | else |
| 10244 | vsi->veb_idx = veb->veb_idx; |
| 10245 | } else { |
| 10246 | /* floating VEB */ |
| 10247 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10248 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10249 | } |
| 10250 | |
| 10251 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10252 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10253 | } |
| 10254 | |
| 10255 | /** |
| 10256 | * i40e_add_veb - create the VEB in the switch |
| 10257 | * @veb: the VEB to be instantiated |
| 10258 | * @vsi: the controlling VSI |
| 10259 | **/ |
| 10260 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10261 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10262 | struct i40e_pf *pf = veb->pf; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10263 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10264 | int ret; |
| 10265 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10266 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10267 | veb->enabled_tc, false, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10268 | &veb->seid, enable_stats, NULL); |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10269 | |
| 10270 | /* get a VEB from the hardware */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10271 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10272 | dev_info(&pf->pdev->dev, |
| 10273 | "couldn't add VEB, err %s aq_err %s\n", |
| 10274 | i40e_stat_str(&pf->hw, ret), |
| 10275 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10276 | return -EPERM; |
| 10277 | } |
| 10278 | |
| 10279 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10280 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10281 | &veb->stats_idx, NULL, NULL, NULL); |
| 10282 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10283 | dev_info(&pf->pdev->dev, |
| 10284 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10285 | i40e_stat_str(&pf->hw, ret), |
| 10286 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10287 | return -EPERM; |
| 10288 | } |
| 10289 | ret = i40e_veb_get_bw_info(veb); |
| 10290 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10291 | dev_info(&pf->pdev->dev, |
| 10292 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10293 | i40e_stat_str(&pf->hw, ret), |
| 10294 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10295 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10296 | return -ENOENT; |
| 10297 | } |
| 10298 | |
| 10299 | vsi->uplink_seid = veb->seid; |
| 10300 | vsi->veb_idx = veb->idx; |
| 10301 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10302 | |
| 10303 | return 0; |
| 10304 | } |
| 10305 | |
| 10306 | /** |
| 10307 | * i40e_veb_setup - Set up a VEB |
| 10308 | * @pf: board private structure |
| 10309 | * @flags: VEB setup flags |
| 10310 | * @uplink_seid: the switch element to link to |
| 10311 | * @vsi_seid: the initial VSI seid |
| 10312 | * @enabled_tc: Enabled TC bit-map |
| 10313 | * |
| 10314 | * This allocates the sw VEB structure and links it into the switch |
| 10315 | * It is possible and legal for this to be a duplicate of an already |
| 10316 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10317 | * to be zero, in order to create a floating VEB. |
| 10318 | * |
| 10319 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10320 | * success, otherwise returns NULL on failure. |
| 10321 | **/ |
| 10322 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10323 | u16 uplink_seid, u16 vsi_seid, |
| 10324 | u8 enabled_tc) |
| 10325 | { |
| 10326 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10327 | int vsi_idx, veb_idx; |
| 10328 | int ret; |
| 10329 | |
| 10330 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10331 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10332 | (uplink_seid + vsi_seid != 0)) { |
| 10333 | dev_info(&pf->pdev->dev, |
| 10334 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10335 | uplink_seid, vsi_seid); |
| 10336 | return NULL; |
| 10337 | } |
| 10338 | |
| 10339 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10340 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10341 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10342 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10343 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10344 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10345 | vsi_seid); |
| 10346 | return NULL; |
| 10347 | } |
| 10348 | |
| 10349 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10350 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10351 | if (pf->veb[veb_idx] && |
| 10352 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10353 | uplink_veb = pf->veb[veb_idx]; |
| 10354 | break; |
| 10355 | } |
| 10356 | } |
| 10357 | if (!uplink_veb) { |
| 10358 | dev_info(&pf->pdev->dev, |
| 10359 | "uplink seid %d not found\n", uplink_seid); |
| 10360 | return NULL; |
| 10361 | } |
| 10362 | } |
| 10363 | |
| 10364 | /* get veb sw struct */ |
| 10365 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10366 | if (veb_idx < 0) |
| 10367 | goto err_alloc; |
| 10368 | veb = pf->veb[veb_idx]; |
| 10369 | veb->flags = flags; |
| 10370 | veb->uplink_seid = uplink_seid; |
| 10371 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10372 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10373 | |
| 10374 | /* create the VEB in the switch */ |
| 10375 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10376 | if (ret) |
| 10377 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10378 | if (vsi_idx == pf->lan_vsi) |
| 10379 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10380 | |
| 10381 | return veb; |
| 10382 | |
| 10383 | err_veb: |
| 10384 | i40e_veb_clear(veb); |
| 10385 | err_alloc: |
| 10386 | return NULL; |
| 10387 | } |
| 10388 | |
| 10389 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10390 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10391 | * @pf: board private structure |
| 10392 | * @ele: element we are building info from |
| 10393 | * @num_reported: total number of elements |
| 10394 | * @printconfig: should we print the contents |
| 10395 | * |
| 10396 | * helper function to assist in extracting a few useful SEID values. |
| 10397 | **/ |
| 10398 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10399 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10400 | u16 num_reported, bool printconfig) |
| 10401 | { |
| 10402 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10403 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10404 | u8 element_type = ele->element_type; |
| 10405 | u16 seid = le16_to_cpu(ele->seid); |
| 10406 | |
| 10407 | if (printconfig) |
| 10408 | dev_info(&pf->pdev->dev, |
| 10409 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10410 | element_type, seid, uplink_seid, downlink_seid); |
| 10411 | |
| 10412 | switch (element_type) { |
| 10413 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10414 | pf->mac_seid = seid; |
| 10415 | break; |
| 10416 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10417 | /* Main VEB? */ |
| 10418 | if (uplink_seid != pf->mac_seid) |
| 10419 | break; |
| 10420 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10421 | int v; |
| 10422 | |
| 10423 | /* find existing or else empty VEB */ |
| 10424 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10425 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10426 | pf->lan_veb = v; |
| 10427 | break; |
| 10428 | } |
| 10429 | } |
| 10430 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10431 | v = i40e_veb_mem_alloc(pf); |
| 10432 | if (v < 0) |
| 10433 | break; |
| 10434 | pf->lan_veb = v; |
| 10435 | } |
| 10436 | } |
| 10437 | |
| 10438 | pf->veb[pf->lan_veb]->seid = seid; |
| 10439 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10440 | pf->veb[pf->lan_veb]->pf = pf; |
| 10441 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10442 | break; |
| 10443 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10444 | if (num_reported != 1) |
| 10445 | break; |
| 10446 | /* This is immediately after a reset so we can assume this is |
| 10447 | * the PF's VSI |
| 10448 | */ |
| 10449 | pf->mac_seid = uplink_seid; |
| 10450 | pf->pf_seid = downlink_seid; |
| 10451 | pf->main_vsi_seid = seid; |
| 10452 | if (printconfig) |
| 10453 | dev_info(&pf->pdev->dev, |
| 10454 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10455 | pf->pf_seid, pf->main_vsi_seid); |
| 10456 | break; |
| 10457 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10458 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10459 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10460 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10461 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10462 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10463 | /* ignore these for now */ |
| 10464 | break; |
| 10465 | default: |
| 10466 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10467 | element_type, seid); |
| 10468 | break; |
| 10469 | } |
| 10470 | } |
| 10471 | |
| 10472 | /** |
| 10473 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10474 | * @pf: board private structure |
| 10475 | * @printconfig: should we print the contents |
| 10476 | * |
| 10477 | * Get the current switch configuration from the device and |
| 10478 | * extract a few useful SEID values. |
| 10479 | **/ |
| 10480 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10481 | { |
| 10482 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10483 | u16 next_seid = 0; |
| 10484 | int ret = 0; |
| 10485 | u8 *aq_buf; |
| 10486 | int i; |
| 10487 | |
| 10488 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10489 | if (!aq_buf) |
| 10490 | return -ENOMEM; |
| 10491 | |
| 10492 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10493 | do { |
| 10494 | u16 num_reported, num_total; |
| 10495 | |
| 10496 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10497 | I40E_AQ_LARGE_BUF, |
| 10498 | &next_seid, NULL); |
| 10499 | if (ret) { |
| 10500 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10501 | "get switch config failed err %s aq_err %s\n", |
| 10502 | i40e_stat_str(&pf->hw, ret), |
| 10503 | i40e_aq_str(&pf->hw, |
| 10504 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10505 | kfree(aq_buf); |
| 10506 | return -ENOENT; |
| 10507 | } |
| 10508 | |
| 10509 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10510 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10511 | |
| 10512 | if (printconfig) |
| 10513 | dev_info(&pf->pdev->dev, |
| 10514 | "header: %d reported %d total\n", |
| 10515 | num_reported, num_total); |
| 10516 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10517 | for (i = 0; i < num_reported; i++) { |
| 10518 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10519 | &sw_config->element[i]; |
| 10520 | |
| 10521 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10522 | printconfig); |
| 10523 | } |
| 10524 | } while (next_seid != 0); |
| 10525 | |
| 10526 | kfree(aq_buf); |
| 10527 | return ret; |
| 10528 | } |
| 10529 | |
| 10530 | /** |
| 10531 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10532 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10533 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10534 | * |
| 10535 | * Returns 0 on success, negative value on failure |
| 10536 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10537 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10538 | { |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10539 | u16 flags = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10540 | int ret; |
| 10541 | |
| 10542 | /* find out what's out there already */ |
| 10543 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10544 | if (ret) { |
| 10545 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10546 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10547 | i40e_stat_str(&pf->hw, ret), |
| 10548 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10549 | return ret; |
| 10550 | } |
| 10551 | i40e_pf_reset_stats(pf); |
| 10552 | |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10553 | /* set the switch config bit for the whole device to |
| 10554 | * support limited promisc or true promisc |
| 10555 | * when user requests promisc. The default is limited |
| 10556 | * promisc. |
| 10557 | */ |
| 10558 | |
| 10559 | if ((pf->hw.pf_id == 0) && |
| 10560 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) |
| 10561 | flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10562 | |
| 10563 | if (pf->hw.pf_id == 0) { |
| 10564 | u16 valid_flags; |
| 10565 | |
| 10566 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10567 | ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, |
| 10568 | NULL); |
| 10569 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { |
| 10570 | dev_info(&pf->pdev->dev, |
| 10571 | "couldn't set switch config bits, err %s aq_err %s\n", |
| 10572 | i40e_stat_str(&pf->hw, ret), |
| 10573 | i40e_aq_str(&pf->hw, |
| 10574 | pf->hw.aq.asq_last_status)); |
| 10575 | /* not a fatal problem, just keep going */ |
| 10576 | } |
| 10577 | } |
| 10578 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10579 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10580 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10581 | struct i40e_vsi *vsi = NULL; |
| 10582 | u16 uplink_seid; |
| 10583 | |
| 10584 | /* Set up the PF VSI associated with the PF's main VSI |
| 10585 | * that is already in the HW switch |
| 10586 | */ |
| 10587 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10588 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10589 | else |
| 10590 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10591 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10592 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10593 | else if (reinit) |
| 10594 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10595 | if (!vsi) { |
| 10596 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10597 | i40e_fdir_teardown(pf); |
| 10598 | return -EAGAIN; |
| 10599 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10600 | } else { |
| 10601 | /* force a reset of TC and queue layout configurations */ |
| 10602 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10603 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10604 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10605 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10606 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10607 | } |
| 10608 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 10609 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10610 | i40e_fdir_sb_setup(pf); |
| 10611 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10612 | /* Setup static PF queue filter control settings */ |
| 10613 | ret = i40e_setup_pf_filter_control(pf); |
| 10614 | if (ret) { |
| 10615 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 10616 | ret); |
| 10617 | /* Failure here should not stop continuing other steps */ |
| 10618 | } |
| 10619 | |
| 10620 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 10621 | * the hash |
| 10622 | */ |
| 10623 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 10624 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10625 | |
| 10626 | /* fill in link information and enable LSE reporting */ |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 10627 | i40e_update_link_info(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10628 | i40e_link_event(pf); |
| 10629 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10630 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10631 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 10632 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10633 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10634 | i40e_ptp_init(pf); |
| 10635 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10636 | return ret; |
| 10637 | } |
| 10638 | |
| 10639 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10640 | * i40e_determine_queue_usage - Work out queue distribution |
| 10641 | * @pf: board private structure |
| 10642 | **/ |
| 10643 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 10644 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10645 | int queues_left; |
| 10646 | |
| 10647 | pf->num_lan_qps = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10648 | #ifdef I40E_FCOE |
| 10649 | pf->num_fcoe_qps = 0; |
| 10650 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10651 | |
| 10652 | /* Find the max queues to be put into basic use. We'll always be |
| 10653 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 10654 | * big RSS set. |
| 10655 | */ |
| 10656 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 10657 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10658 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10659 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10660 | /* one qp for PF, no queues for anything else */ |
| 10661 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10662 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10663 | |
| 10664 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10665 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10666 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10667 | #ifdef I40E_FCOE |
| 10668 | I40E_FLAG_FCOE_ENABLED | |
| 10669 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10670 | I40E_FLAG_FD_SB_ENABLED | |
| 10671 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10672 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 10673 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10674 | I40E_FLAG_SRIOV_ENABLED | |
| 10675 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10676 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 10677 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 10678 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10679 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10680 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10681 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10682 | queues_left -= pf->num_lan_qps; |
| 10683 | |
| 10684 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10685 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10686 | #ifdef I40E_FCOE |
| 10687 | I40E_FLAG_FCOE_ENABLED | |
| 10688 | #endif |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10689 | I40E_FLAG_FD_SB_ENABLED | |
| 10690 | I40E_FLAG_FD_ATR_ENABLED | |
| 10691 | I40E_FLAG_DCB_ENABLED | |
| 10692 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10693 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10694 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10695 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10696 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 10697 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | |
| 10698 | I40E_FLAG_DCB_ENABLED); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10699 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 10700 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 10701 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 10702 | num_online_cpus()); |
| 10703 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 10704 | pf->hw.func_caps.num_tx_qp); |
| 10705 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10706 | queues_left -= pf->num_lan_qps; |
| 10707 | } |
| 10708 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10709 | #ifdef I40E_FCOE |
| 10710 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 10711 | if (I40E_DEFAULT_FCOE <= queues_left) { |
| 10712 | pf->num_fcoe_qps = I40E_DEFAULT_FCOE; |
| 10713 | } else if (I40E_MINIMUM_FCOE <= queues_left) { |
| 10714 | pf->num_fcoe_qps = I40E_MINIMUM_FCOE; |
| 10715 | } else { |
| 10716 | pf->num_fcoe_qps = 0; |
| 10717 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 10718 | dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n"); |
| 10719 | } |
| 10720 | |
| 10721 | queues_left -= pf->num_fcoe_qps; |
| 10722 | } |
| 10723 | |
| 10724 | #endif |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10725 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10726 | if (queues_left > 1) { |
| 10727 | queues_left -= 1; /* save 1 queue for FD */ |
| 10728 | } else { |
| 10729 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 10730 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 10731 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10732 | } |
| 10733 | |
| 10734 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10735 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10736 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 10737 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10738 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 10739 | } |
| 10740 | |
| 10741 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 10742 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 10743 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 10744 | (queues_left / pf->num_vmdq_qps)); |
| 10745 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 10746 | } |
| 10747 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10748 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10749 | dev_dbg(&pf->pdev->dev, |
| 10750 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 10751 | pf->hw.func_caps.num_tx_qp, |
| 10752 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10753 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 10754 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 10755 | queues_left); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10756 | #ifdef I40E_FCOE |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10757 | 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] | 10758 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10759 | } |
| 10760 | |
| 10761 | /** |
| 10762 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 10763 | * @pf: PF to be setup |
| 10764 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10765 | * 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] | 10766 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 10767 | * based filter sizes required for them. It also enables Flow director, |
| 10768 | * ethertype and macvlan type filter settings for the pf. |
| 10769 | * |
| 10770 | * Returns 0 on success, negative on failure |
| 10771 | **/ |
| 10772 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 10773 | { |
| 10774 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 10775 | |
| 10776 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 10777 | |
| 10778 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10779 | 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] | 10780 | settings->enable_fdir = true; |
| 10781 | |
| 10782 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 10783 | settings->enable_ethtype = true; |
| 10784 | settings->enable_macvlan = true; |
| 10785 | |
| 10786 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 10787 | return -ENOENT; |
| 10788 | |
| 10789 | return 0; |
| 10790 | } |
| 10791 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10792 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10793 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10794 | static void i40e_print_features(struct i40e_pf *pf) |
| 10795 | { |
| 10796 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10797 | char *buf; |
| 10798 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10799 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10800 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 10801 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10802 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10803 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10804 | 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] | 10805 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10806 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10807 | #endif |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10808 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10809 | pf->hw.func_caps.num_vsis, |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10810 | pf->vsi[pf->lan_vsi]->num_queue_pairs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10811 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10812 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10813 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10814 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10815 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10816 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 10817 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10818 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10819 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10820 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10821 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10822 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10823 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10824 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10825 | #ifdef I40E_FCOE |
| 10826 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10827 | i += snprintf(&buf[i], REMAIN(i), " FCOE"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10828 | #endif |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10829 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10830 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10831 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10832 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10833 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10834 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 10835 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10836 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10837 | } |
| 10838 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10839 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10840 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
| 10841 | * |
| 10842 | * @pdev: PCI device information struct |
| 10843 | * @pf: board private structure |
| 10844 | * |
| 10845 | * Look up the MAC address in Open Firmware on systems that support it, |
| 10846 | * and use IDPROM on SPARC if no OF address is found. On return, the |
| 10847 | * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value |
| 10848 | * has been selected. |
| 10849 | **/ |
| 10850 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 10851 | { |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10852 | pf->flags &= ~I40E_FLAG_PF_MAC; |
Sowmini Varadhan | ba94272 | 2016-01-12 19:32:31 -0800 | [diff] [blame] | 10853 | if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10854 | pf->flags |= I40E_FLAG_PF_MAC; |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10855 | } |
| 10856 | |
| 10857 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10858 | * i40e_probe - Device initialization routine |
| 10859 | * @pdev: PCI device information struct |
| 10860 | * @ent: entry in i40e_pci_tbl |
| 10861 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10862 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 10863 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10864 | * and a hardware reset occur. |
| 10865 | * |
| 10866 | * Returns 0 on success, negative on failure |
| 10867 | **/ |
| 10868 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 10869 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 10870 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10871 | struct i40e_pf *pf; |
| 10872 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10873 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10874 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10875 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 10876 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10877 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10878 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10879 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10880 | |
| 10881 | err = pci_enable_device_mem(pdev); |
| 10882 | if (err) |
| 10883 | return err; |
| 10884 | |
| 10885 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10886 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10887 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 10888 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10889 | if (err) { |
| 10890 | dev_err(&pdev->dev, |
| 10891 | "DMA configuration failed: 0x%x\n", err); |
| 10892 | goto err_dma; |
| 10893 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10894 | } |
| 10895 | |
| 10896 | /* set up pci connections */ |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10897 | err = pci_request_mem_regions(pdev, i40e_driver_name); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10898 | if (err) { |
| 10899 | dev_info(&pdev->dev, |
| 10900 | "pci_request_selected_regions failed %d\n", err); |
| 10901 | goto err_pci_reg; |
| 10902 | } |
| 10903 | |
| 10904 | pci_enable_pcie_error_reporting(pdev); |
| 10905 | pci_set_master(pdev); |
| 10906 | |
| 10907 | /* Now that we have a PCI connection, we need to do the |
| 10908 | * low level device setup. This is primarily setting up |
| 10909 | * the Admin Queue structures and then querying for the |
| 10910 | * device's current profile information. |
| 10911 | */ |
| 10912 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 10913 | if (!pf) { |
| 10914 | err = -ENOMEM; |
| 10915 | goto err_pf_alloc; |
| 10916 | } |
| 10917 | pf->next_vsi = 0; |
| 10918 | pf->pdev = pdev; |
| 10919 | set_bit(__I40E_DOWN, &pf->state); |
| 10920 | |
| 10921 | hw = &pf->hw; |
| 10922 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10923 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10924 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 10925 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10926 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10927 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10928 | if (!hw->hw_addr) { |
| 10929 | err = -EIO; |
| 10930 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 10931 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10932 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10933 | goto err_ioremap; |
| 10934 | } |
| 10935 | hw->vendor_id = pdev->vendor; |
| 10936 | hw->device_id = pdev->device; |
| 10937 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 10938 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 10939 | hw->subsystem_device_id = pdev->subsystem_device; |
| 10940 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 10941 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10942 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10943 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 10944 | /* set up the locks for the AQ, do this only once in probe |
| 10945 | * and destroy them only once in remove |
| 10946 | */ |
| 10947 | mutex_init(&hw->aq.asq_mutex); |
| 10948 | mutex_init(&hw->aq.arq_mutex); |
| 10949 | |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 10950 | pf->msg_enable = netif_msg_init(debug, |
| 10951 | NETIF_MSG_DRV | |
| 10952 | NETIF_MSG_PROBE | |
| 10953 | NETIF_MSG_LINK); |
| 10954 | if (debug < -1) |
| 10955 | pf->hw.debug_mask = debug; |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 10956 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10957 | /* do a special CORER for clearing PXE mode once at init */ |
| 10958 | if (hw->revision_id == 0 && |
| 10959 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 10960 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 10961 | i40e_flush(hw); |
| 10962 | msleep(200); |
| 10963 | pf->corer_count++; |
| 10964 | |
| 10965 | i40e_clear_pxe_mode(hw); |
| 10966 | } |
| 10967 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10968 | /* 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] | 10969 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10970 | err = i40e_pf_reset(hw); |
| 10971 | if (err) { |
| 10972 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 10973 | goto err_pf_reset; |
| 10974 | } |
| 10975 | pf->pfr_count++; |
| 10976 | |
| 10977 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 10978 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 10979 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10980 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10981 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10982 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 10983 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10984 | "%s-%s:misc", |
| 10985 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10986 | |
| 10987 | err = i40e_init_shared_code(hw); |
| 10988 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 10989 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 10990 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10991 | goto err_pf_reset; |
| 10992 | } |
| 10993 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10994 | /* set up a default setting for link flow control */ |
| 10995 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 10996 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10997 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 10998 | if (err) { |
| 10999 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 11000 | dev_info(&pdev->dev, |
| 11001 | "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"); |
| 11002 | else |
| 11003 | dev_info(&pdev->dev, |
| 11004 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 11005 | |
| 11006 | goto err_pf_reset; |
| 11007 | } |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 11008 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 11009 | /* provide nvm, fw, api versions */ |
| 11010 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 11011 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 11012 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 11013 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 11014 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 11015 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 11016 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 11017 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 11018 | "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"); |
| 11019 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 11020 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 11021 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 11022 | "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] | 11023 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11024 | i40e_verify_eeprom(pf); |
| 11025 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 11026 | /* Rev 0 hardware was never productized */ |
| 11027 | if (hw->revision_id < 1) |
| 11028 | 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"); |
| 11029 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 11030 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11031 | err = i40e_get_capabilities(pf); |
| 11032 | if (err) |
| 11033 | goto err_adminq_setup; |
| 11034 | |
| 11035 | err = i40e_sw_init(pf); |
| 11036 | if (err) { |
| 11037 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 11038 | goto err_sw_init; |
| 11039 | } |
| 11040 | |
| 11041 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 11042 | hw->func_caps.num_rx_qp, |
| 11043 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 11044 | if (err) { |
| 11045 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 11046 | goto err_init_lan_hmc; |
| 11047 | } |
| 11048 | |
| 11049 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 11050 | if (err) { |
| 11051 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 11052 | err = -ENOENT; |
| 11053 | goto err_configure_lan_hmc; |
| 11054 | } |
| 11055 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 11056 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 11057 | * Ignore error return codes because if it was already disabled via |
| 11058 | * hardware settings this will fail |
| 11059 | */ |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 11060 | if (pf->flags & I40E_FLAG_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 11061 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 11062 | i40e_aq_stop_lldp(hw, true, NULL); |
| 11063 | } |
| 11064 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11065 | i40e_get_mac_addr(hw, hw->mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 11066 | /* allow a platform config to override the HW addr */ |
| 11067 | i40e_get_platform_mac_addr(pdev, pf); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 11068 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11069 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 11070 | err = -EIO; |
| 11071 | goto err_mac_addr; |
| 11072 | } |
| 11073 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 11074 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 11075 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 11076 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 11077 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11078 | #ifdef I40E_FCOE |
| 11079 | err = i40e_get_san_mac_addr(hw, hw->mac.san_addr); |
| 11080 | if (err) |
| 11081 | dev_info(&pdev->dev, |
| 11082 | "(non-fatal) SAN MAC retrieval failed: %d\n", err); |
| 11083 | if (!is_valid_ether_addr(hw->mac.san_addr)) { |
| 11084 | dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n", |
| 11085 | hw->mac.san_addr); |
| 11086 | ether_addr_copy(hw->mac.san_addr, hw->mac.addr); |
| 11087 | } |
| 11088 | dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr); |
| 11089 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11090 | |
| 11091 | pci_set_drvdata(pdev, pf); |
| 11092 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11093 | #ifdef CONFIG_I40E_DCB |
| 11094 | err = i40e_init_pf_dcb(pf); |
| 11095 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 11096 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
David Ertman | c17ef43 | 2016-09-30 01:36:21 -0700 | [diff] [blame] | 11097 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED); |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 11098 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11099 | } |
| 11100 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11101 | |
| 11102 | /* set up periodic task facility */ |
| 11103 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 11104 | pf->service_timer_period = HZ; |
| 11105 | |
| 11106 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 11107 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 11108 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11109 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11110 | /* NVM bit on means WoL disabled for the port */ |
| 11111 | 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] | 11112 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11113 | pf->wol_en = false; |
| 11114 | else |
| 11115 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11116 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 11117 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11118 | /* set up the main switch operations */ |
| 11119 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 11120 | err = i40e_init_interrupt_scheme(pf); |
| 11121 | if (err) |
| 11122 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11123 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11124 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 11125 | * to us; HW supports far more and we share the remaining pool with |
| 11126 | * the other PFs. We allocate space for more than the guarantee with |
| 11127 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11128 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11129 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 11130 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 11131 | else |
| 11132 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 11133 | |
| 11134 | /* 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] | 11135 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 11136 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11137 | if (!pf->vsi) { |
| 11138 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11139 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11140 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11141 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 11142 | #ifdef CONFIG_PCI_IOV |
| 11143 | /* prep for VF support */ |
| 11144 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 11145 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11146 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 11147 | if (pci_num_vf(pdev)) |
| 11148 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 11149 | } |
| 11150 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11151 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11152 | if (err) { |
| 11153 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 11154 | goto err_vsis; |
| 11155 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11156 | |
| 11157 | /* Make sure flow control is set according to current settings */ |
| 11158 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 11159 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 11160 | dev_dbg(&pf->pdev->dev, |
| 11161 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 11162 | i40e_stat_str(hw, err), |
| 11163 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11164 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 11165 | dev_dbg(&pf->pdev->dev, |
| 11166 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 11167 | i40e_stat_str(hw, err), |
| 11168 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11169 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 11170 | dev_dbg(&pf->pdev->dev, |
| 11171 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 11172 | i40e_stat_str(hw, err), |
| 11173 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11174 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11175 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11176 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11177 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 11178 | i40e_vsi_open(pf->vsi[i]); |
| 11179 | break; |
| 11180 | } |
| 11181 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11182 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11183 | /* The driver only wants link up/down and module qualification |
| 11184 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11185 | */ |
| 11186 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11187 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 11188 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11189 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11190 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11191 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 11192 | i40e_stat_str(&pf->hw, err), |
| 11193 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11194 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11195 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 11196 | * of TSO, so that we avoid the MDD being fired and causing |
| 11197 | * a reset in the case of small MSS+TSO. |
| 11198 | */ |
| 11199 | val = rd32(hw, I40E_REG_MSS); |
| 11200 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 11201 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 11202 | val |= I40E_64BYTE_MSS; |
| 11203 | wr32(hw, I40E_REG_MSS, val); |
| 11204 | } |
| 11205 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 11206 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 11207 | msleep(75); |
| 11208 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 11209 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11210 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 11211 | i40e_stat_str(&pf->hw, err), |
| 11212 | i40e_aq_str(&pf->hw, |
| 11213 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 11214 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11215 | /* The main driver is (mostly) up and happy. We need to set this state |
| 11216 | * before setting up the misc vector or we get a race and the vector |
| 11217 | * ends up disabled forever. |
| 11218 | */ |
| 11219 | clear_bit(__I40E_DOWN, &pf->state); |
| 11220 | |
| 11221 | /* In case of MSIX we are going to setup the misc vector right here |
| 11222 | * to handle admin queue events etc. In case of legacy and MSI |
| 11223 | * the misc functionality and queue processing is combined in |
| 11224 | * the same vector and that gets setup at open. |
| 11225 | */ |
| 11226 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 11227 | err = i40e_setup_misc_vector(pf); |
| 11228 | if (err) { |
| 11229 | dev_info(&pdev->dev, |
| 11230 | "setup of misc vector failed: %d\n", err); |
| 11231 | goto err_vsis; |
| 11232 | } |
| 11233 | } |
| 11234 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11235 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11236 | /* prep for VF support */ |
| 11237 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11238 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11239 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11240 | /* disable link interrupts for VFs */ |
| 11241 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11242 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11243 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11244 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11245 | |
| 11246 | if (pci_num_vf(pdev)) { |
| 11247 | dev_info(&pdev->dev, |
| 11248 | "Active VFs found, allocating resources.\n"); |
| 11249 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11250 | if (err) |
| 11251 | dev_info(&pdev->dev, |
| 11252 | "Error %d allocating resources for existing VFs\n", |
| 11253 | err); |
| 11254 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11255 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11256 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11257 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11258 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11259 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11260 | pf->num_iwarp_msix, |
| 11261 | I40E_IWARP_IRQ_PILE_ID); |
| 11262 | if (pf->iwarp_base_vector < 0) { |
| 11263 | dev_info(&pdev->dev, |
| 11264 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 11265 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 11266 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 11267 | } |
| 11268 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11269 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11270 | i40e_dbg_pf_init(pf); |
| 11271 | |
| 11272 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11273 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11274 | |
| 11275 | /* since everything's happy, start the service_task timer */ |
| 11276 | mod_timer(&pf->service_timer, |
| 11277 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11278 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11279 | /* add this PF to client device list and launch a client service task */ |
| 11280 | err = i40e_lan_add_device(pf); |
| 11281 | if (err) |
| 11282 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 11283 | err); |
| 11284 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11285 | #ifdef I40E_FCOE |
| 11286 | /* create FCoE interface */ |
| 11287 | i40e_fcoe_vsi_setup(pf); |
| 11288 | |
| 11289 | #endif |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11290 | #define PCI_SPEED_SIZE 8 |
| 11291 | #define PCI_WIDTH_SIZE 8 |
| 11292 | /* Devices on the IOSF bus do not have this information |
| 11293 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11294 | * checking them. |
| 11295 | */ |
| 11296 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { |
| 11297 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11298 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11299 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11300 | /* Get the negotiated link width and speed from PCI config |
| 11301 | * space |
| 11302 | */ |
| 11303 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11304 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11305 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11306 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11307 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11308 | switch (hw->bus.speed) { |
| 11309 | case i40e_bus_speed_8000: |
| 11310 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11311 | case i40e_bus_speed_5000: |
| 11312 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11313 | case i40e_bus_speed_2500: |
| 11314 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11315 | default: |
| 11316 | break; |
| 11317 | } |
| 11318 | switch (hw->bus.width) { |
| 11319 | case i40e_bus_width_pcie_x8: |
| 11320 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11321 | case i40e_bus_width_pcie_x4: |
| 11322 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11323 | case i40e_bus_width_pcie_x2: |
| 11324 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11325 | case i40e_bus_width_pcie_x1: |
| 11326 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11327 | default: |
| 11328 | break; |
| 11329 | } |
| 11330 | |
| 11331 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11332 | speed, width); |
| 11333 | |
| 11334 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11335 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11336 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11337 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11338 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11339 | } |
| 11340 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11341 | /* get the requested speeds from the fw */ |
| 11342 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11343 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11344 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11345 | i40e_stat_str(&pf->hw, err), |
| 11346 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11347 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11348 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11349 | /* get the supported phy types from the fw */ |
| 11350 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11351 | if (err) |
| 11352 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11353 | i40e_stat_str(&pf->hw, err), |
| 11354 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 11355 | pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type); |
| 11356 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11357 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11358 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11359 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11360 | * PF/VF VSIs. |
| 11361 | * The FW can still send Flow control frames if enabled. |
| 11362 | */ |
| 11363 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11364 | pf->main_vsi_seid); |
| 11365 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 11366 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
| 11367 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
| 11368 | pf->flags |= I40E_FLAG_HAVE_10GBASET_PHY; |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 11369 | if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722) |
| 11370 | pf->flags |= I40E_FLAG_HAVE_CRT_RETIMER; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11371 | /* print a string summarizing features */ |
| 11372 | i40e_print_features(pf); |
| 11373 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11374 | return 0; |
| 11375 | |
| 11376 | /* Unwind what we've done if something failed in the setup */ |
| 11377 | err_vsis: |
| 11378 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11379 | i40e_clear_interrupt_scheme(pf); |
| 11380 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11381 | err_switch_setup: |
| 11382 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11383 | del_timer_sync(&pf->service_timer); |
| 11384 | err_mac_addr: |
| 11385 | err_configure_lan_hmc: |
| 11386 | (void)i40e_shutdown_lan_hmc(hw); |
| 11387 | err_init_lan_hmc: |
| 11388 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11389 | err_sw_init: |
| 11390 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11391 | err_pf_reset: |
| 11392 | iounmap(hw->hw_addr); |
| 11393 | err_ioremap: |
| 11394 | kfree(pf); |
| 11395 | err_pf_alloc: |
| 11396 | pci_disable_pcie_error_reporting(pdev); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11397 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11398 | err_pci_reg: |
| 11399 | err_dma: |
| 11400 | pci_disable_device(pdev); |
| 11401 | return err; |
| 11402 | } |
| 11403 | |
| 11404 | /** |
| 11405 | * i40e_remove - Device removal routine |
| 11406 | * @pdev: PCI device information struct |
| 11407 | * |
| 11408 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11409 | * that is should release a PCI device. This could be caused by a |
| 11410 | * Hot-Plug event, or because the driver is going to be removed from |
| 11411 | * memory. |
| 11412 | **/ |
| 11413 | static void i40e_remove(struct pci_dev *pdev) |
| 11414 | { |
| 11415 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11416 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11417 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11418 | int i; |
| 11419 | |
| 11420 | i40e_dbg_pf_exit(pf); |
| 11421 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11422 | i40e_ptp_stop(pf); |
| 11423 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11424 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 11425 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 11426 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11427 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11428 | /* no more scheduling of any task */ |
Pandi Kumar Maharajan | a4618ec | 2016-02-18 09:19:25 -0800 | [diff] [blame] | 11429 | set_bit(__I40E_SUSPENDED, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11430 | set_bit(__I40E_DOWN, &pf->state); |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 11431 | if (pf->service_timer.data) |
| 11432 | del_timer_sync(&pf->service_timer); |
| 11433 | if (pf->service_task.func) |
| 11434 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11435 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11436 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11437 | i40e_free_vfs(pf); |
| 11438 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11439 | } |
| 11440 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11441 | i40e_fdir_teardown(pf); |
| 11442 | |
| 11443 | /* If there is a switch structure or any orphans, remove them. |
| 11444 | * This will leave only the PF's VSI remaining. |
| 11445 | */ |
| 11446 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11447 | if (!pf->veb[i]) |
| 11448 | continue; |
| 11449 | |
| 11450 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11451 | pf->veb[i]->uplink_seid == 0) |
| 11452 | i40e_switch_branch_release(pf->veb[i]); |
| 11453 | } |
| 11454 | |
| 11455 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11456 | * adminq and hmc. |
| 11457 | */ |
| 11458 | if (pf->vsi[pf->lan_vsi]) |
| 11459 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11460 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11461 | /* remove attached clients */ |
| 11462 | ret_code = i40e_lan_del_device(pf); |
| 11463 | if (ret_code) { |
| 11464 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 11465 | ret_code); |
| 11466 | } |
| 11467 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11468 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11469 | if (hw->hmc.hmc_obj) { |
| 11470 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11471 | if (ret_code) |
| 11472 | dev_warn(&pdev->dev, |
| 11473 | "Failed to destroy the HMC resources: %d\n", |
| 11474 | ret_code); |
| 11475 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11476 | |
| 11477 | /* shutdown the adminq */ |
Henry Tieman | ac9c5c6 | 2016-09-06 18:05:11 -0700 | [diff] [blame] | 11478 | i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11479 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11480 | /* destroy the locks only once, here */ |
| 11481 | mutex_destroy(&hw->aq.arq_mutex); |
| 11482 | mutex_destroy(&hw->aq.asq_mutex); |
| 11483 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11484 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11485 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11486 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11487 | if (pf->vsi[i]) { |
| 11488 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11489 | i40e_vsi_clear(pf->vsi[i]); |
| 11490 | pf->vsi[i] = NULL; |
| 11491 | } |
| 11492 | } |
| 11493 | |
| 11494 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11495 | kfree(pf->veb[i]); |
| 11496 | pf->veb[i] = NULL; |
| 11497 | } |
| 11498 | |
| 11499 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11500 | kfree(pf->vsi); |
| 11501 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11502 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11503 | kfree(pf); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11504 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11505 | |
| 11506 | pci_disable_pcie_error_reporting(pdev); |
| 11507 | pci_disable_device(pdev); |
| 11508 | } |
| 11509 | |
| 11510 | /** |
| 11511 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11512 | * @pdev: PCI device information struct |
| 11513 | * |
| 11514 | * Called to warn that something happened and the error handling steps |
| 11515 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11516 | * remediation. |
| 11517 | **/ |
| 11518 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11519 | enum pci_channel_state error) |
| 11520 | { |
| 11521 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11522 | |
| 11523 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11524 | |
Guilherme G Piccoli | edfc23ee | 2016-10-03 00:31:12 -0700 | [diff] [blame] | 11525 | if (!pf) { |
| 11526 | dev_info(&pdev->dev, |
| 11527 | "Cannot recover - error happened during device probe\n"); |
| 11528 | return PCI_ERS_RESULT_DISCONNECT; |
| 11529 | } |
| 11530 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11531 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11532 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11533 | rtnl_lock(); |
| 11534 | i40e_prep_for_reset(pf); |
| 11535 | rtnl_unlock(); |
| 11536 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11537 | |
| 11538 | /* Request a slot reset */ |
| 11539 | return PCI_ERS_RESULT_NEED_RESET; |
| 11540 | } |
| 11541 | |
| 11542 | /** |
| 11543 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11544 | * @pdev: PCI device information struct |
| 11545 | * |
| 11546 | * Called to find if the driver can work with the device now that |
| 11547 | * the pci slot has been reset. If a basic connection seems good |
| 11548 | * (registers are readable and have sane content) then return a |
| 11549 | * happy little PCI_ERS_RESULT_xxx. |
| 11550 | **/ |
| 11551 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11552 | { |
| 11553 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11554 | pci_ers_result_t result; |
| 11555 | int err; |
| 11556 | u32 reg; |
| 11557 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11558 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11559 | if (pci_enable_device_mem(pdev)) { |
| 11560 | dev_info(&pdev->dev, |
| 11561 | "Cannot re-enable PCI device after reset.\n"); |
| 11562 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11563 | } else { |
| 11564 | pci_set_master(pdev); |
| 11565 | pci_restore_state(pdev); |
| 11566 | pci_save_state(pdev); |
| 11567 | pci_wake_from_d3(pdev, false); |
| 11568 | |
| 11569 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11570 | if (reg == 0) |
| 11571 | result = PCI_ERS_RESULT_RECOVERED; |
| 11572 | else |
| 11573 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11574 | } |
| 11575 | |
| 11576 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11577 | if (err) { |
| 11578 | dev_info(&pdev->dev, |
| 11579 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11580 | err); |
| 11581 | /* non-fatal, continue */ |
| 11582 | } |
| 11583 | |
| 11584 | return result; |
| 11585 | } |
| 11586 | |
| 11587 | /** |
| 11588 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11589 | * @pdev: PCI device information struct |
| 11590 | * |
| 11591 | * Called to allow the driver to bring things back up after PCI error |
| 11592 | * and/or reset recovery has finished. |
| 11593 | **/ |
| 11594 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11595 | { |
| 11596 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11597 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11598 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11599 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 11600 | return; |
| 11601 | |
| 11602 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11603 | i40e_handle_reset_warning(pf); |
Vasily Averin | 4c4935a | 2015-07-08 15:04:26 +0300 | [diff] [blame] | 11604 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11605 | } |
| 11606 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11607 | /** |
| 11608 | * i40e_shutdown - PCI callback for shutting down |
| 11609 | * @pdev: PCI device information struct |
| 11610 | **/ |
| 11611 | static void i40e_shutdown(struct pci_dev *pdev) |
| 11612 | { |
| 11613 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11614 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11615 | |
| 11616 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11617 | set_bit(__I40E_DOWN, &pf->state); |
| 11618 | rtnl_lock(); |
| 11619 | i40e_prep_for_reset(pf); |
| 11620 | rtnl_unlock(); |
| 11621 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11622 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11623 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11624 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11625 | del_timer_sync(&pf->service_timer); |
| 11626 | cancel_work_sync(&pf->service_task); |
| 11627 | i40e_fdir_teardown(pf); |
| 11628 | |
| 11629 | rtnl_lock(); |
| 11630 | i40e_prep_for_reset(pf); |
| 11631 | rtnl_unlock(); |
| 11632 | |
| 11633 | wr32(hw, I40E_PFPM_APM, |
| 11634 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11635 | wr32(hw, I40E_PFPM_WUFC, |
| 11636 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11637 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 11638 | i40e_clear_interrupt_scheme(pf); |
| 11639 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11640 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11641 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11642 | pci_set_power_state(pdev, PCI_D3hot); |
| 11643 | } |
| 11644 | } |
| 11645 | |
| 11646 | #ifdef CONFIG_PM |
| 11647 | /** |
| 11648 | * i40e_suspend - PCI callback for moving to D3 |
| 11649 | * @pdev: PCI device information struct |
| 11650 | **/ |
| 11651 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11652 | { |
| 11653 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11654 | struct i40e_hw *hw = &pf->hw; |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11655 | int retval = 0; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11656 | |
| 11657 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11658 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 11659 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11660 | rtnl_lock(); |
| 11661 | i40e_prep_for_reset(pf); |
| 11662 | rtnl_unlock(); |
| 11663 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11664 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11665 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11666 | |
Greg Rose | b33d3b7 | 2016-05-16 10:26:37 -0700 | [diff] [blame] | 11667 | i40e_stop_misc_vector(pf); |
| 11668 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11669 | retval = pci_save_state(pdev); |
| 11670 | if (retval) |
| 11671 | return retval; |
| 11672 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11673 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11674 | pci_set_power_state(pdev, PCI_D3hot); |
| 11675 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11676 | return retval; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11677 | } |
| 11678 | |
| 11679 | /** |
| 11680 | * i40e_resume - PCI callback for waking up from D3 |
| 11681 | * @pdev: PCI device information struct |
| 11682 | **/ |
| 11683 | static int i40e_resume(struct pci_dev *pdev) |
| 11684 | { |
| 11685 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11686 | u32 err; |
| 11687 | |
| 11688 | pci_set_power_state(pdev, PCI_D0); |
| 11689 | pci_restore_state(pdev); |
| 11690 | /* pci_restore_state() clears dev->state_saves, so |
| 11691 | * call pci_save_state() again to restore it. |
| 11692 | */ |
| 11693 | pci_save_state(pdev); |
| 11694 | |
| 11695 | err = pci_enable_device_mem(pdev); |
| 11696 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11697 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11698 | return err; |
| 11699 | } |
| 11700 | pci_set_master(pdev); |
| 11701 | |
| 11702 | /* no wakeup events while running */ |
| 11703 | pci_wake_from_d3(pdev, false); |
| 11704 | |
| 11705 | /* handling the reset will rebuild the device state */ |
| 11706 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11707 | clear_bit(__I40E_DOWN, &pf->state); |
| 11708 | rtnl_lock(); |
| 11709 | i40e_reset_and_rebuild(pf, false); |
| 11710 | rtnl_unlock(); |
| 11711 | } |
| 11712 | |
| 11713 | return 0; |
| 11714 | } |
| 11715 | |
| 11716 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11717 | static const struct pci_error_handlers i40e_err_handler = { |
| 11718 | .error_detected = i40e_pci_error_detected, |
| 11719 | .slot_reset = i40e_pci_error_slot_reset, |
| 11720 | .resume = i40e_pci_error_resume, |
| 11721 | }; |
| 11722 | |
| 11723 | static struct pci_driver i40e_driver = { |
| 11724 | .name = i40e_driver_name, |
| 11725 | .id_table = i40e_pci_tbl, |
| 11726 | .probe = i40e_probe, |
| 11727 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11728 | #ifdef CONFIG_PM |
| 11729 | .suspend = i40e_suspend, |
| 11730 | .resume = i40e_resume, |
| 11731 | #endif |
| 11732 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11733 | .err_handler = &i40e_err_handler, |
| 11734 | .sriov_configure = i40e_pci_sriov_configure, |
| 11735 | }; |
| 11736 | |
| 11737 | /** |
| 11738 | * i40e_init_module - Driver registration routine |
| 11739 | * |
| 11740 | * i40e_init_module is the first routine called when the driver is |
| 11741 | * loaded. All it does is register with the PCI subsystem. |
| 11742 | **/ |
| 11743 | static int __init i40e_init_module(void) |
| 11744 | { |
| 11745 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 11746 | i40e_driver_string, i40e_driver_version_str); |
| 11747 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 11748 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11749 | /* we will see if single thread per module is enough for now, |
| 11750 | * it can't be any worse than using the system workqueue which |
| 11751 | * was already single threaded |
| 11752 | */ |
Jacob Keller | 6992a6c | 2016-08-04 11:37:01 -0700 | [diff] [blame] | 11753 | i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1, |
| 11754 | i40e_driver_name); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11755 | if (!i40e_wq) { |
| 11756 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 11757 | return -ENOMEM; |
| 11758 | } |
| 11759 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11760 | i40e_dbg_init(); |
| 11761 | return pci_register_driver(&i40e_driver); |
| 11762 | } |
| 11763 | module_init(i40e_init_module); |
| 11764 | |
| 11765 | /** |
| 11766 | * i40e_exit_module - Driver exit cleanup routine |
| 11767 | * |
| 11768 | * i40e_exit_module is called just before the driver is removed |
| 11769 | * from memory. |
| 11770 | **/ |
| 11771 | static void __exit i40e_exit_module(void) |
| 11772 | { |
| 11773 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11774 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11775 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11776 | } |
| 11777 | module_exit(i40e_exit_module); |