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 |
| 1214 | * i40e_vsi_sync_filters_subtask. |
| 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 |
| 1219 | * i40e_vsi_sync_filters_subtask, but we already have to search |
| 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 | |
Kiran Patil | f6bd096 | 2016-06-20 09:10:34 -0700 | [diff] [blame] | 1248 | /* Do not allow broadcast filter to be added since broadcast filter |
| 1249 | * is added as part of add VSI for any newly created VSI except |
| 1250 | * FDIR VSI |
| 1251 | */ |
| 1252 | if (is_broadcast_ether_addr(macaddr)) |
| 1253 | return NULL; |
| 1254 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1255 | f = i40e_find_filter(vsi, macaddr, vlan); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1256 | if (!f) { |
| 1257 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1258 | if (!f) |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1259 | return NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1260 | |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 1261 | /* Update the boolean indicating if we need to function in |
| 1262 | * VLAN mode. |
| 1263 | */ |
| 1264 | if (vlan >= 0) |
| 1265 | vsi->has_vlan_filter = true; |
| 1266 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1267 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1268 | f->vlan = vlan; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1269 | /* If we're in overflow promisc mode, set the state directly |
| 1270 | * to failed, so we don't bother to try sending the filter |
| 1271 | * to the hardware. |
| 1272 | */ |
| 1273 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state)) |
| 1274 | f->state = I40E_FILTER_FAILED; |
| 1275 | else |
| 1276 | f->state = I40E_FILTER_NEW; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1277 | INIT_HLIST_NODE(&f->hlist); |
| 1278 | |
| 1279 | key = i40e_addr_to_hkey(macaddr); |
| 1280 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1281 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1282 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1283 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1284 | } |
| 1285 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1286 | /* If we're asked to add a filter that has been marked for removal, it |
| 1287 | * is safe to simply restore it to active state. __i40e_del_filter |
| 1288 | * will have simply deleted any filters which were previously marked |
| 1289 | * NEW or FAILED, so if it is currently marked REMOVE it must have |
| 1290 | * previously been ACTIVE. Since we haven't yet run the sync filters |
| 1291 | * task, just restore this filter to the ACTIVE state so that the |
| 1292 | * sync task leaves it in place |
| 1293 | */ |
| 1294 | if (f->state == I40E_FILTER_REMOVE) |
| 1295 | f->state = I40E_FILTER_ACTIVE; |
| 1296 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1297 | return f; |
| 1298 | } |
| 1299 | |
| 1300 | /** |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1301 | * __i40e_del_filter - Remove a specific filter from the VSI |
| 1302 | * @vsi: VSI to remove from |
| 1303 | * @f: the filter to remove from the list |
| 1304 | * |
| 1305 | * This function should be called instead of i40e_del_filter only if you know |
| 1306 | * the exact filter you will remove already, such as via i40e_find_filter or |
| 1307 | * i40e_find_mac. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1308 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1309 | * 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] | 1310 | * being held. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1311 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1312 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1313 | * instead of list_for_each_entry(). |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1314 | **/ |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1315 | 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] | 1316 | { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1317 | if (!f) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1318 | return; |
| 1319 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1320 | if ((f->state == I40E_FILTER_FAILED) || |
| 1321 | (f->state == I40E_FILTER_NEW)) { |
| 1322 | /* this one never got added by the FW. Just remove it, |
| 1323 | * no need to sync anything. |
| 1324 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1325 | hash_del(&f->hlist); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1326 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1327 | } else { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1328 | f->state = I40E_FILTER_REMOVE; |
| 1329 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1330 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | /** |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1335 | * i40e_del_filter - Remove a MAC/VLAN filter from the VSI |
| 1336 | * @vsi: the VSI to be searched |
| 1337 | * @macaddr: the MAC address |
| 1338 | * @vlan: the VLAN |
| 1339 | * |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1340 | * 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] | 1341 | * being held. |
| 1342 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1343 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1344 | * instead of list_for_each_entry(). |
| 1345 | **/ |
| 1346 | void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan) |
| 1347 | { |
| 1348 | struct i40e_mac_filter *f; |
| 1349 | |
| 1350 | if (!vsi || !macaddr) |
| 1351 | return; |
| 1352 | |
| 1353 | f = i40e_find_filter(vsi, macaddr, vlan); |
| 1354 | __i40e_del_filter(vsi, f); |
| 1355 | } |
| 1356 | |
| 1357 | /** |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1358 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1359 | * @vsi: the VSI to be searched |
| 1360 | * @macaddr: the mac address to be filtered |
| 1361 | * |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1362 | * Goes through all the macvlan filters and adds a macvlan filter for each |
| 1363 | * unique vlan that already exists. If a PVID has been assigned, instead only |
| 1364 | * add the macaddr to that VLAN. |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1365 | * |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1366 | * Returns last filter added on success, else NULL |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1367 | **/ |
| 1368 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, |
| 1369 | const u8 *macaddr) |
| 1370 | { |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1371 | struct i40e_mac_filter *f, *add = NULL; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1372 | struct hlist_node *h; |
| 1373 | int bkt; |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1374 | |
| 1375 | if (vsi->info.pvid) |
| 1376 | return i40e_add_filter(vsi, macaddr, |
| 1377 | le16_to_cpu(vsi->info.pvid)); |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1378 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1379 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 1380 | if (f->state == I40E_FILTER_REMOVE) |
| 1381 | continue; |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1382 | add = i40e_add_filter(vsi, macaddr, f->vlan); |
| 1383 | if (!add) |
| 1384 | return NULL; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
Jacob Keller | 5feb3d7 | 2016-10-05 09:30:34 -0700 | [diff] [blame] | 1387 | return add; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | /** |
| 1391 | * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS |
| 1392 | * @vsi: the VSI to be searched |
| 1393 | * @macaddr: the mac address to be removed |
| 1394 | * |
| 1395 | * Removes a given MAC address from a VSI, regardless of VLAN |
| 1396 | * |
| 1397 | * Returns 0 for success, or error |
| 1398 | **/ |
| 1399 | int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, const u8 *macaddr) |
| 1400 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1401 | struct i40e_mac_filter *f; |
| 1402 | struct hlist_node *h; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1403 | bool found = false; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1404 | int bkt; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1405 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1406 | WARN(!spin_is_locked(&vsi->mac_filter_hash_lock), |
| 1407 | "Missing mac_filter_hash_lock\n"); |
| 1408 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1409 | if (ether_addr_equal(macaddr, f->macaddr)) { |
| 1410 | __i40e_del_filter(vsi, f); |
| 1411 | found = true; |
| 1412 | } |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1413 | } |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1414 | |
| 1415 | if (found) |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1416 | return 0; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 1417 | else |
| 1418 | return -ENOENT; |
Jacob Keller | 35ec2ff | 2016-10-05 09:30:33 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1422 | * i40e_set_mac - NDO callback to set mac address |
| 1423 | * @netdev: network interface device structure |
| 1424 | * @p: pointer to an address structure |
| 1425 | * |
| 1426 | * Returns 0 on success, negative on failure |
| 1427 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1428 | #ifdef I40E_FCOE |
| 1429 | int i40e_set_mac(struct net_device *netdev, void *p) |
| 1430 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1431 | static int i40e_set_mac(struct net_device *netdev, void *p) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1432 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1433 | { |
| 1434 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1435 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1436 | struct i40e_pf *pf = vsi->back; |
| 1437 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1438 | struct sockaddr *addr = p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1439 | |
| 1440 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1441 | return -EADDRNOTAVAIL; |
| 1442 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1443 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1444 | netdev_info(netdev, "already using mac address %pM\n", |
| 1445 | addr->sa_data); |
| 1446 | return 0; |
| 1447 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1448 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1449 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1450 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1451 | return -EADDRNOTAVAIL; |
| 1452 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1453 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1454 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1455 | hw->mac.addr); |
| 1456 | else |
| 1457 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1458 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1459 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 1460 | i40e_del_mac_all_vlan(vsi, netdev->dev_addr); |
| 1461 | i40e_put_mac_in_vlan(vsi, addr->sa_data); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1462 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1463 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1464 | if (vsi->type == I40E_VSI_MAIN) { |
| 1465 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1466 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1467 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1468 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1469 | addr->sa_data, NULL); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1470 | if (ret) |
| 1471 | netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n", |
| 1472 | i40e_stat_str(hw, ret), |
| 1473 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1476 | /* schedule our worker thread which will take care of |
| 1477 | * applying the new filter changes |
| 1478 | */ |
| 1479 | i40e_service_event_schedule(vsi->back); |
| 1480 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | /** |
| 1484 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1485 | * @vsi: the VSI being setup |
| 1486 | * @ctxt: VSI context structure |
| 1487 | * @enabled_tc: Enabled TCs bitmap |
| 1488 | * @is_add: True if called before Add VSI |
| 1489 | * |
| 1490 | * Setup VSI queue mapping for enabled traffic classes. |
| 1491 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1492 | #ifdef I40E_FCOE |
| 1493 | void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1494 | struct i40e_vsi_context *ctxt, |
| 1495 | u8 enabled_tc, |
| 1496 | bool is_add) |
| 1497 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1498 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1499 | struct i40e_vsi_context *ctxt, |
| 1500 | u8 enabled_tc, |
| 1501 | bool is_add) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1502 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1503 | { |
| 1504 | struct i40e_pf *pf = vsi->back; |
| 1505 | u16 sections = 0; |
| 1506 | u8 netdev_tc = 0; |
| 1507 | u16 numtc = 0; |
| 1508 | u16 qcount; |
| 1509 | u8 offset; |
| 1510 | u16 qmap; |
| 1511 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1512 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1513 | |
| 1514 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1515 | offset = 0; |
| 1516 | |
| 1517 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1518 | /* Find numtc from enabled TC bitmap */ |
| 1519 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1520 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1521 | numtc++; |
| 1522 | } |
| 1523 | if (!numtc) { |
| 1524 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1525 | numtc = 1; |
| 1526 | } |
| 1527 | } else { |
| 1528 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1529 | numtc = 1; |
| 1530 | } |
| 1531 | |
| 1532 | vsi->tc_config.numtc = numtc; |
| 1533 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1534 | /* Number of queues per enabled TC */ |
Catherine Sullivan | 7d64402 | 2016-05-16 10:26:41 -0700 | [diff] [blame] | 1535 | qcount = vsi->alloc_queue_pairs; |
| 1536 | |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1537 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1538 | 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] | 1539 | |
| 1540 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1541 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1542 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1543 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1544 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1545 | int pow, num_qps; |
| 1546 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1547 | switch (vsi->type) { |
| 1548 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1549 | qcount = min_t(int, pf->alloc_rss_size, |
| 1550 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1551 | break; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1552 | #ifdef I40E_FCOE |
| 1553 | case I40E_VSI_FCOE: |
| 1554 | qcount = num_tc_qps; |
| 1555 | break; |
| 1556 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1557 | case I40E_VSI_FDIR: |
| 1558 | case I40E_VSI_SRIOV: |
| 1559 | case I40E_VSI_VMDQ2: |
| 1560 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1561 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1562 | WARN_ON(i != 0); |
| 1563 | break; |
| 1564 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1565 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1566 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1567 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1568 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1569 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1570 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1571 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1572 | pow++; |
| 1573 | num_qps >>= 1; |
| 1574 | } |
| 1575 | |
| 1576 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1577 | qmap = |
| 1578 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1579 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1580 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1581 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1582 | } else { |
| 1583 | /* TC is not enabled so set the offset to |
| 1584 | * default queue and allocate one queue |
| 1585 | * for the given TC. |
| 1586 | */ |
| 1587 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1588 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1589 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1590 | |
| 1591 | qmap = 0; |
| 1592 | } |
| 1593 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1594 | } |
| 1595 | |
| 1596 | /* Set actual Tx/Rx queue pairs */ |
| 1597 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1598 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1599 | if (vsi->req_queue_pairs > 0) |
| 1600 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1601 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1602 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1603 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1604 | |
| 1605 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1606 | if (is_add) { |
| 1607 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1608 | |
| 1609 | ctxt->info.up_enable_bits = enabled_tc; |
| 1610 | } |
| 1611 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1612 | ctxt->info.mapping_flags |= |
| 1613 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1614 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1615 | ctxt->info.queue_mapping[i] = |
| 1616 | cpu_to_le16(vsi->base_queue + i); |
| 1617 | } else { |
| 1618 | ctxt->info.mapping_flags |= |
| 1619 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1620 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1621 | } |
| 1622 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1623 | } |
| 1624 | |
| 1625 | /** |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1626 | * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address |
| 1627 | * @netdev: the netdevice |
| 1628 | * @addr: address to add |
| 1629 | * |
| 1630 | * Called by __dev_(mc|uc)_sync when an address needs to be added. We call |
| 1631 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1632 | */ |
| 1633 | static int i40e_addr_sync(struct net_device *netdev, const u8 *addr) |
| 1634 | { |
| 1635 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1636 | struct i40e_vsi *vsi = np->vsi; |
| 1637 | struct i40e_mac_filter *f; |
| 1638 | |
| 1639 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1640 | f = i40e_put_mac_in_vlan(vsi, addr); |
| 1641 | else |
| 1642 | f = i40e_add_filter(vsi, addr, I40E_VLAN_ANY); |
| 1643 | |
| 1644 | if (f) |
| 1645 | return 0; |
| 1646 | else |
| 1647 | return -ENOMEM; |
| 1648 | } |
| 1649 | |
| 1650 | /** |
| 1651 | * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address |
| 1652 | * @netdev: the netdevice |
| 1653 | * @addr: address to add |
| 1654 | * |
| 1655 | * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call |
| 1656 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. |
| 1657 | */ |
| 1658 | static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr) |
| 1659 | { |
| 1660 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1661 | struct i40e_vsi *vsi = np->vsi; |
| 1662 | |
| 1663 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1664 | i40e_del_mac_all_vlan(vsi, addr); |
| 1665 | else |
| 1666 | i40e_del_filter(vsi, addr, I40E_VLAN_ANY); |
| 1667 | |
| 1668 | return 0; |
| 1669 | } |
| 1670 | |
| 1671 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1672 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1673 | * @netdev: network interface device structure |
| 1674 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1675 | #ifdef I40E_FCOE |
| 1676 | void i40e_set_rx_mode(struct net_device *netdev) |
| 1677 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1678 | static void i40e_set_rx_mode(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1679 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1680 | { |
| 1681 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1682 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1683 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1684 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1685 | |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 1686 | __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
| 1687 | __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1688 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1689 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1690 | |
| 1691 | /* check for other flag changes */ |
| 1692 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1693 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1694 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1695 | } |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1696 | |
| 1697 | /* schedule our worker thread which will take care of |
| 1698 | * applying the new filter changes |
| 1699 | */ |
| 1700 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | /** |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 1704 | * i40e_undo_filter_entries - Undo the changes made to MAC filter entries |
| 1705 | * @vsi: Pointer to VSI struct |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1706 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1707 | * those entries needs to be undone. |
| 1708 | * |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 1709 | * MAC filter entries from list were slated to be sent to firmware, either for |
| 1710 | * addition or deletion. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1711 | **/ |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 1712 | static void i40e_undo_filter_entries(struct i40e_vsi *vsi, |
| 1713 | struct hlist_head *from) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1714 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1715 | struct i40e_mac_filter *f; |
| 1716 | struct hlist_node *h; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1717 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1718 | hlist_for_each_entry_safe(f, h, from, hlist) { |
| 1719 | u64 key = i40e_addr_to_hkey(f->macaddr); |
| 1720 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1721 | /* Move the element back into MAC filter list*/ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1722 | hlist_del(&f->hlist); |
| 1723 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | /** |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1728 | * i40e_update_filter_state - Update filter state based on return data |
| 1729 | * from firmware |
| 1730 | * @count: Number of filters added |
| 1731 | * @add_list: return data from fw |
| 1732 | * @head: pointer to first filter in current batch |
| 1733 | * @aq_err: status from fw |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1734 | * |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1735 | * MAC filter entries from list were slated to be added to device. Returns |
| 1736 | * number of successful filters. Note that 0 does NOT mean success! |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1737 | **/ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1738 | static int |
| 1739 | i40e_update_filter_state(int count, |
| 1740 | struct i40e_aqc_add_macvlan_element_data *add_list, |
| 1741 | struct i40e_mac_filter *add_head, int aq_err) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1742 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1743 | int retval = 0; |
| 1744 | int i; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1745 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1746 | |
| 1747 | if (!aq_err) { |
| 1748 | retval = count; |
| 1749 | /* Everything's good, mark all filters active. */ |
| 1750 | for (i = 0; i < count ; i++) { |
| 1751 | add_head->state = I40E_FILTER_ACTIVE; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1752 | add_head = hlist_entry(add_head->hlist.next, |
| 1753 | typeof(struct i40e_mac_filter), |
| 1754 | hlist); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1755 | } |
| 1756 | } else if (aq_err == I40E_AQ_RC_ENOSPC) { |
| 1757 | /* Device ran out of filter space. Check the return value |
| 1758 | * for each filter to see which ones are active. |
| 1759 | */ |
| 1760 | for (i = 0; i < count ; i++) { |
| 1761 | if (add_list[i].match_method == |
| 1762 | I40E_AQC_MM_ERR_NO_RES) { |
| 1763 | add_head->state = I40E_FILTER_FAILED; |
| 1764 | } else { |
| 1765 | add_head->state = I40E_FILTER_ACTIVE; |
| 1766 | retval++; |
| 1767 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1768 | add_head = hlist_entry(add_head->hlist.next, |
| 1769 | typeof(struct i40e_mac_filter), |
| 1770 | hlist); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1771 | } |
| 1772 | } else { |
| 1773 | /* Some other horrible thing happened, fail all filters */ |
| 1774 | retval = 0; |
| 1775 | for (i = 0; i < count ; i++) { |
| 1776 | add_head->state = I40E_FILTER_FAILED; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1777 | add_head = hlist_entry(add_head->hlist.next, |
| 1778 | typeof(struct i40e_mac_filter), |
| 1779 | hlist); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1780 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1781 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1782 | return retval; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | /** |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame^] | 1786 | * i40e_aqc_del_filters - Request firmware to delete a set of filters |
| 1787 | * @vsi: ptr to the VSI |
| 1788 | * @vsi_name: name to display in messages |
| 1789 | * @list: the list of filters to send to firmware |
| 1790 | * @num_del: the number of filters to delete |
| 1791 | * @retval: Set to -EIO on failure to delete |
| 1792 | * |
| 1793 | * Send a request to firmware via AdminQ to delete a set of filters. Uses |
| 1794 | * *retval instead of a return value so that success does not force ret_val to |
| 1795 | * be set to 0. This ensures that a sequence of calls to this function |
| 1796 | * preserve the previous value of *retval on successful delete. |
| 1797 | */ |
| 1798 | static |
| 1799 | void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 1800 | struct i40e_aqc_remove_macvlan_element_data *list, |
| 1801 | int num_del, int *retval) |
| 1802 | { |
| 1803 | struct i40e_hw *hw = &vsi->back->hw; |
| 1804 | i40e_status aq_ret; |
| 1805 | int aq_err; |
| 1806 | |
| 1807 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL); |
| 1808 | aq_err = hw->aq.asq_last_status; |
| 1809 | |
| 1810 | /* Explicitly ignore and do not report when firmware returns ENOENT */ |
| 1811 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { |
| 1812 | *retval = -EIO; |
| 1813 | dev_info(&vsi->back->pdev->dev, |
| 1814 | "ignoring delete macvlan error on %s, err %s, aq_err %s\n", |
| 1815 | vsi_name, i40e_stat_str(hw, aq_ret), |
| 1816 | i40e_aq_str(hw, aq_err)); |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | /** |
| 1821 | * i40e_aqc_add_filters - Request firmware to add a set of filters |
| 1822 | * @vsi: ptr to the VSI |
| 1823 | * @vsi_name: name to display in messages |
| 1824 | * @list: the list of filters to send to firmware |
| 1825 | * @add_head: Position in the add hlist |
| 1826 | * @num_add: the number of filters to add |
| 1827 | * @promisc_change: set to true on exit if promiscuous mode was forced on |
| 1828 | * |
| 1829 | * Send a request to firmware via AdminQ to add a chunk of filters. Will set |
| 1830 | * promisc_changed to true if the firmware has run out of space for more |
| 1831 | * filters. |
| 1832 | */ |
| 1833 | static |
| 1834 | void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name, |
| 1835 | struct i40e_aqc_add_macvlan_element_data *list, |
| 1836 | struct i40e_mac_filter *add_head, |
| 1837 | int num_add, bool *promisc_changed) |
| 1838 | { |
| 1839 | struct i40e_hw *hw = &vsi->back->hw; |
| 1840 | i40e_status aq_ret; |
| 1841 | int aq_err, fcnt; |
| 1842 | |
| 1843 | aq_ret = i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL); |
| 1844 | aq_err = hw->aq.asq_last_status; |
| 1845 | fcnt = i40e_update_filter_state(num_add, list, add_head, aq_ret); |
| 1846 | vsi->active_filters += fcnt; |
| 1847 | |
| 1848 | if (fcnt != num_add) { |
| 1849 | *promisc_changed = true; |
| 1850 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 1851 | vsi->promisc_threshold = (vsi->active_filters * 3) / 4; |
| 1852 | dev_warn(&vsi->back->pdev->dev, |
| 1853 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", |
| 1854 | i40e_aq_str(hw, aq_err), |
| 1855 | vsi_name); |
| 1856 | } |
| 1857 | } |
| 1858 | |
| 1859 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1860 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1861 | * @vsi: ptr to the VSI |
| 1862 | * |
| 1863 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1864 | * |
| 1865 | * Returns 0 or error value |
| 1866 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 1867 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1868 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1869 | struct hlist_head tmp_add_list, tmp_del_list; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1870 | struct i40e_mac_filter *f, *add_head = NULL; |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1871 | struct i40e_hw *hw = &vsi->back->hw; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1872 | unsigned int vlan_any_filters = 0; |
| 1873 | unsigned int non_vlan_filters = 0; |
| 1874 | unsigned int vlan_filters = 0; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1875 | bool promisc_changed = false; |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1876 | char vsi_name[16] = "PF"; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1877 | int filter_list_len = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1878 | i40e_status aq_ret = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1879 | u32 changed_flags = 0; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1880 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1881 | struct i40e_pf *pf; |
| 1882 | int num_add = 0; |
| 1883 | int num_del = 0; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1884 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1885 | u16 cmd_flags; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1886 | int list_size; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1887 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1888 | |
| 1889 | /* empty array typed pointers, kcalloc later */ |
| 1890 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1891 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1892 | |
| 1893 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1894 | usleep_range(1000, 2000); |
| 1895 | pf = vsi->back; |
| 1896 | |
| 1897 | if (vsi->netdev) { |
| 1898 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1899 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1900 | } |
| 1901 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1902 | INIT_HLIST_HEAD(&tmp_add_list); |
| 1903 | INIT_HLIST_HEAD(&tmp_del_list); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1904 | |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1905 | if (vsi->type == I40E_VSI_SRIOV) |
| 1906 | snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id); |
| 1907 | else if (vsi->type != I40E_VSI_MAIN) |
| 1908 | snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid); |
| 1909 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1910 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1911 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1912 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1913 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1914 | /* Create a list of filters to delete. */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1915 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1916 | if (f->state == I40E_FILTER_REMOVE) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1917 | /* Move the element into temporary del_list */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1918 | hash_del(&f->hlist); |
| 1919 | hlist_add_head(&f->hlist, &tmp_del_list); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1920 | vsi->active_filters--; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1921 | |
| 1922 | /* Avoid counting removed filters */ |
| 1923 | continue; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1924 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1925 | if (f->state == I40E_FILTER_NEW) { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1926 | hash_del(&f->hlist); |
| 1927 | hlist_add_head(&f->hlist, &tmp_add_list); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1928 | } |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 1929 | |
| 1930 | /* Count the number of each type of filter we have |
| 1931 | * remaining, ignoring any filters we're about to |
| 1932 | * delete. |
| 1933 | */ |
| 1934 | if (f->vlan > 0) |
| 1935 | vlan_filters++; |
| 1936 | else if (!f->vlan) |
| 1937 | non_vlan_filters++; |
| 1938 | else |
| 1939 | vlan_any_filters++; |
| 1940 | } |
| 1941 | |
| 1942 | /* We should never have VLAN=-1 filters at the same time as we |
| 1943 | * have either VLAN=0 or VLAN>0 filters, so warn about this |
| 1944 | * case here to help catch any issues. |
| 1945 | */ |
| 1946 | WARN_ON(vlan_any_filters && (vlan_filters + non_vlan_filters)); |
| 1947 | |
| 1948 | /* If we only have VLAN=0 filters remaining, and don't have |
| 1949 | * any other VLAN filters, we need to convert these VLAN=0 |
| 1950 | * filters into VLAN=-1 (I40E_VLAN_ANY) so that we operate |
| 1951 | * correctly in non-VLAN mode and receive all traffic tagged |
| 1952 | * or untagged. |
| 1953 | */ |
| 1954 | if (non_vlan_filters && !vlan_filters) { |
| 1955 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, |
| 1956 | hlist) { |
| 1957 | /* Only replace VLAN=0 filters */ |
| 1958 | if (f->vlan) |
| 1959 | continue; |
| 1960 | |
| 1961 | /* Allocate a replacement element */ |
| 1962 | add_head = kzalloc(sizeof(*add_head), |
| 1963 | GFP_KERNEL); |
| 1964 | if (!add_head) |
| 1965 | goto err_no_memory_locked; |
| 1966 | |
| 1967 | /* Copy the filter, with new state and VLAN */ |
| 1968 | *add_head = *f; |
| 1969 | add_head->state = I40E_FILTER_NEW; |
| 1970 | add_head->vlan = I40E_VLAN_ANY; |
| 1971 | |
| 1972 | /* Move the replacement to the add list */ |
| 1973 | INIT_HLIST_NODE(&add_head->hlist); |
| 1974 | hlist_add_head(&add_head->hlist, |
| 1975 | &tmp_add_list); |
| 1976 | |
| 1977 | /* Move the original to the delete list */ |
| 1978 | f->state = I40E_FILTER_REMOVE; |
| 1979 | hash_del(&f->hlist); |
| 1980 | hlist_add_head(&f->hlist, &tmp_del_list); |
| 1981 | vsi->active_filters--; |
| 1982 | } |
| 1983 | |
| 1984 | /* Also update any filters on the tmp_add list */ |
| 1985 | hlist_for_each_entry(f, &tmp_add_list, hlist) { |
| 1986 | if (!f->vlan) |
| 1987 | f->vlan = I40E_VLAN_ANY; |
| 1988 | } |
| 1989 | add_head = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1990 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1991 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | /* Now process 'del_list' outside the lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 1995 | if (!hlist_empty(&tmp_del_list)) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1996 | filter_list_len = hw->aq.asq_buf_size / |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1997 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1998 | list_size = filter_list_len * |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1999 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2000 | del_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2001 | if (!del_list) |
| 2002 | goto err_no_memory; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2003 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2004 | hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2005 | cmd_flags = 0; |
| 2006 | |
| 2007 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2008 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2009 | if (f->vlan == I40E_VLAN_ANY) { |
| 2010 | del_list[num_del].vlan_tag = 0; |
Alan Brady | a6cb914 | 2016-09-06 18:05:07 -0700 | [diff] [blame] | 2011 | cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2012 | } else { |
| 2013 | del_list[num_del].vlan_tag = |
| 2014 | cpu_to_le16((u16)(f->vlan)); |
| 2015 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2016 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2017 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 2018 | del_list[num_del].flags = cmd_flags; |
| 2019 | num_del++; |
| 2020 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2021 | /* flush a full buffer */ |
| 2022 | if (num_del == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame^] | 2023 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2024 | num_del, &retval); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2025 | memset(del_list, 0, list_size); |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame^] | 2026 | num_del = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2027 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2028 | /* Release memory for MAC filter entries which were |
| 2029 | * synced up with HW. |
| 2030 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2031 | hlist_del(&f->hlist); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2032 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2033 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2034 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2035 | if (num_del) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame^] | 2036 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
| 2037 | num_del, &retval); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | kfree(del_list); |
| 2041 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2042 | } |
| 2043 | |
Jacob Keller | cbebb85 | 2016-10-05 09:30:40 -0700 | [diff] [blame] | 2044 | /* After finishing notifying firmware of the deleted filters, update |
| 2045 | * the cached value of vsi->has_vlan_filter. Note that we are safe to |
| 2046 | * use just !!vlan_filters here because if we only have VLAN=0 (that |
| 2047 | * is, non_vlan_filters) these will all be converted to VLAN=-1 in the |
| 2048 | * logic above already so this value would still be correct. |
| 2049 | */ |
| 2050 | vsi->has_vlan_filter = !!vlan_filters; |
| 2051 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2052 | if (!hlist_empty(&tmp_add_list)) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2053 | /* Do all the adds now. */ |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2054 | filter_list_len = hw->aq.asq_buf_size / |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2055 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2056 | list_size = filter_list_len * |
| 2057 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
| 2058 | add_list = kzalloc(list_size, GFP_ATOMIC); |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2059 | if (!add_list) |
| 2060 | goto err_no_memory; |
| 2061 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2062 | num_add = 0; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2063 | hlist_for_each_entry(f, &tmp_add_list, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2064 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2065 | &vsi->state)) { |
| 2066 | f->state = I40E_FILTER_FAILED; |
| 2067 | continue; |
| 2068 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2069 | /* add to add array */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2070 | if (num_add == 0) |
| 2071 | add_head = f; |
| 2072 | cmd_flags = 0; |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2073 | ether_addr_copy(add_list[num_add].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2074 | if (f->vlan == I40E_VLAN_ANY) { |
| 2075 | add_list[num_add].vlan_tag = 0; |
| 2076 | cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; |
| 2077 | } else { |
| 2078 | add_list[num_add].vlan_tag = |
| 2079 | cpu_to_le16((u16)(f->vlan)); |
| 2080 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2081 | add_list[num_add].queue_number = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2082 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2083 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2084 | num_add++; |
| 2085 | |
| 2086 | /* flush a full buffer */ |
| 2087 | if (num_add == filter_list_len) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame^] | 2088 | i40e_aqc_add_filters(vsi, vsi_name, add_list, |
| 2089 | add_head, num_add, |
| 2090 | &promisc_changed); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2091 | memset(add_list, 0, list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2092 | num_add = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2093 | } |
| 2094 | } |
| 2095 | if (num_add) { |
Jacob Keller | 0093631 | 2016-10-05 09:30:41 -0700 | [diff] [blame^] | 2096 | i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head, |
| 2097 | num_add, &promisc_changed); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2098 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2099 | /* Now move all of the filters from the temp add list back to |
| 2100 | * the VSI's list. |
| 2101 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2102 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2103 | hlist_for_each_entry_safe(f, h, &tmp_add_list, hlist) { |
| 2104 | u64 key = i40e_addr_to_hkey(f->macaddr); |
| 2105 | |
| 2106 | hlist_del(&f->hlist); |
| 2107 | hash_add(vsi->mac_filter_hash, &f->hlist, key); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2108 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2109 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2110 | kfree(add_list); |
| 2111 | add_list = NULL; |
| 2112 | } |
| 2113 | |
| 2114 | /* Check to see if we can drop out of overflow promiscuous mode. */ |
| 2115 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) && |
| 2116 | (vsi->active_filters < vsi->promisc_threshold)) { |
| 2117 | int failed_count = 0; |
| 2118 | /* See if we have any failed filters. We can't drop out of |
| 2119 | * promiscuous until these have all been deleted. |
| 2120 | */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2121 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
| 2122 | hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2123 | if (f->state == I40E_FILTER_FAILED) |
| 2124 | failed_count++; |
| 2125 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2126 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2127 | if (!failed_count) { |
| 2128 | dev_info(&pf->pdev->dev, |
| 2129 | "filter logjam cleared on %s, leaving overflow promiscuous mode\n", |
| 2130 | vsi_name); |
| 2131 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2132 | promisc_changed = true; |
| 2133 | vsi->promisc_threshold = 0; |
| 2134 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2137 | /* if the VF is not trusted do not do promisc */ |
| 2138 | if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) { |
| 2139 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2140 | goto out; |
| 2141 | } |
| 2142 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2143 | /* check for changes in promiscuous modes */ |
| 2144 | if (changed_flags & IFF_ALLMULTI) { |
| 2145 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2146 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2147 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2148 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2149 | vsi->seid, |
| 2150 | cur_multipromisc, |
| 2151 | NULL); |
| 2152 | if (aq_ret) { |
| 2153 | retval = i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2154 | hw->aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2155 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2156 | "set multi promisc failed on %s, err %s aq_err %s\n", |
| 2157 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2158 | i40e_stat_str(hw, aq_ret), |
| 2159 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2160 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2161 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2162 | if ((changed_flags & IFF_PROMISC) || |
| 2163 | (promisc_changed && |
| 2164 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2165 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2166 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2167 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 2168 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2169 | &vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2170 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2171 | (pf->lan_veb != I40E_NO_VEB) && |
| 2172 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2173 | /* set defport ON for Main VSI instead of true promisc |
| 2174 | * this way we will get all unicast/multicast and VLAN |
| 2175 | * promisc behavior but will not get VF or VMDq traffic |
| 2176 | * replicated on the Main VSI. |
| 2177 | */ |
| 2178 | if (pf->cur_promisc != cur_promisc) { |
| 2179 | pf->cur_promisc = cur_promisc; |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2180 | if (cur_promisc) |
| 2181 | aq_ret = |
| 2182 | i40e_aq_set_default_vsi(hw, |
| 2183 | vsi->seid, |
| 2184 | NULL); |
| 2185 | else |
| 2186 | aq_ret = |
| 2187 | i40e_aq_clear_default_vsi(hw, |
| 2188 | vsi->seid, |
| 2189 | NULL); |
| 2190 | if (aq_ret) { |
| 2191 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2192 | hw->aq.asq_last_status); |
| 2193 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2194 | "Set default VSI failed on %s, err %s, aq_err %s\n", |
| 2195 | vsi_name, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2196 | i40e_stat_str(hw, aq_ret), |
| 2197 | i40e_aq_str(hw, |
| 2198 | hw->aq.asq_last_status)); |
| 2199 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2200 | } |
| 2201 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2202 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2203 | hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2204 | vsi->seid, |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 2205 | cur_promisc, NULL, |
| 2206 | true); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2207 | if (aq_ret) { |
| 2208 | retval = |
| 2209 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2210 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2211 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2212 | "set unicast promisc failed on %s, err %s, aq_err %s\n", |
| 2213 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2214 | i40e_stat_str(hw, aq_ret), |
| 2215 | i40e_aq_str(hw, |
| 2216 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2217 | } |
| 2218 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2219 | hw, |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2220 | vsi->seid, |
| 2221 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2222 | if (aq_ret) { |
| 2223 | retval = |
| 2224 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2225 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2226 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2227 | "set multicast promisc failed on %s, err %s, aq_err %s\n", |
| 2228 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2229 | i40e_stat_str(hw, aq_ret), |
| 2230 | i40e_aq_str(hw, |
| 2231 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2232 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2233 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2234 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2235 | vsi->seid, |
| 2236 | cur_promisc, NULL); |
| 2237 | if (aq_ret) { |
| 2238 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2239 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2240 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2241 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2242 | i40e_stat_str(hw, aq_ret), |
| 2243 | i40e_aq_str(hw, |
| 2244 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2245 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2246 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2247 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2248 | /* if something went wrong then set the changed flag so we try again */ |
| 2249 | if (retval) |
| 2250 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2251 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2252 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2253 | return retval; |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2254 | |
| 2255 | err_no_memory: |
| 2256 | /* Restore elements on the temporary add and delete lists */ |
| 2257 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2258 | err_no_memory_locked: |
Jacob Keller | 4a2ce27 | 2016-10-05 09:30:38 -0700 | [diff] [blame] | 2259 | i40e_undo_filter_entries(vsi, &tmp_del_list); |
| 2260 | i40e_undo_filter_entries(vsi, &tmp_add_list); |
| 2261 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
| 2262 | |
| 2263 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2264 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
| 2265 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | /** |
| 2269 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2270 | * @pf: board private structure |
| 2271 | **/ |
| 2272 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2273 | { |
| 2274 | int v; |
| 2275 | |
| 2276 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2277 | return; |
| 2278 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2279 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2280 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2281 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2282 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2283 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2284 | |
| 2285 | if (ret) { |
| 2286 | /* come back and try again later */ |
| 2287 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2288 | break; |
| 2289 | } |
| 2290 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | /** |
| 2295 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2296 | * @netdev: network interface device structure |
| 2297 | * @new_mtu: new value for maximum frame size |
| 2298 | * |
| 2299 | * Returns 0 on success, negative on failure |
| 2300 | **/ |
| 2301 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2302 | { |
| 2303 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2304 | struct i40e_vsi *vsi = np->vsi; |
| 2305 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2306 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2307 | netdev->mtu, new_mtu); |
| 2308 | netdev->mtu = new_mtu; |
| 2309 | if (netif_running(netdev)) |
| 2310 | i40e_vsi_reinit_locked(vsi); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 2311 | i40e_notify_client_of_l2_param_changes(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2312 | return 0; |
| 2313 | } |
| 2314 | |
| 2315 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2316 | * i40e_ioctl - Access the hwtstamp interface |
| 2317 | * @netdev: network interface device structure |
| 2318 | * @ifr: interface request data |
| 2319 | * @cmd: ioctl command |
| 2320 | **/ |
| 2321 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2322 | { |
| 2323 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2324 | struct i40e_pf *pf = np->vsi->back; |
| 2325 | |
| 2326 | switch (cmd) { |
| 2327 | case SIOCGHWTSTAMP: |
| 2328 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2329 | case SIOCSHWTSTAMP: |
| 2330 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2331 | default: |
| 2332 | return -EOPNOTSUPP; |
| 2333 | } |
| 2334 | } |
| 2335 | |
| 2336 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2337 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2338 | * @vsi: the vsi being adjusted |
| 2339 | **/ |
| 2340 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2341 | { |
| 2342 | struct i40e_vsi_context ctxt; |
| 2343 | i40e_status ret; |
| 2344 | |
| 2345 | if ((vsi->info.valid_sections & |
| 2346 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2347 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2348 | return; /* already enabled */ |
| 2349 | |
| 2350 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2351 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2352 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2353 | |
| 2354 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2355 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2356 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2357 | if (ret) { |
| 2358 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2359 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2360 | i40e_stat_str(&vsi->back->hw, ret), |
| 2361 | i40e_aq_str(&vsi->back->hw, |
| 2362 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | /** |
| 2367 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2368 | * @vsi: the vsi being adjusted |
| 2369 | **/ |
| 2370 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2371 | { |
| 2372 | struct i40e_vsi_context ctxt; |
| 2373 | i40e_status ret; |
| 2374 | |
| 2375 | if ((vsi->info.valid_sections & |
| 2376 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2377 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2378 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2379 | return; /* already disabled */ |
| 2380 | |
| 2381 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2382 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2383 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2384 | |
| 2385 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2386 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2387 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2388 | if (ret) { |
| 2389 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2390 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2391 | i40e_stat_str(&vsi->back->hw, ret), |
| 2392 | i40e_aq_str(&vsi->back->hw, |
| 2393 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2394 | } |
| 2395 | } |
| 2396 | |
| 2397 | /** |
| 2398 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2399 | * @netdev: network interface to be adjusted |
| 2400 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2401 | **/ |
| 2402 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2403 | { |
| 2404 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2405 | struct i40e_vsi *vsi = np->vsi; |
| 2406 | |
| 2407 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2408 | i40e_vlan_stripping_enable(vsi); |
| 2409 | else |
| 2410 | i40e_vlan_stripping_disable(vsi); |
| 2411 | } |
| 2412 | |
| 2413 | /** |
| 2414 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 2415 | * @vsi: the vsi being configured |
| 2416 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 2417 | **/ |
| 2418 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2419 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2420 | struct i40e_mac_filter *f, *add_f, *del_f; |
| 2421 | struct hlist_node *h; |
| 2422 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2423 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2424 | /* Locked once because all functions invoked below iterates list*/ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2425 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2426 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2427 | if (vsi->netdev) { |
| 2428 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2429 | if (!add_f) { |
| 2430 | dev_info(&vsi->back->pdev->dev, |
| 2431 | "Could not add vlan filter %d for %pM\n", |
| 2432 | vid, vsi->netdev->dev_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2433 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2434 | return -ENOMEM; |
| 2435 | } |
| 2436 | } |
| 2437 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2438 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 2439 | if (f->state == I40E_FILTER_REMOVE) |
| 2440 | continue; |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2441 | add_f = i40e_add_filter(vsi, f->macaddr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2442 | if (!add_f) { |
| 2443 | dev_info(&vsi->back->pdev->dev, |
| 2444 | "Could not add vlan filter %d for %pM\n", |
| 2445 | vid, f->macaddr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2446 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2447 | return -ENOMEM; |
| 2448 | } |
| 2449 | } |
| 2450 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2451 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 2452 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 2453 | * with 0, so we now accept untagged and specified tagged traffic |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2454 | * (and not all tags along with untagged) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2455 | */ |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 2456 | if (vid > 0 && vsi->netdev) { |
| 2457 | del_f = i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 2458 | I40E_VLAN_ANY); |
| 2459 | if (del_f) { |
| 2460 | __i40e_del_filter(vsi, del_f); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2461 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2462 | if (!add_f) { |
| 2463 | dev_info(&vsi->back->pdev->dev, |
| 2464 | "Could not add filter 0 for %pM\n", |
| 2465 | vsi->netdev->dev_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2466 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2467 | return -ENOMEM; |
| 2468 | } |
| 2469 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2470 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2471 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2472 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
| 2473 | if (vid > 0 && !vsi->info.pvid) { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2474 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 57b341d | 2016-10-05 09:30:35 -0700 | [diff] [blame] | 2475 | if (f->state == I40E_FILTER_REMOVE) |
| 2476 | continue; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 2477 | del_f = i40e_find_filter(vsi, f->macaddr, |
| 2478 | I40E_VLAN_ANY); |
| 2479 | if (!del_f) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2480 | continue; |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 2481 | __i40e_del_filter(vsi, del_f); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2482 | add_f = i40e_add_filter(vsi, f->macaddr, 0); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2483 | if (!add_f) { |
| 2484 | dev_info(&vsi->back->pdev->dev, |
| 2485 | "Could not add filter 0 for %pM\n", |
| 2486 | f->macaddr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2487 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2488 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2489 | } |
| 2490 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2491 | } |
| 2492 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2493 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2494 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2495 | /* schedule our worker thread which will take care of |
| 2496 | * applying the new filter changes |
| 2497 | */ |
| 2498 | i40e_service_event_schedule(vsi->back); |
| 2499 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | /** |
| 2503 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 2504 | * @vsi: the vsi being configured |
| 2505 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2506 | * |
| 2507 | * Return: 0 on success or negative otherwise |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2508 | **/ |
| 2509 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2510 | { |
| 2511 | struct net_device *netdev = vsi->netdev; |
Alan Brady | 84f5ca6 | 2016-10-05 09:30:39 -0700 | [diff] [blame] | 2512 | struct i40e_mac_filter *f; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2513 | struct hlist_node *h; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2514 | int bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2515 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2516 | /* Locked once because all functions invoked below iterates list */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2517 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2518 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 2519 | if (vsi->netdev) |
| 2520 | i40e_del_filter(vsi, netdev->dev_addr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2521 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2522 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 2523 | if (f->vlan == vid) |
| 2524 | __i40e_del_filter(vsi, f); |
| 2525 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2526 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 2527 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2528 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2529 | /* schedule our worker thread which will take care of |
| 2530 | * applying the new filter changes |
| 2531 | */ |
| 2532 | i40e_service_event_schedule(vsi->back); |
| 2533 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | /** |
| 2537 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2538 | * @netdev: network interface to be adjusted |
| 2539 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2540 | * |
| 2541 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2542 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2543 | #ifdef I40E_FCOE |
| 2544 | int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2545 | __always_unused __be16 proto, u16 vid) |
| 2546 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2547 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2548 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2549 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2550 | { |
| 2551 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2552 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2553 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2554 | |
| 2555 | if (vid > 4095) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2556 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2557 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2558 | /* If the network stack called us with vid = 0 then |
| 2559 | * it is asking to receive priority tagged packets with |
| 2560 | * vlan id 0. Our HW receives them by default when configured |
| 2561 | * to receive untagged packets so there is no need to add an |
| 2562 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2563 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2564 | if (vid) |
| 2565 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2566 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2567 | if (!ret && (vid < VLAN_N_VID)) |
| 2568 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2569 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2570 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | /** |
| 2574 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2575 | * @netdev: network interface to be adjusted |
| 2576 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2577 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2578 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2579 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2580 | #ifdef I40E_FCOE |
| 2581 | int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2582 | __always_unused __be16 proto, u16 vid) |
| 2583 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2584 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2585 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2586 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2587 | { |
| 2588 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2589 | struct i40e_vsi *vsi = np->vsi; |
| 2590 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2591 | /* return code is ignored as there is nothing a user |
| 2592 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2593 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2594 | */ |
| 2595 | i40e_vsi_kill_vlan(vsi, vid); |
| 2596 | |
| 2597 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2598 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2599 | return 0; |
| 2600 | } |
| 2601 | |
| 2602 | /** |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 2603 | * i40e_macaddr_init - explicitly write the mac address filters |
| 2604 | * |
| 2605 | * @vsi: pointer to the vsi |
| 2606 | * @macaddr: the MAC address |
| 2607 | * |
| 2608 | * This is needed when the macaddr has been obtained by other |
| 2609 | * means than the default, e.g., from Open Firmware or IDPROM. |
| 2610 | * Returns 0 on success, negative on failure |
| 2611 | **/ |
| 2612 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) |
| 2613 | { |
| 2614 | int ret; |
| 2615 | struct i40e_aqc_add_macvlan_element_data element; |
| 2616 | |
| 2617 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 2618 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 2619 | macaddr, NULL); |
| 2620 | if (ret) { |
| 2621 | dev_info(&vsi->back->pdev->dev, |
| 2622 | "Addr change for VSI failed: %d\n", ret); |
| 2623 | return -EADDRNOTAVAIL; |
| 2624 | } |
| 2625 | |
| 2626 | memset(&element, 0, sizeof(element)); |
| 2627 | ether_addr_copy(element.mac_addr, macaddr); |
| 2628 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 2629 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); |
| 2630 | if (ret) { |
| 2631 | dev_info(&vsi->back->pdev->dev, |
| 2632 | "add filter failed err %s aq_err %s\n", |
| 2633 | i40e_stat_str(&vsi->back->hw, ret), |
| 2634 | i40e_aq_str(&vsi->back->hw, |
| 2635 | vsi->back->hw.aq.asq_last_status)); |
| 2636 | } |
| 2637 | return ret; |
| 2638 | } |
| 2639 | |
| 2640 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2641 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2642 | * @vsi: the vsi being brought back up |
| 2643 | **/ |
| 2644 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2645 | { |
| 2646 | u16 vid; |
| 2647 | |
| 2648 | if (!vsi->netdev) |
| 2649 | return; |
| 2650 | |
| 2651 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2652 | |
| 2653 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2654 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2655 | vid); |
| 2656 | } |
| 2657 | |
| 2658 | /** |
| 2659 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2660 | * @vsi: the vsi being adjusted |
| 2661 | * @vid: the vlan id to set as a PVID |
| 2662 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2663 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2664 | { |
| 2665 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2666 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2667 | |
| 2668 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2669 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2670 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2671 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2672 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2673 | |
| 2674 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2675 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2676 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2677 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2678 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2679 | "add pvid failed, err %s aq_err %s\n", |
| 2680 | i40e_stat_str(&vsi->back->hw, ret), |
| 2681 | i40e_aq_str(&vsi->back->hw, |
| 2682 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2683 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2684 | } |
| 2685 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2686 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | /** |
| 2690 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2691 | * @vsi: the vsi being adjusted |
| 2692 | * |
| 2693 | * Just use the vlan_rx_register() service to put it back to normal |
| 2694 | **/ |
| 2695 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2696 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2697 | i40e_vlan_stripping_disable(vsi); |
| 2698 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2699 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | /** |
| 2703 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2704 | * @vsi: ptr to the VSI |
| 2705 | * |
| 2706 | * If this function returns with an error, then it's possible one or |
| 2707 | * more of the rings is populated (while the rest are not). It is the |
| 2708 | * callers duty to clean those orphaned rings. |
| 2709 | * |
| 2710 | * Return 0 on success, negative on failure |
| 2711 | **/ |
| 2712 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2713 | { |
| 2714 | int i, err = 0; |
| 2715 | |
| 2716 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2717 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2718 | |
| 2719 | return err; |
| 2720 | } |
| 2721 | |
| 2722 | /** |
| 2723 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2724 | * @vsi: ptr to the VSI |
| 2725 | * |
| 2726 | * Free VSI's transmit software resources |
| 2727 | **/ |
| 2728 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2729 | { |
| 2730 | int i; |
| 2731 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2732 | if (!vsi->tx_rings) |
| 2733 | return; |
| 2734 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2735 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2736 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2737 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | /** |
| 2741 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2742 | * @vsi: ptr to the VSI |
| 2743 | * |
| 2744 | * If this function returns with an error, then it's possible one or |
| 2745 | * more of the rings is populated (while the rest are not). It is the |
| 2746 | * callers duty to clean those orphaned rings. |
| 2747 | * |
| 2748 | * Return 0 on success, negative on failure |
| 2749 | **/ |
| 2750 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2751 | { |
| 2752 | int i, err = 0; |
| 2753 | |
| 2754 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2755 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2756 | #ifdef I40E_FCOE |
| 2757 | i40e_fcoe_setup_ddp_resources(vsi); |
| 2758 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2759 | return err; |
| 2760 | } |
| 2761 | |
| 2762 | /** |
| 2763 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2764 | * @vsi: ptr to the VSI |
| 2765 | * |
| 2766 | * Free all receive software resources |
| 2767 | **/ |
| 2768 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2769 | { |
| 2770 | int i; |
| 2771 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2772 | if (!vsi->rx_rings) |
| 2773 | return; |
| 2774 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2775 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2776 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2777 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2778 | #ifdef I40E_FCOE |
| 2779 | i40e_fcoe_free_ddp_resources(vsi); |
| 2780 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2784 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2785 | * @ring: The Tx ring to configure |
| 2786 | * |
| 2787 | * This enables/disables XPS for a given Tx descriptor ring |
| 2788 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2789 | **/ |
| 2790 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2791 | { |
| 2792 | struct i40e_vsi *vsi = ring->vsi; |
| 2793 | cpumask_var_t mask; |
| 2794 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2795 | if (!ring->q_vector || !ring->netdev) |
| 2796 | return; |
| 2797 | |
| 2798 | /* Single TC mode enable XPS */ |
| 2799 | if (vsi->tc_config.numtc <= 1) { |
| 2800 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2801 | netif_set_xps_queue(ring->netdev, |
| 2802 | &ring->q_vector->affinity_mask, |
| 2803 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2804 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2805 | /* Disable XPS to allow selection based on TC */ |
| 2806 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2807 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2808 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2809 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2810 | |
| 2811 | /* schedule our worker thread which will take care of |
| 2812 | * applying the new filter changes |
| 2813 | */ |
| 2814 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2818 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2819 | * @ring: The Tx ring to configure |
| 2820 | * |
| 2821 | * Configure the Tx descriptor ring in the HMC context. |
| 2822 | **/ |
| 2823 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2824 | { |
| 2825 | struct i40e_vsi *vsi = ring->vsi; |
| 2826 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2827 | struct i40e_hw *hw = &vsi->back->hw; |
| 2828 | struct i40e_hmc_obj_txq tx_ctx; |
| 2829 | i40e_status err = 0; |
| 2830 | u32 qtx_ctl = 0; |
| 2831 | |
| 2832 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2833 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2834 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2835 | ring->atr_count = 0; |
| 2836 | } else { |
| 2837 | ring->atr_sample_rate = 0; |
| 2838 | } |
| 2839 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2840 | /* configure XPS */ |
| 2841 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2842 | |
| 2843 | /* clear the context structure first */ |
| 2844 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2845 | |
| 2846 | tx_ctx.new_context = 1; |
| 2847 | tx_ctx.base = (ring->dma / 128); |
| 2848 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2849 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2850 | I40E_FLAG_FD_ATR_ENABLED)); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2851 | #ifdef I40E_FCOE |
| 2852 | tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2853 | #endif |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2854 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2855 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2856 | if (vsi->type != I40E_VSI_FDIR) |
| 2857 | tx_ctx.head_wb_ena = 1; |
| 2858 | tx_ctx.head_wb_addr = ring->dma + |
| 2859 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2860 | |
| 2861 | /* As part of VSI creation/update, FW allocates certain |
| 2862 | * Tx arbitration queue sets for each TC enabled for |
| 2863 | * the VSI. The FW returns the handles to these queue |
| 2864 | * sets as part of the response buffer to Add VSI, |
| 2865 | * Update VSI, etc. AQ commands. It is expected that |
| 2866 | * these queue set handles be associated with the Tx |
| 2867 | * queues by the driver as part of the TX queue context |
| 2868 | * initialization. This has to be done regardless of |
| 2869 | * DCB as by default everything is mapped to TC0. |
| 2870 | */ |
| 2871 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2872 | tx_ctx.rdylist_act = 0; |
| 2873 | |
| 2874 | /* clear the context in the HMC */ |
| 2875 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2876 | if (err) { |
| 2877 | dev_info(&vsi->back->pdev->dev, |
| 2878 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2879 | ring->queue_index, pf_q, err); |
| 2880 | return -ENOMEM; |
| 2881 | } |
| 2882 | |
| 2883 | /* set the context in the HMC */ |
| 2884 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2885 | if (err) { |
| 2886 | dev_info(&vsi->back->pdev->dev, |
| 2887 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2888 | ring->queue_index, pf_q, err); |
| 2889 | return -ENOMEM; |
| 2890 | } |
| 2891 | |
| 2892 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2893 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2894 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2895 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2896 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2897 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2898 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2901 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2902 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2903 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2904 | i40e_flush(hw); |
| 2905 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2906 | /* cache tail off for easier writes later */ |
| 2907 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2908 | |
| 2909 | return 0; |
| 2910 | } |
| 2911 | |
| 2912 | /** |
| 2913 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2914 | * @ring: The Rx ring to configure |
| 2915 | * |
| 2916 | * Configure the Rx descriptor ring in the HMC context. |
| 2917 | **/ |
| 2918 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2919 | { |
| 2920 | struct i40e_vsi *vsi = ring->vsi; |
| 2921 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2922 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2923 | struct i40e_hw *hw = &vsi->back->hw; |
| 2924 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2925 | i40e_status err = 0; |
| 2926 | |
| 2927 | ring->state = 0; |
| 2928 | |
| 2929 | /* clear the context structure first */ |
| 2930 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2931 | |
| 2932 | ring->rx_buf_len = vsi->rx_buf_len; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2933 | |
| 2934 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2935 | |
| 2936 | rx_ctx.base = (ring->dma / 128); |
| 2937 | rx_ctx.qlen = ring->count; |
| 2938 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 2939 | /* use 32 byte descriptors */ |
| 2940 | rx_ctx.dsize = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2941 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 2942 | /* descriptor type is always zero |
| 2943 | * rx_ctx.dtype = 0; |
| 2944 | */ |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 2945 | rx_ctx.hsplit_0 = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2946 | |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 2947 | 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] | 2948 | if (hw->revision_id == 0) |
| 2949 | rx_ctx.lrxqthresh = 0; |
| 2950 | else |
| 2951 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2952 | rx_ctx.crcstrip = 1; |
| 2953 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 2954 | /* this controls whether VLAN is stripped from inner headers */ |
| 2955 | rx_ctx.showiv = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2956 | #ifdef I40E_FCOE |
| 2957 | rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2958 | #endif |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 2959 | /* set the prefena field to 1 because the manual says to */ |
| 2960 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2961 | |
| 2962 | /* clear the context in the HMC */ |
| 2963 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 2964 | if (err) { |
| 2965 | dev_info(&vsi->back->pdev->dev, |
| 2966 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2967 | ring->queue_index, pf_q, err); |
| 2968 | return -ENOMEM; |
| 2969 | } |
| 2970 | |
| 2971 | /* set the context in the HMC */ |
| 2972 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 2973 | if (err) { |
| 2974 | dev_info(&vsi->back->pdev->dev, |
| 2975 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2976 | ring->queue_index, pf_q, err); |
| 2977 | return -ENOMEM; |
| 2978 | } |
| 2979 | |
| 2980 | /* cache tail for quicker writes, and clear the reg before use */ |
| 2981 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 2982 | writel(0, ring->tail); |
| 2983 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 2984 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2985 | |
| 2986 | return 0; |
| 2987 | } |
| 2988 | |
| 2989 | /** |
| 2990 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 2991 | * @vsi: VSI structure describing this set of rings and resources |
| 2992 | * |
| 2993 | * Configure the Tx VSI for operation. |
| 2994 | **/ |
| 2995 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 2996 | { |
| 2997 | int err = 0; |
| 2998 | u16 i; |
| 2999 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3000 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 3001 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3002 | |
| 3003 | return err; |
| 3004 | } |
| 3005 | |
| 3006 | /** |
| 3007 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 3008 | * @vsi: the VSI being configured |
| 3009 | * |
| 3010 | * Configure the Rx VSI for operation. |
| 3011 | **/ |
| 3012 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 3013 | { |
| 3014 | int err = 0; |
| 3015 | u16 i; |
| 3016 | |
| 3017 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 3018 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 3019 | + ETH_FCS_LEN + VLAN_HLEN; |
| 3020 | else |
| 3021 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 3022 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 3023 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3024 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3025 | #ifdef I40E_FCOE |
| 3026 | /* setup rx buffer for FCoE */ |
| 3027 | if ((vsi->type == I40E_VSI_FCOE) && |
| 3028 | (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) { |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3029 | vsi->rx_buf_len = I40E_RXBUFFER_3072; |
| 3030 | vsi->max_frame = I40E_RXBUFFER_3072; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3031 | } |
| 3032 | |
| 3033 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3034 | /* round up for the chip's needs */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3035 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3036 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3037 | |
| 3038 | /* set up individual rings */ |
| 3039 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3040 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3041 | |
| 3042 | return err; |
| 3043 | } |
| 3044 | |
| 3045 | /** |
| 3046 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3047 | * @vsi: ptr to the VSI |
| 3048 | **/ |
| 3049 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3050 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3051 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3052 | u16 qoffset, qcount; |
| 3053 | int i, n; |
| 3054 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3055 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3056 | /* Reset the TC information */ |
| 3057 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3058 | rx_ring = vsi->rx_rings[i]; |
| 3059 | tx_ring = vsi->tx_rings[i]; |
| 3060 | rx_ring->dcb_tc = 0; |
| 3061 | tx_ring->dcb_tc = 0; |
| 3062 | } |
| 3063 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3064 | |
| 3065 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3066 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3067 | continue; |
| 3068 | |
| 3069 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3070 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3071 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3072 | rx_ring = vsi->rx_rings[i]; |
| 3073 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3074 | rx_ring->dcb_tc = n; |
| 3075 | tx_ring->dcb_tc = n; |
| 3076 | } |
| 3077 | } |
| 3078 | } |
| 3079 | |
| 3080 | /** |
| 3081 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3082 | * @vsi: ptr to the VSI |
| 3083 | **/ |
| 3084 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3085 | { |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 3086 | struct i40e_pf *pf = vsi->back; |
| 3087 | int err; |
| 3088 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3089 | if (vsi->netdev) |
| 3090 | i40e_set_rx_mode(vsi->netdev); |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 3091 | |
| 3092 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 3093 | err = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 3094 | if (err) { |
| 3095 | dev_warn(&pf->pdev->dev, |
| 3096 | "could not set up macaddr; err %d\n", err); |
| 3097 | } |
| 3098 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3102 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3103 | * @vsi: Pointer to the targeted VSI |
| 3104 | * |
| 3105 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3106 | * filters were saved. |
| 3107 | **/ |
| 3108 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3109 | { |
| 3110 | struct i40e_fdir_filter *filter; |
| 3111 | struct i40e_pf *pf = vsi->back; |
| 3112 | struct hlist_node *node; |
| 3113 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3114 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3115 | return; |
| 3116 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3117 | hlist_for_each_entry_safe(filter, node, |
| 3118 | &pf->fdir_filter_list, fdir_node) { |
| 3119 | i40e_add_del_fdir(vsi, filter, true); |
| 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3124 | * i40e_vsi_configure - Set up the VSI for action |
| 3125 | * @vsi: the VSI being configured |
| 3126 | **/ |
| 3127 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3128 | { |
| 3129 | int err; |
| 3130 | |
| 3131 | i40e_set_vsi_rx_mode(vsi); |
| 3132 | i40e_restore_vlan(vsi); |
| 3133 | i40e_vsi_config_dcb_rings(vsi); |
| 3134 | err = i40e_vsi_configure_tx(vsi); |
| 3135 | if (!err) |
| 3136 | err = i40e_vsi_configure_rx(vsi); |
| 3137 | |
| 3138 | return err; |
| 3139 | } |
| 3140 | |
| 3141 | /** |
| 3142 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3143 | * @vsi: the VSI being configured |
| 3144 | **/ |
| 3145 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3146 | { |
| 3147 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3148 | struct i40e_hw *hw = &pf->hw; |
| 3149 | u16 vector; |
| 3150 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3151 | u32 qp; |
| 3152 | |
| 3153 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3154 | * and PFINT_LNKLSTn registers, e.g.: |
| 3155 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3156 | */ |
| 3157 | qp = vsi->base_queue; |
| 3158 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3159 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3160 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3161 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3162 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3163 | 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] | 3164 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3165 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3166 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3167 | 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] | 3168 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3169 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3170 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3171 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
| 3172 | INTRL_USEC_TO_REG(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3173 | |
| 3174 | /* Linked list for the queuepairs assigned to this vector */ |
| 3175 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3176 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3177 | u32 val; |
| 3178 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3179 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3180 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3181 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3182 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 3183 | (I40E_QUEUE_TYPE_TX |
| 3184 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 3185 | |
| 3186 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3187 | |
| 3188 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3189 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3190 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3191 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 3192 | (I40E_QUEUE_TYPE_RX |
| 3193 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3194 | |
| 3195 | /* Terminate the linked list */ |
| 3196 | if (q == (q_vector->num_ringpairs - 1)) |
| 3197 | val |= (I40E_QUEUE_END_OF_LIST |
| 3198 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3199 | |
| 3200 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3201 | qp++; |
| 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | i40e_flush(hw); |
| 3206 | } |
| 3207 | |
| 3208 | /** |
| 3209 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3210 | * @hw: ptr to the hardware info |
| 3211 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3212 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3213 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3214 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3215 | u32 val; |
| 3216 | |
| 3217 | /* clear things first */ |
| 3218 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3219 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3220 | |
| 3221 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3222 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3223 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3224 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3225 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3226 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3227 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3228 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3229 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3230 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3231 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3232 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3233 | if (pf->flags & I40E_FLAG_PTP) |
| 3234 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3235 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3236 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3237 | |
| 3238 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3239 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3240 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3241 | |
| 3242 | /* OTHER_ITR_IDX = 0 */ |
| 3243 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3244 | } |
| 3245 | |
| 3246 | /** |
| 3247 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3248 | * @vsi: the VSI being configured |
| 3249 | **/ |
| 3250 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3251 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3252 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3253 | struct i40e_pf *pf = vsi->back; |
| 3254 | struct i40e_hw *hw = &pf->hw; |
| 3255 | u32 val; |
| 3256 | |
| 3257 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3258 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3259 | 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] | 3260 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3261 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3262 | 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] | 3263 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3264 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3265 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3266 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3267 | |
| 3268 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3269 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3270 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3271 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3272 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3273 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3274 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3275 | |
| 3276 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3277 | |
| 3278 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3279 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3280 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3281 | |
| 3282 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3283 | i40e_flush(hw); |
| 3284 | } |
| 3285 | |
| 3286 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3287 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3288 | * @pf: board private structure |
| 3289 | **/ |
| 3290 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3291 | { |
| 3292 | struct i40e_hw *hw = &pf->hw; |
| 3293 | |
| 3294 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3295 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3296 | i40e_flush(hw); |
| 3297 | } |
| 3298 | |
| 3299 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3300 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3301 | * @pf: board private structure |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3302 | * @clearpba: true when all pending interrupt events should be cleared |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3303 | **/ |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3304 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3305 | { |
| 3306 | struct i40e_hw *hw = &pf->hw; |
| 3307 | u32 val; |
| 3308 | |
| 3309 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3310 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3311 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3312 | |
| 3313 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3314 | i40e_flush(hw); |
| 3315 | } |
| 3316 | |
| 3317 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3318 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3319 | * @irq: interrupt number |
| 3320 | * @data: pointer to a q_vector |
| 3321 | **/ |
| 3322 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3323 | { |
| 3324 | struct i40e_q_vector *q_vector = data; |
| 3325 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3326 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3327 | return IRQ_HANDLED; |
| 3328 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3329 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3330 | |
| 3331 | return IRQ_HANDLED; |
| 3332 | } |
| 3333 | |
| 3334 | /** |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3335 | * i40e_irq_affinity_notify - Callback for affinity changes |
| 3336 | * @notify: context as to what irq was changed |
| 3337 | * @mask: the new affinity mask |
| 3338 | * |
| 3339 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3340 | * so that we may register to receive changes to the irq affinity masks. |
| 3341 | **/ |
| 3342 | static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify, |
| 3343 | const cpumask_t *mask) |
| 3344 | { |
| 3345 | struct i40e_q_vector *q_vector = |
| 3346 | container_of(notify, struct i40e_q_vector, affinity_notify); |
| 3347 | |
| 3348 | q_vector->affinity_mask = *mask; |
| 3349 | } |
| 3350 | |
| 3351 | /** |
| 3352 | * i40e_irq_affinity_release - Callback for affinity notifier release |
| 3353 | * @ref: internal core kernel usage |
| 3354 | * |
| 3355 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3356 | * to inform the current notification subscriber that they will no longer |
| 3357 | * receive notifications. |
| 3358 | **/ |
| 3359 | static void i40e_irq_affinity_release(struct kref *ref) {} |
| 3360 | |
| 3361 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3362 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3363 | * @vsi: the VSI being configured |
| 3364 | * @basename: name for the vector |
| 3365 | * |
| 3366 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3367 | **/ |
| 3368 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3369 | { |
| 3370 | int q_vectors = vsi->num_q_vectors; |
| 3371 | struct i40e_pf *pf = vsi->back; |
| 3372 | int base = vsi->base_vector; |
| 3373 | int rx_int_idx = 0; |
| 3374 | int tx_int_idx = 0; |
| 3375 | int vector, err; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3376 | int irq_num; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3377 | |
| 3378 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3379 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3380 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3381 | irq_num = pf->msix_entries[base + vector].vector; |
| 3382 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3383 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3384 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3385 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3386 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3387 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3388 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3389 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3390 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3391 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3392 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3393 | } else { |
| 3394 | /* skip this unused q_vector */ |
| 3395 | continue; |
| 3396 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3397 | err = request_irq(irq_num, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3398 | vsi->irq_handler, |
| 3399 | 0, |
| 3400 | q_vector->name, |
| 3401 | q_vector); |
| 3402 | if (err) { |
| 3403 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3404 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3405 | goto free_queue_irqs; |
| 3406 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3407 | |
| 3408 | /* register for affinity change notifications */ |
| 3409 | q_vector->affinity_notify.notify = i40e_irq_affinity_notify; |
| 3410 | q_vector->affinity_notify.release = i40e_irq_affinity_release; |
| 3411 | irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3412 | /* assign the mask for this irq */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3413 | irq_set_affinity_hint(irq_num, &q_vector->affinity_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3414 | } |
| 3415 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3416 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3417 | return 0; |
| 3418 | |
| 3419 | free_queue_irqs: |
| 3420 | while (vector) { |
| 3421 | vector--; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3422 | irq_num = pf->msix_entries[base + vector].vector; |
| 3423 | irq_set_affinity_notifier(irq_num, NULL); |
| 3424 | irq_set_affinity_hint(irq_num, NULL); |
| 3425 | free_irq(irq_num, &vsi->q_vectors[vector]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3426 | } |
| 3427 | return err; |
| 3428 | } |
| 3429 | |
| 3430 | /** |
| 3431 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3432 | * @vsi: the VSI being un-configured |
| 3433 | **/ |
| 3434 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3435 | { |
| 3436 | struct i40e_pf *pf = vsi->back; |
| 3437 | struct i40e_hw *hw = &pf->hw; |
| 3438 | int base = vsi->base_vector; |
| 3439 | int i; |
| 3440 | |
| 3441 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3442 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3443 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3444 | } |
| 3445 | |
| 3446 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3447 | for (i = vsi->base_vector; |
| 3448 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3449 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3450 | |
| 3451 | i40e_flush(hw); |
| 3452 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3453 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3454 | } else { |
| 3455 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3456 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3457 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3458 | i40e_flush(hw); |
| 3459 | synchronize_irq(pf->pdev->irq); |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | /** |
| 3464 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3465 | * @vsi: the VSI being configured |
| 3466 | **/ |
| 3467 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3468 | { |
| 3469 | struct i40e_pf *pf = vsi->back; |
| 3470 | int i; |
| 3471 | |
| 3472 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3473 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3474 | i40e_irq_dynamic_enable(vsi, i); |
| 3475 | } else { |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3476 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3477 | } |
| 3478 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3479 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3480 | return 0; |
| 3481 | } |
| 3482 | |
| 3483 | /** |
| 3484 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3485 | * @pf: board private structure |
| 3486 | **/ |
| 3487 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3488 | { |
| 3489 | /* Disable ICR 0 */ |
| 3490 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3491 | i40e_flush(&pf->hw); |
| 3492 | } |
| 3493 | |
| 3494 | /** |
| 3495 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3496 | * @irq: interrupt number |
| 3497 | * @data: pointer to a q_vector |
| 3498 | * |
| 3499 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3500 | * with both queue and non-queue interrupts. This is also used in |
| 3501 | * MSIX mode to handle the non-queue interrupts. |
| 3502 | **/ |
| 3503 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3504 | { |
| 3505 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3506 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3507 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3508 | u32 icr0, icr0_remaining; |
| 3509 | u32 val, ena_mask; |
| 3510 | |
| 3511 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3512 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3513 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3514 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3515 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3516 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3517 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3518 | /* if interrupt but no bits showing, must be SWINT */ |
| 3519 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3520 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3521 | pf->sw_int_count++; |
| 3522 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3523 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 3524 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
| 3525 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3526 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3527 | dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
| 3528 | } |
| 3529 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3530 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3531 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3532 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3533 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3534 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3535 | /* We do not have a way to disarm Queue causes while leaving |
| 3536 | * interrupt enabled for all other causes, ideally |
| 3537 | * interrupt should be disabled while we are in NAPI but |
| 3538 | * this is not a performance path and napi_schedule() |
| 3539 | * can deal with rescheduling. |
| 3540 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3541 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3542 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3546 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3547 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3548 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3552 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3553 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3554 | } |
| 3555 | |
| 3556 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3557 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3558 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3559 | } |
| 3560 | |
| 3561 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3562 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3563 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3564 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3565 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3566 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3567 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3568 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3569 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3570 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3571 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3572 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3573 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3574 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3575 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3576 | } |
| 3577 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3578 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3579 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3580 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3581 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3582 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3583 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3584 | } |
| 3585 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3586 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3587 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3588 | |
| 3589 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3590 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3591 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3592 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3593 | } |
| 3594 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3595 | /* If a critical error is pending we have no choice but to reset the |
| 3596 | * device. |
| 3597 | * Report and mask out any remaining unexpected interrupts. |
| 3598 | */ |
| 3599 | icr0_remaining = icr0 & ena_mask; |
| 3600 | if (icr0_remaining) { |
| 3601 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3602 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3603 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3604 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3605 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3606 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3607 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3608 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3609 | } |
| 3610 | ena_mask &= ~icr0_remaining; |
| 3611 | } |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3612 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3613 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3614 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3615 | /* re-enable interrupt causes */ |
| 3616 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3617 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3618 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3619 | i40e_irq_dynamic_enable_icr0(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3620 | } |
| 3621 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3622 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3626 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3627 | * @tx_ring: tx ring to clean |
| 3628 | * @budget: how many cleans we're allowed |
| 3629 | * |
| 3630 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3631 | **/ |
| 3632 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3633 | { |
| 3634 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3635 | u16 i = tx_ring->next_to_clean; |
| 3636 | struct i40e_tx_buffer *tx_buf; |
| 3637 | struct i40e_tx_desc *tx_desc; |
| 3638 | |
| 3639 | tx_buf = &tx_ring->tx_bi[i]; |
| 3640 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3641 | i -= tx_ring->count; |
| 3642 | |
| 3643 | do { |
| 3644 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3645 | |
| 3646 | /* if next_to_watch is not set then there is no work pending */ |
| 3647 | if (!eop_desc) |
| 3648 | break; |
| 3649 | |
| 3650 | /* prevent any other reads prior to eop_desc */ |
| 3651 | read_barrier_depends(); |
| 3652 | |
| 3653 | /* if the descriptor isn't done, no work yet to do */ |
| 3654 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3655 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3656 | break; |
| 3657 | |
| 3658 | /* clear next_to_watch to prevent false hangs */ |
| 3659 | tx_buf->next_to_watch = NULL; |
| 3660 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3661 | tx_desc->buffer_addr = 0; |
| 3662 | tx_desc->cmd_type_offset_bsz = 0; |
| 3663 | /* move past filter desc */ |
| 3664 | tx_buf++; |
| 3665 | tx_desc++; |
| 3666 | i++; |
| 3667 | if (unlikely(!i)) { |
| 3668 | i -= tx_ring->count; |
| 3669 | tx_buf = tx_ring->tx_bi; |
| 3670 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3671 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3672 | /* unmap skb header data */ |
| 3673 | dma_unmap_single(tx_ring->dev, |
| 3674 | dma_unmap_addr(tx_buf, dma), |
| 3675 | dma_unmap_len(tx_buf, len), |
| 3676 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3677 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3678 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3679 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3680 | tx_buf->raw_buf = NULL; |
| 3681 | tx_buf->tx_flags = 0; |
| 3682 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3683 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3684 | tx_desc->buffer_addr = 0; |
| 3685 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3686 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3687 | /* 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] | 3688 | tx_buf++; |
| 3689 | tx_desc++; |
| 3690 | i++; |
| 3691 | if (unlikely(!i)) { |
| 3692 | i -= tx_ring->count; |
| 3693 | tx_buf = tx_ring->tx_bi; |
| 3694 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3695 | } |
| 3696 | |
| 3697 | /* update budget accounting */ |
| 3698 | budget--; |
| 3699 | } while (likely(budget)); |
| 3700 | |
| 3701 | i += tx_ring->count; |
| 3702 | tx_ring->next_to_clean = i; |
| 3703 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3704 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3705 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3706 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3707 | return budget > 0; |
| 3708 | } |
| 3709 | |
| 3710 | /** |
| 3711 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3712 | * @irq: interrupt number |
| 3713 | * @data: pointer to a q_vector |
| 3714 | **/ |
| 3715 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3716 | { |
| 3717 | struct i40e_q_vector *q_vector = data; |
| 3718 | struct i40e_vsi *vsi; |
| 3719 | |
| 3720 | if (!q_vector->tx.ring) |
| 3721 | return IRQ_HANDLED; |
| 3722 | |
| 3723 | vsi = q_vector->tx.ring->vsi; |
| 3724 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3725 | |
| 3726 | return IRQ_HANDLED; |
| 3727 | } |
| 3728 | |
| 3729 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3730 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3731 | * @vsi: the VSI being configured |
| 3732 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3733 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3734 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3735 | 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] | 3736 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3737 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3738 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3739 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3740 | |
| 3741 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3742 | tx_ring->next = q_vector->tx.ring; |
| 3743 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3744 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3745 | |
| 3746 | rx_ring->q_vector = q_vector; |
| 3747 | rx_ring->next = q_vector->rx.ring; |
| 3748 | q_vector->rx.ring = rx_ring; |
| 3749 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | /** |
| 3753 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3754 | * @vsi: the VSI being configured |
| 3755 | * |
| 3756 | * This function maps descriptor rings to the queue-specific vectors |
| 3757 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3758 | * one vector per queue pair, but on a constrained vector budget, we |
| 3759 | * group the queue pairs as "efficiently" as possible. |
| 3760 | **/ |
| 3761 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3762 | { |
| 3763 | int qp_remaining = vsi->num_queue_pairs; |
| 3764 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3765 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3766 | int v_start = 0; |
| 3767 | int qp_idx = 0; |
| 3768 | |
| 3769 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3770 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3771 | * It is also important to go through all the vectors available to be |
| 3772 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3773 | * are cleared. This is especially important when decreasing the |
| 3774 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3775 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3776 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3777 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3778 | |
| 3779 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3780 | |
| 3781 | q_vector->num_ringpairs = num_ringpairs; |
| 3782 | |
| 3783 | q_vector->rx.count = 0; |
| 3784 | q_vector->tx.count = 0; |
| 3785 | q_vector->rx.ring = NULL; |
| 3786 | q_vector->tx.ring = NULL; |
| 3787 | |
| 3788 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3789 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3790 | qp_idx++; |
| 3791 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3792 | } |
| 3793 | } |
| 3794 | } |
| 3795 | |
| 3796 | /** |
| 3797 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3798 | * @vsi: the VSI being configured |
| 3799 | * @basename: name for the vector |
| 3800 | **/ |
| 3801 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3802 | { |
| 3803 | struct i40e_pf *pf = vsi->back; |
| 3804 | int err; |
| 3805 | |
| 3806 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3807 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3808 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3809 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3810 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3811 | else |
| 3812 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3813 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3814 | |
| 3815 | if (err) |
| 3816 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3817 | |
| 3818 | return err; |
| 3819 | } |
| 3820 | |
| 3821 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3822 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3823 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3824 | * @netdev: network interface device structure |
| 3825 | * |
| 3826 | * This is used by netconsole to send skbs without having to re-enable |
| 3827 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3828 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3829 | #ifdef I40E_FCOE |
| 3830 | void i40e_netpoll(struct net_device *netdev) |
| 3831 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3832 | static void i40e_netpoll(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3833 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3834 | { |
| 3835 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3836 | struct i40e_vsi *vsi = np->vsi; |
| 3837 | struct i40e_pf *pf = vsi->back; |
| 3838 | int i; |
| 3839 | |
| 3840 | /* if interface is down do nothing */ |
| 3841 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3842 | return; |
| 3843 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3844 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3845 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3846 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3847 | } else { |
| 3848 | i40e_intr(pf->pdev->irq, netdev); |
| 3849 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3850 | } |
| 3851 | #endif |
| 3852 | |
| 3853 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3854 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3855 | * @pf: the PF being configured |
| 3856 | * @pf_q: the PF queue |
| 3857 | * @enable: enable or disable state of the queue |
| 3858 | * |
| 3859 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3860 | * enabled or disabled state. |
| 3861 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3862 | * multiple retries; else will return 0 in case of success. |
| 3863 | **/ |
| 3864 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3865 | { |
| 3866 | int i; |
| 3867 | u32 tx_reg; |
| 3868 | |
| 3869 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3870 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3871 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3872 | break; |
| 3873 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3874 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3875 | } |
| 3876 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3877 | return -ETIMEDOUT; |
| 3878 | |
| 3879 | return 0; |
| 3880 | } |
| 3881 | |
| 3882 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3883 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3884 | * @vsi: the VSI being configured |
| 3885 | * @enable: start or stop the rings |
| 3886 | **/ |
| 3887 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3888 | { |
| 3889 | struct i40e_pf *pf = vsi->back; |
| 3890 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3891 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3892 | u32 tx_reg; |
| 3893 | |
| 3894 | pf_q = vsi->base_queue; |
| 3895 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3896 | |
| 3897 | /* warn the TX unit of coming changes */ |
| 3898 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3899 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3900 | usleep_range(10, 20); |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3901 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3902 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3903 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3904 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3905 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3906 | break; |
| 3907 | usleep_range(1000, 2000); |
| 3908 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3909 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3910 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3911 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3912 | |
| 3913 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3914 | if (enable) { |
| 3915 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3916 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3917 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3918 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3919 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3920 | |
| 3921 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 3922 | /* No waiting for the Tx queue to disable */ |
| 3923 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3924 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3925 | |
| 3926 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3927 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 3928 | if (ret) { |
| 3929 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3930 | "VSI seid %d Tx ring %d %sable timeout\n", |
| 3931 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3932 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3933 | } |
| 3934 | } |
| 3935 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3936 | if (hw->revision_id == 0) |
| 3937 | mdelay(50); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3938 | return ret; |
| 3939 | } |
| 3940 | |
| 3941 | /** |
| 3942 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 3943 | * @pf: the PF being configured |
| 3944 | * @pf_q: the PF queue |
| 3945 | * @enable: enable or disable state of the queue |
| 3946 | * |
| 3947 | * This routine will wait for the given Rx queue of the PF to reach the |
| 3948 | * enabled or disabled state. |
| 3949 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3950 | * multiple retries; else will return 0 in case of success. |
| 3951 | **/ |
| 3952 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3953 | { |
| 3954 | int i; |
| 3955 | u32 rx_reg; |
| 3956 | |
| 3957 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3958 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 3959 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3960 | break; |
| 3961 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3962 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3963 | } |
| 3964 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3965 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3966 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3967 | return 0; |
| 3968 | } |
| 3969 | |
| 3970 | /** |
| 3971 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 3972 | * @vsi: the VSI being configured |
| 3973 | * @enable: start or stop the rings |
| 3974 | **/ |
| 3975 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 3976 | { |
| 3977 | struct i40e_pf *pf = vsi->back; |
| 3978 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3979 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3980 | u32 rx_reg; |
| 3981 | |
| 3982 | pf_q = vsi->base_queue; |
| 3983 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3984 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3985 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3986 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3987 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3988 | break; |
| 3989 | usleep_range(1000, 2000); |
| 3990 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3991 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3992 | /* Skip if the queue is already in the requested state */ |
| 3993 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3994 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3995 | |
| 3996 | /* turn on/off the queue */ |
| 3997 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3998 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3999 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 4000 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4001 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4002 | /* No waiting for the Tx queue to disable */ |
| 4003 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 4004 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4005 | |
| 4006 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4007 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 4008 | if (ret) { |
| 4009 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4010 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 4011 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4012 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4013 | } |
| 4014 | } |
| 4015 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 4016 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4017 | } |
| 4018 | |
| 4019 | /** |
| 4020 | * i40e_vsi_control_rings - Start or stop a VSI's rings |
| 4021 | * @vsi: the VSI being configured |
| 4022 | * @enable: start or stop the rings |
| 4023 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 4024 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4025 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 4026 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4027 | |
| 4028 | /* do rx first for enable and last for disable */ |
| 4029 | if (request) { |
| 4030 | ret = i40e_vsi_control_rx(vsi, request); |
| 4031 | if (ret) |
| 4032 | return ret; |
| 4033 | ret = i40e_vsi_control_tx(vsi, request); |
| 4034 | } else { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 4035 | /* Ignore return value, we need to shutdown whatever we can */ |
| 4036 | i40e_vsi_control_tx(vsi, request); |
| 4037 | i40e_vsi_control_rx(vsi, request); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4038 | } |
| 4039 | |
| 4040 | return ret; |
| 4041 | } |
| 4042 | |
| 4043 | /** |
| 4044 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 4045 | * @vsi: the VSI being configured |
| 4046 | **/ |
| 4047 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 4048 | { |
| 4049 | struct i40e_pf *pf = vsi->back; |
| 4050 | struct i40e_hw *hw = &pf->hw; |
| 4051 | int base = vsi->base_vector; |
| 4052 | u32 val, qp; |
| 4053 | int i; |
| 4054 | |
| 4055 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4056 | if (!vsi->q_vectors) |
| 4057 | return; |
| 4058 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 4059 | if (!vsi->irqs_ready) |
| 4060 | return; |
| 4061 | |
| 4062 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4063 | for (i = 0; i < vsi->num_q_vectors; i++) { |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4064 | int irq_num; |
| 4065 | u16 vector; |
| 4066 | |
| 4067 | vector = i + base; |
| 4068 | irq_num = pf->msix_entries[vector].vector; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4069 | |
| 4070 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 4071 | if (!vsi->q_vectors[i] || |
| 4072 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4073 | continue; |
| 4074 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4075 | /* clear the affinity notifier in the IRQ descriptor */ |
| 4076 | irq_set_affinity_notifier(irq_num, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4077 | /* clear the affinity_mask in the IRQ descriptor */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 4078 | irq_set_affinity_hint(irq_num, NULL); |
| 4079 | synchronize_irq(irq_num); |
| 4080 | free_irq(irq_num, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4081 | |
| 4082 | /* Tear down the interrupt queue link list |
| 4083 | * |
| 4084 | * We know that they come in pairs and always |
| 4085 | * the Rx first, then the Tx. To clear the |
| 4086 | * link list, stick the EOL value into the |
| 4087 | * next_q field of the registers. |
| 4088 | */ |
| 4089 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4090 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4091 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4092 | val |= I40E_QUEUE_END_OF_LIST |
| 4093 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4094 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4095 | |
| 4096 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4097 | u32 next; |
| 4098 | |
| 4099 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4100 | |
| 4101 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4102 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4103 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4104 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4105 | |
| 4106 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4107 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4108 | |
| 4109 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4110 | |
| 4111 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4112 | |
| 4113 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4114 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4115 | |
| 4116 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4117 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4118 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4119 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4120 | |
| 4121 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4122 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4123 | |
| 4124 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4125 | qp = next; |
| 4126 | } |
| 4127 | } |
| 4128 | } else { |
| 4129 | free_irq(pf->pdev->irq, pf); |
| 4130 | |
| 4131 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4132 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4133 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4134 | val |= I40E_QUEUE_END_OF_LIST |
| 4135 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4136 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4137 | |
| 4138 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4139 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4140 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4141 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4142 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4143 | |
| 4144 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4145 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4146 | |
| 4147 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4148 | |
| 4149 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4150 | |
| 4151 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4152 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4153 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4154 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4155 | |
| 4156 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4157 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4158 | |
| 4159 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4160 | } |
| 4161 | } |
| 4162 | |
| 4163 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4164 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4165 | * @vsi: the VSI being configured |
| 4166 | * @v_idx: Index of vector to be freed |
| 4167 | * |
| 4168 | * This function frees the memory allocated to the q_vector. In addition if |
| 4169 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4170 | * to freeing the q_vector. |
| 4171 | **/ |
| 4172 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4173 | { |
| 4174 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4175 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4176 | |
| 4177 | if (!q_vector) |
| 4178 | return; |
| 4179 | |
| 4180 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4181 | i40e_for_each_ring(ring, q_vector->tx) |
| 4182 | ring->q_vector = NULL; |
| 4183 | |
| 4184 | i40e_for_each_ring(ring, q_vector->rx) |
| 4185 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4186 | |
| 4187 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4188 | if (vsi->netdev) |
| 4189 | netif_napi_del(&q_vector->napi); |
| 4190 | |
| 4191 | vsi->q_vectors[v_idx] = NULL; |
| 4192 | |
| 4193 | kfree_rcu(q_vector, rcu); |
| 4194 | } |
| 4195 | |
| 4196 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4197 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4198 | * @vsi: the VSI being un-configured |
| 4199 | * |
| 4200 | * This frees the memory allocated to the q_vectors and |
| 4201 | * deletes references to the NAPI struct. |
| 4202 | **/ |
| 4203 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4204 | { |
| 4205 | int v_idx; |
| 4206 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4207 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4208 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4209 | } |
| 4210 | |
| 4211 | /** |
| 4212 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4213 | * @pf: board private structure |
| 4214 | **/ |
| 4215 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4216 | { |
| 4217 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4218 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4219 | pci_disable_msix(pf->pdev); |
| 4220 | kfree(pf->msix_entries); |
| 4221 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4222 | kfree(pf->irq_pile); |
| 4223 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4224 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4225 | pci_disable_msi(pf->pdev); |
| 4226 | } |
| 4227 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4228 | } |
| 4229 | |
| 4230 | /** |
| 4231 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4232 | * @pf: board private structure |
| 4233 | * |
| 4234 | * We go through and clear interrupt specific resources and reset the structure |
| 4235 | * to pre-load conditions |
| 4236 | **/ |
| 4237 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4238 | { |
| 4239 | int i; |
| 4240 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4241 | i40e_stop_misc_vector(pf); |
Shannon Nelson | 6927839 | 2016-03-10 14:59:43 -0800 | [diff] [blame] | 4242 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4243 | synchronize_irq(pf->msix_entries[0].vector); |
| 4244 | free_irq(pf->msix_entries[0].vector, pf); |
| 4245 | } |
| 4246 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4247 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4248 | I40E_IWARP_IRQ_PILE_ID); |
| 4249 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4250 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4251 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4252 | if (pf->vsi[i]) |
| 4253 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4254 | i40e_reset_interrupt_capability(pf); |
| 4255 | } |
| 4256 | |
| 4257 | /** |
| 4258 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4259 | * @vsi: the VSI being configured |
| 4260 | **/ |
| 4261 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4262 | { |
| 4263 | int q_idx; |
| 4264 | |
| 4265 | if (!vsi->netdev) |
| 4266 | return; |
| 4267 | |
| 4268 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4269 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | /** |
| 4273 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4274 | * @vsi: the VSI being configured |
| 4275 | **/ |
| 4276 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4277 | { |
| 4278 | int q_idx; |
| 4279 | |
| 4280 | if (!vsi->netdev) |
| 4281 | return; |
| 4282 | |
| 4283 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4284 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4288 | * i40e_vsi_close - Shut down a VSI |
| 4289 | * @vsi: the vsi to be quelled |
| 4290 | **/ |
| 4291 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4292 | { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4293 | bool reset = false; |
| 4294 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4295 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4296 | i40e_down(vsi); |
| 4297 | i40e_vsi_free_irq(vsi); |
| 4298 | i40e_vsi_free_tx_resources(vsi); |
| 4299 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4300 | vsi->current_netdev_flags = 0; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4301 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4302 | reset = true; |
| 4303 | i40e_notify_client_of_netdev_close(vsi, reset); |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4307 | * i40e_quiesce_vsi - Pause a given VSI |
| 4308 | * @vsi: the VSI being paused |
| 4309 | **/ |
| 4310 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4311 | { |
| 4312 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4313 | return; |
| 4314 | |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4315 | /* No need to disable FCoE VSI when Tx suspended */ |
| 4316 | if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) && |
| 4317 | vsi->type == I40E_VSI_FCOE) { |
| 4318 | dev_dbg(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4319 | "VSI seid %d skipping FCoE VSI disable\n", vsi->seid); |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4320 | return; |
| 4321 | } |
| 4322 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4323 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4324 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4325 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4326 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4327 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | /** |
| 4331 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4332 | * @vsi: the VSI being resumed |
| 4333 | **/ |
| 4334 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4335 | { |
| 4336 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 4337 | return; |
| 4338 | |
| 4339 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4340 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4341 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4342 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4343 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4344 | } |
| 4345 | |
| 4346 | /** |
| 4347 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4348 | * @pf: the PF |
| 4349 | **/ |
| 4350 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4351 | { |
| 4352 | int v; |
| 4353 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4354 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4355 | if (pf->vsi[v]) |
| 4356 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4357 | } |
| 4358 | } |
| 4359 | |
| 4360 | /** |
| 4361 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4362 | * @pf: the PF |
| 4363 | **/ |
| 4364 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4365 | { |
| 4366 | int v; |
| 4367 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4368 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4369 | if (pf->vsi[v]) |
| 4370 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4371 | } |
| 4372 | } |
| 4373 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4374 | #ifdef CONFIG_I40E_DCB |
| 4375 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4376 | * 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] | 4377 | * @vsi: the VSI being configured |
| 4378 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4379 | * This function waits for the given VSI's queues to be disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4380 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4381 | static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4382 | { |
| 4383 | struct i40e_pf *pf = vsi->back; |
| 4384 | int i, pf_q, ret; |
| 4385 | |
| 4386 | pf_q = vsi->base_queue; |
| 4387 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4388 | /* Check and wait for the disable status of the queue */ |
| 4389 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4390 | if (ret) { |
| 4391 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4392 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4393 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4394 | return ret; |
| 4395 | } |
| 4396 | } |
| 4397 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4398 | pf_q = vsi->base_queue; |
| 4399 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4400 | /* Check and wait for the disable status of the queue */ |
| 4401 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4402 | if (ret) { |
| 4403 | dev_info(&pf->pdev->dev, |
| 4404 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4405 | vsi->seid, pf_q); |
| 4406 | return ret; |
| 4407 | } |
| 4408 | } |
| 4409 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4410 | return 0; |
| 4411 | } |
| 4412 | |
| 4413 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4414 | * 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] | 4415 | * @pf: the PF |
| 4416 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4417 | * 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] | 4418 | * VSIs that are managed by this PF. |
| 4419 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4420 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4421 | { |
| 4422 | int v, ret = 0; |
| 4423 | |
| 4424 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4425 | /* No need to wait for FCoE VSI queues */ |
| 4426 | if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4427 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4428 | if (ret) |
| 4429 | break; |
| 4430 | } |
| 4431 | } |
| 4432 | |
| 4433 | return ret; |
| 4434 | } |
| 4435 | |
| 4436 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4437 | |
| 4438 | /** |
| 4439 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4440 | * @q_idx: TX queue number |
| 4441 | * @vsi: Pointer to VSI struct |
| 4442 | * |
| 4443 | * This function checks specified queue for given VSI. Detects hung condition. |
| 4444 | * Sets hung bit since it is two step process. Before next run of service task |
| 4445 | * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not, |
| 4446 | * hung condition remain unchanged and during subsequent run, this function |
| 4447 | * issues SW interrupt to recover from hung condition. |
| 4448 | **/ |
| 4449 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4450 | { |
| 4451 | struct i40e_ring *tx_ring = NULL; |
| 4452 | struct i40e_pf *pf; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4453 | u32 head, val, tx_pending_hw; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4454 | int i; |
| 4455 | |
| 4456 | pf = vsi->back; |
| 4457 | |
| 4458 | /* now that we have an index, find the tx_ring struct */ |
| 4459 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4460 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4461 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4462 | tx_ring = vsi->tx_rings[i]; |
| 4463 | break; |
| 4464 | } |
| 4465 | } |
| 4466 | } |
| 4467 | |
| 4468 | if (!tx_ring) |
| 4469 | return; |
| 4470 | |
| 4471 | /* Read interrupt register */ |
| 4472 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4473 | val = rd32(&pf->hw, |
| 4474 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4475 | tx_ring->vsi->base_vector - 1)); |
| 4476 | else |
| 4477 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4478 | |
| 4479 | head = i40e_get_head(tx_ring); |
| 4480 | |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4481 | tx_pending_hw = i40e_get_tx_pending(tx_ring, false); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4482 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4483 | /* HW is done executing descriptors, updated HEAD write back, |
| 4484 | * but SW hasn't processed those descriptors. If interrupt is |
| 4485 | * not generated from this point ON, it could result into |
| 4486 | * dev_watchdog detecting timeout on those netdev_queue, |
| 4487 | * hence proactively trigger SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4488 | */ |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4489 | if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4490 | /* NAPI Poll didn't run and clear since it was set */ |
| 4491 | if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4492 | &tx_ring->q_vector->hung_detected)) { |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4493 | 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", |
| 4494 | vsi->seid, q_idx, tx_pending_hw, |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4495 | tx_ring->next_to_clean, head, |
| 4496 | tx_ring->next_to_use, |
| 4497 | readl(tx_ring->tail)); |
| 4498 | netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n", |
| 4499 | vsi->seid, q_idx, val); |
| 4500 | i40e_force_wb(vsi, tx_ring->q_vector); |
| 4501 | } else { |
| 4502 | /* First Chance - detected possible hung */ |
| 4503 | set_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4504 | &tx_ring->q_vector->hung_detected); |
| 4505 | } |
| 4506 | } |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4507 | |
| 4508 | /* This is the case where we have interrupts missing, |
| 4509 | * so the tx_pending in HW will most likely be 0, but we |
| 4510 | * will have tx_pending in SW since the WB happened but the |
| 4511 | * interrupt got lost. |
| 4512 | */ |
| 4513 | if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) && |
| 4514 | (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
| 4515 | if (napi_reschedule(&tx_ring->q_vector->napi)) |
| 4516 | tx_ring->tx_stats.tx_lost_interrupt++; |
| 4517 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4518 | } |
| 4519 | |
| 4520 | /** |
| 4521 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4522 | * @pf: pointer to PF struct |
| 4523 | * |
| 4524 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4525 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4526 | * SW interrupt. |
| 4527 | **/ |
| 4528 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4529 | { |
| 4530 | struct net_device *netdev; |
| 4531 | struct i40e_vsi *vsi; |
| 4532 | int i; |
| 4533 | |
| 4534 | /* Only for LAN VSI */ |
| 4535 | vsi = pf->vsi[pf->lan_vsi]; |
| 4536 | |
| 4537 | if (!vsi) |
| 4538 | return; |
| 4539 | |
| 4540 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
| 4541 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 4542 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4543 | return; |
| 4544 | |
| 4545 | /* Make sure type is MAIN VSI */ |
| 4546 | if (vsi->type != I40E_VSI_MAIN) |
| 4547 | return; |
| 4548 | |
| 4549 | netdev = vsi->netdev; |
| 4550 | if (!netdev) |
| 4551 | return; |
| 4552 | |
| 4553 | /* Bail out if netif_carrier is not OK */ |
| 4554 | if (!netif_carrier_ok(netdev)) |
| 4555 | return; |
| 4556 | |
| 4557 | /* Go thru' TX queues for netdev */ |
| 4558 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4559 | struct netdev_queue *q; |
| 4560 | |
| 4561 | q = netdev_get_tx_queue(netdev, i); |
| 4562 | if (q) |
| 4563 | i40e_detect_recover_hung_queue(i, vsi); |
| 4564 | } |
| 4565 | } |
| 4566 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4567 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4568 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4569 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4570 | * |
| 4571 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4572 | * and LAN TC. |
| 4573 | **/ |
| 4574 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4575 | { |
| 4576 | struct i40e_dcb_app_priority_table app; |
| 4577 | struct i40e_hw *hw = &pf->hw; |
| 4578 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4579 | u8 tc, i; |
| 4580 | /* Get the iSCSI APP TLV */ |
| 4581 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4582 | |
| 4583 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4584 | app = dcbcfg->app[i]; |
| 4585 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4586 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4587 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4588 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4589 | break; |
| 4590 | } |
| 4591 | } |
| 4592 | |
| 4593 | return enabled_tc; |
| 4594 | } |
| 4595 | |
| 4596 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4597 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4598 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4599 | * |
| 4600 | * Return the number of TCs from given DCBx configuration |
| 4601 | **/ |
| 4602 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4603 | { |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4604 | int i, tc_unused = 0; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4605 | u8 num_tc = 0; |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4606 | u8 ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4607 | |
| 4608 | /* Scan the ETS Config Priority Table to find |
| 4609 | * traffic class enabled for a given priority |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4610 | * and create a bitmask of enabled TCs |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4611 | */ |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4612 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) |
| 4613 | num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]); |
| 4614 | |
| 4615 | /* Now scan the bitmask to check for |
| 4616 | * contiguous TCs starting with TC0 |
| 4617 | */ |
| 4618 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4619 | if (num_tc & BIT(i)) { |
| 4620 | if (!tc_unused) { |
| 4621 | ret++; |
| 4622 | } else { |
| 4623 | pr_err("Non-contiguous TC - Disabling DCB\n"); |
| 4624 | return 1; |
| 4625 | } |
| 4626 | } else { |
| 4627 | tc_unused = 1; |
| 4628 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4629 | } |
| 4630 | |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4631 | /* There is always at least TC0 */ |
| 4632 | if (!ret) |
| 4633 | ret = 1; |
| 4634 | |
| 4635 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4636 | } |
| 4637 | |
| 4638 | /** |
| 4639 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4640 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4641 | * |
| 4642 | * Query the current DCB configuration and return the number of |
| 4643 | * traffic classes enabled from the given DCBX config |
| 4644 | **/ |
| 4645 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4646 | { |
| 4647 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4648 | u8 enabled_tc = 1; |
| 4649 | u8 i; |
| 4650 | |
| 4651 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4652 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4653 | |
| 4654 | return enabled_tc; |
| 4655 | } |
| 4656 | |
| 4657 | /** |
| 4658 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4659 | * @pf: PF being queried |
| 4660 | * |
| 4661 | * Return number of traffic classes enabled for the given PF |
| 4662 | **/ |
| 4663 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4664 | { |
| 4665 | struct i40e_hw *hw = &pf->hw; |
Dave Ertman | 52a08ca | 2016-07-27 12:02:34 -0700 | [diff] [blame] | 4666 | u8 i, enabled_tc = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4667 | u8 num_tc = 0; |
| 4668 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4669 | |
| 4670 | /* If DCB is not enabled then always in single TC */ |
| 4671 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4672 | return 1; |
| 4673 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4674 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4675 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4676 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4677 | |
| 4678 | /* MFP mode return count of enabled TCs for this PF */ |
| 4679 | if (pf->hw.func_caps.iscsi) |
| 4680 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4681 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4682 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4683 | |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4684 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4685 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4686 | num_tc++; |
| 4687 | } |
| 4688 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4692 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4693 | * @pf: PF being queried |
| 4694 | * |
| 4695 | * Return a bitmap for enabled traffic classes for this PF. |
| 4696 | **/ |
| 4697 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4698 | { |
| 4699 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4700 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4701 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4702 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4703 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4704 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4705 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4706 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4707 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4708 | if (pf->hw.func_caps.iscsi) |
| 4709 | return i40e_get_iscsi_tc_map(pf); |
| 4710 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4711 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | /** |
| 4715 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4716 | * @vsi: the VSI being queried |
| 4717 | * |
| 4718 | * Returns 0 on success, negative value on failure |
| 4719 | **/ |
| 4720 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4721 | { |
| 4722 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4723 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4724 | struct i40e_pf *pf = vsi->back; |
| 4725 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4726 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4727 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4728 | int i; |
| 4729 | |
| 4730 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4731 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4732 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4733 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4734 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4735 | i40e_stat_str(&pf->hw, ret), |
| 4736 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4737 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4738 | } |
| 4739 | |
| 4740 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4741 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4742 | NULL); |
| 4743 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4744 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4745 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4746 | i40e_stat_str(&pf->hw, ret), |
| 4747 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4748 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4749 | } |
| 4750 | |
| 4751 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4752 | dev_info(&pf->pdev->dev, |
| 4753 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4754 | bw_config.tc_valid_bits, |
| 4755 | bw_ets_config.tc_valid_bits); |
| 4756 | /* Still continuing */ |
| 4757 | } |
| 4758 | |
| 4759 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4760 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4761 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4762 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4763 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4764 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4765 | vsi->bw_ets_limit_credits[i] = |
| 4766 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4767 | /* 3 bits out of 4 for each TC */ |
| 4768 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4769 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4770 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4771 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4772 | } |
| 4773 | |
| 4774 | /** |
| 4775 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4776 | * @vsi: the VSI being configured |
| 4777 | * @enabled_tc: TC bitmap |
| 4778 | * @bw_credits: BW shared credits per TC |
| 4779 | * |
| 4780 | * Returns 0 on success, negative value on failure |
| 4781 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4782 | 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] | 4783 | u8 *bw_share) |
| 4784 | { |
| 4785 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4786 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4787 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4788 | |
| 4789 | bw_data.tc_valid_bits = enabled_tc; |
| 4790 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4791 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4792 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4793 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4794 | NULL); |
| 4795 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4796 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4797 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4798 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4799 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4800 | } |
| 4801 | |
| 4802 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4803 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4804 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4805 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
| 4808 | /** |
| 4809 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4810 | * @vsi: the VSI being configured |
| 4811 | * @enabled_tc: TC map to be enabled |
| 4812 | * |
| 4813 | **/ |
| 4814 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4815 | { |
| 4816 | struct net_device *netdev = vsi->netdev; |
| 4817 | struct i40e_pf *pf = vsi->back; |
| 4818 | struct i40e_hw *hw = &pf->hw; |
| 4819 | u8 netdev_tc = 0; |
| 4820 | int i; |
| 4821 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4822 | |
| 4823 | if (!netdev) |
| 4824 | return; |
| 4825 | |
| 4826 | if (!enabled_tc) { |
| 4827 | netdev_reset_tc(netdev); |
| 4828 | return; |
| 4829 | } |
| 4830 | |
| 4831 | /* Set up actual enabled TCs on the VSI */ |
| 4832 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 4833 | return; |
| 4834 | |
| 4835 | /* set per TC queues for the VSI */ |
| 4836 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4837 | /* Only set TC queues for enabled tcs |
| 4838 | * |
| 4839 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 4840 | * enabled_tc bitmap would be 0x00001001; the driver |
| 4841 | * will set the numtc for netdev as 2 that will be |
| 4842 | * referenced by the netdev layer as TC 0 and 1. |
| 4843 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4844 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4845 | netdev_set_tc_queue(netdev, |
| 4846 | vsi->tc_config.tc_info[i].netdev_tc, |
| 4847 | vsi->tc_config.tc_info[i].qcount, |
| 4848 | vsi->tc_config.tc_info[i].qoffset); |
| 4849 | } |
| 4850 | |
| 4851 | /* Assign UP2TC map for the VSI */ |
| 4852 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4853 | /* Get the actual TC# for the UP */ |
| 4854 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4855 | /* Get the mapped netdev TC# for the UP */ |
| 4856 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 4857 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 4858 | } |
| 4859 | } |
| 4860 | |
| 4861 | /** |
| 4862 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 4863 | * @vsi: the VSI being configured |
| 4864 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 4865 | **/ |
| 4866 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 4867 | struct i40e_vsi_context *ctxt) |
| 4868 | { |
| 4869 | /* copy just the sections touched not the entire info |
| 4870 | * since not all sections are valid as returned by |
| 4871 | * update vsi params |
| 4872 | */ |
| 4873 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 4874 | memcpy(&vsi->info.queue_mapping, |
| 4875 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 4876 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 4877 | sizeof(vsi->info.tc_mapping)); |
| 4878 | } |
| 4879 | |
| 4880 | /** |
| 4881 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 4882 | * @vsi: VSI to be configured |
| 4883 | * @enabled_tc: TC bitmap |
| 4884 | * |
| 4885 | * This configures a particular VSI for TCs that are mapped to the |
| 4886 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 4887 | * VSIs to configure TC for a particular VSI. |
| 4888 | * |
| 4889 | * NOTE: |
| 4890 | * It is expected that the VSI queues have been quisced before calling |
| 4891 | * this function. |
| 4892 | **/ |
| 4893 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4894 | { |
| 4895 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 4896 | struct i40e_vsi_context ctxt; |
| 4897 | int ret = 0; |
| 4898 | int i; |
| 4899 | |
| 4900 | /* Check if enabled_tc is same as existing or new TCs */ |
| 4901 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 4902 | return ret; |
| 4903 | |
| 4904 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 4905 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4906 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4907 | bw_share[i] = 1; |
| 4908 | } |
| 4909 | |
| 4910 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 4911 | if (ret) { |
| 4912 | dev_info(&vsi->back->pdev->dev, |
| 4913 | "Failed configuring TC map %d for VSI %d\n", |
| 4914 | enabled_tc, vsi->seid); |
| 4915 | goto out; |
| 4916 | } |
| 4917 | |
| 4918 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 4919 | ctxt.seid = vsi->seid; |
| 4920 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 4921 | ctxt.vf_num = 0; |
| 4922 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 4923 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4924 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 4925 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4926 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 4927 | ctxt.info.valid_sections |= |
| 4928 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 4929 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 4930 | } |
| 4931 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4932 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 4933 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 4934 | if (ret) { |
| 4935 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4936 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 4937 | i40e_stat_str(&vsi->back->hw, ret), |
| 4938 | i40e_aq_str(&vsi->back->hw, |
| 4939 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4940 | goto out; |
| 4941 | } |
| 4942 | /* update the local VSI info with updated queue map */ |
| 4943 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 4944 | vsi->info.valid_sections = 0; |
| 4945 | |
| 4946 | /* Update current VSI BW information */ |
| 4947 | ret = i40e_vsi_get_bw_info(vsi); |
| 4948 | if (ret) { |
| 4949 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4950 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 4951 | i40e_stat_str(&vsi->back->hw, ret), |
| 4952 | i40e_aq_str(&vsi->back->hw, |
| 4953 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4954 | goto out; |
| 4955 | } |
| 4956 | |
| 4957 | /* Update the netdev TC setup */ |
| 4958 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 4959 | out: |
| 4960 | return ret; |
| 4961 | } |
| 4962 | |
| 4963 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4964 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 4965 | * @veb: given VEB |
| 4966 | * @enabled_tc: TC bitmap |
| 4967 | * |
| 4968 | * Configures given TC bitmap for VEB (switching) element |
| 4969 | **/ |
| 4970 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 4971 | { |
| 4972 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 4973 | struct i40e_pf *pf = veb->pf; |
| 4974 | int ret = 0; |
| 4975 | int i; |
| 4976 | |
| 4977 | /* No TCs or already enabled TCs just return */ |
| 4978 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 4979 | return ret; |
| 4980 | |
| 4981 | bw_data.tc_valid_bits = enabled_tc; |
| 4982 | /* bw_data.absolute_credits is not set (relative) */ |
| 4983 | |
| 4984 | /* Enable ETS TCs with equal BW Share for now */ |
| 4985 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4986 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4987 | bw_data.tc_bw_share_credits[i] = 1; |
| 4988 | } |
| 4989 | |
| 4990 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 4991 | &bw_data, NULL); |
| 4992 | if (ret) { |
| 4993 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4994 | "VEB bw config failed, err %s aq_err %s\n", |
| 4995 | i40e_stat_str(&pf->hw, ret), |
| 4996 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4997 | goto out; |
| 4998 | } |
| 4999 | |
| 5000 | /* Update the BW information */ |
| 5001 | ret = i40e_veb_get_bw_info(veb); |
| 5002 | if (ret) { |
| 5003 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5004 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 5005 | i40e_stat_str(&pf->hw, ret), |
| 5006 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | out: |
| 5010 | return ret; |
| 5011 | } |
| 5012 | |
| 5013 | #ifdef CONFIG_I40E_DCB |
| 5014 | /** |
| 5015 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 5016 | * @pf: PF struct |
| 5017 | * |
| 5018 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 5019 | * the caller would've quiesce all the VSIs before calling |
| 5020 | * this function |
| 5021 | **/ |
| 5022 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 5023 | { |
| 5024 | u8 tc_map = 0; |
| 5025 | int ret; |
| 5026 | u8 v; |
| 5027 | |
| 5028 | /* Enable the TCs available on PF to all VEBs */ |
| 5029 | tc_map = i40e_pf_get_tc_map(pf); |
| 5030 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 5031 | if (!pf->veb[v]) |
| 5032 | continue; |
| 5033 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 5034 | if (ret) { |
| 5035 | dev_info(&pf->pdev->dev, |
| 5036 | "Failed configuring TC for VEB seid=%d\n", |
| 5037 | pf->veb[v]->seid); |
| 5038 | /* Will try to configure as many components */ |
| 5039 | } |
| 5040 | } |
| 5041 | |
| 5042 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5043 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5044 | if (!pf->vsi[v]) |
| 5045 | continue; |
| 5046 | |
| 5047 | /* - Enable all TCs for the LAN VSI |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5048 | #ifdef I40E_FCOE |
| 5049 | * - For FCoE VSI only enable the TC configured |
| 5050 | * as per the APP TLV |
| 5051 | #endif |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5052 | * - For all others keep them at TC0 for now |
| 5053 | */ |
| 5054 | if (v == pf->lan_vsi) |
| 5055 | tc_map = i40e_pf_get_tc_map(pf); |
| 5056 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5057 | tc_map = I40E_DEFAULT_TRAFFIC_CLASS; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5058 | #ifdef I40E_FCOE |
| 5059 | if (pf->vsi[v]->type == I40E_VSI_FCOE) |
| 5060 | tc_map = i40e_get_fcoe_tc_map(pf); |
| 5061 | #endif /* #ifdef I40E_FCOE */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5062 | |
| 5063 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 5064 | if (ret) { |
| 5065 | dev_info(&pf->pdev->dev, |
| 5066 | "Failed configuring TC for VSI seid=%d\n", |
| 5067 | pf->vsi[v]->seid); |
| 5068 | /* Will try to configure as many components */ |
| 5069 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 5070 | /* Re-configure VSI vectors based on updated TC map */ |
| 5071 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5072 | if (pf->vsi[v]->netdev) |
| 5073 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 5074 | } |
| 5075 | } |
| 5076 | } |
| 5077 | |
| 5078 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5079 | * i40e_resume_port_tx - Resume port Tx |
| 5080 | * @pf: PF struct |
| 5081 | * |
| 5082 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 5083 | * resume. |
| 5084 | **/ |
| 5085 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 5086 | { |
| 5087 | struct i40e_hw *hw = &pf->hw; |
| 5088 | int ret; |
| 5089 | |
| 5090 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 5091 | if (ret) { |
| 5092 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5093 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 5094 | i40e_stat_str(&pf->hw, ret), |
| 5095 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5096 | /* Schedule PF reset to recover */ |
| 5097 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5098 | i40e_service_event_schedule(pf); |
| 5099 | } |
| 5100 | |
| 5101 | return ret; |
| 5102 | } |
| 5103 | |
| 5104 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5105 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 5106 | * @pf: PF being configured |
| 5107 | * |
| 5108 | * Query the current DCB configuration and cache it |
| 5109 | * in the hardware structure |
| 5110 | **/ |
| 5111 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 5112 | { |
| 5113 | struct i40e_hw *hw = &pf->hw; |
| 5114 | int err = 0; |
| 5115 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5116 | /* 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] | 5117 | if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5118 | goto out; |
| 5119 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5120 | /* Get the initial DCB configuration */ |
| 5121 | err = i40e_init_dcb(hw); |
| 5122 | if (!err) { |
| 5123 | /* Device/Function is not DCBX capable */ |
| 5124 | if ((!hw->func_caps.dcb) || |
| 5125 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5126 | dev_info(&pf->pdev->dev, |
| 5127 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 5128 | |
| 5129 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 5130 | goto out; |
| 5131 | |
| 5132 | } else { |
| 5133 | /* When status is not DISABLED then DCBX in FW */ |
| 5134 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5135 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5136 | |
| 5137 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5138 | /* Enable DCB tagging only when more than one TC |
| 5139 | * or explicitly disable if only one TC |
| 5140 | */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5141 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5142 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5143 | else |
| 5144 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5145 | dev_dbg(&pf->pdev->dev, |
| 5146 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5147 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5148 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5149 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5150 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5151 | i40e_stat_str(&pf->hw, err), |
| 5152 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5153 | } |
| 5154 | |
| 5155 | out: |
| 5156 | return err; |
| 5157 | } |
| 5158 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5159 | #define SPEED_SIZE 14 |
| 5160 | #define FC_SIZE 8 |
| 5161 | /** |
| 5162 | * i40e_print_link_message - print link up or down |
| 5163 | * @vsi: the VSI for which link needs a message |
| 5164 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5165 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5166 | { |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5167 | char *speed = "Unknown"; |
| 5168 | char *fc = "Unknown"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5169 | |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5170 | if (vsi->current_isup == isup) |
| 5171 | return; |
| 5172 | vsi->current_isup = isup; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5173 | if (!isup) { |
| 5174 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5175 | return; |
| 5176 | } |
| 5177 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5178 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5179 | * least 10GB |
| 5180 | */ |
| 5181 | if (vsi->back->hw.func_caps.npar_enable && |
| 5182 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5183 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5184 | netdev_warn(vsi->netdev, |
| 5185 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5186 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5187 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5188 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5189 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5190 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5191 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5192 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5193 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5194 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5195 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5196 | break; |
| 5197 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5198 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5199 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5200 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5201 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5202 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5203 | default: |
| 5204 | break; |
| 5205 | } |
| 5206 | |
| 5207 | switch (vsi->back->hw.fc.current_mode) { |
| 5208 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5209 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5210 | break; |
| 5211 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5212 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5213 | break; |
| 5214 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5215 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5216 | break; |
| 5217 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5218 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5219 | break; |
| 5220 | } |
| 5221 | |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5222 | 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] | 5223 | speed, fc); |
| 5224 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5225 | |
| 5226 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5227 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5228 | * @vsi: the VSI being configured |
| 5229 | **/ |
| 5230 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5231 | { |
| 5232 | struct i40e_pf *pf = vsi->back; |
| 5233 | int err; |
| 5234 | |
| 5235 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5236 | i40e_vsi_configure_msix(vsi); |
| 5237 | else |
| 5238 | i40e_configure_msi_and_legacy(vsi); |
| 5239 | |
| 5240 | /* start rings */ |
| 5241 | err = i40e_vsi_control_rings(vsi, true); |
| 5242 | if (err) |
| 5243 | return err; |
| 5244 | |
| 5245 | clear_bit(__I40E_DOWN, &vsi->state); |
| 5246 | i40e_napi_enable_all(vsi); |
| 5247 | i40e_vsi_enable_irq(vsi); |
| 5248 | |
| 5249 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5250 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5251 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5252 | netif_tx_start_all_queues(vsi->netdev); |
| 5253 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5254 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5255 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5256 | /* need to check for qualified module here*/ |
| 5257 | if ((pf->hw.phy.link_info.link_info & |
| 5258 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5259 | (!(pf->hw.phy.link_info.an_info & |
| 5260 | I40E_AQ_QUALIFIED_MODULE))) |
| 5261 | netdev_err(vsi->netdev, |
| 5262 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5263 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5264 | |
| 5265 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5266 | if (vsi->type == I40E_VSI_FDIR) { |
| 5267 | /* reset fd counters */ |
| 5268 | pf->fd_add_err = pf->fd_atr_cnt = 0; |
| 5269 | if (pf->fd_tcp_rule > 0) { |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 5270 | pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5271 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5272 | 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] | 5273 | pf->fd_tcp_rule = 0; |
| 5274 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5275 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5276 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5277 | |
| 5278 | /* On the next run of the service_task, notify any clients of the new |
| 5279 | * opened netdev |
| 5280 | */ |
| 5281 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5282 | i40e_service_event_schedule(pf); |
| 5283 | |
| 5284 | return 0; |
| 5285 | } |
| 5286 | |
| 5287 | /** |
| 5288 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5289 | * @vsi: the VSI being configured |
| 5290 | * |
| 5291 | * Rebuild the ring structs after some configuration |
| 5292 | * has changed, e.g. MTU size. |
| 5293 | **/ |
| 5294 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5295 | { |
| 5296 | struct i40e_pf *pf = vsi->back; |
| 5297 | |
| 5298 | WARN_ON(in_interrupt()); |
| 5299 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5300 | usleep_range(1000, 2000); |
| 5301 | i40e_down(vsi); |
| 5302 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5303 | i40e_up(vsi); |
| 5304 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 5305 | } |
| 5306 | |
| 5307 | /** |
| 5308 | * i40e_up - Bring the connection back up after being down |
| 5309 | * @vsi: the VSI being configured |
| 5310 | **/ |
| 5311 | int i40e_up(struct i40e_vsi *vsi) |
| 5312 | { |
| 5313 | int err; |
| 5314 | |
| 5315 | err = i40e_vsi_configure(vsi); |
| 5316 | if (!err) |
| 5317 | err = i40e_up_complete(vsi); |
| 5318 | |
| 5319 | return err; |
| 5320 | } |
| 5321 | |
| 5322 | /** |
| 5323 | * i40e_down - Shutdown the connection processing |
| 5324 | * @vsi: the VSI being stopped |
| 5325 | **/ |
| 5326 | void i40e_down(struct i40e_vsi *vsi) |
| 5327 | { |
| 5328 | int i; |
| 5329 | |
| 5330 | /* It is assumed that the caller of this function |
| 5331 | * sets the vsi->state __I40E_DOWN bit. |
| 5332 | */ |
| 5333 | if (vsi->netdev) { |
| 5334 | netif_carrier_off(vsi->netdev); |
| 5335 | netif_tx_disable(vsi->netdev); |
| 5336 | } |
| 5337 | i40e_vsi_disable_irq(vsi); |
| 5338 | i40e_vsi_control_rings(vsi, false); |
| 5339 | i40e_napi_disable_all(vsi); |
| 5340 | |
| 5341 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5342 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 5343 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5344 | } |
Catherine Sullivan | f980d44 | 2016-05-16 10:26:34 -0700 | [diff] [blame] | 5345 | |
| 5346 | i40e_notify_client_of_netdev_close(vsi, false); |
| 5347 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | /** |
| 5351 | * i40e_setup_tc - configure multiple traffic classes |
| 5352 | * @netdev: net device to configure |
| 5353 | * @tc: number of traffic classes to enable |
| 5354 | **/ |
| 5355 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5356 | { |
| 5357 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5358 | struct i40e_vsi *vsi = np->vsi; |
| 5359 | struct i40e_pf *pf = vsi->back; |
| 5360 | u8 enabled_tc = 0; |
| 5361 | int ret = -EINVAL; |
| 5362 | int i; |
| 5363 | |
| 5364 | /* Check if DCB enabled to continue */ |
| 5365 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5366 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5367 | goto exit; |
| 5368 | } |
| 5369 | |
| 5370 | /* Check if MFP enabled */ |
| 5371 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5372 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5373 | goto exit; |
| 5374 | } |
| 5375 | |
| 5376 | /* Check whether tc count is within enabled limit */ |
| 5377 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5378 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5379 | goto exit; |
| 5380 | } |
| 5381 | |
| 5382 | /* Generate TC map for number of tc requested */ |
| 5383 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5384 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5385 | |
| 5386 | /* Requesting same TC configuration as already enabled */ |
| 5387 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5388 | return 0; |
| 5389 | |
| 5390 | /* Quiesce VSI queues */ |
| 5391 | i40e_quiesce_vsi(vsi); |
| 5392 | |
| 5393 | /* Configure VSI for enabled TCs */ |
| 5394 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5395 | if (ret) { |
| 5396 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5397 | vsi->seid); |
| 5398 | goto exit; |
| 5399 | } |
| 5400 | |
| 5401 | /* Unquiesce VSI */ |
| 5402 | i40e_unquiesce_vsi(vsi); |
| 5403 | |
| 5404 | exit: |
| 5405 | return ret; |
| 5406 | } |
| 5407 | |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5408 | #ifdef I40E_FCOE |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5409 | int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5410 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5411 | #else |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5412 | static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5413 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5414 | #endif |
| 5415 | { |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5416 | if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5417 | return -EINVAL; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5418 | return i40e_setup_tc(netdev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5419 | } |
| 5420 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5421 | /** |
| 5422 | * i40e_open - Called when a network interface is made active |
| 5423 | * @netdev: network interface device structure |
| 5424 | * |
| 5425 | * The open entry point is called when a network interface is made |
| 5426 | * active by the system (IFF_UP). At this point all resources needed |
| 5427 | * for transmit and receive operations are allocated, the interrupt |
| 5428 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5429 | * enabled, and the stack is notified that the interface is ready. |
| 5430 | * |
| 5431 | * Returns 0 on success, negative value on failure |
| 5432 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5433 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5434 | { |
| 5435 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5436 | struct i40e_vsi *vsi = np->vsi; |
| 5437 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5438 | int err; |
| 5439 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5440 | /* disallow open during test or if eeprom is broken */ |
| 5441 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 5442 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5443 | return -EBUSY; |
| 5444 | |
| 5445 | netif_carrier_off(netdev); |
| 5446 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5447 | err = i40e_vsi_open(vsi); |
| 5448 | if (err) |
| 5449 | return err; |
| 5450 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5451 | /* configure global TSO hardware offload settings */ |
| 5452 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5453 | TCP_FLAG_FIN) >> 16); |
| 5454 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5455 | TCP_FLAG_FIN | |
| 5456 | TCP_FLAG_CWR) >> 16); |
| 5457 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5458 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 5459 | udp_tunnel_get_rx_info(netdev); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5460 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5461 | return 0; |
| 5462 | } |
| 5463 | |
| 5464 | /** |
| 5465 | * i40e_vsi_open - |
| 5466 | * @vsi: the VSI to open |
| 5467 | * |
| 5468 | * Finish initialization of the VSI. |
| 5469 | * |
| 5470 | * Returns 0 on success, negative value on failure |
| 5471 | **/ |
| 5472 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5473 | { |
| 5474 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5475 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5476 | int err; |
| 5477 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5478 | /* allocate descriptors */ |
| 5479 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5480 | if (err) |
| 5481 | goto err_setup_tx; |
| 5482 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5483 | if (err) |
| 5484 | goto err_setup_rx; |
| 5485 | |
| 5486 | err = i40e_vsi_configure(vsi); |
| 5487 | if (err) |
| 5488 | goto err_setup_rx; |
| 5489 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5490 | if (vsi->netdev) { |
| 5491 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5492 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5493 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5494 | if (err) |
| 5495 | goto err_setup_rx; |
| 5496 | |
| 5497 | /* Notify the stack of the actual queue counts. */ |
| 5498 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5499 | vsi->num_queue_pairs); |
| 5500 | if (err) |
| 5501 | goto err_set_queues; |
| 5502 | |
| 5503 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5504 | vsi->num_queue_pairs); |
| 5505 | if (err) |
| 5506 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5507 | |
| 5508 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5509 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5510 | dev_driver_string(&pf->pdev->dev), |
| 5511 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5512 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5513 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5514 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5515 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5516 | goto err_setup_rx; |
| 5517 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5518 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5519 | err = i40e_up_complete(vsi); |
| 5520 | if (err) |
| 5521 | goto err_up_complete; |
| 5522 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5523 | return 0; |
| 5524 | |
| 5525 | err_up_complete: |
| 5526 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5527 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5528 | i40e_vsi_free_irq(vsi); |
| 5529 | err_setup_rx: |
| 5530 | i40e_vsi_free_rx_resources(vsi); |
| 5531 | err_setup_tx: |
| 5532 | i40e_vsi_free_tx_resources(vsi); |
| 5533 | if (vsi == pf->vsi[pf->lan_vsi]) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5534 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5535 | |
| 5536 | return err; |
| 5537 | } |
| 5538 | |
| 5539 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5540 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5541 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5542 | * |
| 5543 | * This function destroys the hlist where all the Flow Director |
| 5544 | * filters were saved. |
| 5545 | **/ |
| 5546 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5547 | { |
| 5548 | struct i40e_fdir_filter *filter; |
| 5549 | struct hlist_node *node2; |
| 5550 | |
| 5551 | hlist_for_each_entry_safe(filter, node2, |
| 5552 | &pf->fdir_filter_list, fdir_node) { |
| 5553 | hlist_del(&filter->fdir_node); |
| 5554 | kfree(filter); |
| 5555 | } |
| 5556 | pf->fdir_pf_active_filters = 0; |
| 5557 | } |
| 5558 | |
| 5559 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5560 | * i40e_close - Disables a network interface |
| 5561 | * @netdev: network interface device structure |
| 5562 | * |
| 5563 | * The close entry point is called when an interface is de-activated |
| 5564 | * by the OS. The hardware is still under the driver's control, but |
| 5565 | * this netdev interface is disabled. |
| 5566 | * |
| 5567 | * Returns 0, this is not allowed to fail |
| 5568 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5569 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5570 | { |
| 5571 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5572 | struct i40e_vsi *vsi = np->vsi; |
| 5573 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5574 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5575 | |
| 5576 | return 0; |
| 5577 | } |
| 5578 | |
| 5579 | /** |
| 5580 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5581 | * @pf: board private structure |
| 5582 | * @reset_flags: which reset is requested |
| 5583 | * |
| 5584 | * The essential difference in resets is that the PF Reset |
| 5585 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5586 | * firmware, and doesn't bother the other PFs on the chip. |
| 5587 | **/ |
| 5588 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5589 | { |
| 5590 | u32 val; |
| 5591 | |
| 5592 | WARN_ON(in_interrupt()); |
| 5593 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5594 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5595 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5596 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5597 | |
| 5598 | /* Request a Global Reset |
| 5599 | * |
| 5600 | * This will start the chip's countdown to the actual full |
| 5601 | * chip reset event, and a warning interrupt to be sent |
| 5602 | * to all PFs, including the requestor. Our handler |
| 5603 | * for the warning interrupt will deal with the shutdown |
| 5604 | * and recovery of the switch setup. |
| 5605 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5606 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5607 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5608 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5609 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5610 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5611 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5612 | |
| 5613 | /* Request a Core Reset |
| 5614 | * |
| 5615 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5616 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5617 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5618 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5619 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5620 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5621 | i40e_flush(&pf->hw); |
| 5622 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5623 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5624 | |
| 5625 | /* Request a PF Reset |
| 5626 | * |
| 5627 | * Resets only the PF-specific registers |
| 5628 | * |
| 5629 | * This goes directly to the tear-down and rebuild of |
| 5630 | * the switch, since we need to do all the recovery as |
| 5631 | * for the Core Reset. |
| 5632 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5633 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5634 | i40e_handle_reset_warning(pf); |
| 5635 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5636 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5637 | int v; |
| 5638 | |
| 5639 | /* Find the VSI(s) that requested a re-init */ |
| 5640 | dev_info(&pf->pdev->dev, |
| 5641 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5642 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5643 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5644 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5645 | if (vsi != NULL && |
| 5646 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5647 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5648 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5649 | } |
| 5650 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5651 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5652 | int v; |
| 5653 | |
| 5654 | /* Find the VSI(s) that needs to be brought down */ |
| 5655 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5656 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5657 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5658 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5659 | if (vsi != NULL && |
| 5660 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5661 | set_bit(__I40E_DOWN, &vsi->state); |
| 5662 | i40e_down(vsi); |
| 5663 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5664 | } |
| 5665 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5666 | } else { |
| 5667 | dev_info(&pf->pdev->dev, |
| 5668 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5669 | } |
| 5670 | } |
| 5671 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5672 | #ifdef CONFIG_I40E_DCB |
| 5673 | /** |
| 5674 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5675 | * @pf: board private structure |
| 5676 | * @old_cfg: current DCB config |
| 5677 | * @new_cfg: new DCB config |
| 5678 | **/ |
| 5679 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5680 | struct i40e_dcbx_config *old_cfg, |
| 5681 | struct i40e_dcbx_config *new_cfg) |
| 5682 | { |
| 5683 | bool need_reconfig = false; |
| 5684 | |
| 5685 | /* Check if ETS configuration has changed */ |
| 5686 | if (memcmp(&new_cfg->etscfg, |
| 5687 | &old_cfg->etscfg, |
| 5688 | sizeof(new_cfg->etscfg))) { |
| 5689 | /* If Priority Table has changed reconfig is needed */ |
| 5690 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5691 | &old_cfg->etscfg.prioritytable, |
| 5692 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5693 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5694 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5695 | } |
| 5696 | |
| 5697 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5698 | &old_cfg->etscfg.tcbwtable, |
| 5699 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5700 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5701 | |
| 5702 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5703 | &old_cfg->etscfg.tsatable, |
| 5704 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5705 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5706 | } |
| 5707 | |
| 5708 | /* Check if PFC configuration has changed */ |
| 5709 | if (memcmp(&new_cfg->pfc, |
| 5710 | &old_cfg->pfc, |
| 5711 | sizeof(new_cfg->pfc))) { |
| 5712 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5713 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5714 | } |
| 5715 | |
| 5716 | /* Check if APP Table has changed */ |
| 5717 | if (memcmp(&new_cfg->app, |
| 5718 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5719 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5720 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5721 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5722 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5723 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5724 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5725 | return need_reconfig; |
| 5726 | } |
| 5727 | |
| 5728 | /** |
| 5729 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5730 | * @pf: board private structure |
| 5731 | * @e: event info posted on ARQ |
| 5732 | **/ |
| 5733 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5734 | struct i40e_arq_event_info *e) |
| 5735 | { |
| 5736 | struct i40e_aqc_lldp_get_mib *mib = |
| 5737 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5738 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5739 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5740 | bool need_reconfig = false; |
| 5741 | int ret = 0; |
| 5742 | u8 type; |
| 5743 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5744 | /* Not DCB capable or capability disabled */ |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5745 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5746 | return ret; |
| 5747 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5748 | /* Ignore if event is not for Nearest Bridge */ |
| 5749 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5750 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5751 | 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] | 5752 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5753 | return ret; |
| 5754 | |
| 5755 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5756 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5757 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5758 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5759 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5760 | /* Update the remote cached instance and return */ |
| 5761 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5762 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5763 | &hw->remote_dcbx_config); |
| 5764 | goto exit; |
| 5765 | } |
| 5766 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5767 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5768 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5769 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5770 | /* Reset the old DCBx configuration data */ |
| 5771 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5772 | /* Get updated DCBX data from firmware */ |
| 5773 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5774 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5775 | dev_info(&pf->pdev->dev, |
| 5776 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 5777 | i40e_stat_str(&pf->hw, ret), |
| 5778 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5779 | goto exit; |
| 5780 | } |
| 5781 | |
| 5782 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5783 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5784 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5785 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5786 | goto exit; |
| 5787 | } |
| 5788 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5789 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5790 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5791 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5792 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5793 | |
| 5794 | if (!need_reconfig) |
| 5795 | goto exit; |
| 5796 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5797 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5798 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5799 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5800 | else |
| 5801 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5802 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5803 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5804 | /* Reconfiguration needed quiesce all VSIs */ |
| 5805 | i40e_pf_quiesce_all_vsi(pf); |
| 5806 | |
| 5807 | /* Changes in configuration update VEB/VSI */ |
| 5808 | i40e_dcb_reconfigure(pf); |
| 5809 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5810 | ret = i40e_resume_port_tx(pf); |
| 5811 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5812 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5813 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5814 | if (ret) |
| 5815 | goto exit; |
| 5816 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 5817 | /* Wait for the PF's queues to be disabled */ |
| 5818 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5819 | if (ret) { |
| 5820 | /* Schedule PF reset to recover */ |
| 5821 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5822 | i40e_service_event_schedule(pf); |
| 5823 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5824 | i40e_pf_unquiesce_all_vsi(pf); |
Neerav Parikh | 85a1aab | 2016-06-07 09:14:55 -0700 | [diff] [blame] | 5825 | /* Notify the client for the DCB changes */ |
| 5826 | i40e_notify_client_of_l2_param_changes(pf->vsi[pf->lan_vsi]); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5827 | } |
| 5828 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5829 | exit: |
| 5830 | return ret; |
| 5831 | } |
| 5832 | #endif /* CONFIG_I40E_DCB */ |
| 5833 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5834 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5835 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 5836 | * @pf: board private structure |
| 5837 | * @reset_flags: which reset is requested |
| 5838 | * |
| 5839 | **/ |
| 5840 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 5841 | { |
| 5842 | rtnl_lock(); |
| 5843 | i40e_do_reset(pf, reset_flags); |
| 5844 | rtnl_unlock(); |
| 5845 | } |
| 5846 | |
| 5847 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5848 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 5849 | * @pf: board private structure |
| 5850 | * @e: event info posted on ARQ |
| 5851 | * |
| 5852 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 5853 | * and VF queues |
| 5854 | **/ |
| 5855 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 5856 | struct i40e_arq_event_info *e) |
| 5857 | { |
| 5858 | struct i40e_aqc_lan_overflow *data = |
| 5859 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 5860 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 5861 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 5862 | struct i40e_hw *hw = &pf->hw; |
| 5863 | struct i40e_vf *vf; |
| 5864 | u16 vf_id; |
| 5865 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5866 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 5867 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5868 | |
| 5869 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 5870 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 5871 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 5872 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 5873 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 5874 | vf_id -= hw->func_caps.vf_base_id; |
| 5875 | vf = &pf->vf[vf_id]; |
| 5876 | i40e_vc_notify_vf_reset(vf); |
| 5877 | /* Allow VF to process pending reset notification */ |
| 5878 | msleep(20); |
| 5879 | i40e_reset_vf(vf, false); |
| 5880 | } |
| 5881 | } |
| 5882 | |
| 5883 | /** |
| 5884 | * i40e_service_event_complete - Finish up the service event |
| 5885 | * @pf: board private structure |
| 5886 | **/ |
| 5887 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 5888 | { |
Shannon Nelson | b875f99 | 2015-10-21 19:47:03 -0400 | [diff] [blame] | 5889 | WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5890 | |
| 5891 | /* flush memory to make sure state is correct before next watchog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5892 | smp_mb__before_atomic(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5893 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 5894 | } |
| 5895 | |
| 5896 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5897 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 5898 | * @pf: board private structure |
| 5899 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5900 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5901 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5902 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5903 | |
| 5904 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5905 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 5906 | return fcnt_prog; |
| 5907 | } |
| 5908 | |
| 5909 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5910 | * 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] | 5911 | * @pf: board private structure |
| 5912 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5913 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5914 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5915 | u32 val, fcnt_prog; |
| 5916 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5917 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5918 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 5919 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 5920 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 5921 | return fcnt_prog; |
| 5922 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5923 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5924 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5925 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 5926 | * @pf: board private structure |
| 5927 | **/ |
| 5928 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 5929 | { |
| 5930 | u32 val, fcnt_prog; |
| 5931 | |
| 5932 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 5933 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 5934 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 5935 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 5936 | return fcnt_prog; |
| 5937 | } |
| 5938 | |
| 5939 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5940 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 5941 | * @pf: board private structure |
| 5942 | **/ |
| 5943 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 5944 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5945 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5946 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5947 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5948 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5949 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 5950 | return; |
| 5951 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5952 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 5953 | * to re-enable |
| 5954 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5955 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5956 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5957 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 5958 | (pf->fd_add_err == 0) || |
| 5959 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5960 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 5961 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 5962 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5963 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5964 | 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] | 5965 | } |
| 5966 | } |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 5967 | |
| 5968 | /* Wait for some more space to be available to turn on ATR. We also |
| 5969 | * must check that no existing ntuple rules for TCP are in effect |
| 5970 | */ |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5971 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 5972 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 5973 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 5974 | (pf->fd_tcp_rule == 0)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5975 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5976 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 5977 | 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] | 5978 | } |
| 5979 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5980 | |
| 5981 | /* if hw had a problem adding a filter, delete it */ |
| 5982 | if (pf->fd_inv > 0) { |
| 5983 | hlist_for_each_entry_safe(filter, node, |
| 5984 | &pf->fdir_filter_list, fdir_node) { |
| 5985 | if (filter->fd_id == pf->fd_inv) { |
| 5986 | hlist_del(&filter->fdir_node); |
| 5987 | kfree(filter); |
| 5988 | pf->fdir_pf_active_filters--; |
| 5989 | } |
| 5990 | } |
| 5991 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5992 | } |
| 5993 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5994 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5995 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5996 | /** |
| 5997 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 5998 | * @pf: board private structure |
| 5999 | **/ |
| 6000 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 6001 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6002 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6003 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6004 | bool disable_atr = false; |
| 6005 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6006 | int reg; |
| 6007 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6008 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 6009 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 6010 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6011 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6012 | /* If the flush is happening too quick and we have mostly SB rules we |
| 6013 | * should not re-enable ATR for some time. |
| 6014 | */ |
| 6015 | min_flush_time = pf->fd_flush_timestamp + |
| 6016 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 6017 | 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] | 6018 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6019 | if (!(time_after(jiffies, min_flush_time)) && |
| 6020 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 6021 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6022 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 6023 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6024 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6025 | |
| 6026 | pf->fd_flush_timestamp = jiffies; |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 6027 | pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6028 | /* flush all filters */ |
| 6029 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 6030 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 6031 | i40e_flush(&pf->hw); |
| 6032 | pf->fd_flush_cnt++; |
| 6033 | pf->fd_add_err = 0; |
| 6034 | do { |
| 6035 | /* Check FD flush status every 5-6msec */ |
| 6036 | usleep_range(5000, 6000); |
| 6037 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 6038 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 6039 | break; |
| 6040 | } while (flush_wait_retry--); |
| 6041 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 6042 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 6043 | } else { |
| 6044 | /* replay sideband filters */ |
| 6045 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
| 6046 | if (!disable_atr) |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 6047 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 6048 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
| 6049 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6050 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 6051 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6052 | } |
| 6053 | |
| 6054 | /** |
| 6055 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 6056 | * @pf: board private structure |
| 6057 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6058 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6059 | { |
| 6060 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 6061 | } |
| 6062 | |
| 6063 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 6064 | * being applied really fast; before we see the first |
| 6065 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 6066 | * reacting will make sure we don't cause flush too often. |
| 6067 | */ |
| 6068 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 6069 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6070 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6071 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 6072 | * @pf: board private structure |
| 6073 | **/ |
| 6074 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 6075 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6076 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6077 | /* if interface is down do nothing */ |
| 6078 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 6079 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6080 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6081 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6082 | i40e_fdir_flush_and_replay(pf); |
| 6083 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6084 | i40e_fdir_check_and_reenable(pf); |
| 6085 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6086 | } |
| 6087 | |
| 6088 | /** |
| 6089 | * i40e_vsi_link_event - notify VSI of a link event |
| 6090 | * @vsi: vsi to be notified |
| 6091 | * @link_up: link up or down |
| 6092 | **/ |
| 6093 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 6094 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 6095 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6096 | return; |
| 6097 | |
| 6098 | switch (vsi->type) { |
| 6099 | case I40E_VSI_MAIN: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6100 | #ifdef I40E_FCOE |
| 6101 | case I40E_VSI_FCOE: |
| 6102 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6103 | if (!vsi->netdev || !vsi->netdev_registered) |
| 6104 | break; |
| 6105 | |
| 6106 | if (link_up) { |
| 6107 | netif_carrier_on(vsi->netdev); |
| 6108 | netif_tx_wake_all_queues(vsi->netdev); |
| 6109 | } else { |
| 6110 | netif_carrier_off(vsi->netdev); |
| 6111 | netif_tx_stop_all_queues(vsi->netdev); |
| 6112 | } |
| 6113 | break; |
| 6114 | |
| 6115 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6116 | case I40E_VSI_VMDQ2: |
| 6117 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6118 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6119 | case I40E_VSI_MIRROR: |
| 6120 | default: |
| 6121 | /* there is no notification for other VSIs */ |
| 6122 | break; |
| 6123 | } |
| 6124 | } |
| 6125 | |
| 6126 | /** |
| 6127 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6128 | * @veb: veb to be notified |
| 6129 | * @link_up: link up or down |
| 6130 | **/ |
| 6131 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6132 | { |
| 6133 | struct i40e_pf *pf; |
| 6134 | int i; |
| 6135 | |
| 6136 | if (!veb || !veb->pf) |
| 6137 | return; |
| 6138 | pf = veb->pf; |
| 6139 | |
| 6140 | /* depth first... */ |
| 6141 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6142 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6143 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6144 | |
| 6145 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6146 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6147 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6148 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6149 | } |
| 6150 | |
| 6151 | /** |
| 6152 | * i40e_link_event - Update netif_carrier status |
| 6153 | * @pf: board private structure |
| 6154 | **/ |
| 6155 | static void i40e_link_event(struct i40e_pf *pf) |
| 6156 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6157 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6158 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6159 | i40e_status status; |
| 6160 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6161 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6162 | /* save off old link status information */ |
| 6163 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6164 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6165 | /* set this to force the get_link_status call to refresh state */ |
| 6166 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6167 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6168 | 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] | 6169 | |
| 6170 | status = i40e_get_link_status(&pf->hw, &new_link); |
| 6171 | if (status) { |
| 6172 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6173 | status); |
| 6174 | return; |
| 6175 | } |
| 6176 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6177 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6178 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6179 | |
| 6180 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6181 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6182 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 6183 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6184 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6185 | |
| 6186 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 6187 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6188 | |
| 6189 | /* Notify the base of the switch tree connected to |
| 6190 | * the link. Floating VEBs are not notified. |
| 6191 | */ |
| 6192 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6193 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6194 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6195 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6196 | |
| 6197 | if (pf->vf) |
| 6198 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6199 | |
| 6200 | if (pf->flags & I40E_FLAG_PTP) |
| 6201 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6202 | } |
| 6203 | |
| 6204 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6205 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6206 | * @pf: board private structure |
| 6207 | **/ |
| 6208 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6209 | { |
| 6210 | int i; |
| 6211 | |
| 6212 | /* if interface is down do nothing */ |
| 6213 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 6214 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6215 | return; |
| 6216 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6217 | /* make sure we don't do these things too often */ |
| 6218 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6219 | pf->service_timer_period))) |
| 6220 | return; |
| 6221 | pf->service_timer_previous = jiffies; |
| 6222 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6223 | if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) |
| 6224 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6225 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6226 | /* Update the stats for active netdevs so the network stack |
| 6227 | * can look at updated numbers whenever it cares to |
| 6228 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6229 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6230 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6231 | i40e_update_stats(pf->vsi[i]); |
| 6232 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6233 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6234 | /* Update the stats for the active switching components */ |
| 6235 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6236 | if (pf->veb[i]) |
| 6237 | i40e_update_veb_stats(pf->veb[i]); |
| 6238 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6239 | |
| 6240 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6241 | } |
| 6242 | |
| 6243 | /** |
| 6244 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6245 | * @pf: board private structure |
| 6246 | **/ |
| 6247 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6248 | { |
| 6249 | u32 reset_flags = 0; |
| 6250 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6251 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6252 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6253 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6254 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 6255 | } |
| 6256 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6257 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6258 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6259 | } |
| 6260 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6261 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6262 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 6263 | } |
| 6264 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6265 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6266 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 6267 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6268 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6269 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6270 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 6271 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6272 | |
| 6273 | /* If there's a recovery already waiting, it takes |
| 6274 | * precedence before starting a new reset sequence. |
| 6275 | */ |
| 6276 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 6277 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6278 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6279 | } |
| 6280 | |
| 6281 | /* If we're already down or resetting, just bail */ |
| 6282 | if (reset_flags && |
| 6283 | !test_bit(__I40E_DOWN, &pf->state) && |
| 6284 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6285 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6286 | |
| 6287 | unlock: |
| 6288 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6289 | } |
| 6290 | |
| 6291 | /** |
| 6292 | * i40e_handle_link_event - Handle link event |
| 6293 | * @pf: board private structure |
| 6294 | * @e: event info posted on ARQ |
| 6295 | **/ |
| 6296 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6297 | struct i40e_arq_event_info *e) |
| 6298 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6299 | struct i40e_aqc_get_link_status *status = |
| 6300 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6301 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6302 | /* Do a new status request to re-enable LSE reporting |
| 6303 | * and load new status information into the hw struct |
| 6304 | * This completely ignores any state information |
| 6305 | * in the ARQ event info, instead choosing to always |
| 6306 | * issue the AQ update link status command. |
| 6307 | */ |
| 6308 | i40e_link_event(pf); |
| 6309 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6310 | /* check for unqualified module, if link is down */ |
| 6311 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6312 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6313 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6314 | dev_err(&pf->pdev->dev, |
| 6315 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | /** |
| 6319 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6320 | * @pf: board private structure |
| 6321 | **/ |
| 6322 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6323 | { |
| 6324 | struct i40e_arq_event_info event; |
| 6325 | struct i40e_hw *hw = &pf->hw; |
| 6326 | u16 pending, i = 0; |
| 6327 | i40e_status ret; |
| 6328 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6329 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6330 | u32 val; |
| 6331 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6332 | /* Do not run clean AQ when PF reset fails */ |
| 6333 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 6334 | return; |
| 6335 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6336 | /* check for error indications */ |
| 6337 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6338 | oldval = val; |
| 6339 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6340 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6341 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6342 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6343 | } |
| 6344 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6345 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6346 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6347 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6348 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6349 | } |
| 6350 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6351 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6352 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6353 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6354 | } |
| 6355 | if (oldval != val) |
| 6356 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6357 | |
| 6358 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6359 | oldval = val; |
| 6360 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6361 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6362 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6363 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6364 | } |
| 6365 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6366 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6367 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6368 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6369 | } |
| 6370 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6371 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6372 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6373 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6374 | } |
| 6375 | if (oldval != val) |
| 6376 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6377 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6378 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6379 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6380 | if (!event.msg_buf) |
| 6381 | return; |
| 6382 | |
| 6383 | do { |
| 6384 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6385 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6386 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6387 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6388 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6389 | break; |
| 6390 | } |
| 6391 | |
| 6392 | opcode = le16_to_cpu(event.desc.opcode); |
| 6393 | switch (opcode) { |
| 6394 | |
| 6395 | case i40e_aqc_opc_get_link_status: |
| 6396 | i40e_handle_link_event(pf, &event); |
| 6397 | break; |
| 6398 | case i40e_aqc_opc_send_msg_to_pf: |
| 6399 | ret = i40e_vc_process_vf_msg(pf, |
| 6400 | le16_to_cpu(event.desc.retval), |
| 6401 | le32_to_cpu(event.desc.cookie_high), |
| 6402 | le32_to_cpu(event.desc.cookie_low), |
| 6403 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6404 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6405 | break; |
| 6406 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6407 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6408 | #ifdef CONFIG_I40E_DCB |
| 6409 | rtnl_lock(); |
| 6410 | ret = i40e_handle_lldp_event(pf, &event); |
| 6411 | rtnl_unlock(); |
| 6412 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6413 | break; |
| 6414 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6415 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6416 | i40e_handle_lan_overflow_event(pf, &event); |
| 6417 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6418 | case i40e_aqc_opc_send_msg_to_peer: |
| 6419 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6420 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6421 | case i40e_aqc_opc_nvm_erase: |
| 6422 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6423 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 6424 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 6425 | "ARQ NVM operation 0x%04x completed\n", |
| 6426 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6427 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6428 | default: |
| 6429 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 6430 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6431 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6432 | break; |
| 6433 | } |
| 6434 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 6435 | |
| 6436 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 6437 | /* re-enable Admin queue interrupt cause */ |
| 6438 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6439 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6440 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6441 | i40e_flush(hw); |
| 6442 | |
| 6443 | kfree(event.msg_buf); |
| 6444 | } |
| 6445 | |
| 6446 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6447 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6448 | * @pf: board private structure |
| 6449 | **/ |
| 6450 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6451 | { |
| 6452 | int err; |
| 6453 | |
| 6454 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6455 | if (err) { |
| 6456 | /* retry in case of garbage read */ |
| 6457 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6458 | if (err) { |
| 6459 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6460 | err); |
| 6461 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6462 | } |
| 6463 | } |
| 6464 | |
| 6465 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 6466 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 6467 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6468 | } |
| 6469 | } |
| 6470 | |
| 6471 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6472 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6473 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6474 | * |
| 6475 | * enable switch loop back or die - no point in a return value |
| 6476 | **/ |
| 6477 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6478 | { |
| 6479 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6480 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6481 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6482 | |
| 6483 | ctxt.seid = pf->main_vsi_seid; |
| 6484 | ctxt.pf_num = pf->hw.pf_id; |
| 6485 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6486 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6487 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6488 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6489 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6490 | i40e_stat_str(&pf->hw, ret), |
| 6491 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6492 | return; |
| 6493 | } |
| 6494 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6495 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6496 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6497 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6498 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6499 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6500 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6501 | "update vsi switch failed, err %s aq_err %s\n", |
| 6502 | i40e_stat_str(&pf->hw, ret), |
| 6503 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6504 | } |
| 6505 | } |
| 6506 | |
| 6507 | /** |
| 6508 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6509 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6510 | * |
| 6511 | * disable switch loop back or die - no point in a return value |
| 6512 | **/ |
| 6513 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6514 | { |
| 6515 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6516 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6517 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6518 | |
| 6519 | ctxt.seid = pf->main_vsi_seid; |
| 6520 | ctxt.pf_num = pf->hw.pf_id; |
| 6521 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6522 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6523 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6524 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6525 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6526 | i40e_stat_str(&pf->hw, ret), |
| 6527 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6528 | return; |
| 6529 | } |
| 6530 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6531 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6532 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6533 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6534 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6535 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6536 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6537 | "update vsi switch failed, err %s aq_err %s\n", |
| 6538 | i40e_stat_str(&pf->hw, ret), |
| 6539 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6540 | } |
| 6541 | } |
| 6542 | |
| 6543 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6544 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6545 | * @veb: pointer to the bridge instance |
| 6546 | * |
| 6547 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6548 | * specified HW bridge instance. It is expected this function is called |
| 6549 | * when a new HW bridge is instantiated. |
| 6550 | **/ |
| 6551 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6552 | { |
| 6553 | struct i40e_pf *pf = veb->pf; |
| 6554 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6555 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6556 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6557 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6558 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6559 | i40e_disable_pf_switch_lb(pf); |
| 6560 | else |
| 6561 | i40e_enable_pf_switch_lb(pf); |
| 6562 | } |
| 6563 | |
| 6564 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6565 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6566 | * @veb: pointer to the VEB instance |
| 6567 | * |
| 6568 | * This is a recursive function that first builds the attached VSIs then |
| 6569 | * recurses in to build the next layer of VEB. We track the connections |
| 6570 | * through our own index numbers because the seid's from the HW could |
| 6571 | * change across the reset. |
| 6572 | **/ |
| 6573 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6574 | { |
| 6575 | struct i40e_vsi *ctl_vsi = NULL; |
| 6576 | struct i40e_pf *pf = veb->pf; |
| 6577 | int v, veb_idx; |
| 6578 | int ret; |
| 6579 | |
| 6580 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6581 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6582 | if (pf->vsi[v] && |
| 6583 | pf->vsi[v]->veb_idx == veb->idx && |
| 6584 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6585 | ctl_vsi = pf->vsi[v]; |
| 6586 | break; |
| 6587 | } |
| 6588 | } |
| 6589 | if (!ctl_vsi) { |
| 6590 | dev_info(&pf->pdev->dev, |
| 6591 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6592 | ret = -ENOENT; |
| 6593 | goto end_reconstitute; |
| 6594 | } |
| 6595 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6596 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6597 | ret = i40e_add_vsi(ctl_vsi); |
| 6598 | if (ret) { |
| 6599 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6600 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6601 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6602 | goto end_reconstitute; |
| 6603 | } |
| 6604 | i40e_vsi_reset_stats(ctl_vsi); |
| 6605 | |
| 6606 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6607 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6608 | if (ret) |
| 6609 | goto end_reconstitute; |
| 6610 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6611 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6612 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6613 | else |
| 6614 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6615 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6616 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6617 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6618 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6619 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6620 | continue; |
| 6621 | |
| 6622 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6623 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6624 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6625 | vsi->uplink_seid = veb->seid; |
| 6626 | ret = i40e_add_vsi(vsi); |
| 6627 | if (ret) { |
| 6628 | dev_info(&pf->pdev->dev, |
| 6629 | "rebuild of vsi_idx %d failed: %d\n", |
| 6630 | v, ret); |
| 6631 | goto end_reconstitute; |
| 6632 | } |
| 6633 | i40e_vsi_reset_stats(vsi); |
| 6634 | } |
| 6635 | } |
| 6636 | |
| 6637 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6638 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6639 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6640 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6641 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6642 | if (ret) |
| 6643 | break; |
| 6644 | } |
| 6645 | } |
| 6646 | |
| 6647 | end_reconstitute: |
| 6648 | return ret; |
| 6649 | } |
| 6650 | |
| 6651 | /** |
| 6652 | * i40e_get_capabilities - get info about the HW |
| 6653 | * @pf: the PF struct |
| 6654 | **/ |
| 6655 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6656 | { |
| 6657 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6658 | u16 data_size; |
| 6659 | int buf_len; |
| 6660 | int err; |
| 6661 | |
| 6662 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6663 | do { |
| 6664 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6665 | if (!cap_buf) |
| 6666 | return -ENOMEM; |
| 6667 | |
| 6668 | /* this loads the data into the hw struct for us */ |
| 6669 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6670 | &data_size, |
| 6671 | i40e_aqc_opc_list_func_capabilities, |
| 6672 | NULL); |
| 6673 | /* data loaded, buffer no longer needed */ |
| 6674 | kfree(cap_buf); |
| 6675 | |
| 6676 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6677 | /* retry with a larger buffer */ |
| 6678 | buf_len = data_size; |
| 6679 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6680 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6681 | "capability discovery failed, err %s aq_err %s\n", |
| 6682 | i40e_stat_str(&pf->hw, err), |
| 6683 | i40e_aq_str(&pf->hw, |
| 6684 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6685 | return -ENODEV; |
| 6686 | } |
| 6687 | } while (err); |
| 6688 | |
| 6689 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6690 | dev_info(&pf->pdev->dev, |
| 6691 | "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", |
| 6692 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6693 | pf->hw.func_caps.num_msix_vectors, |
| 6694 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6695 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6696 | pf->hw.func_caps.fd_filters_best_effort, |
| 6697 | pf->hw.func_caps.num_tx_qp, |
| 6698 | pf->hw.func_caps.num_vsis); |
| 6699 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6700 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6701 | + pf->hw.func_caps.num_vfs) |
| 6702 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6703 | dev_info(&pf->pdev->dev, |
| 6704 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6705 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6706 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6707 | } |
| 6708 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6709 | return 0; |
| 6710 | } |
| 6711 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6712 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6713 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6714 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6715 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6716 | * @pf: board private structure |
| 6717 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6718 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6719 | { |
| 6720 | struct i40e_vsi *vsi; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6721 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6722 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6723 | /* quick workaround for an NVM issue that leaves a critical register |
| 6724 | * uninitialized |
| 6725 | */ |
| 6726 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6727 | static const u32 hkey[] = { |
| 6728 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6729 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6730 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6731 | 0x95b3a76d}; |
| 6732 | |
| 6733 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6734 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6735 | } |
| 6736 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6737 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6738 | return; |
| 6739 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6740 | /* find existing VSI and see if it needs configuring */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6741 | vsi = NULL; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6742 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6743 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6744 | vsi = pf->vsi[i]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6745 | break; |
| 6746 | } |
| 6747 | } |
| 6748 | |
| 6749 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6750 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6751 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6752 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6753 | if (!vsi) { |
| 6754 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6755 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6756 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6757 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6758 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6759 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6760 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6761 | } |
| 6762 | |
| 6763 | /** |
| 6764 | * i40e_fdir_teardown - release the Flow Director resources |
| 6765 | * @pf: board private structure |
| 6766 | **/ |
| 6767 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6768 | { |
| 6769 | int i; |
| 6770 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6771 | i40e_fdir_filter_exit(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6772 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6773 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 6774 | i40e_vsi_release(pf->vsi[i]); |
| 6775 | break; |
| 6776 | } |
| 6777 | } |
| 6778 | } |
| 6779 | |
| 6780 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6781 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6782 | * @pf: board private structure |
| 6783 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6784 | * 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] | 6785 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6786 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6787 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6788 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6789 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6790 | u32 v; |
| 6791 | |
| 6792 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6793 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6794 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 6795 | if (i40e_check_asq_alive(&pf->hw)) |
| 6796 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6797 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6798 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6799 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6800 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6801 | i40e_pf_quiesce_all_vsi(pf); |
| 6802 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6803 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6804 | if (pf->vsi[v]) |
| 6805 | pf->vsi[v]->seid = 0; |
| 6806 | } |
| 6807 | |
| 6808 | i40e_shutdown_adminq(&pf->hw); |
| 6809 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6810 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6811 | if (hw->hmc.hmc_obj) { |
| 6812 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6813 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6814 | dev_warn(&pf->pdev->dev, |
| 6815 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6816 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6817 | } |
| 6818 | |
| 6819 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6820 | * i40e_send_version - update firmware with driver version |
| 6821 | * @pf: PF struct |
| 6822 | */ |
| 6823 | static void i40e_send_version(struct i40e_pf *pf) |
| 6824 | { |
| 6825 | struct i40e_driver_version dv; |
| 6826 | |
| 6827 | dv.major_version = DRV_VERSION_MAJOR; |
| 6828 | dv.minor_version = DRV_VERSION_MINOR; |
| 6829 | dv.build_version = DRV_VERSION_BUILD; |
| 6830 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 6831 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6832 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 6833 | } |
| 6834 | |
| 6835 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 6836 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6837 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6838 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6839 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6840 | 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] | 6841 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6842 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6843 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6844 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6845 | u32 val; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6846 | u32 v; |
| 6847 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6848 | /* Now we wait for GRST to settle out. |
| 6849 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 6850 | * because the reset will make them disappear. |
| 6851 | */ |
| 6852 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6853 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6854 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6855 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 6856 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6857 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6858 | pf->pfr_count++; |
| 6859 | |
| 6860 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6861 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6862 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6863 | |
| 6864 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 6865 | ret = i40e_init_adminq(&pf->hw); |
| 6866 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6867 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 6868 | i40e_stat_str(&pf->hw, ret), |
| 6869 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6870 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6871 | } |
| 6872 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6873 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 6874 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6875 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6876 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 6877 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6878 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6879 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6880 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6881 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6882 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 6883 | hw->func_caps.num_rx_qp, |
| 6884 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 6885 | if (ret) { |
| 6886 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 6887 | goto end_core_reset; |
| 6888 | } |
| 6889 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 6890 | if (ret) { |
| 6891 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 6892 | goto end_core_reset; |
| 6893 | } |
| 6894 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6895 | #ifdef CONFIG_I40E_DCB |
| 6896 | ret = i40e_init_pf_dcb(pf); |
| 6897 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6898 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 6899 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 6900 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6901 | } |
| 6902 | #endif /* CONFIG_I40E_DCB */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6903 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 6904 | i40e_init_pf_fcoe(pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6905 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6906 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6907 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6908 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6909 | if (ret) |
| 6910 | goto end_core_reset; |
| 6911 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6912 | /* The driver only wants link up/down and module qualification |
| 6913 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6914 | */ |
| 6915 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6916 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 6917 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6918 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6919 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6920 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 6921 | i40e_stat_str(&pf->hw, ret), |
| 6922 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6923 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6924 | /* make sure our flow control settings are restored */ |
| 6925 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 6926 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 6927 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 6928 | i40e_stat_str(&pf->hw, ret), |
| 6929 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6930 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6931 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 6932 | * They are still in our local switch element arrays, so only |
| 6933 | * need to rebuild the switch model in the HW. |
| 6934 | * |
| 6935 | * If there were VEBs but the reconstitution failed, we'll try |
| 6936 | * try to recover minimal use by getting the basic PF VSI working. |
| 6937 | */ |
| 6938 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6939 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6940 | /* find the one VEB connected to the MAC, and find orphans */ |
| 6941 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6942 | if (!pf->veb[v]) |
| 6943 | continue; |
| 6944 | |
| 6945 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 6946 | pf->veb[v]->uplink_seid == 0) { |
| 6947 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 6948 | |
| 6949 | if (!ret) |
| 6950 | continue; |
| 6951 | |
| 6952 | /* If Main VEB failed, we're in deep doodoo, |
| 6953 | * so give up rebuilding the switch and set up |
| 6954 | * for minimal rebuild of PF VSI. |
| 6955 | * If orphan failed, we'll report the error |
| 6956 | * but try to keep going. |
| 6957 | */ |
| 6958 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 6959 | dev_info(&pf->pdev->dev, |
| 6960 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 6961 | ret); |
| 6962 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 6963 | = pf->mac_seid; |
| 6964 | break; |
| 6965 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 6966 | dev_info(&pf->pdev->dev, |
| 6967 | "rebuild of orphan VEB failed: %d\n", |
| 6968 | ret); |
| 6969 | } |
| 6970 | } |
| 6971 | } |
| 6972 | } |
| 6973 | |
| 6974 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 6975 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6976 | /* no VEB, so rebuild only the Main VSI */ |
| 6977 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 6978 | if (ret) { |
| 6979 | dev_info(&pf->pdev->dev, |
| 6980 | "rebuild of Main VSI failed: %d\n", ret); |
| 6981 | goto end_core_reset; |
| 6982 | } |
| 6983 | } |
| 6984 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6985 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 6986 | * of TSO, so that we avoid the MDD being fired and causing |
| 6987 | * a reset in the case of small MSS+TSO. |
| 6988 | */ |
| 6989 | #define I40E_REG_MSS 0x000E64DC |
| 6990 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 6991 | #define I40E_64BYTE_MSS 0x400000 |
| 6992 | val = rd32(hw, I40E_REG_MSS); |
| 6993 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 6994 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 6995 | val |= I40E_64BYTE_MSS; |
| 6996 | wr32(hw, I40E_REG_MSS, val); |
| 6997 | } |
| 6998 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 6999 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 7000 | msleep(75); |
| 7001 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 7002 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7003 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 7004 | i40e_stat_str(&pf->hw, ret), |
| 7005 | i40e_aq_str(&pf->hw, |
| 7006 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 7007 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7008 | /* reinit the misc interrupt */ |
| 7009 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7010 | ret = i40e_setup_misc_vector(pf); |
| 7011 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 7012 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 7013 | * transmitted. By doing so we stop a malicious VF from sending out |
| 7014 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 7015 | * PF/VF VSIs. |
| 7016 | * The FW can still send Flow control frames if enabled. |
| 7017 | */ |
| 7018 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 7019 | pf->main_vsi_seid); |
| 7020 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7021 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 7022 | i40e_pf_unquiesce_all_vsi(pf); |
| 7023 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 7024 | if (pf->num_alloc_vfs) { |
| 7025 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 7026 | i40e_reset_vf(&pf->vf[v], true); |
| 7027 | } |
| 7028 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7029 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 7030 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7031 | |
| 7032 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7033 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 7034 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7035 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 7036 | } |
| 7037 | |
| 7038 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7039 | * 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] | 7040 | * @pf: board private structure |
| 7041 | * |
| 7042 | * Close up the VFs and other things in prep for a Core Reset, |
| 7043 | * then get ready to rebuild the world. |
| 7044 | **/ |
| 7045 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 7046 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 7047 | i40e_prep_for_reset(pf); |
| 7048 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7049 | } |
| 7050 | |
| 7051 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7052 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7053 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7054 | * |
| 7055 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 7056 | **/ |
| 7057 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 7058 | { |
| 7059 | struct i40e_hw *hw = &pf->hw; |
| 7060 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7061 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7062 | struct i40e_vf *vf; |
| 7063 | u32 reg; |
| 7064 | int i; |
| 7065 | |
| 7066 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 7067 | return; |
| 7068 | |
| 7069 | /* find what triggered the MDD event */ |
| 7070 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 7071 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7072 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 7073 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7074 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7075 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7076 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7077 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7078 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 7079 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 7080 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7081 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7082 | 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] | 7083 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7084 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 7085 | mdd_detected = true; |
| 7086 | } |
| 7087 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 7088 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7089 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 7090 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7091 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7092 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7093 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 7094 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 7095 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7096 | if (netif_msg_rx_err(pf)) |
| 7097 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 7098 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7099 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 7100 | mdd_detected = true; |
| 7101 | } |
| 7102 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7103 | if (mdd_detected) { |
| 7104 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 7105 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 7106 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7107 | 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] | 7108 | pf_mdd_detected = true; |
| 7109 | } |
| 7110 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 7111 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 7112 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7113 | 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] | 7114 | pf_mdd_detected = true; |
| 7115 | } |
| 7116 | /* Queue belongs to the PF, initiate a reset */ |
| 7117 | if (pf_mdd_detected) { |
| 7118 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 7119 | i40e_service_event_schedule(pf); |
| 7120 | } |
| 7121 | } |
| 7122 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7123 | /* see if one of the VFs needs its hand slapped */ |
| 7124 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7125 | vf = &(pf->vf[i]); |
| 7126 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7127 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7128 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7129 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7130 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7131 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7132 | } |
| 7133 | |
| 7134 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7135 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7136 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7137 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7138 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7139 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7140 | } |
| 7141 | |
| 7142 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7143 | dev_info(&pf->pdev->dev, |
| 7144 | "Too many MDD events on VF %d, disabled\n", i); |
| 7145 | dev_info(&pf->pdev->dev, |
| 7146 | "Use PF Control I/F to re-enable the VF\n"); |
| 7147 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 7148 | } |
| 7149 | } |
| 7150 | |
| 7151 | /* re-enable mdd interrupt cause */ |
| 7152 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 7153 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7154 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7155 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7156 | i40e_flush(hw); |
| 7157 | } |
| 7158 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7159 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7160 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7161 | * @pf: board private structure |
| 7162 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7163 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7164 | { |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7165 | struct i40e_hw *hw = &pf->hw; |
| 7166 | i40e_status ret; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7167 | __be16 port; |
| 7168 | int i; |
| 7169 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7170 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7171 | return; |
| 7172 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7173 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7174 | |
| 7175 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7176 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7177 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
| 7178 | port = pf->udp_ports[i].index; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7179 | if (port) |
Carolyn Wyborny | b3f5c7b | 2016-08-24 11:33:51 -0700 | [diff] [blame] | 7180 | ret = i40e_aq_add_udp_tunnel(hw, port, |
| 7181 | pf->udp_ports[i].type, |
| 7182 | NULL, NULL); |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7183 | else |
| 7184 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7185 | |
| 7186 | if (ret) { |
Carolyn Wyborny | 730a8f8 | 2016-02-17 16:12:16 -0800 | [diff] [blame] | 7187 | dev_dbg(&pf->pdev->dev, |
| 7188 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 7189 | pf->udp_ports[i].type ? "vxlan" : "geneve", |
| 7190 | port ? "add" : "delete", |
| 7191 | ntohs(port), i, |
| 7192 | i40e_stat_str(&pf->hw, ret), |
| 7193 | i40e_aq_str(&pf->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7194 | pf->hw.aq.asq_last_status)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7195 | pf->udp_ports[i].index = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7196 | } |
| 7197 | } |
| 7198 | } |
| 7199 | } |
| 7200 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7201 | /** |
| 7202 | * i40e_service_task - Run the driver's async subtasks |
| 7203 | * @work: pointer to work_struct containing our data |
| 7204 | **/ |
| 7205 | static void i40e_service_task(struct work_struct *work) |
| 7206 | { |
| 7207 | struct i40e_pf *pf = container_of(work, |
| 7208 | struct i40e_pf, |
| 7209 | service_task); |
| 7210 | unsigned long start_time = jiffies; |
| 7211 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7212 | /* don't bother with service tasks if a reset is in progress */ |
| 7213 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7214 | i40e_service_event_complete(pf); |
| 7215 | return; |
| 7216 | } |
| 7217 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7218 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 7219 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7220 | i40e_reset_subtask(pf); |
| 7221 | i40e_handle_mdd_event(pf); |
| 7222 | i40e_vc_process_vflr_event(pf); |
| 7223 | i40e_watchdog_subtask(pf); |
| 7224 | i40e_fdir_reinit_subtask(pf); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7225 | i40e_client_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7226 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7227 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7228 | i40e_clean_adminq_subtask(pf); |
| 7229 | |
| 7230 | i40e_service_event_complete(pf); |
| 7231 | |
| 7232 | /* If the tasks have taken longer than one timer cycle or there |
| 7233 | * is more work to be done, reschedule the service task now |
| 7234 | * rather than wait for the timer to tick again. |
| 7235 | */ |
| 7236 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 7237 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 7238 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 7239 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 7240 | i40e_service_event_schedule(pf); |
| 7241 | } |
| 7242 | |
| 7243 | /** |
| 7244 | * i40e_service_timer - timer callback |
| 7245 | * @data: pointer to PF struct |
| 7246 | **/ |
| 7247 | static void i40e_service_timer(unsigned long data) |
| 7248 | { |
| 7249 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7250 | |
| 7251 | mod_timer(&pf->service_timer, |
| 7252 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7253 | i40e_service_event_schedule(pf); |
| 7254 | } |
| 7255 | |
| 7256 | /** |
| 7257 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7258 | * @vsi: the VSI being configured |
| 7259 | **/ |
| 7260 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7261 | { |
| 7262 | struct i40e_pf *pf = vsi->back; |
| 7263 | |
| 7264 | switch (vsi->type) { |
| 7265 | case I40E_VSI_MAIN: |
| 7266 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7267 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7268 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7269 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7270 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7271 | else |
| 7272 | vsi->num_q_vectors = 1; |
| 7273 | |
| 7274 | break; |
| 7275 | |
| 7276 | case I40E_VSI_FDIR: |
| 7277 | vsi->alloc_queue_pairs = 1; |
| 7278 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7279 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7280 | vsi->num_q_vectors = pf->num_fdsb_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7281 | break; |
| 7282 | |
| 7283 | case I40E_VSI_VMDQ2: |
| 7284 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7285 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7286 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7287 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7288 | break; |
| 7289 | |
| 7290 | case I40E_VSI_SRIOV: |
| 7291 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7292 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7293 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7294 | break; |
| 7295 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7296 | #ifdef I40E_FCOE |
| 7297 | case I40E_VSI_FCOE: |
| 7298 | vsi->alloc_queue_pairs = pf->num_fcoe_qps; |
| 7299 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7300 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7301 | vsi->num_q_vectors = pf->num_fcoe_msix; |
| 7302 | break; |
| 7303 | |
| 7304 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7305 | default: |
| 7306 | WARN_ON(1); |
| 7307 | return -ENODATA; |
| 7308 | } |
| 7309 | |
| 7310 | return 0; |
| 7311 | } |
| 7312 | |
| 7313 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7314 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7315 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7316 | * @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] | 7317 | * |
| 7318 | * On error: returns error code (negative) |
| 7319 | * On success: returns 0 |
| 7320 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7321 | 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] | 7322 | { |
| 7323 | int size; |
| 7324 | int ret = 0; |
| 7325 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7326 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7327 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 7328 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7329 | if (!vsi->tx_rings) |
| 7330 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7331 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 7332 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7333 | if (alloc_qvectors) { |
| 7334 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7335 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7336 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7337 | if (!vsi->q_vectors) { |
| 7338 | ret = -ENOMEM; |
| 7339 | goto err_vectors; |
| 7340 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7341 | } |
| 7342 | return ret; |
| 7343 | |
| 7344 | err_vectors: |
| 7345 | kfree(vsi->tx_rings); |
| 7346 | return ret; |
| 7347 | } |
| 7348 | |
| 7349 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7350 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7351 | * @pf: board private structure |
| 7352 | * @type: type of VSI |
| 7353 | * |
| 7354 | * On error: returns error code (negative) |
| 7355 | * On success: returns vsi index in PF (positive) |
| 7356 | **/ |
| 7357 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7358 | { |
| 7359 | int ret = -ENODEV; |
| 7360 | struct i40e_vsi *vsi; |
| 7361 | int vsi_idx; |
| 7362 | int i; |
| 7363 | |
| 7364 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7365 | mutex_lock(&pf->switch_mutex); |
| 7366 | |
| 7367 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7368 | * been happening. We can afford to do a quick scan to look |
| 7369 | * for any free VSIs in the list. |
| 7370 | * |
| 7371 | * find next empty vsi slot, looping back around if necessary |
| 7372 | */ |
| 7373 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7374 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7375 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7376 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7377 | i = 0; |
| 7378 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7379 | i++; |
| 7380 | } |
| 7381 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7382 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7383 | vsi_idx = i; /* Found one! */ |
| 7384 | } else { |
| 7385 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7386 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7387 | } |
| 7388 | pf->next_vsi = ++i; |
| 7389 | |
| 7390 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7391 | if (!vsi) { |
| 7392 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7393 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7394 | } |
| 7395 | vsi->type = type; |
| 7396 | vsi->back = pf; |
| 7397 | set_bit(__I40E_DOWN, &vsi->state); |
| 7398 | vsi->flags = 0; |
| 7399 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7400 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7401 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7402 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7403 | vsi->netdev_registered = false; |
| 7404 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 7405 | hash_init(vsi->mac_filter_hash); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7406 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7407 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7408 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7409 | if (ret) |
| 7410 | goto err_rings; |
| 7411 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7412 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7413 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7414 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7415 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7416 | /* Setup default MSIX irq handler for VSI */ |
| 7417 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7418 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7419 | /* Initialize VSI lock */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 7420 | spin_lock_init(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7421 | pf->vsi[vsi_idx] = vsi; |
| 7422 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7423 | goto unlock_pf; |
| 7424 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7425 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7426 | pf->next_vsi = i - 1; |
| 7427 | kfree(vsi); |
| 7428 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7429 | mutex_unlock(&pf->switch_mutex); |
| 7430 | return ret; |
| 7431 | } |
| 7432 | |
| 7433 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7434 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7435 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7436 | * @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] | 7437 | * |
| 7438 | * On error: returns error code (negative) |
| 7439 | * On success: returns 0 |
| 7440 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7441 | 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] | 7442 | { |
| 7443 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7444 | if (free_qvectors) { |
| 7445 | kfree(vsi->q_vectors); |
| 7446 | vsi->q_vectors = NULL; |
| 7447 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7448 | kfree(vsi->tx_rings); |
| 7449 | vsi->tx_rings = NULL; |
| 7450 | vsi->rx_rings = NULL; |
| 7451 | } |
| 7452 | |
| 7453 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7454 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7455 | * and lookup table |
| 7456 | * @vsi: Pointer to VSI structure |
| 7457 | */ |
| 7458 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7459 | { |
| 7460 | if (!vsi) |
| 7461 | return; |
| 7462 | |
| 7463 | kfree(vsi->rss_hkey_user); |
| 7464 | vsi->rss_hkey_user = NULL; |
| 7465 | |
| 7466 | kfree(vsi->rss_lut_user); |
| 7467 | vsi->rss_lut_user = NULL; |
| 7468 | } |
| 7469 | |
| 7470 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7471 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7472 | * @vsi: the VSI being un-configured |
| 7473 | **/ |
| 7474 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7475 | { |
| 7476 | struct i40e_pf *pf; |
| 7477 | |
| 7478 | if (!vsi) |
| 7479 | return 0; |
| 7480 | |
| 7481 | if (!vsi->back) |
| 7482 | goto free_vsi; |
| 7483 | pf = vsi->back; |
| 7484 | |
| 7485 | mutex_lock(&pf->switch_mutex); |
| 7486 | if (!pf->vsi[vsi->idx]) { |
| 7487 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7488 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7489 | goto unlock_vsi; |
| 7490 | } |
| 7491 | |
| 7492 | if (pf->vsi[vsi->idx] != vsi) { |
| 7493 | dev_err(&pf->pdev->dev, |
| 7494 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7495 | pf->vsi[vsi->idx]->idx, |
| 7496 | pf->vsi[vsi->idx], |
| 7497 | pf->vsi[vsi->idx]->type, |
| 7498 | vsi->idx, vsi, vsi->type); |
| 7499 | goto unlock_vsi; |
| 7500 | } |
| 7501 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7502 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7503 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7504 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7505 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7506 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7507 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7508 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7509 | pf->vsi[vsi->idx] = NULL; |
| 7510 | if (vsi->idx < pf->next_vsi) |
| 7511 | pf->next_vsi = vsi->idx; |
| 7512 | |
| 7513 | unlock_vsi: |
| 7514 | mutex_unlock(&pf->switch_mutex); |
| 7515 | free_vsi: |
| 7516 | kfree(vsi); |
| 7517 | |
| 7518 | return 0; |
| 7519 | } |
| 7520 | |
| 7521 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7522 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7523 | * @vsi: the VSI being cleaned |
| 7524 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7525 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7526 | { |
| 7527 | int i; |
| 7528 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7529 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7530 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7531 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7532 | vsi->tx_rings[i] = NULL; |
| 7533 | vsi->rx_rings[i] = NULL; |
| 7534 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7535 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7536 | } |
| 7537 | |
| 7538 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7539 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7540 | * @vsi: the VSI being configured |
| 7541 | **/ |
| 7542 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7543 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7544 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7545 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7546 | int i; |
| 7547 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7548 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7549 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7550 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7551 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7552 | if (!tx_ring) |
| 7553 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7554 | |
| 7555 | tx_ring->queue_index = i; |
| 7556 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7557 | tx_ring->ring_active = false; |
| 7558 | tx_ring->vsi = vsi; |
| 7559 | tx_ring->netdev = vsi->netdev; |
| 7560 | tx_ring->dev = &pf->pdev->dev; |
| 7561 | tx_ring->count = vsi->num_desc; |
| 7562 | tx_ring->size = 0; |
| 7563 | tx_ring->dcb_tc = 0; |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 7564 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 7565 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7566 | tx_ring->tx_itr_setting = pf->tx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7567 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7568 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7569 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7570 | rx_ring->queue_index = i; |
| 7571 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7572 | rx_ring->ring_active = false; |
| 7573 | rx_ring->vsi = vsi; |
| 7574 | rx_ring->netdev = vsi->netdev; |
| 7575 | rx_ring->dev = &pf->pdev->dev; |
| 7576 | rx_ring->count = vsi->num_desc; |
| 7577 | rx_ring->size = 0; |
| 7578 | rx_ring->dcb_tc = 0; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7579 | rx_ring->rx_itr_setting = pf->rx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7580 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7581 | } |
| 7582 | |
| 7583 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7584 | |
| 7585 | err_out: |
| 7586 | i40e_vsi_clear_rings(vsi); |
| 7587 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7588 | } |
| 7589 | |
| 7590 | /** |
| 7591 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7592 | * @pf: board private structure |
| 7593 | * @vectors: the number of MSI-X vectors to request |
| 7594 | * |
| 7595 | * Returns the number of vectors reserved, or error |
| 7596 | **/ |
| 7597 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7598 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7599 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7600 | I40E_MIN_MSIX, vectors); |
| 7601 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7602 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7603 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7604 | vectors = 0; |
| 7605 | } |
| 7606 | |
| 7607 | return vectors; |
| 7608 | } |
| 7609 | |
| 7610 | /** |
| 7611 | * i40e_init_msix - Setup the MSIX capability |
| 7612 | * @pf: board private structure |
| 7613 | * |
| 7614 | * Work with the OS to set up the MSIX vectors needed. |
| 7615 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7616 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7617 | **/ |
| 7618 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7619 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7620 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7621 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7622 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7623 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7624 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7625 | |
| 7626 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7627 | return -ENODEV; |
| 7628 | |
| 7629 | /* The number of vectors we'll request will be comprised of: |
| 7630 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7631 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7632 | * - Queues being used for RSS. |
| 7633 | * We don't need as many as max_rss_size vectors. |
| 7634 | * use rss_size instead in the calculation since that |
| 7635 | * is governed by number of cpus in the system. |
| 7636 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7637 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7638 | * - The CPU count within the NUMA node if iWARP is enabled |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7639 | #ifdef I40E_FCOE |
| 7640 | * - The number of FCOE qps. |
| 7641 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7642 | * Once we count this up, try the request. |
| 7643 | * |
| 7644 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7645 | * and try again. If that still fails, we punt. |
| 7646 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7647 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7648 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7649 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7650 | /* reserve one vector for miscellaneous handler */ |
| 7651 | if (vectors_left) { |
| 7652 | v_budget++; |
| 7653 | vectors_left--; |
| 7654 | } |
| 7655 | |
| 7656 | /* reserve vectors for the main PF traffic queues */ |
| 7657 | pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left); |
| 7658 | vectors_left -= pf->num_lan_msix; |
| 7659 | v_budget += pf->num_lan_msix; |
| 7660 | |
| 7661 | /* reserve one vector for sideband flow director */ |
| 7662 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7663 | if (vectors_left) { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7664 | pf->num_fdsb_msix = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7665 | v_budget++; |
| 7666 | vectors_left--; |
| 7667 | } else { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7668 | pf->num_fdsb_msix = 0; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7669 | } |
| 7670 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7671 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7672 | #ifdef I40E_FCOE |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7673 | /* can we reserve enough for FCoE? */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7674 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7675 | if (!vectors_left) |
| 7676 | pf->num_fcoe_msix = 0; |
| 7677 | else if (vectors_left >= pf->num_fcoe_qps) |
| 7678 | pf->num_fcoe_msix = pf->num_fcoe_qps; |
| 7679 | else |
| 7680 | pf->num_fcoe_msix = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7681 | v_budget += pf->num_fcoe_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7682 | vectors_left -= pf->num_fcoe_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7683 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7684 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7685 | #endif |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7686 | /* can we reserve enough for iWARP? */ |
| 7687 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7688 | iwarp_requested = pf->num_iwarp_msix; |
| 7689 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7690 | if (!vectors_left) |
| 7691 | pf->num_iwarp_msix = 0; |
| 7692 | else if (vectors_left < pf->num_iwarp_msix) |
| 7693 | pf->num_iwarp_msix = 1; |
| 7694 | v_budget += pf->num_iwarp_msix; |
| 7695 | vectors_left -= pf->num_iwarp_msix; |
| 7696 | } |
| 7697 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7698 | /* any vectors left over go for VMDq support */ |
| 7699 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7700 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7701 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7702 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 7703 | if (!vectors_left) { |
| 7704 | pf->num_vmdq_msix = 0; |
| 7705 | pf->num_vmdq_qps = 0; |
| 7706 | } else { |
| 7707 | /* if we're short on vectors for what's desired, we limit |
| 7708 | * the queues per vmdq. If this is still more than are |
| 7709 | * available, the user will need to change the number of |
| 7710 | * queues/vectors used by the PF later with the ethtool |
| 7711 | * channels command |
| 7712 | */ |
| 7713 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7714 | pf->num_vmdq_qps = 1; |
| 7715 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7716 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 7717 | v_budget += vmdq_vecs; |
| 7718 | vectors_left -= vmdq_vecs; |
| 7719 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7720 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7721 | |
| 7722 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7723 | GFP_KERNEL); |
| 7724 | if (!pf->msix_entries) |
| 7725 | return -ENOMEM; |
| 7726 | |
| 7727 | for (i = 0; i < v_budget; i++) |
| 7728 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7729 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7730 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7731 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7732 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7733 | kfree(pf->msix_entries); |
| 7734 | pf->msix_entries = NULL; |
Guilherme G Piccoli | 4c95aa5 | 2016-09-22 10:03:58 -0300 | [diff] [blame] | 7735 | pci_disable_msix(pf->pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7736 | return -ENODEV; |
| 7737 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7738 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7739 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7740 | pf->num_vmdq_vsis = 0; |
| 7741 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7742 | pf->num_lan_qps = 1; |
| 7743 | pf->num_lan_msix = 1; |
| 7744 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7745 | } else if (!vectors_left) { |
| 7746 | /* If we have limited resources, we will start with no vectors |
| 7747 | * for the special features and then allocate vectors to some |
| 7748 | * of these features based on the policy and at the end disable |
| 7749 | * the features that did not get any vectors. |
| 7750 | */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7751 | int vec; |
| 7752 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7753 | dev_info(&pf->pdev->dev, |
| 7754 | "MSI-X vector limit reached, attempting to redistribute vectors\n"); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7755 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7756 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7757 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7758 | /* Scale vector usage down */ |
| 7759 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7760 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7761 | pf->num_vmdq_qps = 1; |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7762 | #ifdef I40E_FCOE |
| 7763 | pf->num_fcoe_qps = 0; |
| 7764 | pf->num_fcoe_msix = 0; |
| 7765 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7766 | |
| 7767 | /* partition out the remaining vectors */ |
| 7768 | switch (vec) { |
| 7769 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7770 | pf->num_lan_msix = 1; |
| 7771 | break; |
| 7772 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7773 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7774 | pf->num_lan_msix = 1; |
| 7775 | pf->num_iwarp_msix = 1; |
| 7776 | } else { |
| 7777 | pf->num_lan_msix = 2; |
| 7778 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7779 | #ifdef I40E_FCOE |
| 7780 | /* give one vector to FCoE */ |
| 7781 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7782 | pf->num_lan_msix = 1; |
| 7783 | pf->num_fcoe_msix = 1; |
| 7784 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7785 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7786 | break; |
| 7787 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7788 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7789 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 7790 | iwarp_requested); |
| 7791 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 7792 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7793 | } else { |
| 7794 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 7795 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7796 | } |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 7797 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7798 | pf->num_fdsb_msix = 1; |
| 7799 | vec--; |
| 7800 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7801 | pf->num_lan_msix = min_t(int, |
| 7802 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 7803 | pf->num_lan_msix); |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7804 | pf->num_lan_qps = pf->num_lan_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7805 | #ifdef I40E_FCOE |
| 7806 | /* give one vector to FCoE */ |
| 7807 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7808 | pf->num_fcoe_msix = 1; |
| 7809 | vec--; |
| 7810 | } |
| 7811 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7812 | break; |
| 7813 | } |
| 7814 | } |
| 7815 | |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 7816 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 7817 | (pf->num_fdsb_msix == 0)) { |
| 7818 | dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n"); |
| 7819 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7820 | } |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7821 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7822 | (pf->num_vmdq_msix == 0)) { |
| 7823 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 7824 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 7825 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7826 | |
| 7827 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 7828 | (pf->num_iwarp_msix == 0)) { |
| 7829 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 7830 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 7831 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7832 | #ifdef I40E_FCOE |
| 7833 | |
| 7834 | if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { |
| 7835 | dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n"); |
| 7836 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 7837 | } |
| 7838 | #endif |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7839 | i40e_debug(&pf->hw, I40E_DEBUG_INIT, |
| 7840 | "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n", |
| 7841 | pf->num_lan_msix, |
| 7842 | pf->num_vmdq_msix * pf->num_vmdq_vsis, |
| 7843 | pf->num_fdsb_msix, |
| 7844 | pf->num_iwarp_msix); |
| 7845 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7846 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7847 | } |
| 7848 | |
| 7849 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7850 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7851 | * @vsi: the VSI being configured |
| 7852 | * @v_idx: index of the vector in the vsi struct |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7853 | * @cpu: cpu to be used on affinity_mask |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7854 | * |
| 7855 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 7856 | **/ |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7857 | 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] | 7858 | { |
| 7859 | struct i40e_q_vector *q_vector; |
| 7860 | |
| 7861 | /* allocate q_vector */ |
| 7862 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 7863 | if (!q_vector) |
| 7864 | return -ENOMEM; |
| 7865 | |
| 7866 | q_vector->vsi = vsi; |
| 7867 | q_vector->v_idx = v_idx; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7868 | cpumask_set_cpu(cpu, &q_vector->affinity_mask); |
| 7869 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7870 | if (vsi->netdev) |
| 7871 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 7872 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7873 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 7874 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 7875 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 7876 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7877 | /* tie q_vector and vsi together */ |
| 7878 | vsi->q_vectors[v_idx] = q_vector; |
| 7879 | |
| 7880 | return 0; |
| 7881 | } |
| 7882 | |
| 7883 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7884 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7885 | * @vsi: the VSI being configured |
| 7886 | * |
| 7887 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 7888 | * return -ENOMEM. |
| 7889 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7890 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7891 | { |
| 7892 | struct i40e_pf *pf = vsi->back; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7893 | int err, v_idx, num_q_vectors, current_cpu; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7894 | |
| 7895 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 7896 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7897 | num_q_vectors = vsi->num_q_vectors; |
| 7898 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 7899 | num_q_vectors = 1; |
| 7900 | else |
| 7901 | return -EINVAL; |
| 7902 | |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7903 | current_cpu = cpumask_first(cpu_online_mask); |
| 7904 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7905 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7906 | err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7907 | if (err) |
| 7908 | goto err_out; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7909 | current_cpu = cpumask_next(current_cpu, cpu_online_mask); |
| 7910 | if (unlikely(current_cpu >= nr_cpu_ids)) |
| 7911 | current_cpu = cpumask_first(cpu_online_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7912 | } |
| 7913 | |
| 7914 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7915 | |
| 7916 | err_out: |
| 7917 | while (v_idx--) |
| 7918 | i40e_free_q_vector(vsi, v_idx); |
| 7919 | |
| 7920 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7921 | } |
| 7922 | |
| 7923 | /** |
| 7924 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 7925 | * @pf: board private structure to initialize |
| 7926 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7927 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7928 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7929 | int vectors = 0; |
| 7930 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7931 | |
| 7932 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7933 | vectors = i40e_init_msix(pf); |
| 7934 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7935 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7936 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7937 | #ifdef I40E_FCOE |
| 7938 | I40E_FLAG_FCOE_ENABLED | |
| 7939 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7940 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7941 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 7942 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7943 | I40E_FLAG_SRIOV_ENABLED | |
| 7944 | I40E_FLAG_FD_SB_ENABLED | |
| 7945 | I40E_FLAG_FD_ATR_ENABLED | |
| 7946 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7947 | |
| 7948 | /* rework the queue expectations without MSIX */ |
| 7949 | i40e_determine_queue_usage(pf); |
| 7950 | } |
| 7951 | } |
| 7952 | |
| 7953 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 7954 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7955 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7956 | vectors = pci_enable_msi(pf->pdev); |
| 7957 | if (vectors < 0) { |
| 7958 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 7959 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7960 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 7961 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7962 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7963 | } |
| 7964 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 7965 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7966 | 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] | 7967 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7968 | /* set up vector assignment tracking */ |
| 7969 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 7970 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7971 | if (!pf->irq_pile) { |
| 7972 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 7973 | return -ENOMEM; |
| 7974 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7975 | pf->irq_pile->num_entries = vectors; |
| 7976 | pf->irq_pile->search_hint = 0; |
| 7977 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7978 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7979 | (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] | 7980 | |
| 7981 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7982 | } |
| 7983 | |
| 7984 | /** |
| 7985 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 7986 | * @pf: board private structure |
| 7987 | * |
| 7988 | * This sets up the handler for MSIX 0, which is used to manage the |
| 7989 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 7990 | * when in MSI or Legacy interrupt mode. |
| 7991 | **/ |
| 7992 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 7993 | { |
| 7994 | struct i40e_hw *hw = &pf->hw; |
| 7995 | int err = 0; |
| 7996 | |
| 7997 | /* Only request the irq if this is the first time through, and |
| 7998 | * not when we're rebuilding after a Reset |
| 7999 | */ |
| 8000 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 8001 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8002 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8003 | if (err) { |
| 8004 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 8005 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 8006 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8007 | return -EFAULT; |
| 8008 | } |
| 8009 | } |
| 8010 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 8011 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8012 | |
| 8013 | /* associate no queues to the misc vector */ |
| 8014 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 8015 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 8016 | |
| 8017 | i40e_flush(hw); |
| 8018 | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 8019 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8020 | |
| 8021 | return err; |
| 8022 | } |
| 8023 | |
| 8024 | /** |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8025 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 8026 | * @vsi: vsi structure |
| 8027 | * @seed: RSS hash seed |
| 8028 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8029 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8030 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8031 | { |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8032 | struct i40e_pf *pf = vsi->back; |
| 8033 | struct i40e_hw *hw = &pf->hw; |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8034 | int ret = 0; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8035 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8036 | if (seed) { |
| 8037 | struct i40e_aqc_get_set_rss_key_data *seed_dw = |
| 8038 | (struct i40e_aqc_get_set_rss_key_data *)seed; |
| 8039 | ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw); |
| 8040 | if (ret) { |
| 8041 | dev_info(&pf->pdev->dev, |
| 8042 | "Cannot set RSS key, err %s aq_err %s\n", |
| 8043 | i40e_stat_str(hw, ret), |
| 8044 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8045 | return ret; |
| 8046 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8047 | } |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8048 | if (lut) { |
| 8049 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8050 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 8051 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8052 | if (ret) { |
| 8053 | dev_info(&pf->pdev->dev, |
| 8054 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 8055 | i40e_stat_str(hw, ret), |
| 8056 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8057 | return ret; |
| 8058 | } |
| 8059 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8060 | return ret; |
| 8061 | } |
| 8062 | |
| 8063 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8064 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 8065 | * @vsi: Pointer to vsi structure |
| 8066 | * @seed: Buffter to store the hash keys |
| 8067 | * @lut: Buffer to store the lookup table entries |
| 8068 | * @lut_size: Size of buffer to store the lookup table entries |
| 8069 | * |
| 8070 | * Return 0 on success, negative on failure |
| 8071 | */ |
| 8072 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8073 | u8 *lut, u16 lut_size) |
| 8074 | { |
| 8075 | struct i40e_pf *pf = vsi->back; |
| 8076 | struct i40e_hw *hw = &pf->hw; |
| 8077 | int ret = 0; |
| 8078 | |
| 8079 | if (seed) { |
| 8080 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 8081 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 8082 | if (ret) { |
| 8083 | dev_info(&pf->pdev->dev, |
| 8084 | "Cannot get RSS key, err %s aq_err %s\n", |
| 8085 | i40e_stat_str(&pf->hw, ret), |
| 8086 | i40e_aq_str(&pf->hw, |
| 8087 | pf->hw.aq.asq_last_status)); |
| 8088 | return ret; |
| 8089 | } |
| 8090 | } |
| 8091 | |
| 8092 | if (lut) { |
| 8093 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 8094 | |
| 8095 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8096 | if (ret) { |
| 8097 | dev_info(&pf->pdev->dev, |
| 8098 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 8099 | i40e_stat_str(&pf->hw, ret), |
| 8100 | i40e_aq_str(&pf->hw, |
| 8101 | pf->hw.aq.asq_last_status)); |
| 8102 | return ret; |
| 8103 | } |
| 8104 | } |
| 8105 | |
| 8106 | return ret; |
| 8107 | } |
| 8108 | |
| 8109 | /** |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8110 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 8111 | * @vsi: VSI structure |
| 8112 | **/ |
| 8113 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 8114 | { |
| 8115 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 8116 | struct i40e_pf *pf = vsi->back; |
| 8117 | u8 *lut; |
| 8118 | int ret; |
| 8119 | |
| 8120 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) |
| 8121 | return 0; |
| 8122 | |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8123 | if (!vsi->rss_size) |
| 8124 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8125 | vsi->num_queue_pairs); |
| 8126 | if (!vsi->rss_size) |
| 8127 | return -EINVAL; |
| 8128 | |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8129 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8130 | if (!lut) |
| 8131 | return -ENOMEM; |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 8132 | /* Use the user configured hash keys and lookup table if there is one, |
| 8133 | * otherwise use default |
| 8134 | */ |
| 8135 | if (vsi->rss_lut_user) |
| 8136 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8137 | else |
| 8138 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
| 8139 | if (vsi->rss_hkey_user) |
| 8140 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8141 | else |
| 8142 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8143 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 8144 | kfree(lut); |
| 8145 | |
| 8146 | return ret; |
| 8147 | } |
| 8148 | |
| 8149 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8150 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8151 | * @vsi: Pointer to vsi structure |
| 8152 | * @seed: RSS hash seed |
| 8153 | * @lut: Lookup table |
| 8154 | * @lut_size: Lookup table size |
| 8155 | * |
| 8156 | * Returns 0 on success, negative on failure |
| 8157 | **/ |
| 8158 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8159 | const u8 *lut, u16 lut_size) |
| 8160 | { |
| 8161 | struct i40e_pf *pf = vsi->back; |
| 8162 | struct i40e_hw *hw = &pf->hw; |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8163 | u16 vf_id = vsi->vf_id; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8164 | u8 i; |
| 8165 | |
| 8166 | /* Fill out hash function seed */ |
| 8167 | if (seed) { |
| 8168 | u32 *seed_dw = (u32 *)seed; |
| 8169 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8170 | if (vsi->type == I40E_VSI_MAIN) { |
| 8171 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 8172 | i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), |
| 8173 | seed_dw[i]); |
| 8174 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8175 | for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++) |
| 8176 | i40e_write_rx_ctl(hw, |
| 8177 | I40E_VFQF_HKEY1(i, vf_id), |
| 8178 | seed_dw[i]); |
| 8179 | } else { |
| 8180 | dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n"); |
| 8181 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8182 | } |
| 8183 | |
| 8184 | if (lut) { |
| 8185 | u32 *lut_dw = (u32 *)lut; |
| 8186 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8187 | if (vsi->type == I40E_VSI_MAIN) { |
| 8188 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8189 | return -EINVAL; |
| 8190 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8191 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8192 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8193 | if (lut_size != I40E_VF_HLUT_ARRAY_SIZE) |
| 8194 | return -EINVAL; |
| 8195 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8196 | i40e_write_rx_ctl(hw, |
| 8197 | I40E_VFQF_HLUT1(i, vf_id), |
| 8198 | lut_dw[i]); |
| 8199 | } else { |
| 8200 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8201 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8202 | } |
| 8203 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8204 | |
| 8205 | return 0; |
| 8206 | } |
| 8207 | |
| 8208 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8209 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8210 | * @vsi: Pointer to VSI structure |
| 8211 | * @seed: Buffer to store the keys |
| 8212 | * @lut: Buffer to store the lookup table entries |
| 8213 | * @lut_size: Size of buffer to store the lookup table entries |
| 8214 | * |
| 8215 | * Returns 0 on success, negative on failure |
| 8216 | */ |
| 8217 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8218 | u8 *lut, u16 lut_size) |
| 8219 | { |
| 8220 | struct i40e_pf *pf = vsi->back; |
| 8221 | struct i40e_hw *hw = &pf->hw; |
| 8222 | u16 i; |
| 8223 | |
| 8224 | if (seed) { |
| 8225 | u32 *seed_dw = (u32 *)seed; |
| 8226 | |
| 8227 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8228 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8229 | } |
| 8230 | if (lut) { |
| 8231 | u32 *lut_dw = (u32 *)lut; |
| 8232 | |
| 8233 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8234 | return -EINVAL; |
| 8235 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8236 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8237 | } |
| 8238 | |
| 8239 | return 0; |
| 8240 | } |
| 8241 | |
| 8242 | /** |
| 8243 | * i40e_config_rss - Configure RSS keys and lut |
| 8244 | * @vsi: Pointer to VSI structure |
| 8245 | * @seed: RSS hash seed |
| 8246 | * @lut: Lookup table |
| 8247 | * @lut_size: Lookup table size |
| 8248 | * |
| 8249 | * Returns 0 on success, negative on failure |
| 8250 | */ |
| 8251 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8252 | { |
| 8253 | struct i40e_pf *pf = vsi->back; |
| 8254 | |
| 8255 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8256 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8257 | else |
| 8258 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8259 | } |
| 8260 | |
| 8261 | /** |
| 8262 | * i40e_get_rss - Get RSS keys and lut |
| 8263 | * @vsi: Pointer to VSI structure |
| 8264 | * @seed: Buffer to store the keys |
| 8265 | * @lut: Buffer to store the lookup table entries |
| 8266 | * lut_size: Size of buffer to store the lookup table entries |
| 8267 | * |
| 8268 | * Returns 0 on success, negative on failure |
| 8269 | */ |
| 8270 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8271 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8272 | struct i40e_pf *pf = vsi->back; |
| 8273 | |
| 8274 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8275 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8276 | else |
| 8277 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8278 | } |
| 8279 | |
| 8280 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8281 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8282 | * @pf: Pointer to board private structure |
| 8283 | * @lut: Lookup table |
| 8284 | * @rss_table_size: Lookup table size |
| 8285 | * @rss_size: Range of queue number for hashing |
| 8286 | */ |
Alan Brady | f158235 | 2016-08-24 11:33:46 -0700 | [diff] [blame] | 8287 | void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8288 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8289 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8290 | u16 i; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8291 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8292 | for (i = 0; i < rss_table_size; i++) |
| 8293 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8294 | } |
| 8295 | |
| 8296 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8297 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8298 | * @pf: board private structure |
| 8299 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8300 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8301 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8302 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8303 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8304 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8305 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8306 | u32 reg_val; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8307 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8308 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8309 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8310 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8311 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 8312 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8313 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8314 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8315 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8316 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8317 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8318 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8319 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8320 | reg_val = (pf->rss_table_size == 512) ? |
| 8321 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8322 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8323 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8324 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8325 | /* Determine the RSS size of the VSI */ |
| 8326 | if (!vsi->rss_size) |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8327 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8328 | vsi->num_queue_pairs); |
Mitch Williams | a4fa59c | 2016-09-12 14:18:43 -0700 | [diff] [blame] | 8329 | if (!vsi->rss_size) |
| 8330 | return -EINVAL; |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8331 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8332 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8333 | if (!lut) |
| 8334 | return -ENOMEM; |
| 8335 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8336 | /* Use user configured lut if there is one, otherwise use default */ |
| 8337 | if (vsi->rss_lut_user) |
| 8338 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8339 | else |
| 8340 | 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] | 8341 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8342 | /* Use user configured hash key if there is one, otherwise |
| 8343 | * use default. |
| 8344 | */ |
| 8345 | if (vsi->rss_hkey_user) |
| 8346 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8347 | else |
| 8348 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8349 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8350 | kfree(lut); |
| 8351 | |
| 8352 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8353 | } |
| 8354 | |
| 8355 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8356 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8357 | * @pf: board private structure |
| 8358 | * @queue_count: the requested queue count for rss. |
| 8359 | * |
| 8360 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8361 | * count which may be different from the requested queue count. |
| 8362 | **/ |
| 8363 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8364 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8365 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8366 | int new_rss_size; |
| 8367 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8368 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8369 | return 0; |
| 8370 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8371 | 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] | 8372 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8373 | if (queue_count != vsi->num_queue_pairs) { |
| 8374 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8375 | i40e_prep_for_reset(pf); |
| 8376 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8377 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8378 | |
| 8379 | i40e_reset_and_rebuild(pf, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8380 | |
| 8381 | /* Discard the user configured hash keys and lut, if less |
| 8382 | * queues are enabled. |
| 8383 | */ |
| 8384 | if (queue_count < vsi->rss_size) { |
| 8385 | i40e_clear_rss_config_user(vsi); |
| 8386 | dev_dbg(&pf->pdev->dev, |
| 8387 | "discard user configured hash keys and lut\n"); |
| 8388 | } |
| 8389 | |
| 8390 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8391 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8392 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8393 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8394 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8395 | } |
Lihong Yang | 1281505 | 2016-09-27 11:28:48 -0700 | [diff] [blame] | 8396 | dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n", |
| 8397 | vsi->req_queue_pairs, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8398 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8399 | } |
| 8400 | |
| 8401 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8402 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 8403 | * @pf: board private structure |
| 8404 | **/ |
| 8405 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 8406 | { |
| 8407 | i40e_status status; |
| 8408 | bool min_valid, max_valid; |
| 8409 | u32 max_bw, min_bw; |
| 8410 | |
| 8411 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8412 | &min_valid, &max_valid); |
| 8413 | |
| 8414 | if (!status) { |
| 8415 | if (min_valid) |
| 8416 | pf->npar_min_bw = min_bw; |
| 8417 | if (max_valid) |
| 8418 | pf->npar_max_bw = max_bw; |
| 8419 | } |
| 8420 | |
| 8421 | return status; |
| 8422 | } |
| 8423 | |
| 8424 | /** |
| 8425 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 8426 | * @pf: board private structure |
| 8427 | **/ |
| 8428 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 8429 | { |
| 8430 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8431 | i40e_status status; |
| 8432 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8433 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8434 | 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] | 8435 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8436 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 8437 | |
| 8438 | /* Set the new bandwidths */ |
| 8439 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8440 | |
| 8441 | return status; |
| 8442 | } |
| 8443 | |
| 8444 | /** |
| 8445 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 8446 | * @pf: board private structure |
| 8447 | **/ |
| 8448 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 8449 | { |
| 8450 | /* Commit temporary BW setting to permanent NVM image */ |
| 8451 | enum i40e_admin_queue_err last_aq_status; |
| 8452 | i40e_status ret; |
| 8453 | u16 nvm_word; |
| 8454 | |
| 8455 | if (pf->hw.partition_id != 1) { |
| 8456 | dev_info(&pf->pdev->dev, |
| 8457 | "Commit BW only works on partition 1! This is partition %d", |
| 8458 | pf->hw.partition_id); |
| 8459 | ret = I40E_NOT_SUPPORTED; |
| 8460 | goto bw_commit_out; |
| 8461 | } |
| 8462 | |
| 8463 | /* Acquire NVM for read access */ |
| 8464 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8465 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8466 | if (ret) { |
| 8467 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8468 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8469 | i40e_stat_str(&pf->hw, ret), |
| 8470 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8471 | goto bw_commit_out; |
| 8472 | } |
| 8473 | |
| 8474 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8475 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8476 | I40E_SR_NVM_CONTROL_WORD, |
| 8477 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8478 | false, NULL); |
| 8479 | /* Save off last admin queue command status before releasing |
| 8480 | * the NVM |
| 8481 | */ |
| 8482 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8483 | i40e_release_nvm(&pf->hw); |
| 8484 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8485 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8486 | i40e_stat_str(&pf->hw, ret), |
| 8487 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8488 | goto bw_commit_out; |
| 8489 | } |
| 8490 | |
| 8491 | /* Wait a bit for NVM release to complete */ |
| 8492 | msleep(50); |
| 8493 | |
| 8494 | /* Acquire NVM for write access */ |
| 8495 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8496 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8497 | if (ret) { |
| 8498 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8499 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8500 | i40e_stat_str(&pf->hw, ret), |
| 8501 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8502 | goto bw_commit_out; |
| 8503 | } |
| 8504 | /* Write it back out unchanged to initiate update NVM, |
| 8505 | * which will force a write of the shadow (alt) RAM to |
| 8506 | * the NVM - thus storing the bandwidth values permanently. |
| 8507 | */ |
| 8508 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8509 | I40E_SR_NVM_CONTROL_WORD, |
| 8510 | 0x10, sizeof(nvm_word), |
| 8511 | &nvm_word, true, NULL); |
| 8512 | /* Save off last admin queue command status before releasing |
| 8513 | * the NVM |
| 8514 | */ |
| 8515 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8516 | i40e_release_nvm(&pf->hw); |
| 8517 | if (ret) |
| 8518 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8519 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8520 | i40e_stat_str(&pf->hw, ret), |
| 8521 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8522 | bw_commit_out: |
| 8523 | |
| 8524 | return ret; |
| 8525 | } |
| 8526 | |
| 8527 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8528 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8529 | * @pf: board private structure to initialize |
| 8530 | * |
| 8531 | * i40e_sw_init initializes the Adapter private data structure. |
| 8532 | * Fields are initialized based on PCI device information and |
| 8533 | * OS network device settings (MTU size). |
| 8534 | **/ |
| 8535 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8536 | { |
| 8537 | int err = 0; |
| 8538 | int size; |
| 8539 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8540 | /* Set default capability flags */ |
| 8541 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8542 | I40E_FLAG_MSI_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8543 | I40E_FLAG_MSIX_ENABLED; |
| 8544 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8545 | /* Set default ITR */ |
| 8546 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8547 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8548 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8549 | /* Depending on PF configurations, it is possible that the RSS |
| 8550 | * maximum might end up larger than the available queues |
| 8551 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8552 | 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] | 8553 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8554 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8555 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8556 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8557 | if (pf->hw.func_caps.rss) { |
| 8558 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8559 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8560 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8561 | } |
| 8562 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8563 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8564 | 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] | 8565 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8566 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8567 | if (i40e_get_npar_bw_setting(pf)) |
| 8568 | dev_warn(&pf->pdev->dev, |
| 8569 | "Could not get NPAR bw settings\n"); |
| 8570 | else |
| 8571 | dev_info(&pf->pdev->dev, |
| 8572 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 8573 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8574 | } |
| 8575 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8576 | /* FW/NVM is not yet fixed in this regard */ |
| 8577 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8578 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8579 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8580 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8581 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8582 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8583 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8584 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8585 | else |
| 8586 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8587 | pf->fdir_pf_filter_count = |
| 8588 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8589 | pf->hw.fdir_shared_filter_count = |
| 8590 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8591 | } |
| 8592 | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8593 | if (i40e_is_mac_710(&pf->hw) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8594 | (((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] | 8595 | (pf->hw.aq.fw_maj_ver < 4))) { |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8596 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8597 | /* No DCB support for FW < v4.33 */ |
| 8598 | pf->flags |= I40E_FLAG_NO_DCB_SUPPORT; |
| 8599 | } |
| 8600 | |
| 8601 | /* Disable FW LLDP if FW < v4.3 */ |
| 8602 | if (i40e_is_mac_710(&pf->hw) && |
| 8603 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 8604 | (pf->hw.aq.fw_maj_ver < 4))) |
| 8605 | pf->flags |= I40E_FLAG_STOP_FW_LLDP; |
| 8606 | |
| 8607 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
| 8608 | if (i40e_is_mac_710(&pf->hw) && |
| 8609 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 8610 | (pf->hw.aq.fw_maj_ver >= 5))) |
| 8611 | pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8612 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8613 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8614 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8615 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 8616 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8617 | } |
| 8618 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8619 | if (pf->hw.func_caps.iwarp) { |
| 8620 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 8621 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 8622 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 8623 | } |
| 8624 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8625 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 8626 | i40e_init_pf_fcoe(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8627 | |
| 8628 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8629 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 8630 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8631 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 8632 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 8633 | pf->num_req_vfs = min_t(int, |
| 8634 | pf->hw.func_caps.num_vfs, |
| 8635 | I40E_MAX_VF_COUNT); |
| 8636 | } |
| 8637 | #endif /* CONFIG_PCI_IOV */ |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8638 | if (pf->hw.mac.type == I40E_MAC_X722) { |
| 8639 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE | |
| 8640 | I40E_FLAG_128_QP_RSS_CAPABLE | |
| 8641 | I40E_FLAG_HW_ATR_EVICT_CAPABLE | |
| 8642 | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE | |
| 8643 | I40E_FLAG_WB_ON_ITR_CAPABLE | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8644 | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
Jesse Brandeburg | 8e2cc0e | 2016-02-29 11:00:24 -0800 | [diff] [blame] | 8645 | I40E_FLAG_NO_PCI_LINK_CHECK | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8646 | I40E_FLAG_USE_SET_LLDP_MIB | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8647 | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8648 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 8649 | ((pf->hw.aq.api_maj_ver == 1) && |
| 8650 | (pf->hw.aq.api_min_ver > 4))) { |
| 8651 | /* Supported in FW API version higher than 1.4 */ |
| 8652 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 8653 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
| 8654 | } else { |
| 8655 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8656 | } |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8657 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8658 | pf->eeprom_version = 0xDEAD; |
| 8659 | pf->lan_veb = I40E_NO_VEB; |
| 8660 | pf->lan_vsi = I40E_NO_VSI; |
| 8661 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 8662 | /* By default FW has this off for performance reasons */ |
| 8663 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 8664 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8665 | /* set up queue assignment tracking */ |
| 8666 | size = sizeof(struct i40e_lump_tracking) |
| 8667 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 8668 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 8669 | if (!pf->qp_pile) { |
| 8670 | err = -ENOMEM; |
| 8671 | goto sw_init_done; |
| 8672 | } |
| 8673 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 8674 | pf->qp_pile->search_hint = 0; |
| 8675 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 8676 | pf->tx_timeout_recovery_level = 1; |
| 8677 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8678 | mutex_init(&pf->switch_mutex); |
| 8679 | |
Greg Rose | c668a12 | 2015-02-26 16:10:39 +0000 | [diff] [blame] | 8680 | /* If NPAR is enabled nudge the Tx scheduler */ |
| 8681 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) |
| 8682 | i40e_set_npar_bw_setting(pf); |
| 8683 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8684 | sw_init_done: |
| 8685 | return err; |
| 8686 | } |
| 8687 | |
| 8688 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8689 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 8690 | * @pf: board private structure to initialize |
| 8691 | * @features: the feature set that the stack is suggesting |
| 8692 | * |
| 8693 | * returns a bool to indicate if reset needs to happen |
| 8694 | **/ |
| 8695 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 8696 | { |
| 8697 | bool need_reset = false; |
| 8698 | |
| 8699 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 8700 | * the state changed, we need to reset. |
| 8701 | */ |
| 8702 | if (features & NETIF_F_NTUPLE) { |
| 8703 | /* Enable filters and mark for reset */ |
| 8704 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 8705 | need_reset = true; |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 8706 | /* enable FD_SB only if there is MSI-X vector */ |
| 8707 | if (pf->num_fdsb_msix > 0) |
| 8708 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8709 | } else { |
| 8710 | /* turn off filters, mark for reset and clear SW filter list */ |
| 8711 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8712 | need_reset = true; |
| 8713 | i40e_fdir_filter_exit(pf); |
| 8714 | } |
| 8715 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8716 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 8717 | /* reset fd counters */ |
| 8718 | pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0; |
| 8719 | pf->fdir_pf_active_filters = 0; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8720 | /* if ATR was auto disabled it can be re-enabled. */ |
| 8721 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 8722 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8723 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 8724 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 8725 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
| 8726 | } |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8727 | } |
| 8728 | return need_reset; |
| 8729 | } |
| 8730 | |
| 8731 | /** |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8732 | * i40e_clear_rss_lut - clear the rx hash lookup table |
| 8733 | * @vsi: the VSI being configured |
| 8734 | **/ |
| 8735 | static void i40e_clear_rss_lut(struct i40e_vsi *vsi) |
| 8736 | { |
| 8737 | struct i40e_pf *pf = vsi->back; |
| 8738 | struct i40e_hw *hw = &pf->hw; |
| 8739 | u16 vf_id = vsi->vf_id; |
| 8740 | u8 i; |
| 8741 | |
| 8742 | if (vsi->type == I40E_VSI_MAIN) { |
| 8743 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8744 | wr32(hw, I40E_PFQF_HLUT(i), 0); |
| 8745 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8746 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8747 | i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0); |
| 8748 | } else { |
| 8749 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8750 | } |
| 8751 | } |
| 8752 | |
| 8753 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8754 | * i40e_set_features - set the netdev feature flags |
| 8755 | * @netdev: ptr to the netdev being adjusted |
| 8756 | * @features: the feature set that the stack is suggesting |
| 8757 | **/ |
| 8758 | static int i40e_set_features(struct net_device *netdev, |
| 8759 | netdev_features_t features) |
| 8760 | { |
| 8761 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8762 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8763 | struct i40e_pf *pf = vsi->back; |
| 8764 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8765 | |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8766 | if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH)) |
| 8767 | i40e_pf_config_rss(pf); |
| 8768 | else if (!(features & NETIF_F_RXHASH) && |
| 8769 | netdev->features & NETIF_F_RXHASH) |
| 8770 | i40e_clear_rss_lut(vsi); |
| 8771 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8772 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8773 | i40e_vlan_stripping_enable(vsi); |
| 8774 | else |
| 8775 | i40e_vlan_stripping_disable(vsi); |
| 8776 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8777 | need_reset = i40e_set_ntuple(pf, features); |
| 8778 | |
| 8779 | if (need_reset) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8780 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8781 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8782 | return 0; |
| 8783 | } |
| 8784 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8785 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8786 | * 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] | 8787 | * @pf: board private structure |
| 8788 | * @port: The UDP port to look up |
| 8789 | * |
| 8790 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 8791 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8792 | 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] | 8793 | { |
| 8794 | u8 i; |
| 8795 | |
| 8796 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8797 | if (pf->udp_ports[i].index == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8798 | return i; |
| 8799 | } |
| 8800 | |
| 8801 | return i; |
| 8802 | } |
| 8803 | |
| 8804 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8805 | * 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] | 8806 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8807 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8808 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8809 | static void i40e_udp_tunnel_add(struct net_device *netdev, |
| 8810 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8811 | { |
| 8812 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8813 | struct i40e_vsi *vsi = np->vsi; |
| 8814 | struct i40e_pf *pf = vsi->back; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8815 | __be16 port = ti->port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8816 | u8 next_idx; |
| 8817 | u8 idx; |
| 8818 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8819 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8820 | |
| 8821 | /* Check if port already exists */ |
| 8822 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8823 | netdev_info(netdev, "port %d already offloaded\n", |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8824 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8825 | return; |
| 8826 | } |
| 8827 | |
| 8828 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8829 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8830 | |
| 8831 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8832 | 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] | 8833 | ntohs(port)); |
| 8834 | return; |
| 8835 | } |
| 8836 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8837 | switch (ti->type) { |
| 8838 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8839 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 8840 | break; |
| 8841 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8842 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8843 | return; |
| 8844 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 8845 | break; |
| 8846 | default: |
| 8847 | return; |
| 8848 | } |
| 8849 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8850 | /* New port: add it and mark its index in the bitmap */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8851 | pf->udp_ports[next_idx].index = port; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8852 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8853 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8854 | } |
| 8855 | |
| 8856 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8857 | * 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] | 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_del(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 idx; |
| 8869 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8870 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8871 | |
| 8872 | /* Check if port already exists */ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8873 | if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS) |
| 8874 | goto not_found; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8875 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8876 | switch (ti->type) { |
| 8877 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8878 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN) |
| 8879 | goto not_found; |
| 8880 | break; |
| 8881 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8882 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE) |
| 8883 | goto not_found; |
| 8884 | break; |
| 8885 | default: |
| 8886 | goto not_found; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8887 | } |
| 8888 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8889 | /* if port exists, set it to 0 (mark for deletion) |
| 8890 | * and make it pending |
| 8891 | */ |
| 8892 | pf->udp_ports[idx].index = 0; |
| 8893 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8894 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8895 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8896 | return; |
| 8897 | not_found: |
| 8898 | netdev_warn(netdev, "UDP port %d was not found, not deleting\n", |
| 8899 | ntohs(port)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8900 | } |
| 8901 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8902 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 8903 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8904 | { |
| 8905 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8906 | struct i40e_pf *pf = np->vsi->back; |
| 8907 | struct i40e_hw *hw = &pf->hw; |
| 8908 | |
| 8909 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 8910 | return -EOPNOTSUPP; |
| 8911 | |
| 8912 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 8913 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 8914 | |
| 8915 | return 0; |
| 8916 | } |
| 8917 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 8918 | /** |
| 8919 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 8920 | * @ndm: the input from the stack |
| 8921 | * @tb: pointer to array of nladdr (unused) |
| 8922 | * @dev: the net device pointer |
| 8923 | * @addr: the MAC address entry being added |
| 8924 | * @flags: instructions from stack about fdb operation |
| 8925 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8926 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 8927 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8928 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8929 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8930 | { |
| 8931 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8932 | struct i40e_pf *pf = np->vsi->back; |
| 8933 | int err = 0; |
| 8934 | |
| 8935 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 8936 | return -EOPNOTSUPP; |
| 8937 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 8938 | if (vid) { |
| 8939 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 8940 | return -EINVAL; |
| 8941 | } |
| 8942 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8943 | /* Hardware does not support aging addresses so if a |
| 8944 | * ndm_state is given only allow permanent addresses |
| 8945 | */ |
| 8946 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 8947 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 8948 | return -EINVAL; |
| 8949 | } |
| 8950 | |
| 8951 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 8952 | err = dev_uc_add_excl(dev, addr); |
| 8953 | else if (is_multicast_ether_addr(addr)) |
| 8954 | err = dev_mc_add_excl(dev, addr); |
| 8955 | else |
| 8956 | err = -EINVAL; |
| 8957 | |
| 8958 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 8959 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 8960 | err = 0; |
| 8961 | |
| 8962 | return err; |
| 8963 | } |
| 8964 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8965 | /** |
| 8966 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 8967 | * @dev: the netdev being configured |
| 8968 | * @nlh: RTNL message |
| 8969 | * |
| 8970 | * Inserts a new hardware bridge if not already created and |
| 8971 | * enables the bridging mode requested (VEB or VEPA). If the |
| 8972 | * hardware bridge has already been inserted and the request |
| 8973 | * is to change the mode then that requires a PF reset to |
| 8974 | * allow rebuild of the components with required hardware |
| 8975 | * bridge mode enabled. |
| 8976 | **/ |
| 8977 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 8978 | struct nlmsghdr *nlh, |
| 8979 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8980 | { |
| 8981 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8982 | struct i40e_vsi *vsi = np->vsi; |
| 8983 | struct i40e_pf *pf = vsi->back; |
| 8984 | struct i40e_veb *veb = NULL; |
| 8985 | struct nlattr *attr, *br_spec; |
| 8986 | int i, rem; |
| 8987 | |
| 8988 | /* Only for PF VSI for now */ |
| 8989 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8990 | return -EOPNOTSUPP; |
| 8991 | |
| 8992 | /* Find the HW bridge for PF VSI */ |
| 8993 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8994 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8995 | veb = pf->veb[i]; |
| 8996 | } |
| 8997 | |
| 8998 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 8999 | |
| 9000 | nla_for_each_nested(attr, br_spec, rem) { |
| 9001 | __u16 mode; |
| 9002 | |
| 9003 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 9004 | continue; |
| 9005 | |
| 9006 | mode = nla_get_u16(attr); |
| 9007 | if ((mode != BRIDGE_MODE_VEPA) && |
| 9008 | (mode != BRIDGE_MODE_VEB)) |
| 9009 | return -EINVAL; |
| 9010 | |
| 9011 | /* Insert a new HW bridge */ |
| 9012 | if (!veb) { |
| 9013 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9014 | vsi->tc_config.enabled_tc); |
| 9015 | if (veb) { |
| 9016 | veb->bridge_mode = mode; |
| 9017 | i40e_config_bridge_mode(veb); |
| 9018 | } else { |
| 9019 | /* No Bridge HW offload available */ |
| 9020 | return -ENOENT; |
| 9021 | } |
| 9022 | break; |
| 9023 | } else if (mode != veb->bridge_mode) { |
| 9024 | /* Existing HW bridge but different mode needs reset */ |
| 9025 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9026 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 9027 | if (mode == BRIDGE_MODE_VEB) |
| 9028 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 9029 | else |
| 9030 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9031 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9032 | break; |
| 9033 | } |
| 9034 | } |
| 9035 | |
| 9036 | return 0; |
| 9037 | } |
| 9038 | |
| 9039 | /** |
| 9040 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 9041 | * @skb: skb buff |
| 9042 | * @pid: process id |
| 9043 | * @seq: RTNL message seq # |
| 9044 | * @dev: the netdev being configured |
| 9045 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 9046 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9047 | * |
| 9048 | * Return the mode in which the hardware bridge is operating in |
| 9049 | * i.e VEB or VEPA. |
| 9050 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9051 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 9052 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 9053 | u32 __always_unused filter_mask, |
| 9054 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9055 | { |
| 9056 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9057 | struct i40e_vsi *vsi = np->vsi; |
| 9058 | struct i40e_pf *pf = vsi->back; |
| 9059 | struct i40e_veb *veb = NULL; |
| 9060 | int i; |
| 9061 | |
| 9062 | /* Only for PF VSI for now */ |
| 9063 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9064 | return -EOPNOTSUPP; |
| 9065 | |
| 9066 | /* Find the HW bridge for the PF VSI */ |
| 9067 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9068 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9069 | veb = pf->veb[i]; |
| 9070 | } |
| 9071 | |
| 9072 | if (!veb) |
| 9073 | return 0; |
| 9074 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9075 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Huaibin Wang | 599b076 | 2016-09-26 09:51:18 +0200 | [diff] [blame] | 9076 | 0, 0, nlflags, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9077 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9078 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9079 | /* Hardware supports L4 tunnel length of 128B (=2^7) which includes |
| 9080 | * inner mac plus all inner ethertypes. |
| 9081 | */ |
| 9082 | #define I40E_MAX_TUNNEL_HDR_LEN 128 |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9083 | /** |
| 9084 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 9085 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 9086 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9087 | * @features: Offload features that the stack believes apply |
| 9088 | **/ |
| 9089 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 9090 | struct net_device *dev, |
| 9091 | netdev_features_t features) |
| 9092 | { |
| 9093 | if (skb->encapsulation && |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9094 | ((skb_inner_network_header(skb) - skb_transport_header(skb)) > |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9095 | I40E_MAX_TUNNEL_HDR_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 9096 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9097 | |
| 9098 | return features; |
| 9099 | } |
| 9100 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 9101 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9102 | .ndo_open = i40e_open, |
| 9103 | .ndo_stop = i40e_close, |
| 9104 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 9105 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 9106 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 9107 | .ndo_validate_addr = eth_validate_addr, |
| 9108 | .ndo_set_mac_address = i40e_set_mac, |
| 9109 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 9110 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9111 | .ndo_tx_timeout = i40e_tx_timeout, |
| 9112 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 9113 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 9114 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9115 | .ndo_poll_controller = i40e_netpoll, |
| 9116 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9117 | .ndo_setup_tc = __i40e_setup_tc, |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9118 | #ifdef I40E_FCOE |
| 9119 | .ndo_fcoe_enable = i40e_fcoe_enable, |
| 9120 | .ndo_fcoe_disable = i40e_fcoe_disable, |
| 9121 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9122 | .ndo_set_features = i40e_set_features, |
| 9123 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 9124 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9125 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9126 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 9127 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 9128 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Anjali Singhai Jain | c3bbbd2 | 2016-04-01 03:56:07 -0700 | [diff] [blame] | 9129 | .ndo_set_vf_trust = i40e_ndo_set_vf_trust, |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9130 | .ndo_udp_tunnel_add = i40e_udp_tunnel_add, |
| 9131 | .ndo_udp_tunnel_del = i40e_udp_tunnel_del, |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9132 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9133 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9134 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9135 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 9136 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9137 | }; |
| 9138 | |
| 9139 | /** |
| 9140 | * i40e_config_netdev - Setup the netdev flags |
| 9141 | * @vsi: the VSI being configured |
| 9142 | * |
| 9143 | * Returns 0 on success, negative value on failure |
| 9144 | **/ |
| 9145 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 9146 | { |
| 9147 | struct i40e_pf *pf = vsi->back; |
| 9148 | struct i40e_hw *hw = &pf->hw; |
| 9149 | struct i40e_netdev_priv *np; |
| 9150 | struct net_device *netdev; |
| 9151 | u8 mac_addr[ETH_ALEN]; |
| 9152 | int etherdev_size; |
| 9153 | |
| 9154 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9155 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9156 | if (!netdev) |
| 9157 | return -ENOMEM; |
| 9158 | |
| 9159 | vsi->netdev = netdev; |
| 9160 | np = netdev_priv(netdev); |
| 9161 | np->vsi = vsi; |
| 9162 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9163 | netdev->hw_enc_features |= NETIF_F_SG | |
| 9164 | NETIF_F_IP_CSUM | |
| 9165 | NETIF_F_IPV6_CSUM | |
| 9166 | NETIF_F_HIGHDMA | |
| 9167 | NETIF_F_SOFT_FEATURES | |
| 9168 | NETIF_F_TSO | |
| 9169 | NETIF_F_TSO_ECN | |
| 9170 | NETIF_F_TSO6 | |
| 9171 | NETIF_F_GSO_GRE | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9172 | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 9173 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 9174 | NETIF_F_GSO_IPXIP6 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9175 | NETIF_F_GSO_UDP_TUNNEL | |
| 9176 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9177 | NETIF_F_GSO_PARTIAL | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9178 | NETIF_F_SCTP_CRC | |
| 9179 | NETIF_F_RXHASH | |
| 9180 | NETIF_F_RXCSUM | |
Jesse Brandeburg | 5afdaaa | 2015-12-10 11:38:50 -0800 | [diff] [blame] | 9181 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9182 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9183 | if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)) |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9184 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
| 9185 | |
| 9186 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9187 | |
| 9188 | /* record features VLANs can make use of */ |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9189 | netdev->vlan_features |= netdev->hw_enc_features | |
| 9190 | NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9191 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9192 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9193 | netdev->hw_features |= NETIF_F_NTUPLE; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9194 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9195 | netdev->hw_features |= netdev->hw_enc_features | |
| 9196 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9197 | NETIF_F_HW_VLAN_CTAG_RX; |
| 9198 | |
| 9199 | netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9200 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9201 | |
| 9202 | if (vsi->type == I40E_VSI_MAIN) { |
| 9203 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9204 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9205 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 9206 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9207 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9208 | } else { |
| 9209 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 9210 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 9211 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9212 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9213 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9214 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame] | 9215 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9216 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9217 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9218 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9219 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9220 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9221 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9222 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9223 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9224 | /* Setup netdev TC information */ |
| 9225 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9226 | |
| 9227 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9228 | netdev->watchdog_timeo = 5 * HZ; |
| 9229 | i40e_set_ethtool_ops(netdev); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9230 | #ifdef I40E_FCOE |
| 9231 | i40e_fcoe_config_netdev(netdev, vsi); |
| 9232 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9233 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 9234 | /* MTU range: 68 - 9706 */ |
| 9235 | netdev->min_mtu = ETH_MIN_MTU; |
| 9236 | netdev->max_mtu = I40E_MAX_RXBUFFER - |
| 9237 | (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
| 9238 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9239 | return 0; |
| 9240 | } |
| 9241 | |
| 9242 | /** |
| 9243 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9244 | * @vsi: the VSI being removed |
| 9245 | * |
| 9246 | * Returns 0 on success, negative value on failure |
| 9247 | **/ |
| 9248 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9249 | { |
| 9250 | /* remove default VSI is not allowed */ |
| 9251 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9252 | return; |
| 9253 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9254 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9255 | } |
| 9256 | |
| 9257 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9258 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9259 | * @vsi: the VSI being queried |
| 9260 | * |
| 9261 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9262 | **/ |
| 9263 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9264 | { |
| 9265 | struct i40e_veb *veb; |
| 9266 | struct i40e_pf *pf = vsi->back; |
| 9267 | |
| 9268 | /* Uplink is not a bridge so default to VEB */ |
| 9269 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9270 | return 1; |
| 9271 | |
| 9272 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9273 | if (!veb) { |
| 9274 | dev_info(&pf->pdev->dev, |
| 9275 | "There is no veb associated with the bridge\n"); |
| 9276 | return -ENOENT; |
| 9277 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9278 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9279 | /* Uplink is a bridge in VEPA mode */ |
| 9280 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9281 | return 0; |
| 9282 | } else { |
| 9283 | /* Uplink is a bridge in VEB mode */ |
| 9284 | return 1; |
| 9285 | } |
| 9286 | |
| 9287 | /* VEPA is now default bridge, so return 0 */ |
| 9288 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9289 | } |
| 9290 | |
| 9291 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9292 | * i40e_add_vsi - Add a VSI to the switch |
| 9293 | * @vsi: the VSI being configured |
| 9294 | * |
| 9295 | * This initializes a VSI context depending on the VSI type to be added and |
| 9296 | * passes it down to the add_vsi aq command. |
| 9297 | **/ |
| 9298 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9299 | { |
| 9300 | int ret = -ENODEV; |
Kiran Patil | f6bd096 | 2016-06-20 09:10:34 -0700 | [diff] [blame] | 9301 | i40e_status aq_ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9302 | struct i40e_pf *pf = vsi->back; |
| 9303 | struct i40e_hw *hw = &pf->hw; |
| 9304 | struct i40e_vsi_context ctxt; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9305 | struct i40e_mac_filter *f; |
| 9306 | struct hlist_node *h; |
| 9307 | int bkt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9308 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9309 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9310 | int f_count = 0; |
| 9311 | |
| 9312 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9313 | switch (vsi->type) { |
| 9314 | case I40E_VSI_MAIN: |
| 9315 | /* The PF's main VSI is already setup as part of the |
| 9316 | * device initialization, so we'll not bother with |
| 9317 | * the add_vsi call, but we will retrieve the current |
| 9318 | * VSI context. |
| 9319 | */ |
| 9320 | ctxt.seid = pf->main_vsi_seid; |
| 9321 | ctxt.pf_num = pf->hw.pf_id; |
| 9322 | ctxt.vf_num = 0; |
| 9323 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9324 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9325 | if (ret) { |
| 9326 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9327 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9328 | i40e_stat_str(&pf->hw, ret), |
| 9329 | i40e_aq_str(&pf->hw, |
| 9330 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9331 | return -ENOENT; |
| 9332 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9333 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9334 | vsi->info.valid_sections = 0; |
| 9335 | |
| 9336 | vsi->seid = ctxt.seid; |
| 9337 | vsi->id = ctxt.vsi_number; |
| 9338 | |
| 9339 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9340 | |
| 9341 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9342 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9343 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9344 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9345 | ctxt.seid = pf->main_vsi_seid; |
| 9346 | ctxt.pf_num = pf->hw.pf_id; |
| 9347 | ctxt.vf_num = 0; |
| 9348 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9349 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9350 | if (ret) { |
| 9351 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9352 | "update vsi failed, err %s aq_err %s\n", |
| 9353 | i40e_stat_str(&pf->hw, ret), |
| 9354 | i40e_aq_str(&pf->hw, |
| 9355 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9356 | ret = -ENOENT; |
| 9357 | goto err; |
| 9358 | } |
| 9359 | /* update the local VSI info queue map */ |
| 9360 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9361 | vsi->info.valid_sections = 0; |
| 9362 | } else { |
| 9363 | /* Default/Main VSI is only enabled for TC0 |
| 9364 | * reconfigure it to enable all TCs that are |
| 9365 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9366 | * For MFP case the iSCSI PF would use this |
| 9367 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9368 | */ |
| 9369 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9370 | if (ret) { |
| 9371 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9372 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9373 | enabled_tc, |
| 9374 | i40e_stat_str(&pf->hw, ret), |
| 9375 | i40e_aq_str(&pf->hw, |
| 9376 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9377 | ret = -ENOENT; |
| 9378 | } |
| 9379 | } |
| 9380 | break; |
| 9381 | |
| 9382 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9383 | ctxt.pf_num = hw->pf_id; |
| 9384 | ctxt.vf_num = 0; |
| 9385 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9386 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9387 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9388 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9389 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9390 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9391 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9392 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9393 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9394 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9395 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9396 | break; |
| 9397 | |
| 9398 | case I40E_VSI_VMDQ2: |
| 9399 | ctxt.pf_num = hw->pf_id; |
| 9400 | ctxt.vf_num = 0; |
| 9401 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9402 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9403 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9404 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9405 | /* This VSI is connected to VEB so the switch_id |
| 9406 | * should be set to zero by default. |
| 9407 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9408 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9409 | ctxt.info.valid_sections |= |
| 9410 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9411 | ctxt.info.switch_id = |
| 9412 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9413 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9414 | |
| 9415 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9416 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9417 | break; |
| 9418 | |
| 9419 | case I40E_VSI_SRIOV: |
| 9420 | ctxt.pf_num = hw->pf_id; |
| 9421 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9422 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9423 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9424 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9425 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9426 | /* This VSI is connected to VEB so the switch_id |
| 9427 | * should be set to zero by default. |
| 9428 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9429 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9430 | ctxt.info.valid_sections |= |
| 9431 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9432 | ctxt.info.switch_id = |
| 9433 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9434 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9435 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9436 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9437 | ctxt.info.valid_sections |= |
| 9438 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 9439 | ctxt.info.queueing_opt_flags |= |
Ashish Shah | 4b28cdb | 2016-05-03 15:13:17 -0700 | [diff] [blame] | 9440 | (I40E_AQ_VSI_QUE_OPT_TCP_ENA | |
| 9441 | I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9442 | } |
| 9443 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9444 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9445 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9446 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9447 | ctxt.info.valid_sections |= |
| 9448 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9449 | ctxt.info.sec_flags |= |
| 9450 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9451 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9452 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9453 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9454 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9455 | break; |
| 9456 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9457 | #ifdef I40E_FCOE |
| 9458 | case I40E_VSI_FCOE: |
| 9459 | ret = i40e_fcoe_vsi_init(vsi, &ctxt); |
| 9460 | if (ret) { |
| 9461 | dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n"); |
| 9462 | return ret; |
| 9463 | } |
| 9464 | break; |
| 9465 | |
| 9466 | #endif /* I40E_FCOE */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9467 | case I40E_VSI_IWARP: |
| 9468 | /* send down message to iWARP */ |
| 9469 | break; |
| 9470 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9471 | default: |
| 9472 | return -ENODEV; |
| 9473 | } |
| 9474 | |
| 9475 | if (vsi->type != I40E_VSI_MAIN) { |
| 9476 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9477 | if (ret) { |
| 9478 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9479 | "add vsi failed, err %s aq_err %s\n", |
| 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 | goto err; |
| 9485 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9486 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9487 | vsi->info.valid_sections = 0; |
| 9488 | vsi->seid = ctxt.seid; |
| 9489 | vsi->id = ctxt.vsi_number; |
| 9490 | } |
Kiran Patil | f6bd096 | 2016-06-20 09:10:34 -0700 | [diff] [blame] | 9491 | /* Except FDIR VSI, for all othet VSI set the broadcast filter */ |
| 9492 | if (vsi->type != I40E_VSI_FDIR) { |
| 9493 | aq_ret = i40e_aq_set_vsi_broadcast(hw, vsi->seid, true, NULL); |
| 9494 | if (aq_ret) { |
| 9495 | ret = i40e_aq_rc_to_posix(aq_ret, |
| 9496 | hw->aq.asq_last_status); |
| 9497 | dev_info(&pf->pdev->dev, |
| 9498 | "set brdcast promisc failed, err %s, aq_err %s\n", |
| 9499 | i40e_stat_str(hw, aq_ret), |
| 9500 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 9501 | } |
| 9502 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9503 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9504 | vsi->active_filters = 0; |
| 9505 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9506 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9507 | /* If macvlan filters already exist, force them to get loaded */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9508 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9509 | f->state = I40E_FILTER_NEW; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9510 | f_count++; |
| 9511 | } |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9512 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9513 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9514 | if (f_count) { |
| 9515 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 9516 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 9517 | } |
| 9518 | |
| 9519 | /* Update VSI BW information */ |
| 9520 | ret = i40e_vsi_get_bw_info(vsi); |
| 9521 | if (ret) { |
| 9522 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9523 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 9524 | i40e_stat_str(&pf->hw, ret), |
| 9525 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9526 | /* VSI is already added so not tearing that up */ |
| 9527 | ret = 0; |
| 9528 | } |
| 9529 | |
| 9530 | err: |
| 9531 | return ret; |
| 9532 | } |
| 9533 | |
| 9534 | /** |
| 9535 | * i40e_vsi_release - Delete a VSI and free its resources |
| 9536 | * @vsi: the VSI being removed |
| 9537 | * |
| 9538 | * Returns 0 on success or < 0 on error |
| 9539 | **/ |
| 9540 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 9541 | { |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9542 | struct i40e_mac_filter *f; |
| 9543 | struct hlist_node *h; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9544 | struct i40e_veb *veb = NULL; |
| 9545 | struct i40e_pf *pf; |
| 9546 | u16 uplink_seid; |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9547 | int i, n, bkt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9548 | |
| 9549 | pf = vsi->back; |
| 9550 | |
| 9551 | /* release of a VEB-owner or last VSI is not allowed */ |
| 9552 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 9553 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 9554 | vsi->seid, vsi->uplink_seid); |
| 9555 | return -ENODEV; |
| 9556 | } |
| 9557 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 9558 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 9559 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 9560 | return -ENODEV; |
| 9561 | } |
| 9562 | |
| 9563 | uplink_seid = vsi->uplink_seid; |
| 9564 | if (vsi->type != I40E_VSI_SRIOV) { |
| 9565 | if (vsi->netdev_registered) { |
| 9566 | vsi->netdev_registered = false; |
| 9567 | if (vsi->netdev) { |
| 9568 | /* results in a call to i40e_close() */ |
| 9569 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9570 | } |
| 9571 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 9572 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9573 | } |
| 9574 | i40e_vsi_disable_irq(vsi); |
| 9575 | } |
| 9576 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9577 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 9578 | |
| 9579 | /* clear the sync flag on all filters */ |
| 9580 | if (vsi->netdev) { |
| 9581 | __dev_uc_unsync(vsi->netdev, NULL); |
| 9582 | __dev_mc_unsync(vsi->netdev, NULL); |
| 9583 | } |
| 9584 | |
| 9585 | /* make sure any remaining filters are marked for deletion */ |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9586 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) |
Jacob Keller | 290d255 | 2016-10-05 09:30:36 -0700 | [diff] [blame] | 9587 | __i40e_del_filter(vsi, f); |
Jacob Keller | 6622f5c | 2016-10-05 09:30:32 -0700 | [diff] [blame] | 9588 | |
Jacob Keller | 278e7d0 | 2016-10-05 09:30:37 -0700 | [diff] [blame] | 9589 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9590 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 9591 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9592 | |
| 9593 | i40e_vsi_delete(vsi); |
| 9594 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 9595 | if (vsi->netdev) { |
| 9596 | free_netdev(vsi->netdev); |
| 9597 | vsi->netdev = NULL; |
| 9598 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9599 | i40e_vsi_clear_rings(vsi); |
| 9600 | i40e_vsi_clear(vsi); |
| 9601 | |
| 9602 | /* If this was the last thing on the VEB, except for the |
| 9603 | * controlling VSI, remove the VEB, which puts the controlling |
| 9604 | * VSI onto the next level down in the switch. |
| 9605 | * |
| 9606 | * Well, okay, there's one more exception here: don't remove |
| 9607 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 9608 | * from up the network stack. |
| 9609 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9610 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9611 | if (pf->vsi[i] && |
| 9612 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 9613 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9614 | n++; /* count the VSIs */ |
| 9615 | } |
| 9616 | } |
| 9617 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9618 | if (!pf->veb[i]) |
| 9619 | continue; |
| 9620 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 9621 | n++; /* count the VEBs */ |
| 9622 | if (pf->veb[i]->seid == uplink_seid) |
| 9623 | veb = pf->veb[i]; |
| 9624 | } |
| 9625 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 9626 | i40e_veb_release(veb); |
| 9627 | |
| 9628 | return 0; |
| 9629 | } |
| 9630 | |
| 9631 | /** |
| 9632 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 9633 | * @vsi: ptr to the VSI |
| 9634 | * |
| 9635 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 9636 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 9637 | * newly allocated VSI. |
| 9638 | * |
| 9639 | * Returns 0 on success or negative on failure |
| 9640 | **/ |
| 9641 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 9642 | { |
| 9643 | int ret = -ENOENT; |
| 9644 | struct i40e_pf *pf = vsi->back; |
| 9645 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9646 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9647 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 9648 | vsi->seid); |
| 9649 | return -EEXIST; |
| 9650 | } |
| 9651 | |
| 9652 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 9653 | 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] | 9654 | vsi->seid, vsi->base_vector); |
| 9655 | return -EEXIST; |
| 9656 | } |
| 9657 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9658 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9659 | if (ret) { |
| 9660 | dev_info(&pf->pdev->dev, |
| 9661 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 9662 | vsi->num_q_vectors, vsi->seid, ret); |
| 9663 | vsi->num_q_vectors = 0; |
| 9664 | goto vector_setup_out; |
| 9665 | } |
| 9666 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 9667 | /* In Legacy mode, we do not have to get any other vector since we |
| 9668 | * piggyback on the misc/ICR0 for queue interrupts. |
| 9669 | */ |
| 9670 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9671 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9672 | if (vsi->num_q_vectors) |
| 9673 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 9674 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9675 | if (vsi->base_vector < 0) { |
| 9676 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9677 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 9678 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9679 | i40e_vsi_free_q_vectors(vsi); |
| 9680 | ret = -ENOENT; |
| 9681 | goto vector_setup_out; |
| 9682 | } |
| 9683 | |
| 9684 | vector_setup_out: |
| 9685 | return ret; |
| 9686 | } |
| 9687 | |
| 9688 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9689 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 9690 | * @vsi: pointer to the vsi. |
| 9691 | * |
| 9692 | * This re-allocates a vsi's queue resources. |
| 9693 | * |
| 9694 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 9695 | * on success, otherwise returns NULL on failure. |
| 9696 | **/ |
| 9697 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 9698 | { |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9699 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9700 | u8 enabled_tc; |
| 9701 | int ret; |
| 9702 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9703 | if (!vsi) |
| 9704 | return NULL; |
| 9705 | |
| 9706 | pf = vsi->back; |
| 9707 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9708 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9709 | i40e_vsi_clear_rings(vsi); |
| 9710 | |
| 9711 | i40e_vsi_free_arrays(vsi, false); |
| 9712 | i40e_set_num_rings_in_vsi(vsi); |
| 9713 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 9714 | if (ret) |
| 9715 | goto err_vsi; |
| 9716 | |
| 9717 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 9718 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9719 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9720 | "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] | 9721 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9722 | goto err_vsi; |
| 9723 | } |
| 9724 | vsi->base_queue = ret; |
| 9725 | |
| 9726 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 9727 | * layout configurations. |
| 9728 | */ |
| 9729 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9730 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9731 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9732 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 9733 | |
| 9734 | /* assign it some queues */ |
| 9735 | ret = i40e_alloc_rings(vsi); |
| 9736 | if (ret) |
| 9737 | goto err_rings; |
| 9738 | |
| 9739 | /* map all of the rings to the q_vectors */ |
| 9740 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9741 | return vsi; |
| 9742 | |
| 9743 | err_rings: |
| 9744 | i40e_vsi_free_q_vectors(vsi); |
| 9745 | if (vsi->netdev_registered) { |
| 9746 | vsi->netdev_registered = false; |
| 9747 | unregister_netdev(vsi->netdev); |
| 9748 | free_netdev(vsi->netdev); |
| 9749 | vsi->netdev = NULL; |
| 9750 | } |
| 9751 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9752 | err_vsi: |
| 9753 | i40e_vsi_clear(vsi); |
| 9754 | return NULL; |
| 9755 | } |
| 9756 | |
| 9757 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9758 | * i40e_vsi_setup - Set up a VSI by a given type |
| 9759 | * @pf: board private structure |
| 9760 | * @type: VSI type |
| 9761 | * @uplink_seid: the switch element to link to |
| 9762 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 9763 | * |
| 9764 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 9765 | * to the identified VEB. |
| 9766 | * |
| 9767 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 9768 | * success, otherwise returns NULL on failure. |
| 9769 | **/ |
| 9770 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 9771 | u16 uplink_seid, u32 param1) |
| 9772 | { |
| 9773 | struct i40e_vsi *vsi = NULL; |
| 9774 | struct i40e_veb *veb = NULL; |
| 9775 | int ret, i; |
| 9776 | int v_idx; |
| 9777 | |
| 9778 | /* The requested uplink_seid must be either |
| 9779 | * - the PF's port seid |
| 9780 | * no VEB is needed because this is the PF |
| 9781 | * or this is a Flow Director special case VSI |
| 9782 | * - seid of an existing VEB |
| 9783 | * - seid of a VSI that owns an existing VEB |
| 9784 | * - seid of a VSI that doesn't own a VEB |
| 9785 | * a new VEB is created and the VSI becomes the owner |
| 9786 | * - seid of the PF VSI, which is what creates the first VEB |
| 9787 | * this is a special case of the previous |
| 9788 | * |
| 9789 | * Find which uplink_seid we were given and create a new VEB if needed |
| 9790 | */ |
| 9791 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9792 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 9793 | veb = pf->veb[i]; |
| 9794 | break; |
| 9795 | } |
| 9796 | } |
| 9797 | |
| 9798 | if (!veb && uplink_seid != pf->mac_seid) { |
| 9799 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9800 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9801 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 9802 | vsi = pf->vsi[i]; |
| 9803 | break; |
| 9804 | } |
| 9805 | } |
| 9806 | if (!vsi) { |
| 9807 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 9808 | uplink_seid); |
| 9809 | return NULL; |
| 9810 | } |
| 9811 | |
| 9812 | if (vsi->uplink_seid == pf->mac_seid) |
| 9813 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 9814 | vsi->tc_config.enabled_tc); |
| 9815 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 9816 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9817 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9818 | if (veb) { |
| 9819 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 9820 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 9821 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9822 | return NULL; |
| 9823 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 9824 | /* We come up by default in VEPA mode if SRIOV is not |
| 9825 | * already enabled, in which case we can't force VEPA |
| 9826 | * mode. |
| 9827 | */ |
| 9828 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 9829 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 9830 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9831 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9832 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9833 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9834 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9835 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9836 | veb = pf->veb[i]; |
| 9837 | } |
| 9838 | if (!veb) { |
| 9839 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 9840 | return NULL; |
| 9841 | } |
| 9842 | |
| 9843 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 9844 | uplink_seid = veb->seid; |
| 9845 | } |
| 9846 | |
| 9847 | /* get vsi sw struct */ |
| 9848 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 9849 | if (v_idx < 0) |
| 9850 | goto err_alloc; |
| 9851 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9852 | if (!vsi) |
| 9853 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9854 | vsi->type = type; |
| 9855 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 9856 | |
| 9857 | if (type == I40E_VSI_MAIN) |
| 9858 | pf->lan_vsi = v_idx; |
| 9859 | else if (type == I40E_VSI_SRIOV) |
| 9860 | vsi->vf_id = param1; |
| 9861 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9862 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 9863 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9864 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9865 | dev_info(&pf->pdev->dev, |
| 9866 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 9867 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9868 | goto err_vsi; |
| 9869 | } |
| 9870 | vsi->base_queue = ret; |
| 9871 | |
| 9872 | /* get a VSI from the hardware */ |
| 9873 | vsi->uplink_seid = uplink_seid; |
| 9874 | ret = i40e_add_vsi(vsi); |
| 9875 | if (ret) |
| 9876 | goto err_vsi; |
| 9877 | |
| 9878 | switch (vsi->type) { |
| 9879 | /* setup the netdev if needed */ |
| 9880 | case I40E_VSI_MAIN: |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9881 | /* Apply relevant filters if a platform-specific mac |
| 9882 | * address was selected. |
| 9883 | */ |
| 9884 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 9885 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 9886 | if (ret) { |
| 9887 | dev_warn(&pf->pdev->dev, |
| 9888 | "could not set up macaddr; err %d\n", |
| 9889 | ret); |
| 9890 | } |
| 9891 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9892 | case I40E_VSI_VMDQ2: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9893 | case I40E_VSI_FCOE: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9894 | ret = i40e_config_netdev(vsi); |
| 9895 | if (ret) |
| 9896 | goto err_netdev; |
| 9897 | ret = register_netdev(vsi->netdev); |
| 9898 | if (ret) |
| 9899 | goto err_netdev; |
| 9900 | vsi->netdev_registered = true; |
| 9901 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9902 | #ifdef CONFIG_I40E_DCB |
| 9903 | /* Setup DCB netlink interface */ |
| 9904 | i40e_dcbnl_setup(vsi); |
| 9905 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9906 | /* fall through */ |
| 9907 | |
| 9908 | case I40E_VSI_FDIR: |
| 9909 | /* set up vectors and rings if needed */ |
| 9910 | ret = i40e_vsi_setup_vectors(vsi); |
| 9911 | if (ret) |
| 9912 | goto err_msix; |
| 9913 | |
| 9914 | ret = i40e_alloc_rings(vsi); |
| 9915 | if (ret) |
| 9916 | goto err_rings; |
| 9917 | |
| 9918 | /* map all of the rings to the q_vectors */ |
| 9919 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9920 | |
| 9921 | i40e_vsi_reset_stats(vsi); |
| 9922 | break; |
| 9923 | |
| 9924 | default: |
| 9925 | /* no netdev or rings for the other VSI types */ |
| 9926 | break; |
| 9927 | } |
| 9928 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9929 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
| 9930 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 9931 | ret = i40e_vsi_config_rss(vsi); |
| 9932 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9933 | return vsi; |
| 9934 | |
| 9935 | err_rings: |
| 9936 | i40e_vsi_free_q_vectors(vsi); |
| 9937 | err_msix: |
| 9938 | if (vsi->netdev_registered) { |
| 9939 | vsi->netdev_registered = false; |
| 9940 | unregister_netdev(vsi->netdev); |
| 9941 | free_netdev(vsi->netdev); |
| 9942 | vsi->netdev = NULL; |
| 9943 | } |
| 9944 | err_netdev: |
| 9945 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9946 | err_vsi: |
| 9947 | i40e_vsi_clear(vsi); |
| 9948 | err_alloc: |
| 9949 | return NULL; |
| 9950 | } |
| 9951 | |
| 9952 | /** |
| 9953 | * i40e_veb_get_bw_info - Query VEB BW information |
| 9954 | * @veb: the veb to query |
| 9955 | * |
| 9956 | * Query the Tx scheduler BW configuration data for given VEB |
| 9957 | **/ |
| 9958 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 9959 | { |
| 9960 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 9961 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 9962 | struct i40e_pf *pf = veb->pf; |
| 9963 | struct i40e_hw *hw = &pf->hw; |
| 9964 | u32 tc_bw_max; |
| 9965 | int ret = 0; |
| 9966 | int i; |
| 9967 | |
| 9968 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 9969 | &bw_data, NULL); |
| 9970 | if (ret) { |
| 9971 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9972 | "query veb bw config failed, err %s aq_err %s\n", |
| 9973 | i40e_stat_str(&pf->hw, ret), |
| 9974 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9975 | goto out; |
| 9976 | } |
| 9977 | |
| 9978 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 9979 | &ets_data, NULL); |
| 9980 | if (ret) { |
| 9981 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9982 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 9983 | i40e_stat_str(&pf->hw, ret), |
| 9984 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9985 | goto out; |
| 9986 | } |
| 9987 | |
| 9988 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 9989 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 9990 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 9991 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9992 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 9993 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 9994 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 9995 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 9996 | veb->bw_tc_limit_credits[i] = |
| 9997 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 9998 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 9999 | } |
| 10000 | |
| 10001 | out: |
| 10002 | return ret; |
| 10003 | } |
| 10004 | |
| 10005 | /** |
| 10006 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 10007 | * @pf: board private structure |
| 10008 | * |
| 10009 | * On error: returns error code (negative) |
| 10010 | * On success: returns vsi index in PF (positive) |
| 10011 | **/ |
| 10012 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 10013 | { |
| 10014 | int ret = -ENOENT; |
| 10015 | struct i40e_veb *veb; |
| 10016 | int i; |
| 10017 | |
| 10018 | /* Need to protect the allocation of switch elements at the PF level */ |
| 10019 | mutex_lock(&pf->switch_mutex); |
| 10020 | |
| 10021 | /* VEB list may be fragmented if VEB creation/destruction has |
| 10022 | * been happening. We can afford to do a quick scan to look |
| 10023 | * for any free slots in the list. |
| 10024 | * |
| 10025 | * find next empty veb slot, looping back around if necessary |
| 10026 | */ |
| 10027 | i = 0; |
| 10028 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 10029 | i++; |
| 10030 | if (i >= I40E_MAX_VEB) { |
| 10031 | ret = -ENOMEM; |
| 10032 | goto err_alloc_veb; /* out of VEB slots! */ |
| 10033 | } |
| 10034 | |
| 10035 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 10036 | if (!veb) { |
| 10037 | ret = -ENOMEM; |
| 10038 | goto err_alloc_veb; |
| 10039 | } |
| 10040 | veb->pf = pf; |
| 10041 | veb->idx = i; |
| 10042 | veb->enabled_tc = 1; |
| 10043 | |
| 10044 | pf->veb[i] = veb; |
| 10045 | ret = i; |
| 10046 | err_alloc_veb: |
| 10047 | mutex_unlock(&pf->switch_mutex); |
| 10048 | return ret; |
| 10049 | } |
| 10050 | |
| 10051 | /** |
| 10052 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 10053 | * @branch: where to start deleting |
| 10054 | * |
| 10055 | * This uses recursion to find the tips of the branch to be |
| 10056 | * removed, deleting until we get back to and can delete this VEB. |
| 10057 | **/ |
| 10058 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 10059 | { |
| 10060 | struct i40e_pf *pf = branch->pf; |
| 10061 | u16 branch_seid = branch->seid; |
| 10062 | u16 veb_idx = branch->idx; |
| 10063 | int i; |
| 10064 | |
| 10065 | /* release any VEBs on this VEB - RECURSION */ |
| 10066 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10067 | if (!pf->veb[i]) |
| 10068 | continue; |
| 10069 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 10070 | i40e_switch_branch_release(pf->veb[i]); |
| 10071 | } |
| 10072 | |
| 10073 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 10074 | * |
| 10075 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 10076 | * the VEB itself, so don't use (*branch) after this loop. |
| 10077 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10078 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10079 | if (!pf->vsi[i]) |
| 10080 | continue; |
| 10081 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 10082 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 10083 | i40e_vsi_release(pf->vsi[i]); |
| 10084 | } |
| 10085 | } |
| 10086 | |
| 10087 | /* There's one corner case where the VEB might not have been |
| 10088 | * removed, so double check it here and remove it if needed. |
| 10089 | * This case happens if the veb was created from the debugfs |
| 10090 | * commands and no VSIs were added to it. |
| 10091 | */ |
| 10092 | if (pf->veb[veb_idx]) |
| 10093 | i40e_veb_release(pf->veb[veb_idx]); |
| 10094 | } |
| 10095 | |
| 10096 | /** |
| 10097 | * i40e_veb_clear - remove veb struct |
| 10098 | * @veb: the veb to remove |
| 10099 | **/ |
| 10100 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 10101 | { |
| 10102 | if (!veb) |
| 10103 | return; |
| 10104 | |
| 10105 | if (veb->pf) { |
| 10106 | struct i40e_pf *pf = veb->pf; |
| 10107 | |
| 10108 | mutex_lock(&pf->switch_mutex); |
| 10109 | if (pf->veb[veb->idx] == veb) |
| 10110 | pf->veb[veb->idx] = NULL; |
| 10111 | mutex_unlock(&pf->switch_mutex); |
| 10112 | } |
| 10113 | |
| 10114 | kfree(veb); |
| 10115 | } |
| 10116 | |
| 10117 | /** |
| 10118 | * i40e_veb_release - Delete a VEB and free its resources |
| 10119 | * @veb: the VEB being removed |
| 10120 | **/ |
| 10121 | void i40e_veb_release(struct i40e_veb *veb) |
| 10122 | { |
| 10123 | struct i40e_vsi *vsi = NULL; |
| 10124 | struct i40e_pf *pf; |
| 10125 | int i, n = 0; |
| 10126 | |
| 10127 | pf = veb->pf; |
| 10128 | |
| 10129 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10130 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10131 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 10132 | n++; |
| 10133 | vsi = pf->vsi[i]; |
| 10134 | } |
| 10135 | } |
| 10136 | if (n != 1) { |
| 10137 | dev_info(&pf->pdev->dev, |
| 10138 | "can't remove VEB %d with %d VSIs left\n", |
| 10139 | veb->seid, n); |
| 10140 | return; |
| 10141 | } |
| 10142 | |
| 10143 | /* move the remaining VSI to uplink veb */ |
| 10144 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10145 | if (veb->uplink_seid) { |
| 10146 | vsi->uplink_seid = veb->uplink_seid; |
| 10147 | if (veb->uplink_seid == pf->mac_seid) |
| 10148 | vsi->veb_idx = I40E_NO_VEB; |
| 10149 | else |
| 10150 | vsi->veb_idx = veb->veb_idx; |
| 10151 | } else { |
| 10152 | /* floating VEB */ |
| 10153 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10154 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10155 | } |
| 10156 | |
| 10157 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10158 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10159 | } |
| 10160 | |
| 10161 | /** |
| 10162 | * i40e_add_veb - create the VEB in the switch |
| 10163 | * @veb: the VEB to be instantiated |
| 10164 | * @vsi: the controlling VSI |
| 10165 | **/ |
| 10166 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10167 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10168 | struct i40e_pf *pf = veb->pf; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10169 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10170 | int ret; |
| 10171 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10172 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10173 | veb->enabled_tc, false, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10174 | &veb->seid, enable_stats, NULL); |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10175 | |
| 10176 | /* get a VEB from the hardware */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10177 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10178 | dev_info(&pf->pdev->dev, |
| 10179 | "couldn't add VEB, err %s aq_err %s\n", |
| 10180 | i40e_stat_str(&pf->hw, ret), |
| 10181 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10182 | return -EPERM; |
| 10183 | } |
| 10184 | |
| 10185 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10186 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10187 | &veb->stats_idx, NULL, NULL, NULL); |
| 10188 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10189 | dev_info(&pf->pdev->dev, |
| 10190 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10191 | i40e_stat_str(&pf->hw, ret), |
| 10192 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10193 | return -EPERM; |
| 10194 | } |
| 10195 | ret = i40e_veb_get_bw_info(veb); |
| 10196 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10197 | dev_info(&pf->pdev->dev, |
| 10198 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10199 | i40e_stat_str(&pf->hw, ret), |
| 10200 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10201 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10202 | return -ENOENT; |
| 10203 | } |
| 10204 | |
| 10205 | vsi->uplink_seid = veb->seid; |
| 10206 | vsi->veb_idx = veb->idx; |
| 10207 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10208 | |
| 10209 | return 0; |
| 10210 | } |
| 10211 | |
| 10212 | /** |
| 10213 | * i40e_veb_setup - Set up a VEB |
| 10214 | * @pf: board private structure |
| 10215 | * @flags: VEB setup flags |
| 10216 | * @uplink_seid: the switch element to link to |
| 10217 | * @vsi_seid: the initial VSI seid |
| 10218 | * @enabled_tc: Enabled TC bit-map |
| 10219 | * |
| 10220 | * This allocates the sw VEB structure and links it into the switch |
| 10221 | * It is possible and legal for this to be a duplicate of an already |
| 10222 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10223 | * to be zero, in order to create a floating VEB. |
| 10224 | * |
| 10225 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10226 | * success, otherwise returns NULL on failure. |
| 10227 | **/ |
| 10228 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10229 | u16 uplink_seid, u16 vsi_seid, |
| 10230 | u8 enabled_tc) |
| 10231 | { |
| 10232 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10233 | int vsi_idx, veb_idx; |
| 10234 | int ret; |
| 10235 | |
| 10236 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10237 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10238 | (uplink_seid + vsi_seid != 0)) { |
| 10239 | dev_info(&pf->pdev->dev, |
| 10240 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10241 | uplink_seid, vsi_seid); |
| 10242 | return NULL; |
| 10243 | } |
| 10244 | |
| 10245 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10246 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10247 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10248 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10249 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10250 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10251 | vsi_seid); |
| 10252 | return NULL; |
| 10253 | } |
| 10254 | |
| 10255 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10256 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10257 | if (pf->veb[veb_idx] && |
| 10258 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10259 | uplink_veb = pf->veb[veb_idx]; |
| 10260 | break; |
| 10261 | } |
| 10262 | } |
| 10263 | if (!uplink_veb) { |
| 10264 | dev_info(&pf->pdev->dev, |
| 10265 | "uplink seid %d not found\n", uplink_seid); |
| 10266 | return NULL; |
| 10267 | } |
| 10268 | } |
| 10269 | |
| 10270 | /* get veb sw struct */ |
| 10271 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10272 | if (veb_idx < 0) |
| 10273 | goto err_alloc; |
| 10274 | veb = pf->veb[veb_idx]; |
| 10275 | veb->flags = flags; |
| 10276 | veb->uplink_seid = uplink_seid; |
| 10277 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10278 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10279 | |
| 10280 | /* create the VEB in the switch */ |
| 10281 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10282 | if (ret) |
| 10283 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10284 | if (vsi_idx == pf->lan_vsi) |
| 10285 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10286 | |
| 10287 | return veb; |
| 10288 | |
| 10289 | err_veb: |
| 10290 | i40e_veb_clear(veb); |
| 10291 | err_alloc: |
| 10292 | return NULL; |
| 10293 | } |
| 10294 | |
| 10295 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10296 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10297 | * @pf: board private structure |
| 10298 | * @ele: element we are building info from |
| 10299 | * @num_reported: total number of elements |
| 10300 | * @printconfig: should we print the contents |
| 10301 | * |
| 10302 | * helper function to assist in extracting a few useful SEID values. |
| 10303 | **/ |
| 10304 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10305 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10306 | u16 num_reported, bool printconfig) |
| 10307 | { |
| 10308 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10309 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10310 | u8 element_type = ele->element_type; |
| 10311 | u16 seid = le16_to_cpu(ele->seid); |
| 10312 | |
| 10313 | if (printconfig) |
| 10314 | dev_info(&pf->pdev->dev, |
| 10315 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10316 | element_type, seid, uplink_seid, downlink_seid); |
| 10317 | |
| 10318 | switch (element_type) { |
| 10319 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10320 | pf->mac_seid = seid; |
| 10321 | break; |
| 10322 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10323 | /* Main VEB? */ |
| 10324 | if (uplink_seid != pf->mac_seid) |
| 10325 | break; |
| 10326 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10327 | int v; |
| 10328 | |
| 10329 | /* find existing or else empty VEB */ |
| 10330 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10331 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10332 | pf->lan_veb = v; |
| 10333 | break; |
| 10334 | } |
| 10335 | } |
| 10336 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10337 | v = i40e_veb_mem_alloc(pf); |
| 10338 | if (v < 0) |
| 10339 | break; |
| 10340 | pf->lan_veb = v; |
| 10341 | } |
| 10342 | } |
| 10343 | |
| 10344 | pf->veb[pf->lan_veb]->seid = seid; |
| 10345 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10346 | pf->veb[pf->lan_veb]->pf = pf; |
| 10347 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10348 | break; |
| 10349 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10350 | if (num_reported != 1) |
| 10351 | break; |
| 10352 | /* This is immediately after a reset so we can assume this is |
| 10353 | * the PF's VSI |
| 10354 | */ |
| 10355 | pf->mac_seid = uplink_seid; |
| 10356 | pf->pf_seid = downlink_seid; |
| 10357 | pf->main_vsi_seid = seid; |
| 10358 | if (printconfig) |
| 10359 | dev_info(&pf->pdev->dev, |
| 10360 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10361 | pf->pf_seid, pf->main_vsi_seid); |
| 10362 | break; |
| 10363 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10364 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10365 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10366 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10367 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10368 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10369 | /* ignore these for now */ |
| 10370 | break; |
| 10371 | default: |
| 10372 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10373 | element_type, seid); |
| 10374 | break; |
| 10375 | } |
| 10376 | } |
| 10377 | |
| 10378 | /** |
| 10379 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10380 | * @pf: board private structure |
| 10381 | * @printconfig: should we print the contents |
| 10382 | * |
| 10383 | * Get the current switch configuration from the device and |
| 10384 | * extract a few useful SEID values. |
| 10385 | **/ |
| 10386 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10387 | { |
| 10388 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10389 | u16 next_seid = 0; |
| 10390 | int ret = 0; |
| 10391 | u8 *aq_buf; |
| 10392 | int i; |
| 10393 | |
| 10394 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10395 | if (!aq_buf) |
| 10396 | return -ENOMEM; |
| 10397 | |
| 10398 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10399 | do { |
| 10400 | u16 num_reported, num_total; |
| 10401 | |
| 10402 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10403 | I40E_AQ_LARGE_BUF, |
| 10404 | &next_seid, NULL); |
| 10405 | if (ret) { |
| 10406 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10407 | "get switch config failed err %s aq_err %s\n", |
| 10408 | i40e_stat_str(&pf->hw, ret), |
| 10409 | i40e_aq_str(&pf->hw, |
| 10410 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10411 | kfree(aq_buf); |
| 10412 | return -ENOENT; |
| 10413 | } |
| 10414 | |
| 10415 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10416 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10417 | |
| 10418 | if (printconfig) |
| 10419 | dev_info(&pf->pdev->dev, |
| 10420 | "header: %d reported %d total\n", |
| 10421 | num_reported, num_total); |
| 10422 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10423 | for (i = 0; i < num_reported; i++) { |
| 10424 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10425 | &sw_config->element[i]; |
| 10426 | |
| 10427 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10428 | printconfig); |
| 10429 | } |
| 10430 | } while (next_seid != 0); |
| 10431 | |
| 10432 | kfree(aq_buf); |
| 10433 | return ret; |
| 10434 | } |
| 10435 | |
| 10436 | /** |
| 10437 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10438 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10439 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10440 | * |
| 10441 | * Returns 0 on success, negative value on failure |
| 10442 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10443 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10444 | { |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10445 | u16 flags = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10446 | int ret; |
| 10447 | |
| 10448 | /* find out what's out there already */ |
| 10449 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10450 | if (ret) { |
| 10451 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10452 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10453 | i40e_stat_str(&pf->hw, ret), |
| 10454 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10455 | return ret; |
| 10456 | } |
| 10457 | i40e_pf_reset_stats(pf); |
| 10458 | |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10459 | /* set the switch config bit for the whole device to |
| 10460 | * support limited promisc or true promisc |
| 10461 | * when user requests promisc. The default is limited |
| 10462 | * promisc. |
| 10463 | */ |
| 10464 | |
| 10465 | if ((pf->hw.pf_id == 0) && |
| 10466 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) |
| 10467 | flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10468 | |
| 10469 | if (pf->hw.pf_id == 0) { |
| 10470 | u16 valid_flags; |
| 10471 | |
| 10472 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10473 | ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, |
| 10474 | NULL); |
| 10475 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { |
| 10476 | dev_info(&pf->pdev->dev, |
| 10477 | "couldn't set switch config bits, err %s aq_err %s\n", |
| 10478 | i40e_stat_str(&pf->hw, ret), |
| 10479 | i40e_aq_str(&pf->hw, |
| 10480 | pf->hw.aq.asq_last_status)); |
| 10481 | /* not a fatal problem, just keep going */ |
| 10482 | } |
| 10483 | } |
| 10484 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10485 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10486 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10487 | struct i40e_vsi *vsi = NULL; |
| 10488 | u16 uplink_seid; |
| 10489 | |
| 10490 | /* Set up the PF VSI associated with the PF's main VSI |
| 10491 | * that is already in the HW switch |
| 10492 | */ |
| 10493 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10494 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10495 | else |
| 10496 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10497 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10498 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10499 | else if (reinit) |
| 10500 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10501 | if (!vsi) { |
| 10502 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10503 | i40e_fdir_teardown(pf); |
| 10504 | return -EAGAIN; |
| 10505 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10506 | } else { |
| 10507 | /* force a reset of TC and queue layout configurations */ |
| 10508 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10509 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10510 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10511 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10512 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10513 | } |
| 10514 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 10515 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10516 | i40e_fdir_sb_setup(pf); |
| 10517 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10518 | /* Setup static PF queue filter control settings */ |
| 10519 | ret = i40e_setup_pf_filter_control(pf); |
| 10520 | if (ret) { |
| 10521 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 10522 | ret); |
| 10523 | /* Failure here should not stop continuing other steps */ |
| 10524 | } |
| 10525 | |
| 10526 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 10527 | * the hash |
| 10528 | */ |
| 10529 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 10530 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10531 | |
| 10532 | /* fill in link information and enable LSE reporting */ |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 10533 | i40e_update_link_info(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10534 | i40e_link_event(pf); |
| 10535 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10536 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10537 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 10538 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10539 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10540 | i40e_ptp_init(pf); |
| 10541 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10542 | return ret; |
| 10543 | } |
| 10544 | |
| 10545 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10546 | * i40e_determine_queue_usage - Work out queue distribution |
| 10547 | * @pf: board private structure |
| 10548 | **/ |
| 10549 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 10550 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10551 | int queues_left; |
| 10552 | |
| 10553 | pf->num_lan_qps = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10554 | #ifdef I40E_FCOE |
| 10555 | pf->num_fcoe_qps = 0; |
| 10556 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10557 | |
| 10558 | /* Find the max queues to be put into basic use. We'll always be |
| 10559 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 10560 | * big RSS set. |
| 10561 | */ |
| 10562 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 10563 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10564 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10565 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10566 | /* one qp for PF, no queues for anything else */ |
| 10567 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10568 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10569 | |
| 10570 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10571 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10572 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10573 | #ifdef I40E_FCOE |
| 10574 | I40E_FLAG_FCOE_ENABLED | |
| 10575 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10576 | I40E_FLAG_FD_SB_ENABLED | |
| 10577 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10578 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 10579 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10580 | I40E_FLAG_SRIOV_ENABLED | |
| 10581 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10582 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 10583 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 10584 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10585 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10586 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10587 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10588 | queues_left -= pf->num_lan_qps; |
| 10589 | |
| 10590 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10591 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10592 | #ifdef I40E_FCOE |
| 10593 | I40E_FLAG_FCOE_ENABLED | |
| 10594 | #endif |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10595 | I40E_FLAG_FD_SB_ENABLED | |
| 10596 | I40E_FLAG_FD_ATR_ENABLED | |
| 10597 | I40E_FLAG_DCB_ENABLED | |
| 10598 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10599 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10600 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10601 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10602 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 10603 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | |
| 10604 | I40E_FLAG_DCB_ENABLED); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10605 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 10606 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 10607 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 10608 | num_online_cpus()); |
| 10609 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 10610 | pf->hw.func_caps.num_tx_qp); |
| 10611 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10612 | queues_left -= pf->num_lan_qps; |
| 10613 | } |
| 10614 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10615 | #ifdef I40E_FCOE |
| 10616 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 10617 | if (I40E_DEFAULT_FCOE <= queues_left) { |
| 10618 | pf->num_fcoe_qps = I40E_DEFAULT_FCOE; |
| 10619 | } else if (I40E_MINIMUM_FCOE <= queues_left) { |
| 10620 | pf->num_fcoe_qps = I40E_MINIMUM_FCOE; |
| 10621 | } else { |
| 10622 | pf->num_fcoe_qps = 0; |
| 10623 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 10624 | dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n"); |
| 10625 | } |
| 10626 | |
| 10627 | queues_left -= pf->num_fcoe_qps; |
| 10628 | } |
| 10629 | |
| 10630 | #endif |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10631 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10632 | if (queues_left > 1) { |
| 10633 | queues_left -= 1; /* save 1 queue for FD */ |
| 10634 | } else { |
| 10635 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 10636 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 10637 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10638 | } |
| 10639 | |
| 10640 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10641 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10642 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 10643 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10644 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 10645 | } |
| 10646 | |
| 10647 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 10648 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 10649 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 10650 | (queues_left / pf->num_vmdq_qps)); |
| 10651 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 10652 | } |
| 10653 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10654 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10655 | dev_dbg(&pf->pdev->dev, |
| 10656 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 10657 | pf->hw.func_caps.num_tx_qp, |
| 10658 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10659 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 10660 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 10661 | queues_left); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10662 | #ifdef I40E_FCOE |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10663 | 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] | 10664 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10665 | } |
| 10666 | |
| 10667 | /** |
| 10668 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 10669 | * @pf: PF to be setup |
| 10670 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10671 | * 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] | 10672 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 10673 | * based filter sizes required for them. It also enables Flow director, |
| 10674 | * ethertype and macvlan type filter settings for the pf. |
| 10675 | * |
| 10676 | * Returns 0 on success, negative on failure |
| 10677 | **/ |
| 10678 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 10679 | { |
| 10680 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 10681 | |
| 10682 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 10683 | |
| 10684 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10685 | 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] | 10686 | settings->enable_fdir = true; |
| 10687 | |
| 10688 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 10689 | settings->enable_ethtype = true; |
| 10690 | settings->enable_macvlan = true; |
| 10691 | |
| 10692 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 10693 | return -ENOENT; |
| 10694 | |
| 10695 | return 0; |
| 10696 | } |
| 10697 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10698 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10699 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10700 | static void i40e_print_features(struct i40e_pf *pf) |
| 10701 | { |
| 10702 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10703 | char *buf; |
| 10704 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10705 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10706 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 10707 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10708 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10709 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10710 | 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] | 10711 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10712 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10713 | #endif |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10714 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10715 | pf->hw.func_caps.num_vsis, |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10716 | pf->vsi[pf->lan_vsi]->num_queue_pairs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10717 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10718 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10719 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10720 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10721 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10722 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 10723 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10724 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10725 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10726 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10727 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10728 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10729 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10730 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10731 | #ifdef I40E_FCOE |
| 10732 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10733 | i += snprintf(&buf[i], REMAIN(i), " FCOE"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10734 | #endif |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10735 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10736 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10737 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10738 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10739 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10740 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 10741 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10742 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10743 | } |
| 10744 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10745 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10746 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
| 10747 | * |
| 10748 | * @pdev: PCI device information struct |
| 10749 | * @pf: board private structure |
| 10750 | * |
| 10751 | * Look up the MAC address in Open Firmware on systems that support it, |
| 10752 | * and use IDPROM on SPARC if no OF address is found. On return, the |
| 10753 | * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value |
| 10754 | * has been selected. |
| 10755 | **/ |
| 10756 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 10757 | { |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10758 | pf->flags &= ~I40E_FLAG_PF_MAC; |
Sowmini Varadhan | ba94272 | 2016-01-12 19:32:31 -0800 | [diff] [blame] | 10759 | if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10760 | pf->flags |= I40E_FLAG_PF_MAC; |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10761 | } |
| 10762 | |
| 10763 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10764 | * i40e_probe - Device initialization routine |
| 10765 | * @pdev: PCI device information struct |
| 10766 | * @ent: entry in i40e_pci_tbl |
| 10767 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10768 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 10769 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10770 | * and a hardware reset occur. |
| 10771 | * |
| 10772 | * Returns 0 on success, negative on failure |
| 10773 | **/ |
| 10774 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 10775 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 10776 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10777 | struct i40e_pf *pf; |
| 10778 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10779 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10780 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10781 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 10782 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10783 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10784 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10785 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10786 | |
| 10787 | err = pci_enable_device_mem(pdev); |
| 10788 | if (err) |
| 10789 | return err; |
| 10790 | |
| 10791 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10792 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10793 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 10794 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10795 | if (err) { |
| 10796 | dev_err(&pdev->dev, |
| 10797 | "DMA configuration failed: 0x%x\n", err); |
| 10798 | goto err_dma; |
| 10799 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10800 | } |
| 10801 | |
| 10802 | /* set up pci connections */ |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10803 | err = pci_request_mem_regions(pdev, i40e_driver_name); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10804 | if (err) { |
| 10805 | dev_info(&pdev->dev, |
| 10806 | "pci_request_selected_regions failed %d\n", err); |
| 10807 | goto err_pci_reg; |
| 10808 | } |
| 10809 | |
| 10810 | pci_enable_pcie_error_reporting(pdev); |
| 10811 | pci_set_master(pdev); |
| 10812 | |
| 10813 | /* Now that we have a PCI connection, we need to do the |
| 10814 | * low level device setup. This is primarily setting up |
| 10815 | * the Admin Queue structures and then querying for the |
| 10816 | * device's current profile information. |
| 10817 | */ |
| 10818 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 10819 | if (!pf) { |
| 10820 | err = -ENOMEM; |
| 10821 | goto err_pf_alloc; |
| 10822 | } |
| 10823 | pf->next_vsi = 0; |
| 10824 | pf->pdev = pdev; |
| 10825 | set_bit(__I40E_DOWN, &pf->state); |
| 10826 | |
| 10827 | hw = &pf->hw; |
| 10828 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10829 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10830 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 10831 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10832 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10833 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10834 | if (!hw->hw_addr) { |
| 10835 | err = -EIO; |
| 10836 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 10837 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10838 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10839 | goto err_ioremap; |
| 10840 | } |
| 10841 | hw->vendor_id = pdev->vendor; |
| 10842 | hw->device_id = pdev->device; |
| 10843 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 10844 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 10845 | hw->subsystem_device_id = pdev->subsystem_device; |
| 10846 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 10847 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10848 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10849 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 10850 | /* set up the locks for the AQ, do this only once in probe |
| 10851 | * and destroy them only once in remove |
| 10852 | */ |
| 10853 | mutex_init(&hw->aq.asq_mutex); |
| 10854 | mutex_init(&hw->aq.arq_mutex); |
| 10855 | |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 10856 | pf->msg_enable = netif_msg_init(debug, |
| 10857 | NETIF_MSG_DRV | |
| 10858 | NETIF_MSG_PROBE | |
| 10859 | NETIF_MSG_LINK); |
| 10860 | if (debug < -1) |
| 10861 | pf->hw.debug_mask = debug; |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 10862 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10863 | /* do a special CORER for clearing PXE mode once at init */ |
| 10864 | if (hw->revision_id == 0 && |
| 10865 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 10866 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 10867 | i40e_flush(hw); |
| 10868 | msleep(200); |
| 10869 | pf->corer_count++; |
| 10870 | |
| 10871 | i40e_clear_pxe_mode(hw); |
| 10872 | } |
| 10873 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10874 | /* 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] | 10875 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10876 | err = i40e_pf_reset(hw); |
| 10877 | if (err) { |
| 10878 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 10879 | goto err_pf_reset; |
| 10880 | } |
| 10881 | pf->pfr_count++; |
| 10882 | |
| 10883 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 10884 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 10885 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10886 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10887 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10888 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 10889 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10890 | "%s-%s:misc", |
| 10891 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10892 | |
| 10893 | err = i40e_init_shared_code(hw); |
| 10894 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 10895 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 10896 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10897 | goto err_pf_reset; |
| 10898 | } |
| 10899 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10900 | /* set up a default setting for link flow control */ |
| 10901 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 10902 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10903 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 10904 | if (err) { |
| 10905 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 10906 | dev_info(&pdev->dev, |
| 10907 | "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"); |
| 10908 | else |
| 10909 | dev_info(&pdev->dev, |
| 10910 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 10911 | |
| 10912 | goto err_pf_reset; |
| 10913 | } |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10914 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10915 | /* provide nvm, fw, api versions */ |
| 10916 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 10917 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 10918 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 10919 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10920 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10921 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 10922 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10923 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10924 | "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"); |
| 10925 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 10926 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10927 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10928 | "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] | 10929 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 10930 | i40e_verify_eeprom(pf); |
| 10931 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 10932 | /* Rev 0 hardware was never productized */ |
| 10933 | if (hw->revision_id < 1) |
| 10934 | 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"); |
| 10935 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 10936 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10937 | err = i40e_get_capabilities(pf); |
| 10938 | if (err) |
| 10939 | goto err_adminq_setup; |
| 10940 | |
| 10941 | err = i40e_sw_init(pf); |
| 10942 | if (err) { |
| 10943 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 10944 | goto err_sw_init; |
| 10945 | } |
| 10946 | |
| 10947 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 10948 | hw->func_caps.num_rx_qp, |
| 10949 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 10950 | if (err) { |
| 10951 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 10952 | goto err_init_lan_hmc; |
| 10953 | } |
| 10954 | |
| 10955 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 10956 | if (err) { |
| 10957 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 10958 | err = -ENOENT; |
| 10959 | goto err_configure_lan_hmc; |
| 10960 | } |
| 10961 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10962 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 10963 | * Ignore error return codes because if it was already disabled via |
| 10964 | * hardware settings this will fail |
| 10965 | */ |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 10966 | if (pf->flags & I40E_FLAG_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10967 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 10968 | i40e_aq_stop_lldp(hw, true, NULL); |
| 10969 | } |
| 10970 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10971 | i40e_get_mac_addr(hw, hw->mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10972 | /* allow a platform config to override the HW addr */ |
| 10973 | i40e_get_platform_mac_addr(pdev, pf); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 10974 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10975 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 10976 | err = -EIO; |
| 10977 | goto err_mac_addr; |
| 10978 | } |
| 10979 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 10980 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10981 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 10982 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 10983 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10984 | #ifdef I40E_FCOE |
| 10985 | err = i40e_get_san_mac_addr(hw, hw->mac.san_addr); |
| 10986 | if (err) |
| 10987 | dev_info(&pdev->dev, |
| 10988 | "(non-fatal) SAN MAC retrieval failed: %d\n", err); |
| 10989 | if (!is_valid_ether_addr(hw->mac.san_addr)) { |
| 10990 | dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n", |
| 10991 | hw->mac.san_addr); |
| 10992 | ether_addr_copy(hw->mac.san_addr, hw->mac.addr); |
| 10993 | } |
| 10994 | dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr); |
| 10995 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10996 | |
| 10997 | pci_set_drvdata(pdev, pf); |
| 10998 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10999 | #ifdef CONFIG_I40E_DCB |
| 11000 | err = i40e_init_pf_dcb(pf); |
| 11001 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 11002 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
David Ertman | c17ef43 | 2016-09-30 01:36:21 -0700 | [diff] [blame] | 11003 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED); |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 11004 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 11005 | } |
| 11006 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11007 | |
| 11008 | /* set up periodic task facility */ |
| 11009 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 11010 | pf->service_timer_period = HZ; |
| 11011 | |
| 11012 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 11013 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 11014 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11015 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11016 | /* NVM bit on means WoL disabled for the port */ |
| 11017 | 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] | 11018 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11019 | pf->wol_en = false; |
| 11020 | else |
| 11021 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11022 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 11023 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11024 | /* set up the main switch operations */ |
| 11025 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 11026 | err = i40e_init_interrupt_scheme(pf); |
| 11027 | if (err) |
| 11028 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11029 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11030 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 11031 | * to us; HW supports far more and we share the remaining pool with |
| 11032 | * the other PFs. We allocate space for more than the guarantee with |
| 11033 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11034 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11035 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 11036 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 11037 | else |
| 11038 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 11039 | |
| 11040 | /* 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] | 11041 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 11042 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11043 | if (!pf->vsi) { |
| 11044 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11045 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11046 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11047 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 11048 | #ifdef CONFIG_PCI_IOV |
| 11049 | /* prep for VF support */ |
| 11050 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 11051 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11052 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 11053 | if (pci_num_vf(pdev)) |
| 11054 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 11055 | } |
| 11056 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11057 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11058 | if (err) { |
| 11059 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 11060 | goto err_vsis; |
| 11061 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11062 | |
| 11063 | /* Make sure flow control is set according to current settings */ |
| 11064 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 11065 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 11066 | dev_dbg(&pf->pdev->dev, |
| 11067 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 11068 | i40e_stat_str(hw, err), |
| 11069 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11070 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 11071 | dev_dbg(&pf->pdev->dev, |
| 11072 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 11073 | i40e_stat_str(hw, err), |
| 11074 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11075 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 11076 | dev_dbg(&pf->pdev->dev, |
| 11077 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 11078 | i40e_stat_str(hw, err), |
| 11079 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11080 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11081 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11082 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11083 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 11084 | i40e_vsi_open(pf->vsi[i]); |
| 11085 | break; |
| 11086 | } |
| 11087 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11088 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11089 | /* The driver only wants link up/down and module qualification |
| 11090 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11091 | */ |
| 11092 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11093 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 11094 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11095 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11096 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11097 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 11098 | i40e_stat_str(&pf->hw, err), |
| 11099 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11100 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11101 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 11102 | * of TSO, so that we avoid the MDD being fired and causing |
| 11103 | * a reset in the case of small MSS+TSO. |
| 11104 | */ |
| 11105 | val = rd32(hw, I40E_REG_MSS); |
| 11106 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 11107 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 11108 | val |= I40E_64BYTE_MSS; |
| 11109 | wr32(hw, I40E_REG_MSS, val); |
| 11110 | } |
| 11111 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 11112 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 11113 | msleep(75); |
| 11114 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 11115 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11116 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 11117 | i40e_stat_str(&pf->hw, err), |
| 11118 | i40e_aq_str(&pf->hw, |
| 11119 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 11120 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11121 | /* The main driver is (mostly) up and happy. We need to set this state |
| 11122 | * before setting up the misc vector or we get a race and the vector |
| 11123 | * ends up disabled forever. |
| 11124 | */ |
| 11125 | clear_bit(__I40E_DOWN, &pf->state); |
| 11126 | |
| 11127 | /* In case of MSIX we are going to setup the misc vector right here |
| 11128 | * to handle admin queue events etc. In case of legacy and MSI |
| 11129 | * the misc functionality and queue processing is combined in |
| 11130 | * the same vector and that gets setup at open. |
| 11131 | */ |
| 11132 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 11133 | err = i40e_setup_misc_vector(pf); |
| 11134 | if (err) { |
| 11135 | dev_info(&pdev->dev, |
| 11136 | "setup of misc vector failed: %d\n", err); |
| 11137 | goto err_vsis; |
| 11138 | } |
| 11139 | } |
| 11140 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11141 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11142 | /* prep for VF support */ |
| 11143 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11144 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11145 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11146 | /* disable link interrupts for VFs */ |
| 11147 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11148 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11149 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11150 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11151 | |
| 11152 | if (pci_num_vf(pdev)) { |
| 11153 | dev_info(&pdev->dev, |
| 11154 | "Active VFs found, allocating resources.\n"); |
| 11155 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11156 | if (err) |
| 11157 | dev_info(&pdev->dev, |
| 11158 | "Error %d allocating resources for existing VFs\n", |
| 11159 | err); |
| 11160 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11161 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11162 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11163 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11164 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11165 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11166 | pf->num_iwarp_msix, |
| 11167 | I40E_IWARP_IRQ_PILE_ID); |
| 11168 | if (pf->iwarp_base_vector < 0) { |
| 11169 | dev_info(&pdev->dev, |
| 11170 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 11171 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 11172 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 11173 | } |
| 11174 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11175 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11176 | i40e_dbg_pf_init(pf); |
| 11177 | |
| 11178 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11179 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11180 | |
| 11181 | /* since everything's happy, start the service_task timer */ |
| 11182 | mod_timer(&pf->service_timer, |
| 11183 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11184 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11185 | /* add this PF to client device list and launch a client service task */ |
| 11186 | err = i40e_lan_add_device(pf); |
| 11187 | if (err) |
| 11188 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 11189 | err); |
| 11190 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11191 | #ifdef I40E_FCOE |
| 11192 | /* create FCoE interface */ |
| 11193 | i40e_fcoe_vsi_setup(pf); |
| 11194 | |
| 11195 | #endif |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11196 | #define PCI_SPEED_SIZE 8 |
| 11197 | #define PCI_WIDTH_SIZE 8 |
| 11198 | /* Devices on the IOSF bus do not have this information |
| 11199 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11200 | * checking them. |
| 11201 | */ |
| 11202 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { |
| 11203 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11204 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11205 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11206 | /* Get the negotiated link width and speed from PCI config |
| 11207 | * space |
| 11208 | */ |
| 11209 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11210 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11211 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11212 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11213 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11214 | switch (hw->bus.speed) { |
| 11215 | case i40e_bus_speed_8000: |
| 11216 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11217 | case i40e_bus_speed_5000: |
| 11218 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11219 | case i40e_bus_speed_2500: |
| 11220 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11221 | default: |
| 11222 | break; |
| 11223 | } |
| 11224 | switch (hw->bus.width) { |
| 11225 | case i40e_bus_width_pcie_x8: |
| 11226 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11227 | case i40e_bus_width_pcie_x4: |
| 11228 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11229 | case i40e_bus_width_pcie_x2: |
| 11230 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11231 | case i40e_bus_width_pcie_x1: |
| 11232 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11233 | default: |
| 11234 | break; |
| 11235 | } |
| 11236 | |
| 11237 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11238 | speed, width); |
| 11239 | |
| 11240 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11241 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11242 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11243 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11244 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11245 | } |
| 11246 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11247 | /* get the requested speeds from the fw */ |
| 11248 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11249 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11250 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11251 | i40e_stat_str(&pf->hw, err), |
| 11252 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11253 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11254 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11255 | /* get the supported phy types from the fw */ |
| 11256 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11257 | if (err) |
| 11258 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11259 | i40e_stat_str(&pf->hw, err), |
| 11260 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 11261 | pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type); |
| 11262 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11263 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11264 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11265 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11266 | * PF/VF VSIs. |
| 11267 | * The FW can still send Flow control frames if enabled. |
| 11268 | */ |
| 11269 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11270 | pf->main_vsi_seid); |
| 11271 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 11272 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
| 11273 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
| 11274 | pf->flags |= I40E_FLAG_HAVE_10GBASET_PHY; |
| 11275 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11276 | /* print a string summarizing features */ |
| 11277 | i40e_print_features(pf); |
| 11278 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11279 | return 0; |
| 11280 | |
| 11281 | /* Unwind what we've done if something failed in the setup */ |
| 11282 | err_vsis: |
| 11283 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11284 | i40e_clear_interrupt_scheme(pf); |
| 11285 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11286 | err_switch_setup: |
| 11287 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11288 | del_timer_sync(&pf->service_timer); |
| 11289 | err_mac_addr: |
| 11290 | err_configure_lan_hmc: |
| 11291 | (void)i40e_shutdown_lan_hmc(hw); |
| 11292 | err_init_lan_hmc: |
| 11293 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11294 | err_sw_init: |
| 11295 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11296 | err_pf_reset: |
| 11297 | iounmap(hw->hw_addr); |
| 11298 | err_ioremap: |
| 11299 | kfree(pf); |
| 11300 | err_pf_alloc: |
| 11301 | pci_disable_pcie_error_reporting(pdev); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11302 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11303 | err_pci_reg: |
| 11304 | err_dma: |
| 11305 | pci_disable_device(pdev); |
| 11306 | return err; |
| 11307 | } |
| 11308 | |
| 11309 | /** |
| 11310 | * i40e_remove - Device removal routine |
| 11311 | * @pdev: PCI device information struct |
| 11312 | * |
| 11313 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11314 | * that is should release a PCI device. This could be caused by a |
| 11315 | * Hot-Plug event, or because the driver is going to be removed from |
| 11316 | * memory. |
| 11317 | **/ |
| 11318 | static void i40e_remove(struct pci_dev *pdev) |
| 11319 | { |
| 11320 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11321 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11322 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11323 | int i; |
| 11324 | |
| 11325 | i40e_dbg_pf_exit(pf); |
| 11326 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11327 | i40e_ptp_stop(pf); |
| 11328 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11329 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 11330 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 11331 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11332 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11333 | /* no more scheduling of any task */ |
Pandi Kumar Maharajan | a4618ec | 2016-02-18 09:19:25 -0800 | [diff] [blame] | 11334 | set_bit(__I40E_SUSPENDED, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11335 | set_bit(__I40E_DOWN, &pf->state); |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 11336 | if (pf->service_timer.data) |
| 11337 | del_timer_sync(&pf->service_timer); |
| 11338 | if (pf->service_task.func) |
| 11339 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11340 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11341 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11342 | i40e_free_vfs(pf); |
| 11343 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11344 | } |
| 11345 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11346 | i40e_fdir_teardown(pf); |
| 11347 | |
| 11348 | /* If there is a switch structure or any orphans, remove them. |
| 11349 | * This will leave only the PF's VSI remaining. |
| 11350 | */ |
| 11351 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11352 | if (!pf->veb[i]) |
| 11353 | continue; |
| 11354 | |
| 11355 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11356 | pf->veb[i]->uplink_seid == 0) |
| 11357 | i40e_switch_branch_release(pf->veb[i]); |
| 11358 | } |
| 11359 | |
| 11360 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11361 | * adminq and hmc. |
| 11362 | */ |
| 11363 | if (pf->vsi[pf->lan_vsi]) |
| 11364 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11365 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11366 | /* remove attached clients */ |
| 11367 | ret_code = i40e_lan_del_device(pf); |
| 11368 | if (ret_code) { |
| 11369 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 11370 | ret_code); |
| 11371 | } |
| 11372 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11373 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11374 | if (hw->hmc.hmc_obj) { |
| 11375 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11376 | if (ret_code) |
| 11377 | dev_warn(&pdev->dev, |
| 11378 | "Failed to destroy the HMC resources: %d\n", |
| 11379 | ret_code); |
| 11380 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11381 | |
| 11382 | /* shutdown the adminq */ |
Henry Tieman | ac9c5c6 | 2016-09-06 18:05:11 -0700 | [diff] [blame] | 11383 | i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11384 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11385 | /* destroy the locks only once, here */ |
| 11386 | mutex_destroy(&hw->aq.arq_mutex); |
| 11387 | mutex_destroy(&hw->aq.asq_mutex); |
| 11388 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11389 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11390 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11391 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11392 | if (pf->vsi[i]) { |
| 11393 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11394 | i40e_vsi_clear(pf->vsi[i]); |
| 11395 | pf->vsi[i] = NULL; |
| 11396 | } |
| 11397 | } |
| 11398 | |
| 11399 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11400 | kfree(pf->veb[i]); |
| 11401 | pf->veb[i] = NULL; |
| 11402 | } |
| 11403 | |
| 11404 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11405 | kfree(pf->vsi); |
| 11406 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11407 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11408 | kfree(pf); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11409 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11410 | |
| 11411 | pci_disable_pcie_error_reporting(pdev); |
| 11412 | pci_disable_device(pdev); |
| 11413 | } |
| 11414 | |
| 11415 | /** |
| 11416 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11417 | * @pdev: PCI device information struct |
| 11418 | * |
| 11419 | * Called to warn that something happened and the error handling steps |
| 11420 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11421 | * remediation. |
| 11422 | **/ |
| 11423 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11424 | enum pci_channel_state error) |
| 11425 | { |
| 11426 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11427 | |
| 11428 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11429 | |
Guilherme G Piccoli | edfc23ee | 2016-10-03 00:31:12 -0700 | [diff] [blame] | 11430 | if (!pf) { |
| 11431 | dev_info(&pdev->dev, |
| 11432 | "Cannot recover - error happened during device probe\n"); |
| 11433 | return PCI_ERS_RESULT_DISCONNECT; |
| 11434 | } |
| 11435 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11436 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11437 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11438 | rtnl_lock(); |
| 11439 | i40e_prep_for_reset(pf); |
| 11440 | rtnl_unlock(); |
| 11441 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11442 | |
| 11443 | /* Request a slot reset */ |
| 11444 | return PCI_ERS_RESULT_NEED_RESET; |
| 11445 | } |
| 11446 | |
| 11447 | /** |
| 11448 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11449 | * @pdev: PCI device information struct |
| 11450 | * |
| 11451 | * Called to find if the driver can work with the device now that |
| 11452 | * the pci slot has been reset. If a basic connection seems good |
| 11453 | * (registers are readable and have sane content) then return a |
| 11454 | * happy little PCI_ERS_RESULT_xxx. |
| 11455 | **/ |
| 11456 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11457 | { |
| 11458 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11459 | pci_ers_result_t result; |
| 11460 | int err; |
| 11461 | u32 reg; |
| 11462 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11463 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11464 | if (pci_enable_device_mem(pdev)) { |
| 11465 | dev_info(&pdev->dev, |
| 11466 | "Cannot re-enable PCI device after reset.\n"); |
| 11467 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11468 | } else { |
| 11469 | pci_set_master(pdev); |
| 11470 | pci_restore_state(pdev); |
| 11471 | pci_save_state(pdev); |
| 11472 | pci_wake_from_d3(pdev, false); |
| 11473 | |
| 11474 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11475 | if (reg == 0) |
| 11476 | result = PCI_ERS_RESULT_RECOVERED; |
| 11477 | else |
| 11478 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11479 | } |
| 11480 | |
| 11481 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11482 | if (err) { |
| 11483 | dev_info(&pdev->dev, |
| 11484 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11485 | err); |
| 11486 | /* non-fatal, continue */ |
| 11487 | } |
| 11488 | |
| 11489 | return result; |
| 11490 | } |
| 11491 | |
| 11492 | /** |
| 11493 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11494 | * @pdev: PCI device information struct |
| 11495 | * |
| 11496 | * Called to allow the driver to bring things back up after PCI error |
| 11497 | * and/or reset recovery has finished. |
| 11498 | **/ |
| 11499 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11500 | { |
| 11501 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11502 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11503 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11504 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 11505 | return; |
| 11506 | |
| 11507 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11508 | i40e_handle_reset_warning(pf); |
Vasily Averin | 4c4935a | 2015-07-08 15:04:26 +0300 | [diff] [blame] | 11509 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11510 | } |
| 11511 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11512 | /** |
| 11513 | * i40e_shutdown - PCI callback for shutting down |
| 11514 | * @pdev: PCI device information struct |
| 11515 | **/ |
| 11516 | static void i40e_shutdown(struct pci_dev *pdev) |
| 11517 | { |
| 11518 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11519 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11520 | |
| 11521 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11522 | set_bit(__I40E_DOWN, &pf->state); |
| 11523 | rtnl_lock(); |
| 11524 | i40e_prep_for_reset(pf); |
| 11525 | rtnl_unlock(); |
| 11526 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11527 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11528 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11529 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11530 | del_timer_sync(&pf->service_timer); |
| 11531 | cancel_work_sync(&pf->service_task); |
| 11532 | i40e_fdir_teardown(pf); |
| 11533 | |
| 11534 | rtnl_lock(); |
| 11535 | i40e_prep_for_reset(pf); |
| 11536 | rtnl_unlock(); |
| 11537 | |
| 11538 | wr32(hw, I40E_PFPM_APM, |
| 11539 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11540 | wr32(hw, I40E_PFPM_WUFC, |
| 11541 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11542 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 11543 | i40e_clear_interrupt_scheme(pf); |
| 11544 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11545 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11546 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11547 | pci_set_power_state(pdev, PCI_D3hot); |
| 11548 | } |
| 11549 | } |
| 11550 | |
| 11551 | #ifdef CONFIG_PM |
| 11552 | /** |
| 11553 | * i40e_suspend - PCI callback for moving to D3 |
| 11554 | * @pdev: PCI device information struct |
| 11555 | **/ |
| 11556 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11557 | { |
| 11558 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11559 | struct i40e_hw *hw = &pf->hw; |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11560 | int retval = 0; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11561 | |
| 11562 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11563 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 11564 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11565 | rtnl_lock(); |
| 11566 | i40e_prep_for_reset(pf); |
| 11567 | rtnl_unlock(); |
| 11568 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11569 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11570 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11571 | |
Greg Rose | b33d3b7 | 2016-05-16 10:26:37 -0700 | [diff] [blame] | 11572 | i40e_stop_misc_vector(pf); |
| 11573 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11574 | retval = pci_save_state(pdev); |
| 11575 | if (retval) |
| 11576 | return retval; |
| 11577 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11578 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11579 | pci_set_power_state(pdev, PCI_D3hot); |
| 11580 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11581 | return retval; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11582 | } |
| 11583 | |
| 11584 | /** |
| 11585 | * i40e_resume - PCI callback for waking up from D3 |
| 11586 | * @pdev: PCI device information struct |
| 11587 | **/ |
| 11588 | static int i40e_resume(struct pci_dev *pdev) |
| 11589 | { |
| 11590 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11591 | u32 err; |
| 11592 | |
| 11593 | pci_set_power_state(pdev, PCI_D0); |
| 11594 | pci_restore_state(pdev); |
| 11595 | /* pci_restore_state() clears dev->state_saves, so |
| 11596 | * call pci_save_state() again to restore it. |
| 11597 | */ |
| 11598 | pci_save_state(pdev); |
| 11599 | |
| 11600 | err = pci_enable_device_mem(pdev); |
| 11601 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11602 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11603 | return err; |
| 11604 | } |
| 11605 | pci_set_master(pdev); |
| 11606 | |
| 11607 | /* no wakeup events while running */ |
| 11608 | pci_wake_from_d3(pdev, false); |
| 11609 | |
| 11610 | /* handling the reset will rebuild the device state */ |
| 11611 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11612 | clear_bit(__I40E_DOWN, &pf->state); |
| 11613 | rtnl_lock(); |
| 11614 | i40e_reset_and_rebuild(pf, false); |
| 11615 | rtnl_unlock(); |
| 11616 | } |
| 11617 | |
| 11618 | return 0; |
| 11619 | } |
| 11620 | |
| 11621 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11622 | static const struct pci_error_handlers i40e_err_handler = { |
| 11623 | .error_detected = i40e_pci_error_detected, |
| 11624 | .slot_reset = i40e_pci_error_slot_reset, |
| 11625 | .resume = i40e_pci_error_resume, |
| 11626 | }; |
| 11627 | |
| 11628 | static struct pci_driver i40e_driver = { |
| 11629 | .name = i40e_driver_name, |
| 11630 | .id_table = i40e_pci_tbl, |
| 11631 | .probe = i40e_probe, |
| 11632 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11633 | #ifdef CONFIG_PM |
| 11634 | .suspend = i40e_suspend, |
| 11635 | .resume = i40e_resume, |
| 11636 | #endif |
| 11637 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11638 | .err_handler = &i40e_err_handler, |
| 11639 | .sriov_configure = i40e_pci_sriov_configure, |
| 11640 | }; |
| 11641 | |
| 11642 | /** |
| 11643 | * i40e_init_module - Driver registration routine |
| 11644 | * |
| 11645 | * i40e_init_module is the first routine called when the driver is |
| 11646 | * loaded. All it does is register with the PCI subsystem. |
| 11647 | **/ |
| 11648 | static int __init i40e_init_module(void) |
| 11649 | { |
| 11650 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 11651 | i40e_driver_string, i40e_driver_version_str); |
| 11652 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 11653 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11654 | /* we will see if single thread per module is enough for now, |
| 11655 | * it can't be any worse than using the system workqueue which |
| 11656 | * was already single threaded |
| 11657 | */ |
Jacob Keller | 6992a6c | 2016-08-04 11:37:01 -0700 | [diff] [blame] | 11658 | i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1, |
| 11659 | i40e_driver_name); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11660 | if (!i40e_wq) { |
| 11661 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 11662 | return -ENOMEM; |
| 11663 | } |
| 11664 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11665 | i40e_dbg_init(); |
| 11666 | return pci_register_driver(&i40e_driver); |
| 11667 | } |
| 11668 | module_init(i40e_init_module); |
| 11669 | |
| 11670 | /** |
| 11671 | * i40e_exit_module - Driver exit cleanup routine |
| 11672 | * |
| 11673 | * i40e_exit_module is called just before the driver is removed |
| 11674 | * from memory. |
| 11675 | **/ |
| 11676 | static void __exit i40e_exit_module(void) |
| 11677 | { |
| 11678 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11679 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11680 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11681 | } |
| 11682 | module_exit(i40e_exit_module); |