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 | 93e6fa2 | 2016-07-27 12:02:41 -0700 | [diff] [blame] | 44 | #define DRV_VERSION_BUILD 12 |
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); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 60 | static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 61 | u16 rss_table_size, u16 rss_size); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 62 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 63 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 64 | |
| 65 | /* i40e_pci_tbl - PCI Device ID Table |
| 66 | * |
| 67 | * Last entry must be all 0s |
| 68 | * |
| 69 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 70 | * Class, Class Mask, private data (not used) } |
| 71 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 72 | static const struct pci_device_id i40e_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 73 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 74 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 75 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, |
| 76 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 77 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, |
| 78 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, |
| 79 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 80 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0}, |
Shannon Nelson | bc5166b9 | 2015-08-26 15:14:10 -0400 | [diff] [blame] | 81 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0}, |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 82 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
Anjali Singhai Jain | 35dae51 | 2015-12-22 14:25:03 -0800 | [diff] [blame] | 83 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0}, |
| 84 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame] | 85 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0}, |
| 86 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0}, |
| 87 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0}, |
Catherine Sullivan | d6bf58c | 2016-03-18 12:18:08 -0700 | [diff] [blame] | 88 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0}, |
Shannon Nelson | 48a3b51 | 2015-07-23 16:54:39 -0400 | [diff] [blame] | 89 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
| 90 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 91 | /* required last entry */ |
| 92 | {0, } |
| 93 | }; |
| 94 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 95 | |
| 96 | #define I40E_MAX_VF_COUNT 128 |
| 97 | static int debug = -1; |
| 98 | module_param(debug, int, 0); |
| 99 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 100 | |
| 101 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 102 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 103 | MODULE_LICENSE("GPL"); |
| 104 | MODULE_VERSION(DRV_VERSION); |
| 105 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 106 | static struct workqueue_struct *i40e_wq; |
| 107 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 108 | /** |
| 109 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 110 | * @hw: pointer to the HW structure |
| 111 | * @mem: ptr to mem struct to fill out |
| 112 | * @size: size of memory requested |
| 113 | * @alignment: what to align the allocation to |
| 114 | **/ |
| 115 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 116 | u64 size, u32 alignment) |
| 117 | { |
| 118 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 119 | |
| 120 | mem->size = ALIGN(size, alignment); |
| 121 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 122 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 123 | if (!mem->va) |
| 124 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 125 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 126 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /** |
| 130 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 131 | * @hw: pointer to the HW structure |
| 132 | * @mem: ptr to mem struct to free |
| 133 | **/ |
| 134 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 135 | { |
| 136 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 137 | |
| 138 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 139 | mem->va = NULL; |
| 140 | mem->pa = 0; |
| 141 | mem->size = 0; |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 148 | * @hw: pointer to the HW structure |
| 149 | * @mem: ptr to mem struct to fill out |
| 150 | * @size: size of memory requested |
| 151 | **/ |
| 152 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 153 | u32 size) |
| 154 | { |
| 155 | mem->size = size; |
| 156 | mem->va = kzalloc(size, GFP_KERNEL); |
| 157 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 158 | if (!mem->va) |
| 159 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 160 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 161 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /** |
| 165 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 166 | * @hw: pointer to the HW structure |
| 167 | * @mem: ptr to mem struct to free |
| 168 | **/ |
| 169 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 170 | { |
| 171 | /* it's ok to kfree a NULL pointer */ |
| 172 | kfree(mem->va); |
| 173 | mem->va = NULL; |
| 174 | mem->size = 0; |
| 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * i40e_get_lump - find a lump of free generic resource |
| 181 | * @pf: board private structure |
| 182 | * @pile: the pile of resource to search |
| 183 | * @needed: the number of items needed |
| 184 | * @id: an owner id to stick on the items assigned |
| 185 | * |
| 186 | * Returns the base item index of the lump, or negative for error |
| 187 | * |
| 188 | * The search_hint trick and lack of advanced fit-finding only work |
| 189 | * because we're highly likely to have all the same size lump requests. |
| 190 | * Linear search time and any fragmentation should be minimal. |
| 191 | **/ |
| 192 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 193 | u16 needed, u16 id) |
| 194 | { |
| 195 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 196 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 197 | |
| 198 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 199 | dev_info(&pf->pdev->dev, |
| 200 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 201 | pile, needed, id); |
| 202 | return -EINVAL; |
| 203 | } |
| 204 | |
| 205 | /* start the linear search with an imperfect hint */ |
| 206 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 207 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 208 | /* skip already allocated entries */ |
| 209 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 210 | i++; |
| 211 | continue; |
| 212 | } |
| 213 | |
| 214 | /* do we have enough in this lump? */ |
| 215 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 216 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 217 | break; |
| 218 | } |
| 219 | |
| 220 | if (j == needed) { |
| 221 | /* there was enough, so assign it to the requestor */ |
| 222 | for (j = 0; j < needed; j++) |
| 223 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 224 | ret = i; |
| 225 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 226 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 227 | } |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 228 | |
| 229 | /* not enough, so skip over it and continue looking */ |
| 230 | i += j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | return ret; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * i40e_put_lump - return a lump of generic resource |
| 238 | * @pile: the pile of resource to search |
| 239 | * @index: the base item index |
| 240 | * @id: the owner id of the items assigned |
| 241 | * |
| 242 | * Returns the count of items in the lump |
| 243 | **/ |
| 244 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 245 | { |
| 246 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 247 | int count = 0; |
| 248 | int i; |
| 249 | |
| 250 | if (!pile || index >= pile->num_entries) |
| 251 | return -EINVAL; |
| 252 | |
| 253 | for (i = index; |
| 254 | i < pile->num_entries && pile->list[i] == valid_id; |
| 255 | i++) { |
| 256 | pile->list[i] = 0; |
| 257 | count++; |
| 258 | } |
| 259 | |
| 260 | if (count && index < pile->search_hint) |
| 261 | pile->search_hint = index; |
| 262 | |
| 263 | return count; |
| 264 | } |
| 265 | |
| 266 | /** |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 267 | * i40e_find_vsi_from_id - searches for the vsi with the given id |
| 268 | * @pf - the pf structure to search for the vsi |
| 269 | * @id - id of the vsi it is searching for |
| 270 | **/ |
| 271 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) |
| 272 | { |
| 273 | int i; |
| 274 | |
| 275 | for (i = 0; i < pf->num_alloc_vsi; i++) |
| 276 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) |
| 277 | return pf->vsi[i]; |
| 278 | |
| 279 | return NULL; |
| 280 | } |
| 281 | |
| 282 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 283 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 284 | * @pf: board private structure |
| 285 | * |
| 286 | * If not already scheduled, this puts the task into the work queue |
| 287 | **/ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 288 | void i40e_service_event_schedule(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 289 | { |
| 290 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 291 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && |
| 292 | !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 293 | queue_work(i40e_wq, &pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | /** |
| 297 | * i40e_tx_timeout - Respond to a Tx Hang |
| 298 | * @netdev: network interface device structure |
| 299 | * |
| 300 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 301 | * device is munged, not just the one netdev port, so go for the full |
| 302 | * reset. |
| 303 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 304 | #ifdef I40E_FCOE |
| 305 | void i40e_tx_timeout(struct net_device *netdev) |
| 306 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 307 | static void i40e_tx_timeout(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 308 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 309 | { |
| 310 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 311 | struct i40e_vsi *vsi = np->vsi; |
| 312 | struct i40e_pf *pf = vsi->back; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 313 | struct i40e_ring *tx_ring = NULL; |
| 314 | unsigned int i, hung_queue = 0; |
| 315 | u32 head, val; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 316 | |
| 317 | pf->tx_timeout_count++; |
| 318 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 319 | /* find the stopped queue the same way the stack does */ |
| 320 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 321 | struct netdev_queue *q; |
| 322 | unsigned long trans_start; |
| 323 | |
| 324 | q = netdev_get_tx_queue(netdev, i); |
Florian Westphal | 9b36627 | 2016-05-03 16:33:14 +0200 | [diff] [blame] | 325 | trans_start = q->trans_start; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 326 | if (netif_xmit_stopped(q) && |
| 327 | time_after(jiffies, |
| 328 | (trans_start + netdev->watchdog_timeo))) { |
| 329 | hung_queue = i; |
| 330 | break; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | if (i == netdev->num_tx_queues) { |
| 335 | netdev_info(netdev, "tx_timeout: no netdev hung queue found\n"); |
| 336 | } else { |
| 337 | /* now that we have an index, find the tx_ring struct */ |
| 338 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 339 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 340 | if (hung_queue == |
| 341 | vsi->tx_rings[i]->queue_index) { |
| 342 | tx_ring = vsi->tx_rings[i]; |
| 343 | break; |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 349 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 350 | pf->tx_timeout_recovery_level = 1; /* reset after some time */ |
| 351 | else if (time_before(jiffies, |
| 352 | (pf->tx_timeout_last_recovery + netdev->watchdog_timeo))) |
| 353 | return; /* don't do any new action before the next timeout */ |
| 354 | |
| 355 | if (tx_ring) { |
| 356 | head = i40e_get_head(tx_ring); |
| 357 | /* Read interrupt register */ |
| 358 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 359 | val = rd32(&pf->hw, |
| 360 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 361 | tx_ring->vsi->base_vector - 1)); |
| 362 | else |
| 363 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 364 | |
| 365 | 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", |
| 366 | vsi->seid, hung_queue, tx_ring->next_to_clean, |
| 367 | head, tx_ring->next_to_use, |
| 368 | readl(tx_ring->tail), val); |
| 369 | } |
| 370 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 371 | pf->tx_timeout_last_recovery = jiffies; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 372 | netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n", |
| 373 | pf->tx_timeout_recovery_level, hung_queue); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 374 | |
| 375 | switch (pf->tx_timeout_recovery_level) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 376 | case 1: |
| 377 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 378 | break; |
| 379 | case 2: |
| 380 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 381 | break; |
| 382 | case 3: |
| 383 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 384 | break; |
| 385 | default: |
| 386 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 387 | break; |
| 388 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 389 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 390 | i40e_service_event_schedule(pf); |
| 391 | pf->tx_timeout_recovery_level++; |
| 392 | } |
| 393 | |
| 394 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 395 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 396 | * @vsi: the VSI we care about |
| 397 | * |
| 398 | * Returns the address of the device statistics structure. |
| 399 | * The statistics are actually updated from the service task. |
| 400 | **/ |
| 401 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 402 | { |
| 403 | return &vsi->net_stats; |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 408 | * @netdev: network interface device structure |
| 409 | * |
| 410 | * Returns the address of the device statistics structure. |
| 411 | * The statistics are actually updated from the service task. |
| 412 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 413 | #ifdef I40E_FCOE |
| 414 | struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 415 | struct net_device *netdev, |
| 416 | struct rtnl_link_stats64 *stats) |
| 417 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 418 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 419 | struct net_device *netdev, |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 420 | struct rtnl_link_stats64 *stats) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 421 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 422 | { |
| 423 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 424 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 425 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 426 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 427 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 428 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 429 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 430 | return stats; |
| 431 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 432 | if (!vsi->tx_rings) |
| 433 | return stats; |
| 434 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 435 | rcu_read_lock(); |
| 436 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 437 | u64 bytes, packets; |
| 438 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 439 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 440 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 441 | if (!tx_ring) |
| 442 | continue; |
| 443 | |
| 444 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 445 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 446 | packets = tx_ring->stats.packets; |
| 447 | bytes = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 448 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 449 | |
| 450 | stats->tx_packets += packets; |
| 451 | stats->tx_bytes += bytes; |
| 452 | rx_ring = &tx_ring[1]; |
| 453 | |
| 454 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 455 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 456 | packets = rx_ring->stats.packets; |
| 457 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 458 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 459 | |
| 460 | stats->rx_packets += packets; |
| 461 | stats->rx_bytes += bytes; |
| 462 | } |
| 463 | rcu_read_unlock(); |
| 464 | |
Akeem G Abodunrin | a5282f4 | 2014-05-10 04:49:03 +0000 | [diff] [blame] | 465 | /* following stats updated by i40e_watchdog_subtask() */ |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 466 | stats->multicast = vsi_stats->multicast; |
| 467 | stats->tx_errors = vsi_stats->tx_errors; |
| 468 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 469 | stats->rx_errors = vsi_stats->rx_errors; |
Jesse Brandeburg | d8201e2 | 2015-07-23 16:54:35 -0400 | [diff] [blame] | 470 | stats->rx_dropped = vsi_stats->rx_dropped; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 471 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 472 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
| 473 | |
| 474 | return stats; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /** |
| 478 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 479 | * @vsi: the VSI to have its stats reset |
| 480 | **/ |
| 481 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 482 | { |
| 483 | struct rtnl_link_stats64 *ns; |
| 484 | int i; |
| 485 | |
| 486 | if (!vsi) |
| 487 | return; |
| 488 | |
| 489 | ns = i40e_get_vsi_stats_struct(vsi); |
| 490 | memset(ns, 0, sizeof(*ns)); |
| 491 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 492 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 493 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 494 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 495 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 496 | memset(&vsi->rx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 497 | sizeof(vsi->rx_rings[i]->stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 498 | memset(&vsi->rx_rings[i]->rx_stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 499 | sizeof(vsi->rx_rings[i]->rx_stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 500 | memset(&vsi->tx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 501 | sizeof(vsi->tx_rings[i]->stats)); |
| 502 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 503 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 504 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 505 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 506 | vsi->stat_offsets_loaded = false; |
| 507 | } |
| 508 | |
| 509 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 510 | * 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] | 511 | * @pf: the PF to be reset |
| 512 | **/ |
| 513 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 514 | { |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 515 | int i; |
| 516 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 517 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 518 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 519 | pf->stat_offsets_loaded = false; |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 520 | |
| 521 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 522 | if (pf->veb[i]) { |
| 523 | memset(&pf->veb[i]->stats, 0, |
| 524 | sizeof(pf->veb[i]->stats)); |
| 525 | memset(&pf->veb[i]->stats_offsets, 0, |
| 526 | sizeof(pf->veb[i]->stats_offsets)); |
| 527 | pf->veb[i]->stat_offsets_loaded = false; |
| 528 | } |
| 529 | } |
Catherine Sullivan | 42bce04 | 2016-07-27 12:02:32 -0700 | [diff] [blame] | 530 | pf->hw_csum_rx_error = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | /** |
| 534 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 535 | * @hw: ptr to the hardware info |
| 536 | * @hireg: the high 32 bit reg to read |
| 537 | * @loreg: the low 32 bit reg to read |
| 538 | * @offset_loaded: has the initial offset been loaded yet |
| 539 | * @offset: ptr to current offset value |
| 540 | * @stat: ptr to the stat |
| 541 | * |
| 542 | * Since the device stats are not reset at PFReset, they likely will not |
| 543 | * be zeroed when the driver starts. We'll save the first values read |
| 544 | * and use them as offsets to be subtracted from the raw values in order |
| 545 | * to report stats that count from zero. In the process, we also manage |
| 546 | * the potential roll-over. |
| 547 | **/ |
| 548 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 549 | bool offset_loaded, u64 *offset, u64 *stat) |
| 550 | { |
| 551 | u64 new_data; |
| 552 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 553 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 554 | new_data = rd32(hw, loreg); |
| 555 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 556 | } else { |
| 557 | new_data = rd64(hw, loreg); |
| 558 | } |
| 559 | if (!offset_loaded) |
| 560 | *offset = new_data; |
| 561 | if (likely(new_data >= *offset)) |
| 562 | *stat = new_data - *offset; |
| 563 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 564 | *stat = (new_data + BIT_ULL(48)) - *offset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 565 | *stat &= 0xFFFFFFFFFFFFULL; |
| 566 | } |
| 567 | |
| 568 | /** |
| 569 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 570 | * @hw: ptr to the hardware info |
| 571 | * @reg: the hw reg to read |
| 572 | * @offset_loaded: has the initial offset been loaded yet |
| 573 | * @offset: ptr to current offset value |
| 574 | * @stat: ptr to the stat |
| 575 | **/ |
| 576 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 577 | bool offset_loaded, u64 *offset, u64 *stat) |
| 578 | { |
| 579 | u32 new_data; |
| 580 | |
| 581 | new_data = rd32(hw, reg); |
| 582 | if (!offset_loaded) |
| 583 | *offset = new_data; |
| 584 | if (likely(new_data >= *offset)) |
| 585 | *stat = (u32)(new_data - *offset); |
| 586 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 587 | *stat = (u32)((new_data + BIT_ULL(32)) - *offset); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | /** |
| 591 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 592 | * @vsi: the VSI to be updated |
| 593 | **/ |
| 594 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 595 | { |
| 596 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 597 | struct i40e_pf *pf = vsi->back; |
| 598 | struct i40e_hw *hw = &pf->hw; |
| 599 | struct i40e_eth_stats *oes; |
| 600 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 601 | |
| 602 | es = &vsi->eth_stats; |
| 603 | oes = &vsi->eth_stats_offsets; |
| 604 | |
| 605 | /* Gather up the stats that the hw collects */ |
| 606 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 607 | vsi->stat_offsets_loaded, |
| 608 | &oes->tx_errors, &es->tx_errors); |
| 609 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 610 | vsi->stat_offsets_loaded, |
| 611 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 612 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 613 | vsi->stat_offsets_loaded, |
| 614 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 615 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 616 | vsi->stat_offsets_loaded, |
| 617 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 618 | |
| 619 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 620 | I40E_GLV_GORCL(stat_idx), |
| 621 | vsi->stat_offsets_loaded, |
| 622 | &oes->rx_bytes, &es->rx_bytes); |
| 623 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 624 | I40E_GLV_UPRCL(stat_idx), |
| 625 | vsi->stat_offsets_loaded, |
| 626 | &oes->rx_unicast, &es->rx_unicast); |
| 627 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 628 | I40E_GLV_MPRCL(stat_idx), |
| 629 | vsi->stat_offsets_loaded, |
| 630 | &oes->rx_multicast, &es->rx_multicast); |
| 631 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 632 | I40E_GLV_BPRCL(stat_idx), |
| 633 | vsi->stat_offsets_loaded, |
| 634 | &oes->rx_broadcast, &es->rx_broadcast); |
| 635 | |
| 636 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 637 | I40E_GLV_GOTCL(stat_idx), |
| 638 | vsi->stat_offsets_loaded, |
| 639 | &oes->tx_bytes, &es->tx_bytes); |
| 640 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 641 | I40E_GLV_UPTCL(stat_idx), |
| 642 | vsi->stat_offsets_loaded, |
| 643 | &oes->tx_unicast, &es->tx_unicast); |
| 644 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 645 | I40E_GLV_MPTCL(stat_idx), |
| 646 | vsi->stat_offsets_loaded, |
| 647 | &oes->tx_multicast, &es->tx_multicast); |
| 648 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 649 | I40E_GLV_BPTCL(stat_idx), |
| 650 | vsi->stat_offsets_loaded, |
| 651 | &oes->tx_broadcast, &es->tx_broadcast); |
| 652 | vsi->stat_offsets_loaded = true; |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * i40e_update_veb_stats - Update Switch component statistics |
| 657 | * @veb: the VEB being updated |
| 658 | **/ |
| 659 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 660 | { |
| 661 | struct i40e_pf *pf = veb->pf; |
| 662 | struct i40e_hw *hw = &pf->hw; |
| 663 | struct i40e_eth_stats *oes; |
| 664 | struct i40e_eth_stats *es; /* device's eth stats */ |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 665 | struct i40e_veb_tc_stats *veb_oes; |
| 666 | struct i40e_veb_tc_stats *veb_es; |
| 667 | int i, idx = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 668 | |
| 669 | idx = veb->stats_idx; |
| 670 | es = &veb->stats; |
| 671 | oes = &veb->stats_offsets; |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 672 | veb_es = &veb->tc_stats; |
| 673 | veb_oes = &veb->tc_stats_offsets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 674 | |
| 675 | /* Gather up the stats that the hw collects */ |
| 676 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 677 | veb->stat_offsets_loaded, |
| 678 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 679 | if (hw->revision_id > 0) |
| 680 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 681 | veb->stat_offsets_loaded, |
| 682 | &oes->rx_unknown_protocol, |
| 683 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 684 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 685 | veb->stat_offsets_loaded, |
| 686 | &oes->rx_bytes, &es->rx_bytes); |
| 687 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 688 | veb->stat_offsets_loaded, |
| 689 | &oes->rx_unicast, &es->rx_unicast); |
| 690 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 691 | veb->stat_offsets_loaded, |
| 692 | &oes->rx_multicast, &es->rx_multicast); |
| 693 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 694 | veb->stat_offsets_loaded, |
| 695 | &oes->rx_broadcast, &es->rx_broadcast); |
| 696 | |
| 697 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 698 | veb->stat_offsets_loaded, |
| 699 | &oes->tx_bytes, &es->tx_bytes); |
| 700 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 701 | veb->stat_offsets_loaded, |
| 702 | &oes->tx_unicast, &es->tx_unicast); |
| 703 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 704 | veb->stat_offsets_loaded, |
| 705 | &oes->tx_multicast, &es->tx_multicast); |
| 706 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 707 | veb->stat_offsets_loaded, |
| 708 | &oes->tx_broadcast, &es->tx_broadcast); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 709 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 710 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), |
| 711 | I40E_GLVEBTC_RPCL(i, idx), |
| 712 | veb->stat_offsets_loaded, |
| 713 | &veb_oes->tc_rx_packets[i], |
| 714 | &veb_es->tc_rx_packets[i]); |
| 715 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), |
| 716 | I40E_GLVEBTC_RBCL(i, idx), |
| 717 | veb->stat_offsets_loaded, |
| 718 | &veb_oes->tc_rx_bytes[i], |
| 719 | &veb_es->tc_rx_bytes[i]); |
| 720 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), |
| 721 | I40E_GLVEBTC_TPCL(i, idx), |
| 722 | veb->stat_offsets_loaded, |
| 723 | &veb_oes->tc_tx_packets[i], |
| 724 | &veb_es->tc_tx_packets[i]); |
| 725 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), |
| 726 | I40E_GLVEBTC_TBCL(i, idx), |
| 727 | veb->stat_offsets_loaded, |
| 728 | &veb_oes->tc_tx_bytes[i], |
| 729 | &veb_es->tc_tx_bytes[i]); |
| 730 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 731 | veb->stat_offsets_loaded = true; |
| 732 | } |
| 733 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 734 | #ifdef I40E_FCOE |
| 735 | /** |
| 736 | * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters. |
| 737 | * @vsi: the VSI that is capable of doing FCoE |
| 738 | **/ |
| 739 | static void i40e_update_fcoe_stats(struct i40e_vsi *vsi) |
| 740 | { |
| 741 | struct i40e_pf *pf = vsi->back; |
| 742 | struct i40e_hw *hw = &pf->hw; |
| 743 | struct i40e_fcoe_stats *ofs; |
| 744 | struct i40e_fcoe_stats *fs; /* device's eth stats */ |
| 745 | int idx; |
| 746 | |
| 747 | if (vsi->type != I40E_VSI_FCOE) |
| 748 | return; |
| 749 | |
Kiran Patil | 4147e2c | 2016-01-15 14:33:14 -0800 | [diff] [blame] | 750 | idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 751 | fs = &vsi->fcoe_stats; |
| 752 | ofs = &vsi->fcoe_stats_offsets; |
| 753 | |
| 754 | i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx), |
| 755 | vsi->fcoe_stat_offsets_loaded, |
| 756 | &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets); |
| 757 | i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx), |
| 758 | vsi->fcoe_stat_offsets_loaded, |
| 759 | &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords); |
| 760 | i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx), |
| 761 | vsi->fcoe_stat_offsets_loaded, |
| 762 | &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped); |
| 763 | i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx), |
| 764 | vsi->fcoe_stat_offsets_loaded, |
| 765 | &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets); |
| 766 | i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx), |
| 767 | vsi->fcoe_stat_offsets_loaded, |
| 768 | &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords); |
| 769 | i40e_stat_update32(hw, I40E_GL_FCOECRC(idx), |
| 770 | vsi->fcoe_stat_offsets_loaded, |
| 771 | &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc); |
| 772 | i40e_stat_update32(hw, I40E_GL_FCOELAST(idx), |
| 773 | vsi->fcoe_stat_offsets_loaded, |
| 774 | &ofs->fcoe_last_error, &fs->fcoe_last_error); |
| 775 | i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx), |
| 776 | vsi->fcoe_stat_offsets_loaded, |
| 777 | &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count); |
| 778 | |
| 779 | vsi->fcoe_stat_offsets_loaded = true; |
| 780 | } |
| 781 | |
| 782 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 783 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 784 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 785 | * @vsi: the VSI to be updated |
| 786 | * |
| 787 | * There are a few instances where we store the same stat in a |
| 788 | * couple of different structs. This is partly because we have |
| 789 | * the netdev stats that need to be filled out, which is slightly |
| 790 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 791 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 792 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 793 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 794 | { |
| 795 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 796 | struct rtnl_link_stats64 *ons; |
| 797 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 798 | struct i40e_eth_stats *oes; |
| 799 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 800 | u32 tx_restart, tx_busy; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 801 | u64 tx_lost_interrupt; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 802 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 803 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 804 | u64 bytes, packets; |
| 805 | unsigned int start; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 806 | u64 tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 807 | u64 tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 808 | u64 rx_p, rx_b; |
| 809 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 810 | u16 q; |
| 811 | |
| 812 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 813 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 814 | return; |
| 815 | |
| 816 | ns = i40e_get_vsi_stats_struct(vsi); |
| 817 | ons = &vsi->net_stats_offsets; |
| 818 | es = &vsi->eth_stats; |
| 819 | oes = &vsi->eth_stats_offsets; |
| 820 | |
| 821 | /* Gather up the netdev and vsi stats that the driver collects |
| 822 | * on the fly during packet processing |
| 823 | */ |
| 824 | rx_b = rx_p = 0; |
| 825 | tx_b = tx_p = 0; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 826 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 827 | tx_lost_interrupt = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 828 | rx_page = 0; |
| 829 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 830 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 831 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 832 | /* locate Tx ring */ |
| 833 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 834 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 835 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 836 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 837 | packets = p->stats.packets; |
| 838 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 839 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 840 | tx_b += bytes; |
| 841 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 842 | tx_restart += p->tx_stats.restart_queue; |
| 843 | tx_busy += p->tx_stats.tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 844 | tx_linearize += p->tx_stats.tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 845 | tx_force_wb += p->tx_stats.tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 846 | tx_lost_interrupt += p->tx_stats.tx_lost_interrupt; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 847 | |
| 848 | /* Rx queue is part of the same block as Tx queue */ |
| 849 | p = &p[1]; |
| 850 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 851 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 852 | packets = p->stats.packets; |
| 853 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 854 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 855 | rx_b += bytes; |
| 856 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 857 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 858 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 859 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 860 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 861 | vsi->tx_restart = tx_restart; |
| 862 | vsi->tx_busy = tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 863 | vsi->tx_linearize = tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 864 | vsi->tx_force_wb = tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 865 | vsi->tx_lost_interrupt = tx_lost_interrupt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 866 | vsi->rx_page_failed = rx_page; |
| 867 | vsi->rx_buf_failed = rx_buf; |
| 868 | |
| 869 | ns->rx_packets = rx_p; |
| 870 | ns->rx_bytes = rx_b; |
| 871 | ns->tx_packets = tx_p; |
| 872 | ns->tx_bytes = tx_b; |
| 873 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 874 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 875 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 876 | ons->tx_errors = oes->tx_errors; |
| 877 | ns->tx_errors = es->tx_errors; |
| 878 | ons->multicast = oes->rx_multicast; |
| 879 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 880 | ons->rx_dropped = oes->rx_discards; |
| 881 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 882 | ons->tx_dropped = oes->tx_discards; |
| 883 | ns->tx_dropped = es->tx_discards; |
| 884 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 885 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 886 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 887 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 888 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 889 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 890 | } |
| 891 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 892 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 893 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 894 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 895 | * @pf: the PF to be updated |
| 896 | **/ |
| 897 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 898 | { |
| 899 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 900 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 901 | struct i40e_hw *hw = &pf->hw; |
| 902 | u32 val; |
| 903 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 904 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 905 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 906 | I40E_GLPRT_GORCL(hw->port), |
| 907 | pf->stat_offsets_loaded, |
| 908 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 909 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 910 | I40E_GLPRT_GOTCL(hw->port), |
| 911 | pf->stat_offsets_loaded, |
| 912 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 913 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 914 | pf->stat_offsets_loaded, |
| 915 | &osd->eth.rx_discards, |
| 916 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 917 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 918 | I40E_GLPRT_UPRCL(hw->port), |
| 919 | pf->stat_offsets_loaded, |
| 920 | &osd->eth.rx_unicast, |
| 921 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 922 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 923 | I40E_GLPRT_MPRCL(hw->port), |
| 924 | pf->stat_offsets_loaded, |
| 925 | &osd->eth.rx_multicast, |
| 926 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 927 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 928 | I40E_GLPRT_BPRCL(hw->port), |
| 929 | pf->stat_offsets_loaded, |
| 930 | &osd->eth.rx_broadcast, |
| 931 | &nsd->eth.rx_broadcast); |
| 932 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 933 | I40E_GLPRT_UPTCL(hw->port), |
| 934 | pf->stat_offsets_loaded, |
| 935 | &osd->eth.tx_unicast, |
| 936 | &nsd->eth.tx_unicast); |
| 937 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 938 | I40E_GLPRT_MPTCL(hw->port), |
| 939 | pf->stat_offsets_loaded, |
| 940 | &osd->eth.tx_multicast, |
| 941 | &nsd->eth.tx_multicast); |
| 942 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 943 | I40E_GLPRT_BPTCL(hw->port), |
| 944 | pf->stat_offsets_loaded, |
| 945 | &osd->eth.tx_broadcast, |
| 946 | &nsd->eth.tx_broadcast); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 947 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 948 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 949 | pf->stat_offsets_loaded, |
| 950 | &osd->tx_dropped_link_down, |
| 951 | &nsd->tx_dropped_link_down); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 952 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 953 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 954 | pf->stat_offsets_loaded, |
| 955 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 956 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 957 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 958 | pf->stat_offsets_loaded, |
| 959 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 960 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 961 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 962 | pf->stat_offsets_loaded, |
| 963 | &osd->mac_local_faults, |
| 964 | &nsd->mac_local_faults); |
| 965 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 966 | pf->stat_offsets_loaded, |
| 967 | &osd->mac_remote_faults, |
| 968 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 969 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 970 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 971 | pf->stat_offsets_loaded, |
| 972 | &osd->rx_length_errors, |
| 973 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 974 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 975 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 976 | pf->stat_offsets_loaded, |
| 977 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 978 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 979 | pf->stat_offsets_loaded, |
| 980 | &osd->link_xon_tx, &nsd->link_xon_tx); |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 981 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 982 | pf->stat_offsets_loaded, |
| 983 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 984 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 985 | pf->stat_offsets_loaded, |
| 986 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 987 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 988 | for (i = 0; i < 8; i++) { |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 989 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 990 | pf->stat_offsets_loaded, |
| 991 | &osd->priority_xoff_rx[i], |
| 992 | &nsd->priority_xoff_rx[i]); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 993 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 994 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 995 | &osd->priority_xon_rx[i], |
| 996 | &nsd->priority_xon_rx[i]); |
| 997 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 998 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 999 | &osd->priority_xon_tx[i], |
| 1000 | &nsd->priority_xon_tx[i]); |
| 1001 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1002 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1003 | &osd->priority_xoff_tx[i], |
| 1004 | &nsd->priority_xoff_tx[i]); |
| 1005 | i40e_stat_update32(hw, |
| 1006 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1007 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1008 | &osd->priority_xon_2_xoff[i], |
| 1009 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1012 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 1013 | I40E_GLPRT_PRC64L(hw->port), |
| 1014 | pf->stat_offsets_loaded, |
| 1015 | &osd->rx_size_64, &nsd->rx_size_64); |
| 1016 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 1017 | I40E_GLPRT_PRC127L(hw->port), |
| 1018 | pf->stat_offsets_loaded, |
| 1019 | &osd->rx_size_127, &nsd->rx_size_127); |
| 1020 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 1021 | I40E_GLPRT_PRC255L(hw->port), |
| 1022 | pf->stat_offsets_loaded, |
| 1023 | &osd->rx_size_255, &nsd->rx_size_255); |
| 1024 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 1025 | I40E_GLPRT_PRC511L(hw->port), |
| 1026 | pf->stat_offsets_loaded, |
| 1027 | &osd->rx_size_511, &nsd->rx_size_511); |
| 1028 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 1029 | I40E_GLPRT_PRC1023L(hw->port), |
| 1030 | pf->stat_offsets_loaded, |
| 1031 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 1032 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 1033 | I40E_GLPRT_PRC1522L(hw->port), |
| 1034 | pf->stat_offsets_loaded, |
| 1035 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 1036 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 1037 | I40E_GLPRT_PRC9522L(hw->port), |
| 1038 | pf->stat_offsets_loaded, |
| 1039 | &osd->rx_size_big, &nsd->rx_size_big); |
| 1040 | |
| 1041 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 1042 | I40E_GLPRT_PTC64L(hw->port), |
| 1043 | pf->stat_offsets_loaded, |
| 1044 | &osd->tx_size_64, &nsd->tx_size_64); |
| 1045 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 1046 | I40E_GLPRT_PTC127L(hw->port), |
| 1047 | pf->stat_offsets_loaded, |
| 1048 | &osd->tx_size_127, &nsd->tx_size_127); |
| 1049 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 1050 | I40E_GLPRT_PTC255L(hw->port), |
| 1051 | pf->stat_offsets_loaded, |
| 1052 | &osd->tx_size_255, &nsd->tx_size_255); |
| 1053 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 1054 | I40E_GLPRT_PTC511L(hw->port), |
| 1055 | pf->stat_offsets_loaded, |
| 1056 | &osd->tx_size_511, &nsd->tx_size_511); |
| 1057 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 1058 | I40E_GLPRT_PTC1023L(hw->port), |
| 1059 | pf->stat_offsets_loaded, |
| 1060 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 1061 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 1062 | I40E_GLPRT_PTC1522L(hw->port), |
| 1063 | pf->stat_offsets_loaded, |
| 1064 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1065 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1066 | I40E_GLPRT_PTC9522L(hw->port), |
| 1067 | pf->stat_offsets_loaded, |
| 1068 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1069 | |
| 1070 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1071 | pf->stat_offsets_loaded, |
| 1072 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1073 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1074 | pf->stat_offsets_loaded, |
| 1075 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1076 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1077 | pf->stat_offsets_loaded, |
| 1078 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1079 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1080 | pf->stat_offsets_loaded, |
| 1081 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1082 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1083 | /* FDIR stats */ |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1084 | i40e_stat_update32(hw, |
| 1085 | 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] | 1086 | pf->stat_offsets_loaded, |
| 1087 | &osd->fd_atr_match, &nsd->fd_atr_match); |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1088 | i40e_stat_update32(hw, |
| 1089 | 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] | 1090 | pf->stat_offsets_loaded, |
| 1091 | &osd->fd_sb_match, &nsd->fd_sb_match); |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 1092 | i40e_stat_update32(hw, |
| 1093 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), |
| 1094 | pf->stat_offsets_loaded, |
| 1095 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1096 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1097 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1098 | nsd->tx_lpi_status = |
| 1099 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1100 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1101 | nsd->rx_lpi_status = |
| 1102 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1103 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1104 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1105 | pf->stat_offsets_loaded, |
| 1106 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1107 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1108 | pf->stat_offsets_loaded, |
| 1109 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1110 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1111 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
| 1112 | !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) |
| 1113 | nsd->fd_sb_status = true; |
| 1114 | else |
| 1115 | nsd->fd_sb_status = false; |
| 1116 | |
| 1117 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
| 1118 | !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 1119 | nsd->fd_atr_status = true; |
| 1120 | else |
| 1121 | nsd->fd_atr_status = false; |
| 1122 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1123 | pf->stat_offsets_loaded = true; |
| 1124 | } |
| 1125 | |
| 1126 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1127 | * i40e_update_stats - Update the various statistics counters. |
| 1128 | * @vsi: the VSI to be updated |
| 1129 | * |
| 1130 | * Update the various stats for this VSI and its related entities. |
| 1131 | **/ |
| 1132 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1133 | { |
| 1134 | struct i40e_pf *pf = vsi->back; |
| 1135 | |
| 1136 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1137 | i40e_update_pf_stats(pf); |
| 1138 | |
| 1139 | i40e_update_vsi_stats(vsi); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1140 | #ifdef I40E_FCOE |
| 1141 | i40e_update_fcoe_stats(vsi); |
| 1142 | #endif |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1146 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1147 | * @vsi: the VSI to be searched |
| 1148 | * @macaddr: the MAC address |
| 1149 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1150 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1151 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1152 | * |
| 1153 | * Returns ptr to the filter object or NULL |
| 1154 | **/ |
| 1155 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
| 1156 | u8 *macaddr, s16 vlan, |
| 1157 | bool is_vf, bool is_netdev) |
| 1158 | { |
| 1159 | struct i40e_mac_filter *f; |
| 1160 | |
| 1161 | if (!vsi || !macaddr) |
| 1162 | return NULL; |
| 1163 | |
| 1164 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1165 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1166 | (vlan == f->vlan) && |
| 1167 | (!is_vf || f->is_vf) && |
| 1168 | (!is_netdev || f->is_netdev)) |
| 1169 | return f; |
| 1170 | } |
| 1171 | return NULL; |
| 1172 | } |
| 1173 | |
| 1174 | /** |
| 1175 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1176 | * @vsi: the VSI to be searched |
| 1177 | * @macaddr: the MAC address we are searching for |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1178 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1179 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1180 | * |
| 1181 | * Returns the first filter with the provided MAC address or NULL if |
| 1182 | * MAC address was not found |
| 1183 | **/ |
| 1184 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr, |
| 1185 | bool is_vf, bool is_netdev) |
| 1186 | { |
| 1187 | struct i40e_mac_filter *f; |
| 1188 | |
| 1189 | if (!vsi || !macaddr) |
| 1190 | return NULL; |
| 1191 | |
| 1192 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1193 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1194 | (!is_vf || f->is_vf) && |
| 1195 | (!is_netdev || f->is_netdev)) |
| 1196 | return f; |
| 1197 | } |
| 1198 | return NULL; |
| 1199 | } |
| 1200 | |
| 1201 | /** |
| 1202 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1203 | * @vsi: the VSI to be searched |
| 1204 | * |
| 1205 | * Returns true if VSI is in vlan mode or false otherwise |
| 1206 | **/ |
| 1207 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1208 | { |
| 1209 | struct i40e_mac_filter *f; |
| 1210 | |
| 1211 | /* Only -1 for all the filters denotes not in vlan mode |
| 1212 | * so we have to go through all the list in order to make sure |
| 1213 | */ |
| 1214 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Greg Rose | d9b68f8 | 2015-07-23 16:54:31 -0400 | [diff] [blame] | 1215 | if (f->vlan >= 0 || vsi->info.pvid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1216 | return true; |
| 1217 | } |
| 1218 | |
| 1219 | return false; |
| 1220 | } |
| 1221 | |
| 1222 | /** |
| 1223 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1224 | * @vsi: the VSI to be searched |
| 1225 | * @macaddr: the mac address to be filtered |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1226 | * @is_vf: true if it is a VF |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1227 | * @is_netdev: true if it is a netdev |
| 1228 | * |
| 1229 | * Goes through all the macvlan filters and adds a |
| 1230 | * macvlan filter for each unique vlan that already exists |
| 1231 | * |
| 1232 | * Returns first filter found on success, else NULL |
| 1233 | **/ |
| 1234 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1235 | bool is_vf, bool is_netdev) |
| 1236 | { |
| 1237 | struct i40e_mac_filter *f; |
| 1238 | |
| 1239 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Mitch Williams | ecbb44e | 2015-07-10 19:35:56 -0400 | [diff] [blame] | 1240 | if (vsi->info.pvid) |
| 1241 | f->vlan = le16_to_cpu(vsi->info.pvid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1242 | if (!i40e_find_filter(vsi, macaddr, f->vlan, |
| 1243 | is_vf, is_netdev)) { |
| 1244 | if (!i40e_add_filter(vsi, macaddr, f->vlan, |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 1245 | is_vf, is_netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1246 | return NULL; |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | return list_first_entry_or_null(&vsi->mac_filter_list, |
| 1251 | struct i40e_mac_filter, list); |
| 1252 | } |
| 1253 | |
| 1254 | /** |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1255 | * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS |
| 1256 | * @vsi: the VSI to be searched |
| 1257 | * @macaddr: the mac address to be removed |
| 1258 | * @is_vf: true if it is a VF |
| 1259 | * @is_netdev: true if it is a netdev |
| 1260 | * |
| 1261 | * Removes a given MAC address from a VSI, regardless of VLAN |
| 1262 | * |
| 1263 | * Returns 0 for success, or error |
| 1264 | **/ |
| 1265 | int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1266 | bool is_vf, bool is_netdev) |
| 1267 | { |
| 1268 | struct i40e_mac_filter *f = NULL; |
| 1269 | int changed = 0; |
| 1270 | |
| 1271 | WARN(!spin_is_locked(&vsi->mac_filter_list_lock), |
| 1272 | "Missing mac_filter_list_lock\n"); |
| 1273 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1274 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1275 | (is_vf == f->is_vf) && |
| 1276 | (is_netdev == f->is_netdev)) { |
| 1277 | f->counter--; |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1278 | changed = 1; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1279 | if (f->counter == 0) |
| 1280 | f->state = I40E_FILTER_REMOVE; |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1281 | } |
| 1282 | } |
| 1283 | if (changed) { |
| 1284 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1285 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1286 | return 0; |
| 1287 | } |
| 1288 | return -ENOENT; |
| 1289 | } |
| 1290 | |
| 1291 | /** |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1292 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM |
| 1293 | * @vsi: the PF Main VSI - inappropriate for any other VSI |
| 1294 | * @macaddr: the MAC address |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1295 | * |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1296 | * Remove whatever filter the firmware set up so the driver can manage |
| 1297 | * its own filtering intelligently. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1298 | **/ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1299 | static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr) |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1300 | { |
| 1301 | struct i40e_aqc_remove_macvlan_element_data element; |
| 1302 | struct i40e_pf *pf = vsi->back; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1303 | |
| 1304 | /* Only appropriate for the PF main VSI */ |
| 1305 | if (vsi->type != I40E_VSI_MAIN) |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1306 | return; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1307 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1308 | memset(&element, 0, sizeof(element)); |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1309 | ether_addr_copy(element.mac_addr, macaddr); |
| 1310 | element.vlan_tag = 0; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1311 | /* Ignore error returns, some firmware does it this way... */ |
| 1312 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1313 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1314 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1315 | memset(&element, 0, sizeof(element)); |
| 1316 | ether_addr_copy(element.mac_addr, macaddr); |
| 1317 | element.vlan_tag = 0; |
| 1318 | /* ...and some firmware does it this way. */ |
| 1319 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | |
| 1320 | I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; |
| 1321 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1325 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1326 | * @vsi: the VSI to be searched |
| 1327 | * @macaddr: the MAC address |
| 1328 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1329 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1330 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1331 | * |
| 1332 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1333 | * |
| 1334 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1335 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1336 | **/ |
| 1337 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
| 1338 | u8 *macaddr, s16 vlan, |
| 1339 | bool is_vf, bool is_netdev) |
| 1340 | { |
| 1341 | struct i40e_mac_filter *f; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1342 | int changed = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1343 | |
| 1344 | if (!vsi || !macaddr) |
| 1345 | return NULL; |
| 1346 | |
Kiran Patil | f6bd096 | 2016-06-20 09:10:34 -0700 | [diff] [blame] | 1347 | /* Do not allow broadcast filter to be added since broadcast filter |
| 1348 | * is added as part of add VSI for any newly created VSI except |
| 1349 | * FDIR VSI |
| 1350 | */ |
| 1351 | if (is_broadcast_ether_addr(macaddr)) |
| 1352 | return NULL; |
| 1353 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1354 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1355 | if (!f) { |
| 1356 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1357 | if (!f) |
| 1358 | goto add_filter_out; |
| 1359 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1360 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1361 | f->vlan = vlan; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1362 | /* If we're in overflow promisc mode, set the state directly |
| 1363 | * to failed, so we don't bother to try sending the filter |
| 1364 | * to the hardware. |
| 1365 | */ |
| 1366 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state)) |
| 1367 | f->state = I40E_FILTER_FAILED; |
| 1368 | else |
| 1369 | f->state = I40E_FILTER_NEW; |
| 1370 | changed = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1371 | INIT_LIST_HEAD(&f->list); |
Kiran Patil | 04d5a21 | 2015-12-09 15:50:23 -0800 | [diff] [blame] | 1372 | list_add_tail(&f->list, &vsi->mac_filter_list); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | /* increment counter and add a new flag if needed */ |
| 1376 | if (is_vf) { |
| 1377 | if (!f->is_vf) { |
| 1378 | f->is_vf = true; |
| 1379 | f->counter++; |
| 1380 | } |
| 1381 | } else if (is_netdev) { |
| 1382 | if (!f->is_netdev) { |
| 1383 | f->is_netdev = true; |
| 1384 | f->counter++; |
| 1385 | } |
| 1386 | } else { |
| 1387 | f->counter++; |
| 1388 | } |
| 1389 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1390 | if (changed) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1391 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1392 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1393 | } |
| 1394 | |
| 1395 | add_filter_out: |
| 1396 | return f; |
| 1397 | } |
| 1398 | |
| 1399 | /** |
| 1400 | * i40e_del_filter - Remove a mac/vlan filter from the VSI |
| 1401 | * @vsi: the VSI to be searched |
| 1402 | * @macaddr: the MAC address |
| 1403 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1404 | * @is_vf: make sure it's a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1405 | * @is_netdev: make sure it's a netdev filter, else doesn't matter |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1406 | * |
| 1407 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1408 | * being held. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1409 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1410 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1411 | * instead of list_for_each_entry(). |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1412 | **/ |
| 1413 | void i40e_del_filter(struct i40e_vsi *vsi, |
| 1414 | u8 *macaddr, s16 vlan, |
| 1415 | bool is_vf, bool is_netdev) |
| 1416 | { |
| 1417 | struct i40e_mac_filter *f; |
| 1418 | |
| 1419 | if (!vsi || !macaddr) |
| 1420 | return; |
| 1421 | |
| 1422 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1423 | if (!f || f->counter == 0) |
| 1424 | return; |
| 1425 | |
| 1426 | if (is_vf) { |
| 1427 | if (f->is_vf) { |
| 1428 | f->is_vf = false; |
| 1429 | f->counter--; |
| 1430 | } |
| 1431 | } else if (is_netdev) { |
| 1432 | if (f->is_netdev) { |
| 1433 | f->is_netdev = false; |
| 1434 | f->counter--; |
| 1435 | } |
| 1436 | } else { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1437 | /* make sure we don't remove a filter in use by VF or netdev */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1438 | int min_f = 0; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1439 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1440 | min_f += (f->is_vf ? 1 : 0); |
| 1441 | min_f += (f->is_netdev ? 1 : 0); |
| 1442 | |
| 1443 | if (f->counter > min_f) |
| 1444 | f->counter--; |
| 1445 | } |
| 1446 | |
| 1447 | /* counter == 0 tells sync_filters_subtask to |
| 1448 | * remove the filter from the firmware's list |
| 1449 | */ |
| 1450 | if (f->counter == 0) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1451 | if ((f->state == I40E_FILTER_FAILED) || |
| 1452 | (f->state == I40E_FILTER_NEW)) { |
| 1453 | /* this one never got added by the FW. Just remove it, |
| 1454 | * no need to sync anything. |
| 1455 | */ |
| 1456 | list_del(&f->list); |
| 1457 | kfree(f); |
| 1458 | } else { |
| 1459 | f->state = I40E_FILTER_REMOVE; |
| 1460 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1461 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1462 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1463 | } |
| 1464 | } |
| 1465 | |
| 1466 | /** |
| 1467 | * i40e_set_mac - NDO callback to set mac address |
| 1468 | * @netdev: network interface device structure |
| 1469 | * @p: pointer to an address structure |
| 1470 | * |
| 1471 | * Returns 0 on success, negative on failure |
| 1472 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1473 | #ifdef I40E_FCOE |
| 1474 | int i40e_set_mac(struct net_device *netdev, void *p) |
| 1475 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1476 | static int i40e_set_mac(struct net_device *netdev, void *p) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1477 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1478 | { |
| 1479 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1480 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1481 | struct i40e_pf *pf = vsi->back; |
| 1482 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1483 | struct sockaddr *addr = p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1484 | |
| 1485 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1486 | return -EADDRNOTAVAIL; |
| 1487 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1488 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1489 | netdev_info(netdev, "already using mac address %pM\n", |
| 1490 | addr->sa_data); |
| 1491 | return 0; |
| 1492 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1493 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1494 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1495 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1496 | return -EADDRNOTAVAIL; |
| 1497 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1498 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1499 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1500 | hw->mac.addr); |
| 1501 | else |
| 1502 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1503 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1504 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1505 | i40e_del_mac_all_vlan(vsi, netdev->dev_addr, false, true); |
| 1506 | i40e_put_mac_in_vlan(vsi, addr->sa_data, false, true); |
| 1507 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 1508 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1509 | if (vsi->type == I40E_VSI_MAIN) { |
| 1510 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1511 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1512 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1513 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1514 | addr->sa_data, NULL); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1515 | if (ret) |
| 1516 | netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n", |
| 1517 | i40e_stat_str(hw, ret), |
| 1518 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1521 | /* schedule our worker thread which will take care of |
| 1522 | * applying the new filter changes |
| 1523 | */ |
| 1524 | i40e_service_event_schedule(vsi->back); |
| 1525 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | /** |
| 1529 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1530 | * @vsi: the VSI being setup |
| 1531 | * @ctxt: VSI context structure |
| 1532 | * @enabled_tc: Enabled TCs bitmap |
| 1533 | * @is_add: True if called before Add VSI |
| 1534 | * |
| 1535 | * Setup VSI queue mapping for enabled traffic classes. |
| 1536 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1537 | #ifdef I40E_FCOE |
| 1538 | void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1539 | struct i40e_vsi_context *ctxt, |
| 1540 | u8 enabled_tc, |
| 1541 | bool is_add) |
| 1542 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1543 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1544 | struct i40e_vsi_context *ctxt, |
| 1545 | u8 enabled_tc, |
| 1546 | bool is_add) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1547 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1548 | { |
| 1549 | struct i40e_pf *pf = vsi->back; |
| 1550 | u16 sections = 0; |
| 1551 | u8 netdev_tc = 0; |
| 1552 | u16 numtc = 0; |
| 1553 | u16 qcount; |
| 1554 | u8 offset; |
| 1555 | u16 qmap; |
| 1556 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1557 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1558 | |
| 1559 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1560 | offset = 0; |
| 1561 | |
| 1562 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1563 | /* Find numtc from enabled TC bitmap */ |
| 1564 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1565 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1566 | numtc++; |
| 1567 | } |
| 1568 | if (!numtc) { |
| 1569 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1570 | numtc = 1; |
| 1571 | } |
| 1572 | } else { |
| 1573 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1574 | numtc = 1; |
| 1575 | } |
| 1576 | |
| 1577 | vsi->tc_config.numtc = numtc; |
| 1578 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1579 | /* Number of queues per enabled TC */ |
Catherine Sullivan | 7d64402 | 2016-05-16 10:26:41 -0700 | [diff] [blame] | 1580 | qcount = vsi->alloc_queue_pairs; |
| 1581 | |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1582 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1583 | 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] | 1584 | |
| 1585 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1586 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1587 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1588 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1589 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1590 | int pow, num_qps; |
| 1591 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1592 | switch (vsi->type) { |
| 1593 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1594 | qcount = min_t(int, pf->alloc_rss_size, |
| 1595 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1596 | break; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1597 | #ifdef I40E_FCOE |
| 1598 | case I40E_VSI_FCOE: |
| 1599 | qcount = num_tc_qps; |
| 1600 | break; |
| 1601 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1602 | case I40E_VSI_FDIR: |
| 1603 | case I40E_VSI_SRIOV: |
| 1604 | case I40E_VSI_VMDQ2: |
| 1605 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1606 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1607 | WARN_ON(i != 0); |
| 1608 | break; |
| 1609 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1610 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1611 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1612 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1613 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1614 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1615 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1616 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1617 | pow++; |
| 1618 | num_qps >>= 1; |
| 1619 | } |
| 1620 | |
| 1621 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1622 | qmap = |
| 1623 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1624 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1625 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1626 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1627 | } else { |
| 1628 | /* TC is not enabled so set the offset to |
| 1629 | * default queue and allocate one queue |
| 1630 | * for the given TC. |
| 1631 | */ |
| 1632 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1633 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1634 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1635 | |
| 1636 | qmap = 0; |
| 1637 | } |
| 1638 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1639 | } |
| 1640 | |
| 1641 | /* Set actual Tx/Rx queue pairs */ |
| 1642 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1643 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1644 | if (vsi->req_queue_pairs > 0) |
| 1645 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1646 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1647 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1648 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1649 | |
| 1650 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1651 | if (is_add) { |
| 1652 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1653 | |
| 1654 | ctxt->info.up_enable_bits = enabled_tc; |
| 1655 | } |
| 1656 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1657 | ctxt->info.mapping_flags |= |
| 1658 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1659 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1660 | ctxt->info.queue_mapping[i] = |
| 1661 | cpu_to_le16(vsi->base_queue + i); |
| 1662 | } else { |
| 1663 | ctxt->info.mapping_flags |= |
| 1664 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1665 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1666 | } |
| 1667 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1668 | } |
| 1669 | |
| 1670 | /** |
| 1671 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1672 | * @netdev: network interface device structure |
| 1673 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1674 | #ifdef I40E_FCOE |
| 1675 | void i40e_set_rx_mode(struct net_device *netdev) |
| 1676 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1677 | static void i40e_set_rx_mode(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1678 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1679 | { |
| 1680 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1681 | struct i40e_mac_filter *f, *ftmp; |
| 1682 | struct i40e_vsi *vsi = np->vsi; |
| 1683 | struct netdev_hw_addr *uca; |
| 1684 | struct netdev_hw_addr *mca; |
| 1685 | struct netdev_hw_addr *ha; |
| 1686 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1687 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1688 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1689 | /* add addr if not already in the filter list */ |
| 1690 | netdev_for_each_uc_addr(uca, netdev) { |
| 1691 | if (!i40e_find_mac(vsi, uca->addr, false, true)) { |
| 1692 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1693 | i40e_put_mac_in_vlan(vsi, uca->addr, |
| 1694 | false, true); |
| 1695 | else |
| 1696 | i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY, |
| 1697 | false, true); |
| 1698 | } |
| 1699 | } |
| 1700 | |
| 1701 | netdev_for_each_mc_addr(mca, netdev) { |
| 1702 | if (!i40e_find_mac(vsi, mca->addr, false, true)) { |
| 1703 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1704 | i40e_put_mac_in_vlan(vsi, mca->addr, |
| 1705 | false, true); |
| 1706 | else |
| 1707 | i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY, |
| 1708 | false, true); |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | /* remove filter if not in netdev list */ |
| 1713 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1714 | |
| 1715 | if (!f->is_netdev) |
| 1716 | continue; |
| 1717 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1718 | netdev_for_each_mc_addr(mca, netdev) |
| 1719 | if (ether_addr_equal(mca->addr, f->macaddr)) |
| 1720 | goto bottom_of_search_loop; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1721 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1722 | netdev_for_each_uc_addr(uca, netdev) |
| 1723 | if (ether_addr_equal(uca->addr, f->macaddr)) |
| 1724 | goto bottom_of_search_loop; |
| 1725 | |
| 1726 | for_each_dev_addr(netdev, ha) |
| 1727 | if (ether_addr_equal(ha->addr, f->macaddr)) |
| 1728 | goto bottom_of_search_loop; |
| 1729 | |
| 1730 | /* f->macaddr wasn't found in uc, mc, or ha list so delete it */ |
| 1731 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true); |
| 1732 | |
| 1733 | bottom_of_search_loop: |
| 1734 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1735 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1736 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1737 | |
| 1738 | /* check for other flag changes */ |
| 1739 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1740 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1741 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1742 | } |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1743 | |
| 1744 | /* schedule our worker thread which will take care of |
| 1745 | * applying the new filter changes |
| 1746 | */ |
| 1747 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | /** |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1751 | * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries |
| 1752 | * @vsi: pointer to vsi struct |
| 1753 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1754 | * those entries needs to be undone. |
| 1755 | * |
| 1756 | * MAC filter entries from list were slated to be removed from device. |
| 1757 | **/ |
| 1758 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1759 | struct list_head *from) |
| 1760 | { |
| 1761 | struct i40e_mac_filter *f, *ftmp; |
| 1762 | |
| 1763 | list_for_each_entry_safe(f, ftmp, from, list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1764 | /* Move the element back into MAC filter list*/ |
| 1765 | list_move_tail(&f->list, &vsi->mac_filter_list); |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | /** |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1770 | * i40e_update_filter_state - Update filter state based on return data |
| 1771 | * from firmware |
| 1772 | * @count: Number of filters added |
| 1773 | * @add_list: return data from fw |
| 1774 | * @head: pointer to first filter in current batch |
| 1775 | * @aq_err: status from fw |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1776 | * |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1777 | * MAC filter entries from list were slated to be added to device. Returns |
| 1778 | * number of successful filters. Note that 0 does NOT mean success! |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1779 | **/ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1780 | static int |
| 1781 | i40e_update_filter_state(int count, |
| 1782 | struct i40e_aqc_add_macvlan_element_data *add_list, |
| 1783 | struct i40e_mac_filter *add_head, int aq_err) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1784 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1785 | int retval = 0; |
| 1786 | int i; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1787 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1788 | |
| 1789 | if (!aq_err) { |
| 1790 | retval = count; |
| 1791 | /* Everything's good, mark all filters active. */ |
| 1792 | for (i = 0; i < count ; i++) { |
| 1793 | add_head->state = I40E_FILTER_ACTIVE; |
| 1794 | add_head = list_next_entry(add_head, list); |
| 1795 | } |
| 1796 | } else if (aq_err == I40E_AQ_RC_ENOSPC) { |
| 1797 | /* Device ran out of filter space. Check the return value |
| 1798 | * for each filter to see which ones are active. |
| 1799 | */ |
| 1800 | for (i = 0; i < count ; i++) { |
| 1801 | if (add_list[i].match_method == |
| 1802 | I40E_AQC_MM_ERR_NO_RES) { |
| 1803 | add_head->state = I40E_FILTER_FAILED; |
| 1804 | } else { |
| 1805 | add_head->state = I40E_FILTER_ACTIVE; |
| 1806 | retval++; |
| 1807 | } |
| 1808 | add_head = list_next_entry(add_head, list); |
| 1809 | } |
| 1810 | } else { |
| 1811 | /* Some other horrible thing happened, fail all filters */ |
| 1812 | retval = 0; |
| 1813 | for (i = 0; i < count ; i++) { |
| 1814 | add_head->state = I40E_FILTER_FAILED; |
| 1815 | add_head = list_next_entry(add_head, list); |
| 1816 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1817 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1818 | return retval; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1822 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1823 | * @vsi: ptr to the VSI |
| 1824 | * |
| 1825 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1826 | * |
| 1827 | * Returns 0 or error value |
| 1828 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 1829 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1830 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1831 | struct i40e_mac_filter *f, *ftmp, *add_head = NULL; |
| 1832 | struct list_head tmp_add_list, tmp_del_list; |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1833 | struct i40e_hw *hw = &vsi->back->hw; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1834 | bool promisc_changed = false; |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1835 | char vsi_name[16] = "PF"; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1836 | int filter_list_len = 0; |
| 1837 | u32 changed_flags = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1838 | i40e_status aq_ret = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1839 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1840 | struct i40e_pf *pf; |
| 1841 | int num_add = 0; |
| 1842 | int num_del = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1843 | int aq_err = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1844 | u16 cmd_flags; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1845 | int list_size; |
| 1846 | int fcnt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1847 | |
| 1848 | /* empty array typed pointers, kcalloc later */ |
| 1849 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1850 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1851 | |
| 1852 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1853 | usleep_range(1000, 2000); |
| 1854 | pf = vsi->back; |
| 1855 | |
| 1856 | if (vsi->netdev) { |
| 1857 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1858 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1859 | } |
| 1860 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1861 | INIT_LIST_HEAD(&tmp_add_list); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1862 | INIT_LIST_HEAD(&tmp_del_list); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1863 | |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1864 | if (vsi->type == I40E_VSI_SRIOV) |
| 1865 | snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id); |
| 1866 | else if (vsi->type != I40E_VSI_MAIN) |
| 1867 | snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid); |
| 1868 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1869 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1870 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1871 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1872 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1873 | /* Create a list of filters to delete. */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1874 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1875 | if (f->state == I40E_FILTER_REMOVE) { |
| 1876 | WARN_ON(f->counter != 0); |
| 1877 | /* Move the element into temporary del_list */ |
| 1878 | list_move_tail(&f->list, &tmp_del_list); |
| 1879 | vsi->active_filters--; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1880 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1881 | if (f->state == I40E_FILTER_NEW) { |
| 1882 | WARN_ON(f->counter == 0); |
| 1883 | /* Move the element into temporary add_list */ |
| 1884 | list_move_tail(&f->list, &tmp_add_list); |
| 1885 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1886 | } |
| 1887 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | /* Now process 'del_list' outside the lock */ |
| 1891 | if (!list_empty(&tmp_del_list)) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1892 | filter_list_len = hw->aq.asq_buf_size / |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1893 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1894 | list_size = filter_list_len * |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1895 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1896 | del_list = kzalloc(list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1897 | if (!del_list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1898 | /* Undo VSI's MAC filter entry element updates */ |
| 1899 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1900 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1901 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1902 | retval = -ENOMEM; |
| 1903 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1907 | cmd_flags = 0; |
| 1908 | |
| 1909 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1910 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1911 | if (f->vlan == I40E_VLAN_ANY) { |
| 1912 | del_list[num_del].vlan_tag = 0; |
| 1913 | cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; |
| 1914 | } else { |
| 1915 | del_list[num_del].vlan_tag = |
| 1916 | cpu_to_le16((u16)(f->vlan)); |
| 1917 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1918 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1919 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1920 | del_list[num_del].flags = cmd_flags; |
| 1921 | num_del++; |
| 1922 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1923 | /* flush a full buffer */ |
| 1924 | if (num_del == filter_list_len) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1925 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, |
| 1926 | del_list, |
| 1927 | num_del, NULL); |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1928 | aq_err = hw->aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1929 | num_del = 0; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1930 | memset(del_list, 0, list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1931 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1932 | /* Explicitly ignore and do not report when |
| 1933 | * firmware returns ENOENT. |
| 1934 | */ |
| 1935 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1936 | retval = -EIO; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1937 | dev_info(&pf->pdev->dev, |
| 1938 | "ignoring delete macvlan error on %s, err %s, aq_err %s\n", |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1939 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1940 | i40e_stat_str(hw, aq_ret), |
| 1941 | i40e_aq_str(hw, aq_err)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1942 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1943 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1944 | /* Release memory for MAC filter entries which were |
| 1945 | * synced up with HW. |
| 1946 | */ |
| 1947 | list_del(&f->list); |
| 1948 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1949 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1950 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1951 | if (num_del) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1952 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, del_list, |
| 1953 | num_del, NULL); |
| 1954 | aq_err = hw->aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1955 | num_del = 0; |
| 1956 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1957 | /* Explicitly ignore and do not report when firmware |
| 1958 | * returns ENOENT. |
| 1959 | */ |
| 1960 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { |
| 1961 | retval = -EIO; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1962 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1963 | "ignoring delete macvlan error on %s, err %s aq_err %s\n", |
| 1964 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1965 | i40e_stat_str(hw, aq_ret), |
| 1966 | i40e_aq_str(hw, aq_err)); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1967 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | kfree(del_list); |
| 1971 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | if (!list_empty(&tmp_add_list)) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1975 | /* Do all the adds now. */ |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1976 | filter_list_len = hw->aq.asq_buf_size / |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1977 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1978 | list_size = filter_list_len * |
| 1979 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
| 1980 | add_list = kzalloc(list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1981 | if (!add_list) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1982 | retval = -ENOMEM; |
| 1983 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1984 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1985 | num_add = 0; |
| 1986 | list_for_each_entry(f, &tmp_add_list, list) { |
| 1987 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1988 | &vsi->state)) { |
| 1989 | f->state = I40E_FILTER_FAILED; |
| 1990 | continue; |
| 1991 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1992 | /* add to add array */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1993 | if (num_add == 0) |
| 1994 | add_head = f; |
| 1995 | cmd_flags = 0; |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1996 | ether_addr_copy(add_list[num_add].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1997 | if (f->vlan == I40E_VLAN_ANY) { |
| 1998 | add_list[num_add].vlan_tag = 0; |
| 1999 | cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; |
| 2000 | } else { |
| 2001 | add_list[num_add].vlan_tag = |
| 2002 | cpu_to_le16((u16)(f->vlan)); |
| 2003 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2004 | add_list[num_add].queue_number = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2005 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2006 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2007 | num_add++; |
| 2008 | |
| 2009 | /* flush a full buffer */ |
| 2010 | if (num_add == filter_list_len) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2011 | aq_ret = i40e_aq_add_macvlan(hw, vsi->seid, |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2012 | add_list, num_add, |
| 2013 | NULL); |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2014 | aq_err = hw->aq.asq_last_status; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2015 | fcnt = i40e_update_filter_state(num_add, |
| 2016 | add_list, |
| 2017 | add_head, |
| 2018 | aq_ret); |
| 2019 | vsi->active_filters += fcnt; |
| 2020 | |
| 2021 | if (fcnt != num_add) { |
| 2022 | promisc_changed = true; |
| 2023 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2024 | &vsi->state); |
| 2025 | vsi->promisc_threshold = |
| 2026 | (vsi->active_filters * 3) / 4; |
| 2027 | dev_warn(&pf->pdev->dev, |
| 2028 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", |
| 2029 | i40e_aq_str(hw, aq_err), |
| 2030 | vsi_name); |
| 2031 | } |
| 2032 | memset(add_list, 0, list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2033 | num_add = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2034 | } |
| 2035 | } |
| 2036 | if (num_add) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2037 | aq_ret = i40e_aq_add_macvlan(hw, vsi->seid, |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2038 | add_list, num_add, NULL); |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2039 | aq_err = hw->aq.asq_last_status; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2040 | fcnt = i40e_update_filter_state(num_add, add_list, |
| 2041 | add_head, aq_ret); |
| 2042 | vsi->active_filters += fcnt; |
| 2043 | if (fcnt != num_add) { |
| 2044 | promisc_changed = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2045 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2046 | &vsi->state); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2047 | vsi->promisc_threshold = |
| 2048 | (vsi->active_filters * 3) / 4; |
| 2049 | dev_warn(&pf->pdev->dev, |
| 2050 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", |
| 2051 | i40e_aq_str(hw, aq_err), vsi_name); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2052 | } |
| 2053 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2054 | /* Now move all of the filters from the temp add list back to |
| 2055 | * the VSI's list. |
| 2056 | */ |
| 2057 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2058 | list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) { |
| 2059 | list_move_tail(&f->list, &vsi->mac_filter_list); |
| 2060 | } |
| 2061 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2062 | kfree(add_list); |
| 2063 | add_list = NULL; |
| 2064 | } |
| 2065 | |
| 2066 | /* Check to see if we can drop out of overflow promiscuous mode. */ |
| 2067 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) && |
| 2068 | (vsi->active_filters < vsi->promisc_threshold)) { |
| 2069 | int failed_count = 0; |
| 2070 | /* See if we have any failed filters. We can't drop out of |
| 2071 | * promiscuous until these have all been deleted. |
| 2072 | */ |
| 2073 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2074 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2075 | if (f->state == I40E_FILTER_FAILED) |
| 2076 | failed_count++; |
| 2077 | } |
| 2078 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2079 | if (!failed_count) { |
| 2080 | dev_info(&pf->pdev->dev, |
| 2081 | "filter logjam cleared on %s, leaving overflow promiscuous mode\n", |
| 2082 | vsi_name); |
| 2083 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2084 | promisc_changed = true; |
| 2085 | vsi->promisc_threshold = 0; |
| 2086 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2089 | /* if the VF is not trusted do not do promisc */ |
| 2090 | if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) { |
| 2091 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2092 | goto out; |
| 2093 | } |
| 2094 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2095 | /* check for changes in promiscuous modes */ |
| 2096 | if (changed_flags & IFF_ALLMULTI) { |
| 2097 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2098 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2099 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2100 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2101 | vsi->seid, |
| 2102 | cur_multipromisc, |
| 2103 | NULL); |
| 2104 | if (aq_ret) { |
| 2105 | retval = i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2106 | hw->aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2107 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2108 | "set multi promisc failed on %s, err %s aq_err %s\n", |
| 2109 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2110 | i40e_stat_str(hw, aq_ret), |
| 2111 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2112 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2113 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2114 | if ((changed_flags & IFF_PROMISC) || |
| 2115 | (promisc_changed && |
| 2116 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2117 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2118 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2119 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 2120 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2121 | &vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2122 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2123 | (pf->lan_veb != I40E_NO_VEB) && |
| 2124 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2125 | /* set defport ON for Main VSI instead of true promisc |
| 2126 | * this way we will get all unicast/multicast and VLAN |
| 2127 | * promisc behavior but will not get VF or VMDq traffic |
| 2128 | * replicated on the Main VSI. |
| 2129 | */ |
| 2130 | if (pf->cur_promisc != cur_promisc) { |
| 2131 | pf->cur_promisc = cur_promisc; |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2132 | if (cur_promisc) |
| 2133 | aq_ret = |
| 2134 | i40e_aq_set_default_vsi(hw, |
| 2135 | vsi->seid, |
| 2136 | NULL); |
| 2137 | else |
| 2138 | aq_ret = |
| 2139 | i40e_aq_clear_default_vsi(hw, |
| 2140 | vsi->seid, |
| 2141 | NULL); |
| 2142 | if (aq_ret) { |
| 2143 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2144 | hw->aq.asq_last_status); |
| 2145 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2146 | "Set default VSI failed on %s, err %s, aq_err %s\n", |
| 2147 | vsi_name, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2148 | i40e_stat_str(hw, aq_ret), |
| 2149 | i40e_aq_str(hw, |
| 2150 | hw->aq.asq_last_status)); |
| 2151 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2152 | } |
| 2153 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2154 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2155 | hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2156 | vsi->seid, |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 2157 | cur_promisc, NULL, |
| 2158 | true); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2159 | if (aq_ret) { |
| 2160 | retval = |
| 2161 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2162 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2163 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2164 | "set unicast promisc failed on %s, err %s, aq_err %s\n", |
| 2165 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2166 | i40e_stat_str(hw, aq_ret), |
| 2167 | i40e_aq_str(hw, |
| 2168 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2169 | } |
| 2170 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2171 | hw, |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2172 | vsi->seid, |
| 2173 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2174 | if (aq_ret) { |
| 2175 | retval = |
| 2176 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2177 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2178 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2179 | "set multicast promisc failed on %s, err %s, aq_err %s\n", |
| 2180 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2181 | i40e_stat_str(hw, aq_ret), |
| 2182 | i40e_aq_str(hw, |
| 2183 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2184 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2185 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2186 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2187 | vsi->seid, |
| 2188 | cur_promisc, NULL); |
| 2189 | if (aq_ret) { |
| 2190 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2191 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2192 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2193 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2194 | i40e_stat_str(hw, aq_ret), |
| 2195 | i40e_aq_str(hw, |
| 2196 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2197 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2198 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2199 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2200 | /* if something went wrong then set the changed flag so we try again */ |
| 2201 | if (retval) |
| 2202 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2203 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2204 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2205 | return retval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | /** |
| 2209 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2210 | * @pf: board private structure |
| 2211 | **/ |
| 2212 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2213 | { |
| 2214 | int v; |
| 2215 | |
| 2216 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2217 | return; |
| 2218 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2219 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2220 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2221 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2222 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2223 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2224 | |
| 2225 | if (ret) { |
| 2226 | /* come back and try again later */ |
| 2227 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2228 | break; |
| 2229 | } |
| 2230 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2231 | } |
| 2232 | } |
| 2233 | |
| 2234 | /** |
| 2235 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2236 | * @netdev: network interface device structure |
| 2237 | * @new_mtu: new value for maximum frame size |
| 2238 | * |
| 2239 | * Returns 0 on success, negative on failure |
| 2240 | **/ |
| 2241 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2242 | { |
| 2243 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 61a46a4 | 2014-04-23 04:50:05 +0000 | [diff] [blame] | 2244 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2245 | struct i40e_vsi *vsi = np->vsi; |
| 2246 | |
| 2247 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 2248 | if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) |
| 2249 | return -EINVAL; |
| 2250 | |
| 2251 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2252 | netdev->mtu, new_mtu); |
| 2253 | netdev->mtu = new_mtu; |
| 2254 | if (netif_running(netdev)) |
| 2255 | i40e_vsi_reinit_locked(vsi); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 2256 | i40e_notify_client_of_l2_param_changes(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2257 | return 0; |
| 2258 | } |
| 2259 | |
| 2260 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2261 | * i40e_ioctl - Access the hwtstamp interface |
| 2262 | * @netdev: network interface device structure |
| 2263 | * @ifr: interface request data |
| 2264 | * @cmd: ioctl command |
| 2265 | **/ |
| 2266 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2267 | { |
| 2268 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2269 | struct i40e_pf *pf = np->vsi->back; |
| 2270 | |
| 2271 | switch (cmd) { |
| 2272 | case SIOCGHWTSTAMP: |
| 2273 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2274 | case SIOCSHWTSTAMP: |
| 2275 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2276 | default: |
| 2277 | return -EOPNOTSUPP; |
| 2278 | } |
| 2279 | } |
| 2280 | |
| 2281 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2282 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2283 | * @vsi: the vsi being adjusted |
| 2284 | **/ |
| 2285 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2286 | { |
| 2287 | struct i40e_vsi_context ctxt; |
| 2288 | i40e_status ret; |
| 2289 | |
| 2290 | if ((vsi->info.valid_sections & |
| 2291 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2292 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2293 | return; /* already enabled */ |
| 2294 | |
| 2295 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2296 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2297 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2298 | |
| 2299 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2300 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2301 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2302 | if (ret) { |
| 2303 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2304 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2305 | i40e_stat_str(&vsi->back->hw, ret), |
| 2306 | i40e_aq_str(&vsi->back->hw, |
| 2307 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2308 | } |
| 2309 | } |
| 2310 | |
| 2311 | /** |
| 2312 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2313 | * @vsi: the vsi being adjusted |
| 2314 | **/ |
| 2315 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2316 | { |
| 2317 | struct i40e_vsi_context ctxt; |
| 2318 | i40e_status ret; |
| 2319 | |
| 2320 | if ((vsi->info.valid_sections & |
| 2321 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2322 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2323 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2324 | return; /* already disabled */ |
| 2325 | |
| 2326 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2327 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2328 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2329 | |
| 2330 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2331 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2332 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2333 | if (ret) { |
| 2334 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2335 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2336 | i40e_stat_str(&vsi->back->hw, ret), |
| 2337 | i40e_aq_str(&vsi->back->hw, |
| 2338 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2339 | } |
| 2340 | } |
| 2341 | |
| 2342 | /** |
| 2343 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2344 | * @netdev: network interface to be adjusted |
| 2345 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2346 | **/ |
| 2347 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2348 | { |
| 2349 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2350 | struct i40e_vsi *vsi = np->vsi; |
| 2351 | |
| 2352 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2353 | i40e_vlan_stripping_enable(vsi); |
| 2354 | else |
| 2355 | i40e_vlan_stripping_disable(vsi); |
| 2356 | } |
| 2357 | |
| 2358 | /** |
| 2359 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 2360 | * @vsi: the vsi being configured |
| 2361 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 2362 | **/ |
| 2363 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2364 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2365 | struct i40e_mac_filter *f, *ftmp, *add_f; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2366 | bool is_netdev, is_vf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2367 | |
| 2368 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2369 | is_netdev = !!(vsi->netdev); |
| 2370 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2371 | /* Locked once because all functions invoked below iterates list*/ |
| 2372 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2373 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2374 | if (is_netdev) { |
| 2375 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid, |
| 2376 | is_vf, is_netdev); |
| 2377 | if (!add_f) { |
| 2378 | dev_info(&vsi->back->pdev->dev, |
| 2379 | "Could not add vlan filter %d for %pM\n", |
| 2380 | vid, vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2381 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2382 | return -ENOMEM; |
| 2383 | } |
| 2384 | } |
| 2385 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2386 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2387 | add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2388 | if (!add_f) { |
| 2389 | dev_info(&vsi->back->pdev->dev, |
| 2390 | "Could not add vlan filter %d for %pM\n", |
| 2391 | vid, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2392 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2393 | return -ENOMEM; |
| 2394 | } |
| 2395 | } |
| 2396 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2397 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 2398 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 2399 | * with 0, so we now accept untagged and specified tagged traffic |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2400 | * (and not all tags along with untagged) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2401 | */ |
| 2402 | if (vid > 0) { |
| 2403 | if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 2404 | I40E_VLAN_ANY, |
| 2405 | is_vf, is_netdev)) { |
| 2406 | i40e_del_filter(vsi, vsi->netdev->dev_addr, |
| 2407 | I40E_VLAN_ANY, is_vf, is_netdev); |
| 2408 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0, |
| 2409 | is_vf, is_netdev); |
| 2410 | if (!add_f) { |
| 2411 | dev_info(&vsi->back->pdev->dev, |
| 2412 | "Could not add filter 0 for %pM\n", |
| 2413 | vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2414 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2415 | return -ENOMEM; |
| 2416 | } |
| 2417 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2418 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2419 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2420 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
| 2421 | if (vid > 0 && !vsi->info.pvid) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2422 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2423 | if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2424 | is_vf, is_netdev)) |
| 2425 | continue; |
| 2426 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2427 | is_vf, is_netdev); |
| 2428 | add_f = i40e_add_filter(vsi, f->macaddr, |
| 2429 | 0, is_vf, is_netdev); |
| 2430 | if (!add_f) { |
| 2431 | dev_info(&vsi->back->pdev->dev, |
| 2432 | "Could not add filter 0 for %pM\n", |
| 2433 | f->macaddr); |
| 2434 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2435 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2436 | } |
| 2437 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2438 | } |
| 2439 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2440 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2441 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2442 | /* schedule our worker thread which will take care of |
| 2443 | * applying the new filter changes |
| 2444 | */ |
| 2445 | i40e_service_event_schedule(vsi->back); |
| 2446 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | /** |
| 2450 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 2451 | * @vsi: the vsi being configured |
| 2452 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2453 | * |
| 2454 | * Return: 0 on success or negative otherwise |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2455 | **/ |
| 2456 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2457 | { |
| 2458 | struct net_device *netdev = vsi->netdev; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2459 | struct i40e_mac_filter *f, *ftmp, *add_f; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2460 | bool is_vf, is_netdev; |
| 2461 | int filter_count = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2462 | |
| 2463 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2464 | is_netdev = !!(netdev); |
| 2465 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2466 | /* Locked once because all functions invoked below iterates list */ |
| 2467 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2468 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2469 | if (is_netdev) |
| 2470 | i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev); |
| 2471 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2472 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2473 | i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2474 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2475 | /* go through all the filters for this VSI and if there is only |
| 2476 | * vid == 0 it means there are no other filters, so vid 0 must |
| 2477 | * be replaced with -1. This signifies that we should from now |
| 2478 | * on accept any traffic (with any tag present, or untagged) |
| 2479 | */ |
| 2480 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2481 | if (is_netdev) { |
| 2482 | if (f->vlan && |
| 2483 | ether_addr_equal(netdev->dev_addr, f->macaddr)) |
| 2484 | filter_count++; |
| 2485 | } |
| 2486 | |
| 2487 | if (f->vlan) |
| 2488 | filter_count++; |
| 2489 | } |
| 2490 | |
| 2491 | if (!filter_count && is_netdev) { |
| 2492 | i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev); |
| 2493 | f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 2494 | is_vf, is_netdev); |
| 2495 | if (!f) { |
| 2496 | dev_info(&vsi->back->pdev->dev, |
| 2497 | "Could not add filter %d for %pM\n", |
| 2498 | I40E_VLAN_ANY, netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2499 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2500 | return -ENOMEM; |
| 2501 | } |
| 2502 | } |
| 2503 | |
| 2504 | if (!filter_count) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2505 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2506 | i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev); |
| 2507 | add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2508 | is_vf, is_netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2509 | if (!add_f) { |
| 2510 | dev_info(&vsi->back->pdev->dev, |
| 2511 | "Could not add filter %d for %pM\n", |
| 2512 | I40E_VLAN_ANY, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2513 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2514 | return -ENOMEM; |
| 2515 | } |
| 2516 | } |
| 2517 | } |
| 2518 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2519 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2520 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2521 | /* schedule our worker thread which will take care of |
| 2522 | * applying the new filter changes |
| 2523 | */ |
| 2524 | i40e_service_event_schedule(vsi->back); |
| 2525 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | /** |
| 2529 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2530 | * @netdev: network interface to be adjusted |
| 2531 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2532 | * |
| 2533 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2534 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2535 | #ifdef I40E_FCOE |
| 2536 | int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2537 | __always_unused __be16 proto, u16 vid) |
| 2538 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2539 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2540 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2541 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2542 | { |
| 2543 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2544 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2545 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2546 | |
| 2547 | if (vid > 4095) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2548 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2549 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2550 | /* If the network stack called us with vid = 0 then |
| 2551 | * it is asking to receive priority tagged packets with |
| 2552 | * vlan id 0. Our HW receives them by default when configured |
| 2553 | * to receive untagged packets so there is no need to add an |
| 2554 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2555 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2556 | if (vid) |
| 2557 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2558 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2559 | if (!ret && (vid < VLAN_N_VID)) |
| 2560 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2561 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2562 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | /** |
| 2566 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2567 | * @netdev: network interface to be adjusted |
| 2568 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2569 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2570 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2571 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2572 | #ifdef I40E_FCOE |
| 2573 | int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2574 | __always_unused __be16 proto, u16 vid) |
| 2575 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2576 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2577 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2578 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2579 | { |
| 2580 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2581 | struct i40e_vsi *vsi = np->vsi; |
| 2582 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2583 | /* return code is ignored as there is nothing a user |
| 2584 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2585 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2586 | */ |
| 2587 | i40e_vsi_kill_vlan(vsi, vid); |
| 2588 | |
| 2589 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2590 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2591 | return 0; |
| 2592 | } |
| 2593 | |
| 2594 | /** |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 2595 | * i40e_macaddr_init - explicitly write the mac address filters |
| 2596 | * |
| 2597 | * @vsi: pointer to the vsi |
| 2598 | * @macaddr: the MAC address |
| 2599 | * |
| 2600 | * This is needed when the macaddr has been obtained by other |
| 2601 | * means than the default, e.g., from Open Firmware or IDPROM. |
| 2602 | * Returns 0 on success, negative on failure |
| 2603 | **/ |
| 2604 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) |
| 2605 | { |
| 2606 | int ret; |
| 2607 | struct i40e_aqc_add_macvlan_element_data element; |
| 2608 | |
| 2609 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 2610 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 2611 | macaddr, NULL); |
| 2612 | if (ret) { |
| 2613 | dev_info(&vsi->back->pdev->dev, |
| 2614 | "Addr change for VSI failed: %d\n", ret); |
| 2615 | return -EADDRNOTAVAIL; |
| 2616 | } |
| 2617 | |
| 2618 | memset(&element, 0, sizeof(element)); |
| 2619 | ether_addr_copy(element.mac_addr, macaddr); |
| 2620 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 2621 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); |
| 2622 | if (ret) { |
| 2623 | dev_info(&vsi->back->pdev->dev, |
| 2624 | "add filter failed err %s aq_err %s\n", |
| 2625 | i40e_stat_str(&vsi->back->hw, ret), |
| 2626 | i40e_aq_str(&vsi->back->hw, |
| 2627 | vsi->back->hw.aq.asq_last_status)); |
| 2628 | } |
| 2629 | return ret; |
| 2630 | } |
| 2631 | |
| 2632 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2633 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2634 | * @vsi: the vsi being brought back up |
| 2635 | **/ |
| 2636 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2637 | { |
| 2638 | u16 vid; |
| 2639 | |
| 2640 | if (!vsi->netdev) |
| 2641 | return; |
| 2642 | |
| 2643 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2644 | |
| 2645 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2646 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2647 | vid); |
| 2648 | } |
| 2649 | |
| 2650 | /** |
| 2651 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2652 | * @vsi: the vsi being adjusted |
| 2653 | * @vid: the vlan id to set as a PVID |
| 2654 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2655 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2656 | { |
| 2657 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2658 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2659 | |
| 2660 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2661 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2662 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2663 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2664 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2665 | |
| 2666 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2667 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2668 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2669 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2670 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2671 | "add pvid failed, err %s aq_err %s\n", |
| 2672 | i40e_stat_str(&vsi->back->hw, ret), |
| 2673 | i40e_aq_str(&vsi->back->hw, |
| 2674 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2675 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2676 | } |
| 2677 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2678 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | /** |
| 2682 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2683 | * @vsi: the vsi being adjusted |
| 2684 | * |
| 2685 | * Just use the vlan_rx_register() service to put it back to normal |
| 2686 | **/ |
| 2687 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2688 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2689 | i40e_vlan_stripping_disable(vsi); |
| 2690 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2691 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | /** |
| 2695 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2696 | * @vsi: ptr to the VSI |
| 2697 | * |
| 2698 | * If this function returns with an error, then it's possible one or |
| 2699 | * more of the rings is populated (while the rest are not). It is the |
| 2700 | * callers duty to clean those orphaned rings. |
| 2701 | * |
| 2702 | * Return 0 on success, negative on failure |
| 2703 | **/ |
| 2704 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2705 | { |
| 2706 | int i, err = 0; |
| 2707 | |
| 2708 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2709 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2710 | |
| 2711 | return err; |
| 2712 | } |
| 2713 | |
| 2714 | /** |
| 2715 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2716 | * @vsi: ptr to the VSI |
| 2717 | * |
| 2718 | * Free VSI's transmit software resources |
| 2719 | **/ |
| 2720 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2721 | { |
| 2722 | int i; |
| 2723 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2724 | if (!vsi->tx_rings) |
| 2725 | return; |
| 2726 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2727 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2728 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2729 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | /** |
| 2733 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2734 | * @vsi: ptr to the VSI |
| 2735 | * |
| 2736 | * If this function returns with an error, then it's possible one or |
| 2737 | * more of the rings is populated (while the rest are not). It is the |
| 2738 | * callers duty to clean those orphaned rings. |
| 2739 | * |
| 2740 | * Return 0 on success, negative on failure |
| 2741 | **/ |
| 2742 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2743 | { |
| 2744 | int i, err = 0; |
| 2745 | |
| 2746 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2747 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2748 | #ifdef I40E_FCOE |
| 2749 | i40e_fcoe_setup_ddp_resources(vsi); |
| 2750 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2751 | return err; |
| 2752 | } |
| 2753 | |
| 2754 | /** |
| 2755 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2756 | * @vsi: ptr to the VSI |
| 2757 | * |
| 2758 | * Free all receive software resources |
| 2759 | **/ |
| 2760 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2761 | { |
| 2762 | int i; |
| 2763 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2764 | if (!vsi->rx_rings) |
| 2765 | return; |
| 2766 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2767 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2768 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2769 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2770 | #ifdef I40E_FCOE |
| 2771 | i40e_fcoe_free_ddp_resources(vsi); |
| 2772 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2776 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2777 | * @ring: The Tx ring to configure |
| 2778 | * |
| 2779 | * This enables/disables XPS for a given Tx descriptor ring |
| 2780 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2781 | **/ |
| 2782 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2783 | { |
| 2784 | struct i40e_vsi *vsi = ring->vsi; |
| 2785 | cpumask_var_t mask; |
| 2786 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2787 | if (!ring->q_vector || !ring->netdev) |
| 2788 | return; |
| 2789 | |
| 2790 | /* Single TC mode enable XPS */ |
| 2791 | if (vsi->tc_config.numtc <= 1) { |
| 2792 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2793 | netif_set_xps_queue(ring->netdev, |
| 2794 | &ring->q_vector->affinity_mask, |
| 2795 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2796 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2797 | /* Disable XPS to allow selection based on TC */ |
| 2798 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2799 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2800 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2801 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2802 | |
| 2803 | /* schedule our worker thread which will take care of |
| 2804 | * applying the new filter changes |
| 2805 | */ |
| 2806 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2810 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2811 | * @ring: The Tx ring to configure |
| 2812 | * |
| 2813 | * Configure the Tx descriptor ring in the HMC context. |
| 2814 | **/ |
| 2815 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2816 | { |
| 2817 | struct i40e_vsi *vsi = ring->vsi; |
| 2818 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2819 | struct i40e_hw *hw = &vsi->back->hw; |
| 2820 | struct i40e_hmc_obj_txq tx_ctx; |
| 2821 | i40e_status err = 0; |
| 2822 | u32 qtx_ctl = 0; |
| 2823 | |
| 2824 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2825 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2826 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2827 | ring->atr_count = 0; |
| 2828 | } else { |
| 2829 | ring->atr_sample_rate = 0; |
| 2830 | } |
| 2831 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2832 | /* configure XPS */ |
| 2833 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2834 | |
| 2835 | /* clear the context structure first */ |
| 2836 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2837 | |
| 2838 | tx_ctx.new_context = 1; |
| 2839 | tx_ctx.base = (ring->dma / 128); |
| 2840 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2841 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2842 | I40E_FLAG_FD_ATR_ENABLED)); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2843 | #ifdef I40E_FCOE |
| 2844 | tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2845 | #endif |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2846 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2847 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2848 | if (vsi->type != I40E_VSI_FDIR) |
| 2849 | tx_ctx.head_wb_ena = 1; |
| 2850 | tx_ctx.head_wb_addr = ring->dma + |
| 2851 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2852 | |
| 2853 | /* As part of VSI creation/update, FW allocates certain |
| 2854 | * Tx arbitration queue sets for each TC enabled for |
| 2855 | * the VSI. The FW returns the handles to these queue |
| 2856 | * sets as part of the response buffer to Add VSI, |
| 2857 | * Update VSI, etc. AQ commands. It is expected that |
| 2858 | * these queue set handles be associated with the Tx |
| 2859 | * queues by the driver as part of the TX queue context |
| 2860 | * initialization. This has to be done regardless of |
| 2861 | * DCB as by default everything is mapped to TC0. |
| 2862 | */ |
| 2863 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2864 | tx_ctx.rdylist_act = 0; |
| 2865 | |
| 2866 | /* clear the context in the HMC */ |
| 2867 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2868 | if (err) { |
| 2869 | dev_info(&vsi->back->pdev->dev, |
| 2870 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2871 | ring->queue_index, pf_q, err); |
| 2872 | return -ENOMEM; |
| 2873 | } |
| 2874 | |
| 2875 | /* set the context in the HMC */ |
| 2876 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2877 | if (err) { |
| 2878 | dev_info(&vsi->back->pdev->dev, |
| 2879 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2880 | ring->queue_index, pf_q, err); |
| 2881 | return -ENOMEM; |
| 2882 | } |
| 2883 | |
| 2884 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2885 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2886 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2887 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2888 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2889 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2890 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2891 | } |
| 2892 | |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2893 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2894 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2895 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2896 | i40e_flush(hw); |
| 2897 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2898 | /* cache tail off for easier writes later */ |
| 2899 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2900 | |
| 2901 | return 0; |
| 2902 | } |
| 2903 | |
| 2904 | /** |
| 2905 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2906 | * @ring: The Rx ring to configure |
| 2907 | * |
| 2908 | * Configure the Rx descriptor ring in the HMC context. |
| 2909 | **/ |
| 2910 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2911 | { |
| 2912 | struct i40e_vsi *vsi = ring->vsi; |
| 2913 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2914 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2915 | struct i40e_hw *hw = &vsi->back->hw; |
| 2916 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2917 | i40e_status err = 0; |
| 2918 | |
| 2919 | ring->state = 0; |
| 2920 | |
| 2921 | /* clear the context structure first */ |
| 2922 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2923 | |
| 2924 | ring->rx_buf_len = vsi->rx_buf_len; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2925 | |
| 2926 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2927 | |
| 2928 | rx_ctx.base = (ring->dma / 128); |
| 2929 | rx_ctx.qlen = ring->count; |
| 2930 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 2931 | /* use 32 byte descriptors */ |
| 2932 | rx_ctx.dsize = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2933 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 2934 | /* descriptor type is always zero |
| 2935 | * rx_ctx.dtype = 0; |
| 2936 | */ |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 2937 | rx_ctx.hsplit_0 = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2938 | |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 2939 | 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] | 2940 | if (hw->revision_id == 0) |
| 2941 | rx_ctx.lrxqthresh = 0; |
| 2942 | else |
| 2943 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2944 | rx_ctx.crcstrip = 1; |
| 2945 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 2946 | /* this controls whether VLAN is stripped from inner headers */ |
| 2947 | rx_ctx.showiv = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2948 | #ifdef I40E_FCOE |
| 2949 | rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2950 | #endif |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 2951 | /* set the prefena field to 1 because the manual says to */ |
| 2952 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2953 | |
| 2954 | /* clear the context in the HMC */ |
| 2955 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 2956 | if (err) { |
| 2957 | dev_info(&vsi->back->pdev->dev, |
| 2958 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2959 | ring->queue_index, pf_q, err); |
| 2960 | return -ENOMEM; |
| 2961 | } |
| 2962 | |
| 2963 | /* set the context in the HMC */ |
| 2964 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 2965 | if (err) { |
| 2966 | dev_info(&vsi->back->pdev->dev, |
| 2967 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2968 | ring->queue_index, pf_q, err); |
| 2969 | return -ENOMEM; |
| 2970 | } |
| 2971 | |
| 2972 | /* cache tail for quicker writes, and clear the reg before use */ |
| 2973 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 2974 | writel(0, ring->tail); |
| 2975 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 2976 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2977 | |
| 2978 | return 0; |
| 2979 | } |
| 2980 | |
| 2981 | /** |
| 2982 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 2983 | * @vsi: VSI structure describing this set of rings and resources |
| 2984 | * |
| 2985 | * Configure the Tx VSI for operation. |
| 2986 | **/ |
| 2987 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 2988 | { |
| 2989 | int err = 0; |
| 2990 | u16 i; |
| 2991 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2992 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 2993 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2994 | |
| 2995 | return err; |
| 2996 | } |
| 2997 | |
| 2998 | /** |
| 2999 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 3000 | * @vsi: the VSI being configured |
| 3001 | * |
| 3002 | * Configure the Rx VSI for operation. |
| 3003 | **/ |
| 3004 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 3005 | { |
| 3006 | int err = 0; |
| 3007 | u16 i; |
| 3008 | |
| 3009 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 3010 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 3011 | + ETH_FCS_LEN + VLAN_HLEN; |
| 3012 | else |
| 3013 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 3014 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 3015 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3016 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3017 | #ifdef I40E_FCOE |
| 3018 | /* setup rx buffer for FCoE */ |
| 3019 | if ((vsi->type == I40E_VSI_FCOE) && |
| 3020 | (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) { |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3021 | vsi->rx_buf_len = I40E_RXBUFFER_3072; |
| 3022 | vsi->max_frame = I40E_RXBUFFER_3072; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3026 | /* round up for the chip's needs */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3027 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3028 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3029 | |
| 3030 | /* set up individual rings */ |
| 3031 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3032 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3033 | |
| 3034 | return err; |
| 3035 | } |
| 3036 | |
| 3037 | /** |
| 3038 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3039 | * @vsi: ptr to the VSI |
| 3040 | **/ |
| 3041 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3042 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3043 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3044 | u16 qoffset, qcount; |
| 3045 | int i, n; |
| 3046 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3047 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3048 | /* Reset the TC information */ |
| 3049 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3050 | rx_ring = vsi->rx_rings[i]; |
| 3051 | tx_ring = vsi->tx_rings[i]; |
| 3052 | rx_ring->dcb_tc = 0; |
| 3053 | tx_ring->dcb_tc = 0; |
| 3054 | } |
| 3055 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3056 | |
| 3057 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3058 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3059 | continue; |
| 3060 | |
| 3061 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3062 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3063 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3064 | rx_ring = vsi->rx_rings[i]; |
| 3065 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3066 | rx_ring->dcb_tc = n; |
| 3067 | tx_ring->dcb_tc = n; |
| 3068 | } |
| 3069 | } |
| 3070 | } |
| 3071 | |
| 3072 | /** |
| 3073 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3074 | * @vsi: ptr to the VSI |
| 3075 | **/ |
| 3076 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3077 | { |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 3078 | struct i40e_pf *pf = vsi->back; |
| 3079 | int err; |
| 3080 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3081 | if (vsi->netdev) |
| 3082 | i40e_set_rx_mode(vsi->netdev); |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 3083 | |
| 3084 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 3085 | err = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 3086 | if (err) { |
| 3087 | dev_warn(&pf->pdev->dev, |
| 3088 | "could not set up macaddr; err %d\n", err); |
| 3089 | } |
| 3090 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3091 | } |
| 3092 | |
| 3093 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3094 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3095 | * @vsi: Pointer to the targeted VSI |
| 3096 | * |
| 3097 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3098 | * filters were saved. |
| 3099 | **/ |
| 3100 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3101 | { |
| 3102 | struct i40e_fdir_filter *filter; |
| 3103 | struct i40e_pf *pf = vsi->back; |
| 3104 | struct hlist_node *node; |
| 3105 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3106 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3107 | return; |
| 3108 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3109 | hlist_for_each_entry_safe(filter, node, |
| 3110 | &pf->fdir_filter_list, fdir_node) { |
| 3111 | i40e_add_del_fdir(vsi, filter, true); |
| 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3116 | * i40e_vsi_configure - Set up the VSI for action |
| 3117 | * @vsi: the VSI being configured |
| 3118 | **/ |
| 3119 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3120 | { |
| 3121 | int err; |
| 3122 | |
| 3123 | i40e_set_vsi_rx_mode(vsi); |
| 3124 | i40e_restore_vlan(vsi); |
| 3125 | i40e_vsi_config_dcb_rings(vsi); |
| 3126 | err = i40e_vsi_configure_tx(vsi); |
| 3127 | if (!err) |
| 3128 | err = i40e_vsi_configure_rx(vsi); |
| 3129 | |
| 3130 | return err; |
| 3131 | } |
| 3132 | |
| 3133 | /** |
| 3134 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3135 | * @vsi: the VSI being configured |
| 3136 | **/ |
| 3137 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3138 | { |
| 3139 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3140 | struct i40e_hw *hw = &pf->hw; |
| 3141 | u16 vector; |
| 3142 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3143 | u32 qp; |
| 3144 | |
| 3145 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3146 | * and PFINT_LNKLSTn registers, e.g.: |
| 3147 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3148 | */ |
| 3149 | qp = vsi->base_queue; |
| 3150 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3151 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3152 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3153 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3154 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3155 | 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] | 3156 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3157 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3158 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3159 | 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] | 3160 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3161 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3162 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3163 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
| 3164 | INTRL_USEC_TO_REG(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3165 | |
| 3166 | /* Linked list for the queuepairs assigned to this vector */ |
| 3167 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3168 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3169 | u32 val; |
| 3170 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3171 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3172 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3173 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3174 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 3175 | (I40E_QUEUE_TYPE_TX |
| 3176 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 3177 | |
| 3178 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3179 | |
| 3180 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3181 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3182 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3183 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 3184 | (I40E_QUEUE_TYPE_RX |
| 3185 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3186 | |
| 3187 | /* Terminate the linked list */ |
| 3188 | if (q == (q_vector->num_ringpairs - 1)) |
| 3189 | val |= (I40E_QUEUE_END_OF_LIST |
| 3190 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3191 | |
| 3192 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3193 | qp++; |
| 3194 | } |
| 3195 | } |
| 3196 | |
| 3197 | i40e_flush(hw); |
| 3198 | } |
| 3199 | |
| 3200 | /** |
| 3201 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3202 | * @hw: ptr to the hardware info |
| 3203 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3204 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3205 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3206 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3207 | u32 val; |
| 3208 | |
| 3209 | /* clear things first */ |
| 3210 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3211 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3212 | |
| 3213 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3214 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3215 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3216 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3217 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3218 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3219 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3220 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3221 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3222 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3223 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3224 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3225 | if (pf->flags & I40E_FLAG_PTP) |
| 3226 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3227 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3228 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3229 | |
| 3230 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3231 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3232 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3233 | |
| 3234 | /* OTHER_ITR_IDX = 0 */ |
| 3235 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3236 | } |
| 3237 | |
| 3238 | /** |
| 3239 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3240 | * @vsi: the VSI being configured |
| 3241 | **/ |
| 3242 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3243 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3244 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3245 | struct i40e_pf *pf = vsi->back; |
| 3246 | struct i40e_hw *hw = &pf->hw; |
| 3247 | u32 val; |
| 3248 | |
| 3249 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3250 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3251 | 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] | 3252 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3253 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3254 | 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] | 3255 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3256 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3257 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3258 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3259 | |
| 3260 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3261 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3262 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3263 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3264 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3265 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3266 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3267 | |
| 3268 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3269 | |
| 3270 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3271 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3272 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3273 | |
| 3274 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3275 | i40e_flush(hw); |
| 3276 | } |
| 3277 | |
| 3278 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3279 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3280 | * @pf: board private structure |
| 3281 | **/ |
| 3282 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3283 | { |
| 3284 | struct i40e_hw *hw = &pf->hw; |
| 3285 | |
| 3286 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3287 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3288 | i40e_flush(hw); |
| 3289 | } |
| 3290 | |
| 3291 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3292 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3293 | * @pf: board private structure |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3294 | * @clearpba: true when all pending interrupt events should be cleared |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3295 | **/ |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3296 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3297 | { |
| 3298 | struct i40e_hw *hw = &pf->hw; |
| 3299 | u32 val; |
| 3300 | |
| 3301 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3302 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3303 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3304 | |
| 3305 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3306 | i40e_flush(hw); |
| 3307 | } |
| 3308 | |
| 3309 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3310 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3311 | * @irq: interrupt number |
| 3312 | * @data: pointer to a q_vector |
| 3313 | **/ |
| 3314 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3315 | { |
| 3316 | struct i40e_q_vector *q_vector = data; |
| 3317 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3318 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3319 | return IRQ_HANDLED; |
| 3320 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3321 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3322 | |
| 3323 | return IRQ_HANDLED; |
| 3324 | } |
| 3325 | |
| 3326 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3327 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3328 | * @vsi: the VSI being configured |
| 3329 | * @basename: name for the vector |
| 3330 | * |
| 3331 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3332 | **/ |
| 3333 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3334 | { |
| 3335 | int q_vectors = vsi->num_q_vectors; |
| 3336 | struct i40e_pf *pf = vsi->back; |
| 3337 | int base = vsi->base_vector; |
| 3338 | int rx_int_idx = 0; |
| 3339 | int tx_int_idx = 0; |
| 3340 | int vector, err; |
| 3341 | |
| 3342 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3343 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3344 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3345 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3346 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3347 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3348 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3349 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3350 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3351 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3352 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3353 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3354 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3355 | } else { |
| 3356 | /* skip this unused q_vector */ |
| 3357 | continue; |
| 3358 | } |
| 3359 | err = request_irq(pf->msix_entries[base + vector].vector, |
| 3360 | vsi->irq_handler, |
| 3361 | 0, |
| 3362 | q_vector->name, |
| 3363 | q_vector); |
| 3364 | if (err) { |
| 3365 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3366 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3367 | goto free_queue_irqs; |
| 3368 | } |
| 3369 | /* assign the mask for this irq */ |
| 3370 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3371 | &q_vector->affinity_mask); |
| 3372 | } |
| 3373 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3374 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3375 | return 0; |
| 3376 | |
| 3377 | free_queue_irqs: |
| 3378 | while (vector) { |
| 3379 | vector--; |
| 3380 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3381 | NULL); |
| 3382 | free_irq(pf->msix_entries[base + vector].vector, |
| 3383 | &(vsi->q_vectors[vector])); |
| 3384 | } |
| 3385 | return err; |
| 3386 | } |
| 3387 | |
| 3388 | /** |
| 3389 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3390 | * @vsi: the VSI being un-configured |
| 3391 | **/ |
| 3392 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3393 | { |
| 3394 | struct i40e_pf *pf = vsi->back; |
| 3395 | struct i40e_hw *hw = &pf->hw; |
| 3396 | int base = vsi->base_vector; |
| 3397 | int i; |
| 3398 | |
| 3399 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3400 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3401 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3405 | for (i = vsi->base_vector; |
| 3406 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3407 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3408 | |
| 3409 | i40e_flush(hw); |
| 3410 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3411 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3412 | } else { |
| 3413 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3414 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3415 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3416 | i40e_flush(hw); |
| 3417 | synchronize_irq(pf->pdev->irq); |
| 3418 | } |
| 3419 | } |
| 3420 | |
| 3421 | /** |
| 3422 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3423 | * @vsi: the VSI being configured |
| 3424 | **/ |
| 3425 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3426 | { |
| 3427 | struct i40e_pf *pf = vsi->back; |
| 3428 | int i; |
| 3429 | |
| 3430 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3431 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3432 | i40e_irq_dynamic_enable(vsi, i); |
| 3433 | } else { |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3434 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3435 | } |
| 3436 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3437 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3438 | return 0; |
| 3439 | } |
| 3440 | |
| 3441 | /** |
| 3442 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3443 | * @pf: board private structure |
| 3444 | **/ |
| 3445 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3446 | { |
| 3447 | /* Disable ICR 0 */ |
| 3448 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3449 | i40e_flush(&pf->hw); |
| 3450 | } |
| 3451 | |
| 3452 | /** |
| 3453 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3454 | * @irq: interrupt number |
| 3455 | * @data: pointer to a q_vector |
| 3456 | * |
| 3457 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3458 | * with both queue and non-queue interrupts. This is also used in |
| 3459 | * MSIX mode to handle the non-queue interrupts. |
| 3460 | **/ |
| 3461 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3462 | { |
| 3463 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3464 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3465 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3466 | u32 icr0, icr0_remaining; |
| 3467 | u32 val, ena_mask; |
| 3468 | |
| 3469 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3470 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3471 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3472 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3473 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3474 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3475 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3476 | /* if interrupt but no bits showing, must be SWINT */ |
| 3477 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3478 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3479 | pf->sw_int_count++; |
| 3480 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3481 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 3482 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
| 3483 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3484 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3485 | dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
| 3486 | } |
| 3487 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3488 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3489 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3490 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3491 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3492 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3493 | /* We do not have a way to disarm Queue causes while leaving |
| 3494 | * interrupt enabled for all other causes, ideally |
| 3495 | * interrupt should be disabled while we are in NAPI but |
| 3496 | * this is not a performance path and napi_schedule() |
| 3497 | * can deal with rescheduling. |
| 3498 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3499 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3500 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3504 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3505 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3506 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3510 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3511 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3512 | } |
| 3513 | |
| 3514 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3515 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3516 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3517 | } |
| 3518 | |
| 3519 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3520 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3521 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3522 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3523 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3524 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3525 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3526 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3527 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3528 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3529 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3530 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3531 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3532 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3533 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3534 | } |
| 3535 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3536 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3537 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3538 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3539 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3540 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3541 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3542 | } |
| 3543 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3544 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3545 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3546 | |
| 3547 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3548 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3549 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3550 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3551 | } |
| 3552 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3553 | /* If a critical error is pending we have no choice but to reset the |
| 3554 | * device. |
| 3555 | * Report and mask out any remaining unexpected interrupts. |
| 3556 | */ |
| 3557 | icr0_remaining = icr0 & ena_mask; |
| 3558 | if (icr0_remaining) { |
| 3559 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3560 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3561 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3562 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3563 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3564 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3565 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3566 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3567 | } |
| 3568 | ena_mask &= ~icr0_remaining; |
| 3569 | } |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3570 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3571 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3572 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3573 | /* re-enable interrupt causes */ |
| 3574 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3575 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3576 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3577 | i40e_irq_dynamic_enable_icr0(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3578 | } |
| 3579 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3580 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3581 | } |
| 3582 | |
| 3583 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3584 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3585 | * @tx_ring: tx ring to clean |
| 3586 | * @budget: how many cleans we're allowed |
| 3587 | * |
| 3588 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3589 | **/ |
| 3590 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3591 | { |
| 3592 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3593 | u16 i = tx_ring->next_to_clean; |
| 3594 | struct i40e_tx_buffer *tx_buf; |
| 3595 | struct i40e_tx_desc *tx_desc; |
| 3596 | |
| 3597 | tx_buf = &tx_ring->tx_bi[i]; |
| 3598 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3599 | i -= tx_ring->count; |
| 3600 | |
| 3601 | do { |
| 3602 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3603 | |
| 3604 | /* if next_to_watch is not set then there is no work pending */ |
| 3605 | if (!eop_desc) |
| 3606 | break; |
| 3607 | |
| 3608 | /* prevent any other reads prior to eop_desc */ |
| 3609 | read_barrier_depends(); |
| 3610 | |
| 3611 | /* if the descriptor isn't done, no work yet to do */ |
| 3612 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3613 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3614 | break; |
| 3615 | |
| 3616 | /* clear next_to_watch to prevent false hangs */ |
| 3617 | tx_buf->next_to_watch = NULL; |
| 3618 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3619 | tx_desc->buffer_addr = 0; |
| 3620 | tx_desc->cmd_type_offset_bsz = 0; |
| 3621 | /* move past filter desc */ |
| 3622 | tx_buf++; |
| 3623 | tx_desc++; |
| 3624 | i++; |
| 3625 | if (unlikely(!i)) { |
| 3626 | i -= tx_ring->count; |
| 3627 | tx_buf = tx_ring->tx_bi; |
| 3628 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3629 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3630 | /* unmap skb header data */ |
| 3631 | dma_unmap_single(tx_ring->dev, |
| 3632 | dma_unmap_addr(tx_buf, dma), |
| 3633 | dma_unmap_len(tx_buf, len), |
| 3634 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3635 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3636 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3637 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3638 | tx_buf->raw_buf = NULL; |
| 3639 | tx_buf->tx_flags = 0; |
| 3640 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3641 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3642 | tx_desc->buffer_addr = 0; |
| 3643 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3644 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3645 | /* 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] | 3646 | tx_buf++; |
| 3647 | tx_desc++; |
| 3648 | i++; |
| 3649 | if (unlikely(!i)) { |
| 3650 | i -= tx_ring->count; |
| 3651 | tx_buf = tx_ring->tx_bi; |
| 3652 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3653 | } |
| 3654 | |
| 3655 | /* update budget accounting */ |
| 3656 | budget--; |
| 3657 | } while (likely(budget)); |
| 3658 | |
| 3659 | i += tx_ring->count; |
| 3660 | tx_ring->next_to_clean = i; |
| 3661 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3662 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3663 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3664 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3665 | return budget > 0; |
| 3666 | } |
| 3667 | |
| 3668 | /** |
| 3669 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3670 | * @irq: interrupt number |
| 3671 | * @data: pointer to a q_vector |
| 3672 | **/ |
| 3673 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3674 | { |
| 3675 | struct i40e_q_vector *q_vector = data; |
| 3676 | struct i40e_vsi *vsi; |
| 3677 | |
| 3678 | if (!q_vector->tx.ring) |
| 3679 | return IRQ_HANDLED; |
| 3680 | |
| 3681 | vsi = q_vector->tx.ring->vsi; |
| 3682 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3683 | |
| 3684 | return IRQ_HANDLED; |
| 3685 | } |
| 3686 | |
| 3687 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3688 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3689 | * @vsi: the VSI being configured |
| 3690 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3691 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3692 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3693 | 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] | 3694 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3695 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3696 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3697 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3698 | |
| 3699 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3700 | tx_ring->next = q_vector->tx.ring; |
| 3701 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3702 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3703 | |
| 3704 | rx_ring->q_vector = q_vector; |
| 3705 | rx_ring->next = q_vector->rx.ring; |
| 3706 | q_vector->rx.ring = rx_ring; |
| 3707 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | /** |
| 3711 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3712 | * @vsi: the VSI being configured |
| 3713 | * |
| 3714 | * This function maps descriptor rings to the queue-specific vectors |
| 3715 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3716 | * one vector per queue pair, but on a constrained vector budget, we |
| 3717 | * group the queue pairs as "efficiently" as possible. |
| 3718 | **/ |
| 3719 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3720 | { |
| 3721 | int qp_remaining = vsi->num_queue_pairs; |
| 3722 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3723 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3724 | int v_start = 0; |
| 3725 | int qp_idx = 0; |
| 3726 | |
| 3727 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3728 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3729 | * It is also important to go through all the vectors available to be |
| 3730 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3731 | * are cleared. This is especially important when decreasing the |
| 3732 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3733 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3734 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3735 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3736 | |
| 3737 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3738 | |
| 3739 | q_vector->num_ringpairs = num_ringpairs; |
| 3740 | |
| 3741 | q_vector->rx.count = 0; |
| 3742 | q_vector->tx.count = 0; |
| 3743 | q_vector->rx.ring = NULL; |
| 3744 | q_vector->tx.ring = NULL; |
| 3745 | |
| 3746 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3747 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3748 | qp_idx++; |
| 3749 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3750 | } |
| 3751 | } |
| 3752 | } |
| 3753 | |
| 3754 | /** |
| 3755 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3756 | * @vsi: the VSI being configured |
| 3757 | * @basename: name for the vector |
| 3758 | **/ |
| 3759 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3760 | { |
| 3761 | struct i40e_pf *pf = vsi->back; |
| 3762 | int err; |
| 3763 | |
| 3764 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3765 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3766 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3767 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3768 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3769 | else |
| 3770 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3771 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3772 | |
| 3773 | if (err) |
| 3774 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3775 | |
| 3776 | return err; |
| 3777 | } |
| 3778 | |
| 3779 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3780 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3781 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3782 | * @netdev: network interface device structure |
| 3783 | * |
| 3784 | * This is used by netconsole to send skbs without having to re-enable |
| 3785 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3786 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3787 | #ifdef I40E_FCOE |
| 3788 | void i40e_netpoll(struct net_device *netdev) |
| 3789 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3790 | static void i40e_netpoll(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3791 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3792 | { |
| 3793 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3794 | struct i40e_vsi *vsi = np->vsi; |
| 3795 | struct i40e_pf *pf = vsi->back; |
| 3796 | int i; |
| 3797 | |
| 3798 | /* if interface is down do nothing */ |
| 3799 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3800 | return; |
| 3801 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3802 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3803 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3804 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3805 | } else { |
| 3806 | i40e_intr(pf->pdev->irq, netdev); |
| 3807 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3808 | } |
| 3809 | #endif |
| 3810 | |
| 3811 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3812 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3813 | * @pf: the PF being configured |
| 3814 | * @pf_q: the PF queue |
| 3815 | * @enable: enable or disable state of the queue |
| 3816 | * |
| 3817 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3818 | * enabled or disabled state. |
| 3819 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3820 | * multiple retries; else will return 0 in case of success. |
| 3821 | **/ |
| 3822 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3823 | { |
| 3824 | int i; |
| 3825 | u32 tx_reg; |
| 3826 | |
| 3827 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3828 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3829 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3830 | break; |
| 3831 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3832 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3833 | } |
| 3834 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3835 | return -ETIMEDOUT; |
| 3836 | |
| 3837 | return 0; |
| 3838 | } |
| 3839 | |
| 3840 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3841 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3842 | * @vsi: the VSI being configured |
| 3843 | * @enable: start or stop the rings |
| 3844 | **/ |
| 3845 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3846 | { |
| 3847 | struct i40e_pf *pf = vsi->back; |
| 3848 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3849 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3850 | u32 tx_reg; |
| 3851 | |
| 3852 | pf_q = vsi->base_queue; |
| 3853 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3854 | |
| 3855 | /* warn the TX unit of coming changes */ |
| 3856 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3857 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3858 | usleep_range(10, 20); |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3859 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3860 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3861 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3862 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3863 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3864 | break; |
| 3865 | usleep_range(1000, 2000); |
| 3866 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3867 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3868 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3869 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3870 | |
| 3871 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3872 | if (enable) { |
| 3873 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3874 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3875 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3876 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3877 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3878 | |
| 3879 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 3880 | /* No waiting for the Tx queue to disable */ |
| 3881 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3882 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3883 | |
| 3884 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3885 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 3886 | if (ret) { |
| 3887 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3888 | "VSI seid %d Tx ring %d %sable timeout\n", |
| 3889 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3890 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3891 | } |
| 3892 | } |
| 3893 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3894 | if (hw->revision_id == 0) |
| 3895 | mdelay(50); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3896 | return ret; |
| 3897 | } |
| 3898 | |
| 3899 | /** |
| 3900 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 3901 | * @pf: the PF being configured |
| 3902 | * @pf_q: the PF queue |
| 3903 | * @enable: enable or disable state of the queue |
| 3904 | * |
| 3905 | * This routine will wait for the given Rx queue of the PF to reach the |
| 3906 | * enabled or disabled state. |
| 3907 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3908 | * multiple retries; else will return 0 in case of success. |
| 3909 | **/ |
| 3910 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3911 | { |
| 3912 | int i; |
| 3913 | u32 rx_reg; |
| 3914 | |
| 3915 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3916 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 3917 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3918 | break; |
| 3919 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3920 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3921 | } |
| 3922 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3923 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3924 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3925 | return 0; |
| 3926 | } |
| 3927 | |
| 3928 | /** |
| 3929 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 3930 | * @vsi: the VSI being configured |
| 3931 | * @enable: start or stop the rings |
| 3932 | **/ |
| 3933 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 3934 | { |
| 3935 | struct i40e_pf *pf = vsi->back; |
| 3936 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3937 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3938 | u32 rx_reg; |
| 3939 | |
| 3940 | pf_q = vsi->base_queue; |
| 3941 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3942 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3943 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3944 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3945 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3946 | break; |
| 3947 | usleep_range(1000, 2000); |
| 3948 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3949 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3950 | /* Skip if the queue is already in the requested state */ |
| 3951 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3952 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3953 | |
| 3954 | /* turn on/off the queue */ |
| 3955 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3956 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3957 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3958 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3959 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 3960 | /* No waiting for the Tx queue to disable */ |
| 3961 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3962 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3963 | |
| 3964 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3965 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 3966 | if (ret) { |
| 3967 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3968 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 3969 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3970 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3971 | } |
| 3972 | } |
| 3973 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3974 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3975 | } |
| 3976 | |
| 3977 | /** |
| 3978 | * i40e_vsi_control_rings - Start or stop a VSI's rings |
| 3979 | * @vsi: the VSI being configured |
| 3980 | * @enable: start or stop the rings |
| 3981 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 3982 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3983 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3984 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3985 | |
| 3986 | /* do rx first for enable and last for disable */ |
| 3987 | if (request) { |
| 3988 | ret = i40e_vsi_control_rx(vsi, request); |
| 3989 | if (ret) |
| 3990 | return ret; |
| 3991 | ret = i40e_vsi_control_tx(vsi, request); |
| 3992 | } else { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3993 | /* Ignore return value, we need to shutdown whatever we can */ |
| 3994 | i40e_vsi_control_tx(vsi, request); |
| 3995 | i40e_vsi_control_rx(vsi, request); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | return ret; |
| 3999 | } |
| 4000 | |
| 4001 | /** |
| 4002 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 4003 | * @vsi: the VSI being configured |
| 4004 | **/ |
| 4005 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 4006 | { |
| 4007 | struct i40e_pf *pf = vsi->back; |
| 4008 | struct i40e_hw *hw = &pf->hw; |
| 4009 | int base = vsi->base_vector; |
| 4010 | u32 val, qp; |
| 4011 | int i; |
| 4012 | |
| 4013 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4014 | if (!vsi->q_vectors) |
| 4015 | return; |
| 4016 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 4017 | if (!vsi->irqs_ready) |
| 4018 | return; |
| 4019 | |
| 4020 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4021 | for (i = 0; i < vsi->num_q_vectors; i++) { |
| 4022 | u16 vector = i + base; |
| 4023 | |
| 4024 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 4025 | if (!vsi->q_vectors[i] || |
| 4026 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4027 | continue; |
| 4028 | |
| 4029 | /* clear the affinity_mask in the IRQ descriptor */ |
| 4030 | irq_set_affinity_hint(pf->msix_entries[vector].vector, |
| 4031 | NULL); |
Greg Rose | b33d3b7 | 2016-05-16 10:26:37 -0700 | [diff] [blame] | 4032 | synchronize_irq(pf->msix_entries[vector].vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4033 | free_irq(pf->msix_entries[vector].vector, |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4034 | vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4035 | |
| 4036 | /* Tear down the interrupt queue link list |
| 4037 | * |
| 4038 | * We know that they come in pairs and always |
| 4039 | * the Rx first, then the Tx. To clear the |
| 4040 | * link list, stick the EOL value into the |
| 4041 | * next_q field of the registers. |
| 4042 | */ |
| 4043 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4044 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4045 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4046 | val |= I40E_QUEUE_END_OF_LIST |
| 4047 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4048 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4049 | |
| 4050 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4051 | u32 next; |
| 4052 | |
| 4053 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4054 | |
| 4055 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4056 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4057 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4058 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4059 | |
| 4060 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4061 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4062 | |
| 4063 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4064 | |
| 4065 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4066 | |
| 4067 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4068 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4069 | |
| 4070 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4071 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4072 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4073 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4074 | |
| 4075 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4076 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4077 | |
| 4078 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4079 | qp = next; |
| 4080 | } |
| 4081 | } |
| 4082 | } else { |
| 4083 | free_irq(pf->pdev->irq, pf); |
| 4084 | |
| 4085 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4086 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4087 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4088 | val |= I40E_QUEUE_END_OF_LIST |
| 4089 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4090 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4091 | |
| 4092 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4093 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4094 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4095 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4096 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4097 | |
| 4098 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4099 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4100 | |
| 4101 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4102 | |
| 4103 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4104 | |
| 4105 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4106 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4107 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4108 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4109 | |
| 4110 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4111 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4112 | |
| 4113 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4114 | } |
| 4115 | } |
| 4116 | |
| 4117 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4118 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4119 | * @vsi: the VSI being configured |
| 4120 | * @v_idx: Index of vector to be freed |
| 4121 | * |
| 4122 | * This function frees the memory allocated to the q_vector. In addition if |
| 4123 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4124 | * to freeing the q_vector. |
| 4125 | **/ |
| 4126 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4127 | { |
| 4128 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4129 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4130 | |
| 4131 | if (!q_vector) |
| 4132 | return; |
| 4133 | |
| 4134 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4135 | i40e_for_each_ring(ring, q_vector->tx) |
| 4136 | ring->q_vector = NULL; |
| 4137 | |
| 4138 | i40e_for_each_ring(ring, q_vector->rx) |
| 4139 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4140 | |
| 4141 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4142 | if (vsi->netdev) |
| 4143 | netif_napi_del(&q_vector->napi); |
| 4144 | |
| 4145 | vsi->q_vectors[v_idx] = NULL; |
| 4146 | |
| 4147 | kfree_rcu(q_vector, rcu); |
| 4148 | } |
| 4149 | |
| 4150 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4151 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4152 | * @vsi: the VSI being un-configured |
| 4153 | * |
| 4154 | * This frees the memory allocated to the q_vectors and |
| 4155 | * deletes references to the NAPI struct. |
| 4156 | **/ |
| 4157 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4158 | { |
| 4159 | int v_idx; |
| 4160 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4161 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4162 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | /** |
| 4166 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4167 | * @pf: board private structure |
| 4168 | **/ |
| 4169 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4170 | { |
| 4171 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4172 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4173 | pci_disable_msix(pf->pdev); |
| 4174 | kfree(pf->msix_entries); |
| 4175 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4176 | kfree(pf->irq_pile); |
| 4177 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4178 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4179 | pci_disable_msi(pf->pdev); |
| 4180 | } |
| 4181 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4182 | } |
| 4183 | |
| 4184 | /** |
| 4185 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4186 | * @pf: board private structure |
| 4187 | * |
| 4188 | * We go through and clear interrupt specific resources and reset the structure |
| 4189 | * to pre-load conditions |
| 4190 | **/ |
| 4191 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4192 | { |
| 4193 | int i; |
| 4194 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4195 | i40e_stop_misc_vector(pf); |
Shannon Nelson | 6927839 | 2016-03-10 14:59:43 -0800 | [diff] [blame] | 4196 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4197 | synchronize_irq(pf->msix_entries[0].vector); |
| 4198 | free_irq(pf->msix_entries[0].vector, pf); |
| 4199 | } |
| 4200 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4201 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4202 | I40E_IWARP_IRQ_PILE_ID); |
| 4203 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4204 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4205 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4206 | if (pf->vsi[i]) |
| 4207 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4208 | i40e_reset_interrupt_capability(pf); |
| 4209 | } |
| 4210 | |
| 4211 | /** |
| 4212 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4213 | * @vsi: the VSI being configured |
| 4214 | **/ |
| 4215 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4216 | { |
| 4217 | int q_idx; |
| 4218 | |
| 4219 | if (!vsi->netdev) |
| 4220 | return; |
| 4221 | |
| 4222 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4223 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4224 | } |
| 4225 | |
| 4226 | /** |
| 4227 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4228 | * @vsi: the VSI being configured |
| 4229 | **/ |
| 4230 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4231 | { |
| 4232 | int q_idx; |
| 4233 | |
| 4234 | if (!vsi->netdev) |
| 4235 | return; |
| 4236 | |
| 4237 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4238 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4239 | } |
| 4240 | |
| 4241 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4242 | * i40e_vsi_close - Shut down a VSI |
| 4243 | * @vsi: the vsi to be quelled |
| 4244 | **/ |
| 4245 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4246 | { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4247 | bool reset = false; |
| 4248 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4249 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4250 | i40e_down(vsi); |
| 4251 | i40e_vsi_free_irq(vsi); |
| 4252 | i40e_vsi_free_tx_resources(vsi); |
| 4253 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4254 | vsi->current_netdev_flags = 0; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4255 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4256 | reset = true; |
| 4257 | i40e_notify_client_of_netdev_close(vsi, reset); |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4261 | * i40e_quiesce_vsi - Pause a given VSI |
| 4262 | * @vsi: the VSI being paused |
| 4263 | **/ |
| 4264 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4265 | { |
| 4266 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4267 | return; |
| 4268 | |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4269 | /* No need to disable FCoE VSI when Tx suspended */ |
| 4270 | if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) && |
| 4271 | vsi->type == I40E_VSI_FCOE) { |
| 4272 | dev_dbg(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4273 | "VSI seid %d skipping FCoE VSI disable\n", vsi->seid); |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4274 | return; |
| 4275 | } |
| 4276 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4277 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4278 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4279 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4280 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4281 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4282 | } |
| 4283 | |
| 4284 | /** |
| 4285 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4286 | * @vsi: the VSI being resumed |
| 4287 | **/ |
| 4288 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4289 | { |
| 4290 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 4291 | return; |
| 4292 | |
| 4293 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4294 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4295 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4296 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4297 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4298 | } |
| 4299 | |
| 4300 | /** |
| 4301 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4302 | * @pf: the PF |
| 4303 | **/ |
| 4304 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4305 | { |
| 4306 | int v; |
| 4307 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4308 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4309 | if (pf->vsi[v]) |
| 4310 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4311 | } |
| 4312 | } |
| 4313 | |
| 4314 | /** |
| 4315 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4316 | * @pf: the PF |
| 4317 | **/ |
| 4318 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4319 | { |
| 4320 | int v; |
| 4321 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4322 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4323 | if (pf->vsi[v]) |
| 4324 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4325 | } |
| 4326 | } |
| 4327 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4328 | #ifdef CONFIG_I40E_DCB |
| 4329 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4330 | * 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] | 4331 | * @vsi: the VSI being configured |
| 4332 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4333 | * This function waits for the given VSI's queues to be disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4334 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4335 | static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4336 | { |
| 4337 | struct i40e_pf *pf = vsi->back; |
| 4338 | int i, pf_q, ret; |
| 4339 | |
| 4340 | pf_q = vsi->base_queue; |
| 4341 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4342 | /* Check and wait for the disable status of the queue */ |
| 4343 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4344 | if (ret) { |
| 4345 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4346 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4347 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4348 | return ret; |
| 4349 | } |
| 4350 | } |
| 4351 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4352 | pf_q = vsi->base_queue; |
| 4353 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4354 | /* Check and wait for the disable status of the queue */ |
| 4355 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4356 | if (ret) { |
| 4357 | dev_info(&pf->pdev->dev, |
| 4358 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4359 | vsi->seid, pf_q); |
| 4360 | return ret; |
| 4361 | } |
| 4362 | } |
| 4363 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4364 | return 0; |
| 4365 | } |
| 4366 | |
| 4367 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4368 | * 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] | 4369 | * @pf: the PF |
| 4370 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4371 | * 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] | 4372 | * VSIs that are managed by this PF. |
| 4373 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4374 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4375 | { |
| 4376 | int v, ret = 0; |
| 4377 | |
| 4378 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4379 | /* No need to wait for FCoE VSI queues */ |
| 4380 | if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4381 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4382 | if (ret) |
| 4383 | break; |
| 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | return ret; |
| 4388 | } |
| 4389 | |
| 4390 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4391 | |
| 4392 | /** |
| 4393 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4394 | * @q_idx: TX queue number |
| 4395 | * @vsi: Pointer to VSI struct |
| 4396 | * |
| 4397 | * This function checks specified queue for given VSI. Detects hung condition. |
| 4398 | * Sets hung bit since it is two step process. Before next run of service task |
| 4399 | * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not, |
| 4400 | * hung condition remain unchanged and during subsequent run, this function |
| 4401 | * issues SW interrupt to recover from hung condition. |
| 4402 | **/ |
| 4403 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4404 | { |
| 4405 | struct i40e_ring *tx_ring = NULL; |
| 4406 | struct i40e_pf *pf; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4407 | u32 head, val, tx_pending_hw; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4408 | int i; |
| 4409 | |
| 4410 | pf = vsi->back; |
| 4411 | |
| 4412 | /* now that we have an index, find the tx_ring struct */ |
| 4413 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4414 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4415 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4416 | tx_ring = vsi->tx_rings[i]; |
| 4417 | break; |
| 4418 | } |
| 4419 | } |
| 4420 | } |
| 4421 | |
| 4422 | if (!tx_ring) |
| 4423 | return; |
| 4424 | |
| 4425 | /* Read interrupt register */ |
| 4426 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4427 | val = rd32(&pf->hw, |
| 4428 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4429 | tx_ring->vsi->base_vector - 1)); |
| 4430 | else |
| 4431 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4432 | |
| 4433 | head = i40e_get_head(tx_ring); |
| 4434 | |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4435 | tx_pending_hw = i40e_get_tx_pending(tx_ring, false); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4436 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4437 | /* HW is done executing descriptors, updated HEAD write back, |
| 4438 | * but SW hasn't processed those descriptors. If interrupt is |
| 4439 | * not generated from this point ON, it could result into |
| 4440 | * dev_watchdog detecting timeout on those netdev_queue, |
| 4441 | * hence proactively trigger SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4442 | */ |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4443 | if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4444 | /* NAPI Poll didn't run and clear since it was set */ |
| 4445 | if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4446 | &tx_ring->q_vector->hung_detected)) { |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4447 | 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", |
| 4448 | vsi->seid, q_idx, tx_pending_hw, |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4449 | tx_ring->next_to_clean, head, |
| 4450 | tx_ring->next_to_use, |
| 4451 | readl(tx_ring->tail)); |
| 4452 | netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n", |
| 4453 | vsi->seid, q_idx, val); |
| 4454 | i40e_force_wb(vsi, tx_ring->q_vector); |
| 4455 | } else { |
| 4456 | /* First Chance - detected possible hung */ |
| 4457 | set_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4458 | &tx_ring->q_vector->hung_detected); |
| 4459 | } |
| 4460 | } |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4461 | |
| 4462 | /* This is the case where we have interrupts missing, |
| 4463 | * so the tx_pending in HW will most likely be 0, but we |
| 4464 | * will have tx_pending in SW since the WB happened but the |
| 4465 | * interrupt got lost. |
| 4466 | */ |
| 4467 | if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) && |
| 4468 | (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
| 4469 | if (napi_reschedule(&tx_ring->q_vector->napi)) |
| 4470 | tx_ring->tx_stats.tx_lost_interrupt++; |
| 4471 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | /** |
| 4475 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4476 | * @pf: pointer to PF struct |
| 4477 | * |
| 4478 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4479 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4480 | * SW interrupt. |
| 4481 | **/ |
| 4482 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4483 | { |
| 4484 | struct net_device *netdev; |
| 4485 | struct i40e_vsi *vsi; |
| 4486 | int i; |
| 4487 | |
| 4488 | /* Only for LAN VSI */ |
| 4489 | vsi = pf->vsi[pf->lan_vsi]; |
| 4490 | |
| 4491 | if (!vsi) |
| 4492 | return; |
| 4493 | |
| 4494 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
| 4495 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 4496 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4497 | return; |
| 4498 | |
| 4499 | /* Make sure type is MAIN VSI */ |
| 4500 | if (vsi->type != I40E_VSI_MAIN) |
| 4501 | return; |
| 4502 | |
| 4503 | netdev = vsi->netdev; |
| 4504 | if (!netdev) |
| 4505 | return; |
| 4506 | |
| 4507 | /* Bail out if netif_carrier is not OK */ |
| 4508 | if (!netif_carrier_ok(netdev)) |
| 4509 | return; |
| 4510 | |
| 4511 | /* Go thru' TX queues for netdev */ |
| 4512 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4513 | struct netdev_queue *q; |
| 4514 | |
| 4515 | q = netdev_get_tx_queue(netdev, i); |
| 4516 | if (q) |
| 4517 | i40e_detect_recover_hung_queue(i, vsi); |
| 4518 | } |
| 4519 | } |
| 4520 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4521 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4522 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4523 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4524 | * |
| 4525 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4526 | * and LAN TC. |
| 4527 | **/ |
| 4528 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4529 | { |
| 4530 | struct i40e_dcb_app_priority_table app; |
| 4531 | struct i40e_hw *hw = &pf->hw; |
| 4532 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4533 | u8 tc, i; |
| 4534 | /* Get the iSCSI APP TLV */ |
| 4535 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4536 | |
| 4537 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4538 | app = dcbcfg->app[i]; |
| 4539 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4540 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4541 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4542 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4543 | break; |
| 4544 | } |
| 4545 | } |
| 4546 | |
| 4547 | return enabled_tc; |
| 4548 | } |
| 4549 | |
| 4550 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4551 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4552 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4553 | * |
| 4554 | * Return the number of TCs from given DCBx configuration |
| 4555 | **/ |
| 4556 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4557 | { |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4558 | int i, tc_unused = 0; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4559 | u8 num_tc = 0; |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4560 | u8 ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4561 | |
| 4562 | /* Scan the ETS Config Priority Table to find |
| 4563 | * traffic class enabled for a given priority |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4564 | * and create a bitmask of enabled TCs |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4565 | */ |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4566 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) |
| 4567 | num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]); |
| 4568 | |
| 4569 | /* Now scan the bitmask to check for |
| 4570 | * contiguous TCs starting with TC0 |
| 4571 | */ |
| 4572 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4573 | if (num_tc & BIT(i)) { |
| 4574 | if (!tc_unused) { |
| 4575 | ret++; |
| 4576 | } else { |
| 4577 | pr_err("Non-contiguous TC - Disabling DCB\n"); |
| 4578 | return 1; |
| 4579 | } |
| 4580 | } else { |
| 4581 | tc_unused = 1; |
| 4582 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4583 | } |
| 4584 | |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4585 | /* There is always at least TC0 */ |
| 4586 | if (!ret) |
| 4587 | ret = 1; |
| 4588 | |
| 4589 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | /** |
| 4593 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4594 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4595 | * |
| 4596 | * Query the current DCB configuration and return the number of |
| 4597 | * traffic classes enabled from the given DCBX config |
| 4598 | **/ |
| 4599 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4600 | { |
| 4601 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4602 | u8 enabled_tc = 1; |
| 4603 | u8 i; |
| 4604 | |
| 4605 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4606 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4607 | |
| 4608 | return enabled_tc; |
| 4609 | } |
| 4610 | |
| 4611 | /** |
| 4612 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4613 | * @pf: PF being queried |
| 4614 | * |
| 4615 | * Return number of traffic classes enabled for the given PF |
| 4616 | **/ |
| 4617 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4618 | { |
| 4619 | struct i40e_hw *hw = &pf->hw; |
Dave Ertman | 52a08ca | 2016-07-27 12:02:34 -0700 | [diff] [blame] | 4620 | u8 i, enabled_tc = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4621 | u8 num_tc = 0; |
| 4622 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4623 | |
| 4624 | /* If DCB is not enabled then always in single TC */ |
| 4625 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4626 | return 1; |
| 4627 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4628 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4629 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4630 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4631 | |
| 4632 | /* MFP mode return count of enabled TCs for this PF */ |
| 4633 | if (pf->hw.func_caps.iscsi) |
| 4634 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4635 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4636 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4637 | |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4638 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4639 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4640 | num_tc++; |
| 4641 | } |
| 4642 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4643 | } |
| 4644 | |
| 4645 | /** |
| 4646 | * i40e_pf_get_default_tc - Get bitmap for first enabled TC |
| 4647 | * @pf: PF being queried |
| 4648 | * |
| 4649 | * Return a bitmap for first enabled traffic class for this PF. |
| 4650 | **/ |
| 4651 | static u8 i40e_pf_get_default_tc(struct i40e_pf *pf) |
| 4652 | { |
| 4653 | u8 enabled_tc = pf->hw.func_caps.enabled_tcmap; |
| 4654 | u8 i = 0; |
| 4655 | |
| 4656 | if (!enabled_tc) |
| 4657 | return 0x1; /* TC0 */ |
| 4658 | |
| 4659 | /* Find the first enabled TC */ |
| 4660 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4661 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4662 | break; |
| 4663 | } |
| 4664 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4665 | return BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | /** |
| 4669 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4670 | * @pf: PF being queried |
| 4671 | * |
| 4672 | * Return a bitmap for enabled traffic classes for this PF. |
| 4673 | **/ |
| 4674 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4675 | { |
| 4676 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4677 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4678 | return i40e_pf_get_default_tc(pf); |
| 4679 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4680 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4681 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4682 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4683 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4684 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4685 | if (pf->hw.func_caps.iscsi) |
| 4686 | return i40e_get_iscsi_tc_map(pf); |
| 4687 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4688 | return i40e_pf_get_default_tc(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | /** |
| 4692 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4693 | * @vsi: the VSI being queried |
| 4694 | * |
| 4695 | * Returns 0 on success, negative value on failure |
| 4696 | **/ |
| 4697 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4698 | { |
| 4699 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4700 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4701 | struct i40e_pf *pf = vsi->back; |
| 4702 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4703 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4704 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4705 | int i; |
| 4706 | |
| 4707 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4708 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4709 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4710 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4711 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4712 | i40e_stat_str(&pf->hw, ret), |
| 4713 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4714 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4718 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4719 | NULL); |
| 4720 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4721 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4722 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4723 | i40e_stat_str(&pf->hw, ret), |
| 4724 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4725 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4726 | } |
| 4727 | |
| 4728 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4729 | dev_info(&pf->pdev->dev, |
| 4730 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4731 | bw_config.tc_valid_bits, |
| 4732 | bw_ets_config.tc_valid_bits); |
| 4733 | /* Still continuing */ |
| 4734 | } |
| 4735 | |
| 4736 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4737 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4738 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4739 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4740 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4741 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4742 | vsi->bw_ets_limit_credits[i] = |
| 4743 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4744 | /* 3 bits out of 4 for each TC */ |
| 4745 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4746 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4747 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4748 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4749 | } |
| 4750 | |
| 4751 | /** |
| 4752 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4753 | * @vsi: the VSI being configured |
| 4754 | * @enabled_tc: TC bitmap |
| 4755 | * @bw_credits: BW shared credits per TC |
| 4756 | * |
| 4757 | * Returns 0 on success, negative value on failure |
| 4758 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4759 | 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] | 4760 | u8 *bw_share) |
| 4761 | { |
| 4762 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4763 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4764 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4765 | |
| 4766 | bw_data.tc_valid_bits = enabled_tc; |
| 4767 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4768 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4769 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4770 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4771 | NULL); |
| 4772 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4773 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4774 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4775 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4776 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4780 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4781 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4782 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | /** |
| 4786 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4787 | * @vsi: the VSI being configured |
| 4788 | * @enabled_tc: TC map to be enabled |
| 4789 | * |
| 4790 | **/ |
| 4791 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4792 | { |
| 4793 | struct net_device *netdev = vsi->netdev; |
| 4794 | struct i40e_pf *pf = vsi->back; |
| 4795 | struct i40e_hw *hw = &pf->hw; |
| 4796 | u8 netdev_tc = 0; |
| 4797 | int i; |
| 4798 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4799 | |
| 4800 | if (!netdev) |
| 4801 | return; |
| 4802 | |
| 4803 | if (!enabled_tc) { |
| 4804 | netdev_reset_tc(netdev); |
| 4805 | return; |
| 4806 | } |
| 4807 | |
| 4808 | /* Set up actual enabled TCs on the VSI */ |
| 4809 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 4810 | return; |
| 4811 | |
| 4812 | /* set per TC queues for the VSI */ |
| 4813 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4814 | /* Only set TC queues for enabled tcs |
| 4815 | * |
| 4816 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 4817 | * enabled_tc bitmap would be 0x00001001; the driver |
| 4818 | * will set the numtc for netdev as 2 that will be |
| 4819 | * referenced by the netdev layer as TC 0 and 1. |
| 4820 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4821 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4822 | netdev_set_tc_queue(netdev, |
| 4823 | vsi->tc_config.tc_info[i].netdev_tc, |
| 4824 | vsi->tc_config.tc_info[i].qcount, |
| 4825 | vsi->tc_config.tc_info[i].qoffset); |
| 4826 | } |
| 4827 | |
| 4828 | /* Assign UP2TC map for the VSI */ |
| 4829 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4830 | /* Get the actual TC# for the UP */ |
| 4831 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4832 | /* Get the mapped netdev TC# for the UP */ |
| 4833 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 4834 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 4835 | } |
| 4836 | } |
| 4837 | |
| 4838 | /** |
| 4839 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 4840 | * @vsi: the VSI being configured |
| 4841 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 4842 | **/ |
| 4843 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 4844 | struct i40e_vsi_context *ctxt) |
| 4845 | { |
| 4846 | /* copy just the sections touched not the entire info |
| 4847 | * since not all sections are valid as returned by |
| 4848 | * update vsi params |
| 4849 | */ |
| 4850 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 4851 | memcpy(&vsi->info.queue_mapping, |
| 4852 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 4853 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 4854 | sizeof(vsi->info.tc_mapping)); |
| 4855 | } |
| 4856 | |
| 4857 | /** |
| 4858 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 4859 | * @vsi: VSI to be configured |
| 4860 | * @enabled_tc: TC bitmap |
| 4861 | * |
| 4862 | * This configures a particular VSI for TCs that are mapped to the |
| 4863 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 4864 | * VSIs to configure TC for a particular VSI. |
| 4865 | * |
| 4866 | * NOTE: |
| 4867 | * It is expected that the VSI queues have been quisced before calling |
| 4868 | * this function. |
| 4869 | **/ |
| 4870 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4871 | { |
| 4872 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 4873 | struct i40e_vsi_context ctxt; |
| 4874 | int ret = 0; |
| 4875 | int i; |
| 4876 | |
| 4877 | /* Check if enabled_tc is same as existing or new TCs */ |
| 4878 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 4879 | return ret; |
| 4880 | |
| 4881 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 4882 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4883 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4884 | bw_share[i] = 1; |
| 4885 | } |
| 4886 | |
| 4887 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 4888 | if (ret) { |
| 4889 | dev_info(&vsi->back->pdev->dev, |
| 4890 | "Failed configuring TC map %d for VSI %d\n", |
| 4891 | enabled_tc, vsi->seid); |
| 4892 | goto out; |
| 4893 | } |
| 4894 | |
| 4895 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 4896 | ctxt.seid = vsi->seid; |
| 4897 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 4898 | ctxt.vf_num = 0; |
| 4899 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 4900 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4901 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 4902 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4903 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 4904 | ctxt.info.valid_sections |= |
| 4905 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 4906 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 4907 | } |
| 4908 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4909 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 4910 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 4911 | if (ret) { |
| 4912 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4913 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 4914 | i40e_stat_str(&vsi->back->hw, ret), |
| 4915 | i40e_aq_str(&vsi->back->hw, |
| 4916 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4917 | goto out; |
| 4918 | } |
| 4919 | /* update the local VSI info with updated queue map */ |
| 4920 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 4921 | vsi->info.valid_sections = 0; |
| 4922 | |
| 4923 | /* Update current VSI BW information */ |
| 4924 | ret = i40e_vsi_get_bw_info(vsi); |
| 4925 | if (ret) { |
| 4926 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4927 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 4928 | i40e_stat_str(&vsi->back->hw, ret), |
| 4929 | i40e_aq_str(&vsi->back->hw, |
| 4930 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4931 | goto out; |
| 4932 | } |
| 4933 | |
| 4934 | /* Update the netdev TC setup */ |
| 4935 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 4936 | out: |
| 4937 | return ret; |
| 4938 | } |
| 4939 | |
| 4940 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4941 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 4942 | * @veb: given VEB |
| 4943 | * @enabled_tc: TC bitmap |
| 4944 | * |
| 4945 | * Configures given TC bitmap for VEB (switching) element |
| 4946 | **/ |
| 4947 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 4948 | { |
| 4949 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 4950 | struct i40e_pf *pf = veb->pf; |
| 4951 | int ret = 0; |
| 4952 | int i; |
| 4953 | |
| 4954 | /* No TCs or already enabled TCs just return */ |
| 4955 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 4956 | return ret; |
| 4957 | |
| 4958 | bw_data.tc_valid_bits = enabled_tc; |
| 4959 | /* bw_data.absolute_credits is not set (relative) */ |
| 4960 | |
| 4961 | /* Enable ETS TCs with equal BW Share for now */ |
| 4962 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4963 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4964 | bw_data.tc_bw_share_credits[i] = 1; |
| 4965 | } |
| 4966 | |
| 4967 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 4968 | &bw_data, NULL); |
| 4969 | if (ret) { |
| 4970 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4971 | "VEB bw config failed, err %s aq_err %s\n", |
| 4972 | i40e_stat_str(&pf->hw, ret), |
| 4973 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4974 | goto out; |
| 4975 | } |
| 4976 | |
| 4977 | /* Update the BW information */ |
| 4978 | ret = i40e_veb_get_bw_info(veb); |
| 4979 | if (ret) { |
| 4980 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4981 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 4982 | i40e_stat_str(&pf->hw, ret), |
| 4983 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4984 | } |
| 4985 | |
| 4986 | out: |
| 4987 | return ret; |
| 4988 | } |
| 4989 | |
| 4990 | #ifdef CONFIG_I40E_DCB |
| 4991 | /** |
| 4992 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 4993 | * @pf: PF struct |
| 4994 | * |
| 4995 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 4996 | * the caller would've quiesce all the VSIs before calling |
| 4997 | * this function |
| 4998 | **/ |
| 4999 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 5000 | { |
| 5001 | u8 tc_map = 0; |
| 5002 | int ret; |
| 5003 | u8 v; |
| 5004 | |
| 5005 | /* Enable the TCs available on PF to all VEBs */ |
| 5006 | tc_map = i40e_pf_get_tc_map(pf); |
| 5007 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 5008 | if (!pf->veb[v]) |
| 5009 | continue; |
| 5010 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 5011 | if (ret) { |
| 5012 | dev_info(&pf->pdev->dev, |
| 5013 | "Failed configuring TC for VEB seid=%d\n", |
| 5014 | pf->veb[v]->seid); |
| 5015 | /* Will try to configure as many components */ |
| 5016 | } |
| 5017 | } |
| 5018 | |
| 5019 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5020 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5021 | if (!pf->vsi[v]) |
| 5022 | continue; |
| 5023 | |
| 5024 | /* - Enable all TCs for the LAN VSI |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5025 | #ifdef I40E_FCOE |
| 5026 | * - For FCoE VSI only enable the TC configured |
| 5027 | * as per the APP TLV |
| 5028 | #endif |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5029 | * - For all others keep them at TC0 for now |
| 5030 | */ |
| 5031 | if (v == pf->lan_vsi) |
| 5032 | tc_map = i40e_pf_get_tc_map(pf); |
| 5033 | else |
| 5034 | tc_map = i40e_pf_get_default_tc(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5035 | #ifdef I40E_FCOE |
| 5036 | if (pf->vsi[v]->type == I40E_VSI_FCOE) |
| 5037 | tc_map = i40e_get_fcoe_tc_map(pf); |
| 5038 | #endif /* #ifdef I40E_FCOE */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5039 | |
| 5040 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 5041 | if (ret) { |
| 5042 | dev_info(&pf->pdev->dev, |
| 5043 | "Failed configuring TC for VSI seid=%d\n", |
| 5044 | pf->vsi[v]->seid); |
| 5045 | /* Will try to configure as many components */ |
| 5046 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 5047 | /* Re-configure VSI vectors based on updated TC map */ |
| 5048 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5049 | if (pf->vsi[v]->netdev) |
| 5050 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 5051 | } |
| 5052 | } |
| 5053 | } |
| 5054 | |
| 5055 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5056 | * i40e_resume_port_tx - Resume port Tx |
| 5057 | * @pf: PF struct |
| 5058 | * |
| 5059 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 5060 | * resume. |
| 5061 | **/ |
| 5062 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 5063 | { |
| 5064 | struct i40e_hw *hw = &pf->hw; |
| 5065 | int ret; |
| 5066 | |
| 5067 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 5068 | if (ret) { |
| 5069 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5070 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 5071 | i40e_stat_str(&pf->hw, ret), |
| 5072 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5073 | /* Schedule PF reset to recover */ |
| 5074 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5075 | i40e_service_event_schedule(pf); |
| 5076 | } |
| 5077 | |
| 5078 | return ret; |
| 5079 | } |
| 5080 | |
| 5081 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5082 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 5083 | * @pf: PF being configured |
| 5084 | * |
| 5085 | * Query the current DCB configuration and cache it |
| 5086 | * in the hardware structure |
| 5087 | **/ |
| 5088 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 5089 | { |
| 5090 | struct i40e_hw *hw = &pf->hw; |
| 5091 | int err = 0; |
| 5092 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5093 | /* 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] | 5094 | if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5095 | goto out; |
| 5096 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5097 | /* Get the initial DCB configuration */ |
| 5098 | err = i40e_init_dcb(hw); |
| 5099 | if (!err) { |
| 5100 | /* Device/Function is not DCBX capable */ |
| 5101 | if ((!hw->func_caps.dcb) || |
| 5102 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5103 | dev_info(&pf->pdev->dev, |
| 5104 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 5105 | |
| 5106 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 5107 | goto out; |
| 5108 | |
| 5109 | } else { |
| 5110 | /* When status is not DISABLED then DCBX in FW */ |
| 5111 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5112 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5113 | |
| 5114 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
| 5115 | /* Enable DCB tagging only when more than one TC */ |
| 5116 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5117 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5118 | dev_dbg(&pf->pdev->dev, |
| 5119 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5120 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5121 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5122 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5123 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5124 | i40e_stat_str(&pf->hw, err), |
| 5125 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5126 | } |
| 5127 | |
| 5128 | out: |
| 5129 | return err; |
| 5130 | } |
| 5131 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5132 | #define SPEED_SIZE 14 |
| 5133 | #define FC_SIZE 8 |
| 5134 | /** |
| 5135 | * i40e_print_link_message - print link up or down |
| 5136 | * @vsi: the VSI for which link needs a message |
| 5137 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5138 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5139 | { |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5140 | char *speed = "Unknown"; |
| 5141 | char *fc = "Unknown"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5142 | |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5143 | if (vsi->current_isup == isup) |
| 5144 | return; |
| 5145 | vsi->current_isup = isup; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5146 | if (!isup) { |
| 5147 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5148 | return; |
| 5149 | } |
| 5150 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5151 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5152 | * least 10GB |
| 5153 | */ |
| 5154 | if (vsi->back->hw.func_caps.npar_enable && |
| 5155 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5156 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5157 | netdev_warn(vsi->netdev, |
| 5158 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5159 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5160 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5161 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5162 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5163 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5164 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5165 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5166 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5167 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5168 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5169 | break; |
| 5170 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5171 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5172 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5173 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5174 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5175 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5176 | default: |
| 5177 | break; |
| 5178 | } |
| 5179 | |
| 5180 | switch (vsi->back->hw.fc.current_mode) { |
| 5181 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5182 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5183 | break; |
| 5184 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5185 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5186 | break; |
| 5187 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5188 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5189 | break; |
| 5190 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5191 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5192 | break; |
| 5193 | } |
| 5194 | |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5195 | 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] | 5196 | speed, fc); |
| 5197 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5198 | |
| 5199 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5200 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5201 | * @vsi: the VSI being configured |
| 5202 | **/ |
| 5203 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5204 | { |
| 5205 | struct i40e_pf *pf = vsi->back; |
| 5206 | int err; |
| 5207 | |
| 5208 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5209 | i40e_vsi_configure_msix(vsi); |
| 5210 | else |
| 5211 | i40e_configure_msi_and_legacy(vsi); |
| 5212 | |
| 5213 | /* start rings */ |
| 5214 | err = i40e_vsi_control_rings(vsi, true); |
| 5215 | if (err) |
| 5216 | return err; |
| 5217 | |
| 5218 | clear_bit(__I40E_DOWN, &vsi->state); |
| 5219 | i40e_napi_enable_all(vsi); |
| 5220 | i40e_vsi_enable_irq(vsi); |
| 5221 | |
| 5222 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5223 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5224 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5225 | netif_tx_start_all_queues(vsi->netdev); |
| 5226 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5227 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5228 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5229 | /* need to check for qualified module here*/ |
| 5230 | if ((pf->hw.phy.link_info.link_info & |
| 5231 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5232 | (!(pf->hw.phy.link_info.an_info & |
| 5233 | I40E_AQ_QUALIFIED_MODULE))) |
| 5234 | netdev_err(vsi->netdev, |
| 5235 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5236 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5237 | |
| 5238 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5239 | if (vsi->type == I40E_VSI_FDIR) { |
| 5240 | /* reset fd counters */ |
| 5241 | pf->fd_add_err = pf->fd_atr_cnt = 0; |
| 5242 | if (pf->fd_tcp_rule > 0) { |
| 5243 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5244 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5245 | 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] | 5246 | pf->fd_tcp_rule = 0; |
| 5247 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5248 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5249 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5250 | |
| 5251 | /* On the next run of the service_task, notify any clients of the new |
| 5252 | * opened netdev |
| 5253 | */ |
| 5254 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5255 | i40e_service_event_schedule(pf); |
| 5256 | |
| 5257 | return 0; |
| 5258 | } |
| 5259 | |
| 5260 | /** |
| 5261 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5262 | * @vsi: the VSI being configured |
| 5263 | * |
| 5264 | * Rebuild the ring structs after some configuration |
| 5265 | * has changed, e.g. MTU size. |
| 5266 | **/ |
| 5267 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5268 | { |
| 5269 | struct i40e_pf *pf = vsi->back; |
| 5270 | |
| 5271 | WARN_ON(in_interrupt()); |
| 5272 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5273 | usleep_range(1000, 2000); |
| 5274 | i40e_down(vsi); |
| 5275 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5276 | i40e_up(vsi); |
| 5277 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 5278 | } |
| 5279 | |
| 5280 | /** |
| 5281 | * i40e_up - Bring the connection back up after being down |
| 5282 | * @vsi: the VSI being configured |
| 5283 | **/ |
| 5284 | int i40e_up(struct i40e_vsi *vsi) |
| 5285 | { |
| 5286 | int err; |
| 5287 | |
| 5288 | err = i40e_vsi_configure(vsi); |
| 5289 | if (!err) |
| 5290 | err = i40e_up_complete(vsi); |
| 5291 | |
| 5292 | return err; |
| 5293 | } |
| 5294 | |
| 5295 | /** |
| 5296 | * i40e_down - Shutdown the connection processing |
| 5297 | * @vsi: the VSI being stopped |
| 5298 | **/ |
| 5299 | void i40e_down(struct i40e_vsi *vsi) |
| 5300 | { |
| 5301 | int i; |
| 5302 | |
| 5303 | /* It is assumed that the caller of this function |
| 5304 | * sets the vsi->state __I40E_DOWN bit. |
| 5305 | */ |
| 5306 | if (vsi->netdev) { |
| 5307 | netif_carrier_off(vsi->netdev); |
| 5308 | netif_tx_disable(vsi->netdev); |
| 5309 | } |
| 5310 | i40e_vsi_disable_irq(vsi); |
| 5311 | i40e_vsi_control_rings(vsi, false); |
| 5312 | i40e_napi_disable_all(vsi); |
| 5313 | |
| 5314 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5315 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 5316 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5317 | } |
Catherine Sullivan | f980d44 | 2016-05-16 10:26:34 -0700 | [diff] [blame] | 5318 | |
| 5319 | i40e_notify_client_of_netdev_close(vsi, false); |
| 5320 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5321 | } |
| 5322 | |
| 5323 | /** |
| 5324 | * i40e_setup_tc - configure multiple traffic classes |
| 5325 | * @netdev: net device to configure |
| 5326 | * @tc: number of traffic classes to enable |
| 5327 | **/ |
| 5328 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5329 | { |
| 5330 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5331 | struct i40e_vsi *vsi = np->vsi; |
| 5332 | struct i40e_pf *pf = vsi->back; |
| 5333 | u8 enabled_tc = 0; |
| 5334 | int ret = -EINVAL; |
| 5335 | int i; |
| 5336 | |
| 5337 | /* Check if DCB enabled to continue */ |
| 5338 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5339 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5340 | goto exit; |
| 5341 | } |
| 5342 | |
| 5343 | /* Check if MFP enabled */ |
| 5344 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5345 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5346 | goto exit; |
| 5347 | } |
| 5348 | |
| 5349 | /* Check whether tc count is within enabled limit */ |
| 5350 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5351 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5352 | goto exit; |
| 5353 | } |
| 5354 | |
| 5355 | /* Generate TC map for number of tc requested */ |
| 5356 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5357 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5358 | |
| 5359 | /* Requesting same TC configuration as already enabled */ |
| 5360 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5361 | return 0; |
| 5362 | |
| 5363 | /* Quiesce VSI queues */ |
| 5364 | i40e_quiesce_vsi(vsi); |
| 5365 | |
| 5366 | /* Configure VSI for enabled TCs */ |
| 5367 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5368 | if (ret) { |
| 5369 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5370 | vsi->seid); |
| 5371 | goto exit; |
| 5372 | } |
| 5373 | |
| 5374 | /* Unquiesce VSI */ |
| 5375 | i40e_unquiesce_vsi(vsi); |
| 5376 | |
| 5377 | exit: |
| 5378 | return ret; |
| 5379 | } |
| 5380 | |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5381 | #ifdef I40E_FCOE |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5382 | int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5383 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5384 | #else |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5385 | static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5386 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5387 | #endif |
| 5388 | { |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5389 | if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5390 | return -EINVAL; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5391 | return i40e_setup_tc(netdev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5392 | } |
| 5393 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5394 | /** |
| 5395 | * i40e_open - Called when a network interface is made active |
| 5396 | * @netdev: network interface device structure |
| 5397 | * |
| 5398 | * The open entry point is called when a network interface is made |
| 5399 | * active by the system (IFF_UP). At this point all resources needed |
| 5400 | * for transmit and receive operations are allocated, the interrupt |
| 5401 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5402 | * enabled, and the stack is notified that the interface is ready. |
| 5403 | * |
| 5404 | * Returns 0 on success, negative value on failure |
| 5405 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5406 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5407 | { |
| 5408 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5409 | struct i40e_vsi *vsi = np->vsi; |
| 5410 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5411 | int err; |
| 5412 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5413 | /* disallow open during test or if eeprom is broken */ |
| 5414 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 5415 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5416 | return -EBUSY; |
| 5417 | |
| 5418 | netif_carrier_off(netdev); |
| 5419 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5420 | err = i40e_vsi_open(vsi); |
| 5421 | if (err) |
| 5422 | return err; |
| 5423 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5424 | /* configure global TSO hardware offload settings */ |
| 5425 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5426 | TCP_FLAG_FIN) >> 16); |
| 5427 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5428 | TCP_FLAG_FIN | |
| 5429 | TCP_FLAG_CWR) >> 16); |
| 5430 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5431 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 5432 | udp_tunnel_get_rx_info(netdev); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5433 | i40e_notify_client_of_netdev_open(vsi); |
| 5434 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5435 | return 0; |
| 5436 | } |
| 5437 | |
| 5438 | /** |
| 5439 | * i40e_vsi_open - |
| 5440 | * @vsi: the VSI to open |
| 5441 | * |
| 5442 | * Finish initialization of the VSI. |
| 5443 | * |
| 5444 | * Returns 0 on success, negative value on failure |
| 5445 | **/ |
| 5446 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5447 | { |
| 5448 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5449 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5450 | int err; |
| 5451 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5452 | /* allocate descriptors */ |
| 5453 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5454 | if (err) |
| 5455 | goto err_setup_tx; |
| 5456 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5457 | if (err) |
| 5458 | goto err_setup_rx; |
| 5459 | |
| 5460 | err = i40e_vsi_configure(vsi); |
| 5461 | if (err) |
| 5462 | goto err_setup_rx; |
| 5463 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5464 | if (vsi->netdev) { |
| 5465 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5466 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5467 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5468 | if (err) |
| 5469 | goto err_setup_rx; |
| 5470 | |
| 5471 | /* Notify the stack of the actual queue counts. */ |
| 5472 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5473 | vsi->num_queue_pairs); |
| 5474 | if (err) |
| 5475 | goto err_set_queues; |
| 5476 | |
| 5477 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5478 | vsi->num_queue_pairs); |
| 5479 | if (err) |
| 5480 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5481 | |
| 5482 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5483 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5484 | dev_driver_string(&pf->pdev->dev), |
| 5485 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5486 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5487 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5488 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5489 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5490 | goto err_setup_rx; |
| 5491 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5492 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5493 | err = i40e_up_complete(vsi); |
| 5494 | if (err) |
| 5495 | goto err_up_complete; |
| 5496 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5497 | return 0; |
| 5498 | |
| 5499 | err_up_complete: |
| 5500 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5501 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5502 | i40e_vsi_free_irq(vsi); |
| 5503 | err_setup_rx: |
| 5504 | i40e_vsi_free_rx_resources(vsi); |
| 5505 | err_setup_tx: |
| 5506 | i40e_vsi_free_tx_resources(vsi); |
| 5507 | if (vsi == pf->vsi[pf->lan_vsi]) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5508 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5509 | |
| 5510 | return err; |
| 5511 | } |
| 5512 | |
| 5513 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5514 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5515 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5516 | * |
| 5517 | * This function destroys the hlist where all the Flow Director |
| 5518 | * filters were saved. |
| 5519 | **/ |
| 5520 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5521 | { |
| 5522 | struct i40e_fdir_filter *filter; |
| 5523 | struct hlist_node *node2; |
| 5524 | |
| 5525 | hlist_for_each_entry_safe(filter, node2, |
| 5526 | &pf->fdir_filter_list, fdir_node) { |
| 5527 | hlist_del(&filter->fdir_node); |
| 5528 | kfree(filter); |
| 5529 | } |
| 5530 | pf->fdir_pf_active_filters = 0; |
| 5531 | } |
| 5532 | |
| 5533 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5534 | * i40e_close - Disables a network interface |
| 5535 | * @netdev: network interface device structure |
| 5536 | * |
| 5537 | * The close entry point is called when an interface is de-activated |
| 5538 | * by the OS. The hardware is still under the driver's control, but |
| 5539 | * this netdev interface is disabled. |
| 5540 | * |
| 5541 | * Returns 0, this is not allowed to fail |
| 5542 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5543 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5544 | { |
| 5545 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5546 | struct i40e_vsi *vsi = np->vsi; |
| 5547 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5548 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5549 | |
| 5550 | return 0; |
| 5551 | } |
| 5552 | |
| 5553 | /** |
| 5554 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5555 | * @pf: board private structure |
| 5556 | * @reset_flags: which reset is requested |
| 5557 | * |
| 5558 | * The essential difference in resets is that the PF Reset |
| 5559 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5560 | * firmware, and doesn't bother the other PFs on the chip. |
| 5561 | **/ |
| 5562 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5563 | { |
| 5564 | u32 val; |
| 5565 | |
| 5566 | WARN_ON(in_interrupt()); |
| 5567 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5568 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5569 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5570 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5571 | |
| 5572 | /* Request a Global Reset |
| 5573 | * |
| 5574 | * This will start the chip's countdown to the actual full |
| 5575 | * chip reset event, and a warning interrupt to be sent |
| 5576 | * to all PFs, including the requestor. Our handler |
| 5577 | * for the warning interrupt will deal with the shutdown |
| 5578 | * and recovery of the switch setup. |
| 5579 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5580 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5581 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5582 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5583 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5584 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5585 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5586 | |
| 5587 | /* Request a Core Reset |
| 5588 | * |
| 5589 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5590 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5591 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5592 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5593 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5594 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5595 | i40e_flush(&pf->hw); |
| 5596 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5597 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5598 | |
| 5599 | /* Request a PF Reset |
| 5600 | * |
| 5601 | * Resets only the PF-specific registers |
| 5602 | * |
| 5603 | * This goes directly to the tear-down and rebuild of |
| 5604 | * the switch, since we need to do all the recovery as |
| 5605 | * for the Core Reset. |
| 5606 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5607 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5608 | i40e_handle_reset_warning(pf); |
| 5609 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5610 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5611 | int v; |
| 5612 | |
| 5613 | /* Find the VSI(s) that requested a re-init */ |
| 5614 | dev_info(&pf->pdev->dev, |
| 5615 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5616 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5617 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5618 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5619 | if (vsi != NULL && |
| 5620 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5621 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5622 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5623 | } |
| 5624 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5625 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5626 | int v; |
| 5627 | |
| 5628 | /* Find the VSI(s) that needs to be brought down */ |
| 5629 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5630 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5631 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5632 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5633 | if (vsi != NULL && |
| 5634 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5635 | set_bit(__I40E_DOWN, &vsi->state); |
| 5636 | i40e_down(vsi); |
| 5637 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5638 | } |
| 5639 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5640 | } else { |
| 5641 | dev_info(&pf->pdev->dev, |
| 5642 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5643 | } |
| 5644 | } |
| 5645 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5646 | #ifdef CONFIG_I40E_DCB |
| 5647 | /** |
| 5648 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5649 | * @pf: board private structure |
| 5650 | * @old_cfg: current DCB config |
| 5651 | * @new_cfg: new DCB config |
| 5652 | **/ |
| 5653 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5654 | struct i40e_dcbx_config *old_cfg, |
| 5655 | struct i40e_dcbx_config *new_cfg) |
| 5656 | { |
| 5657 | bool need_reconfig = false; |
| 5658 | |
| 5659 | /* Check if ETS configuration has changed */ |
| 5660 | if (memcmp(&new_cfg->etscfg, |
| 5661 | &old_cfg->etscfg, |
| 5662 | sizeof(new_cfg->etscfg))) { |
| 5663 | /* If Priority Table has changed reconfig is needed */ |
| 5664 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5665 | &old_cfg->etscfg.prioritytable, |
| 5666 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5667 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5668 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5672 | &old_cfg->etscfg.tcbwtable, |
| 5673 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5674 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5675 | |
| 5676 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5677 | &old_cfg->etscfg.tsatable, |
| 5678 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5679 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5680 | } |
| 5681 | |
| 5682 | /* Check if PFC configuration has changed */ |
| 5683 | if (memcmp(&new_cfg->pfc, |
| 5684 | &old_cfg->pfc, |
| 5685 | sizeof(new_cfg->pfc))) { |
| 5686 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5687 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5688 | } |
| 5689 | |
| 5690 | /* Check if APP Table has changed */ |
| 5691 | if (memcmp(&new_cfg->app, |
| 5692 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5693 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5694 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5695 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5696 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5697 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5698 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5699 | return need_reconfig; |
| 5700 | } |
| 5701 | |
| 5702 | /** |
| 5703 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5704 | * @pf: board private structure |
| 5705 | * @e: event info posted on ARQ |
| 5706 | **/ |
| 5707 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5708 | struct i40e_arq_event_info *e) |
| 5709 | { |
| 5710 | struct i40e_aqc_lldp_get_mib *mib = |
| 5711 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5712 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5713 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5714 | bool need_reconfig = false; |
| 5715 | int ret = 0; |
| 5716 | u8 type; |
| 5717 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5718 | /* Not DCB capable or capability disabled */ |
| 5719 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
| 5720 | return ret; |
| 5721 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5722 | /* Ignore if event is not for Nearest Bridge */ |
| 5723 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5724 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5725 | 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] | 5726 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5727 | return ret; |
| 5728 | |
| 5729 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5730 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5731 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5732 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5733 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5734 | /* Update the remote cached instance and return */ |
| 5735 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5736 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5737 | &hw->remote_dcbx_config); |
| 5738 | goto exit; |
| 5739 | } |
| 5740 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5741 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5742 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5743 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5744 | /* Reset the old DCBx configuration data */ |
| 5745 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5746 | /* Get updated DCBX data from firmware */ |
| 5747 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5748 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5749 | dev_info(&pf->pdev->dev, |
| 5750 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 5751 | i40e_stat_str(&pf->hw, ret), |
| 5752 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5753 | goto exit; |
| 5754 | } |
| 5755 | |
| 5756 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5757 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5758 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5759 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5760 | goto exit; |
| 5761 | } |
| 5762 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5763 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5764 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5765 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5766 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5767 | |
| 5768 | if (!need_reconfig) |
| 5769 | goto exit; |
| 5770 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5771 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5772 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5773 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5774 | else |
| 5775 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5776 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5777 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5778 | /* Reconfiguration needed quiesce all VSIs */ |
| 5779 | i40e_pf_quiesce_all_vsi(pf); |
| 5780 | |
| 5781 | /* Changes in configuration update VEB/VSI */ |
| 5782 | i40e_dcb_reconfigure(pf); |
| 5783 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5784 | ret = i40e_resume_port_tx(pf); |
| 5785 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5786 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5787 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5788 | if (ret) |
| 5789 | goto exit; |
| 5790 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 5791 | /* Wait for the PF's queues to be disabled */ |
| 5792 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5793 | if (ret) { |
| 5794 | /* Schedule PF reset to recover */ |
| 5795 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5796 | i40e_service_event_schedule(pf); |
| 5797 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5798 | i40e_pf_unquiesce_all_vsi(pf); |
Neerav Parikh | 85a1aab | 2016-06-07 09:14:55 -0700 | [diff] [blame] | 5799 | /* Notify the client for the DCB changes */ |
| 5800 | i40e_notify_client_of_l2_param_changes(pf->vsi[pf->lan_vsi]); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5801 | } |
| 5802 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5803 | exit: |
| 5804 | return ret; |
| 5805 | } |
| 5806 | #endif /* CONFIG_I40E_DCB */ |
| 5807 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5808 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5809 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 5810 | * @pf: board private structure |
| 5811 | * @reset_flags: which reset is requested |
| 5812 | * |
| 5813 | **/ |
| 5814 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 5815 | { |
| 5816 | rtnl_lock(); |
| 5817 | i40e_do_reset(pf, reset_flags); |
| 5818 | rtnl_unlock(); |
| 5819 | } |
| 5820 | |
| 5821 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5822 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 5823 | * @pf: board private structure |
| 5824 | * @e: event info posted on ARQ |
| 5825 | * |
| 5826 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 5827 | * and VF queues |
| 5828 | **/ |
| 5829 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 5830 | struct i40e_arq_event_info *e) |
| 5831 | { |
| 5832 | struct i40e_aqc_lan_overflow *data = |
| 5833 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 5834 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 5835 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 5836 | struct i40e_hw *hw = &pf->hw; |
| 5837 | struct i40e_vf *vf; |
| 5838 | u16 vf_id; |
| 5839 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5840 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 5841 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5842 | |
| 5843 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 5844 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 5845 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 5846 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 5847 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 5848 | vf_id -= hw->func_caps.vf_base_id; |
| 5849 | vf = &pf->vf[vf_id]; |
| 5850 | i40e_vc_notify_vf_reset(vf); |
| 5851 | /* Allow VF to process pending reset notification */ |
| 5852 | msleep(20); |
| 5853 | i40e_reset_vf(vf, false); |
| 5854 | } |
| 5855 | } |
| 5856 | |
| 5857 | /** |
| 5858 | * i40e_service_event_complete - Finish up the service event |
| 5859 | * @pf: board private structure |
| 5860 | **/ |
| 5861 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 5862 | { |
Shannon Nelson | b875f99 | 2015-10-21 19:47:03 -0400 | [diff] [blame] | 5863 | WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5864 | |
| 5865 | /* flush memory to make sure state is correct before next watchog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5866 | smp_mb__before_atomic(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5867 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 5868 | } |
| 5869 | |
| 5870 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5871 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 5872 | * @pf: board private structure |
| 5873 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5874 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5875 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5876 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5877 | |
| 5878 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5879 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 5880 | return fcnt_prog; |
| 5881 | } |
| 5882 | |
| 5883 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5884 | * 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] | 5885 | * @pf: board private structure |
| 5886 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5887 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5888 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5889 | u32 val, fcnt_prog; |
| 5890 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5891 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5892 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 5893 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 5894 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 5895 | return fcnt_prog; |
| 5896 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5897 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5898 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5899 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 5900 | * @pf: board private structure |
| 5901 | **/ |
| 5902 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 5903 | { |
| 5904 | u32 val, fcnt_prog; |
| 5905 | |
| 5906 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 5907 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 5908 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 5909 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 5910 | return fcnt_prog; |
| 5911 | } |
| 5912 | |
| 5913 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5914 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 5915 | * @pf: board private structure |
| 5916 | **/ |
| 5917 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 5918 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5919 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5920 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5921 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5922 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5923 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 5924 | return; |
| 5925 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5926 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 5927 | * to re-enable |
| 5928 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5929 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5930 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5931 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 5932 | (pf->fd_add_err == 0) || |
| 5933 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5934 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 5935 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 5936 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5937 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5938 | 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] | 5939 | } |
| 5940 | } |
| 5941 | /* Wait for some more space to be available to turn on ATR */ |
| 5942 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 5943 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 5944 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
| 5945 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5946 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5947 | dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table now\n"); |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5948 | } |
| 5949 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5950 | |
| 5951 | /* if hw had a problem adding a filter, delete it */ |
| 5952 | if (pf->fd_inv > 0) { |
| 5953 | hlist_for_each_entry_safe(filter, node, |
| 5954 | &pf->fdir_filter_list, fdir_node) { |
| 5955 | if (filter->fd_id == pf->fd_inv) { |
| 5956 | hlist_del(&filter->fdir_node); |
| 5957 | kfree(filter); |
| 5958 | pf->fdir_pf_active_filters--; |
| 5959 | } |
| 5960 | } |
| 5961 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5962 | } |
| 5963 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5964 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5965 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5966 | /** |
| 5967 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 5968 | * @pf: board private structure |
| 5969 | **/ |
| 5970 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 5971 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5972 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5973 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5974 | bool disable_atr = false; |
| 5975 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5976 | int reg; |
| 5977 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 5978 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 5979 | return; |
| 5980 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5981 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 5982 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 5983 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5984 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5985 | /* If the flush is happening too quick and we have mostly SB rules we |
| 5986 | * should not re-enable ATR for some time. |
| 5987 | */ |
| 5988 | min_flush_time = pf->fd_flush_timestamp + |
| 5989 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 5990 | 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] | 5991 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5992 | if (!(time_after(jiffies, min_flush_time)) && |
| 5993 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 5994 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5995 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 5996 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5997 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5998 | |
| 5999 | pf->fd_flush_timestamp = jiffies; |
| 6000 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
| 6001 | /* flush all filters */ |
| 6002 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 6003 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 6004 | i40e_flush(&pf->hw); |
| 6005 | pf->fd_flush_cnt++; |
| 6006 | pf->fd_add_err = 0; |
| 6007 | do { |
| 6008 | /* Check FD flush status every 5-6msec */ |
| 6009 | usleep_range(5000, 6000); |
| 6010 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 6011 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 6012 | break; |
| 6013 | } while (flush_wait_retry--); |
| 6014 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 6015 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 6016 | } else { |
| 6017 | /* replay sideband filters */ |
| 6018 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
| 6019 | if (!disable_atr) |
| 6020 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 6021 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
| 6022 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 6023 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 6024 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6025 | } |
| 6026 | |
| 6027 | /** |
| 6028 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 6029 | * @pf: board private structure |
| 6030 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6031 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6032 | { |
| 6033 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 6034 | } |
| 6035 | |
| 6036 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 6037 | * being applied really fast; before we see the first |
| 6038 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 6039 | * reacting will make sure we don't cause flush too often. |
| 6040 | */ |
| 6041 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 6042 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6043 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6044 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 6045 | * @pf: board private structure |
| 6046 | **/ |
| 6047 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 6048 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6049 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6050 | /* if interface is down do nothing */ |
| 6051 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 6052 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6053 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 6054 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 6055 | return; |
| 6056 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6057 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6058 | i40e_fdir_flush_and_replay(pf); |
| 6059 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6060 | i40e_fdir_check_and_reenable(pf); |
| 6061 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6062 | } |
| 6063 | |
| 6064 | /** |
| 6065 | * i40e_vsi_link_event - notify VSI of a link event |
| 6066 | * @vsi: vsi to be notified |
| 6067 | * @link_up: link up or down |
| 6068 | **/ |
| 6069 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 6070 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 6071 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6072 | return; |
| 6073 | |
| 6074 | switch (vsi->type) { |
| 6075 | case I40E_VSI_MAIN: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6076 | #ifdef I40E_FCOE |
| 6077 | case I40E_VSI_FCOE: |
| 6078 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6079 | if (!vsi->netdev || !vsi->netdev_registered) |
| 6080 | break; |
| 6081 | |
| 6082 | if (link_up) { |
| 6083 | netif_carrier_on(vsi->netdev); |
| 6084 | netif_tx_wake_all_queues(vsi->netdev); |
| 6085 | } else { |
| 6086 | netif_carrier_off(vsi->netdev); |
| 6087 | netif_tx_stop_all_queues(vsi->netdev); |
| 6088 | } |
| 6089 | break; |
| 6090 | |
| 6091 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6092 | case I40E_VSI_VMDQ2: |
| 6093 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6094 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6095 | case I40E_VSI_MIRROR: |
| 6096 | default: |
| 6097 | /* there is no notification for other VSIs */ |
| 6098 | break; |
| 6099 | } |
| 6100 | } |
| 6101 | |
| 6102 | /** |
| 6103 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6104 | * @veb: veb to be notified |
| 6105 | * @link_up: link up or down |
| 6106 | **/ |
| 6107 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6108 | { |
| 6109 | struct i40e_pf *pf; |
| 6110 | int i; |
| 6111 | |
| 6112 | if (!veb || !veb->pf) |
| 6113 | return; |
| 6114 | pf = veb->pf; |
| 6115 | |
| 6116 | /* depth first... */ |
| 6117 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6118 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6119 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6120 | |
| 6121 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6122 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6123 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6124 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6125 | } |
| 6126 | |
| 6127 | /** |
| 6128 | * i40e_link_event - Update netif_carrier status |
| 6129 | * @pf: board private structure |
| 6130 | **/ |
| 6131 | static void i40e_link_event(struct i40e_pf *pf) |
| 6132 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6133 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6134 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6135 | i40e_status status; |
| 6136 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6137 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6138 | /* save off old link status information */ |
| 6139 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6140 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6141 | /* set this to force the get_link_status call to refresh state */ |
| 6142 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6143 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6144 | 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] | 6145 | |
| 6146 | status = i40e_get_link_status(&pf->hw, &new_link); |
| 6147 | if (status) { |
| 6148 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6149 | status); |
| 6150 | return; |
| 6151 | } |
| 6152 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6153 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6154 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6155 | |
| 6156 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6157 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6158 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 6159 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6160 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6161 | |
| 6162 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 6163 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6164 | |
| 6165 | /* Notify the base of the switch tree connected to |
| 6166 | * the link. Floating VEBs are not notified. |
| 6167 | */ |
| 6168 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6169 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6170 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6171 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6172 | |
| 6173 | if (pf->vf) |
| 6174 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6175 | |
| 6176 | if (pf->flags & I40E_FLAG_PTP) |
| 6177 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6178 | } |
| 6179 | |
| 6180 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6181 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6182 | * @pf: board private structure |
| 6183 | **/ |
| 6184 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6185 | { |
| 6186 | int i; |
| 6187 | |
| 6188 | /* if interface is down do nothing */ |
| 6189 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 6190 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6191 | return; |
| 6192 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6193 | /* make sure we don't do these things too often */ |
| 6194 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6195 | pf->service_timer_period))) |
| 6196 | return; |
| 6197 | pf->service_timer_previous = jiffies; |
| 6198 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6199 | if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) |
| 6200 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6201 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6202 | /* Update the stats for active netdevs so the network stack |
| 6203 | * can look at updated numbers whenever it cares to |
| 6204 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6205 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6206 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6207 | i40e_update_stats(pf->vsi[i]); |
| 6208 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6209 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6210 | /* Update the stats for the active switching components */ |
| 6211 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6212 | if (pf->veb[i]) |
| 6213 | i40e_update_veb_stats(pf->veb[i]); |
| 6214 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6215 | |
| 6216 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6217 | } |
| 6218 | |
| 6219 | /** |
| 6220 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6221 | * @pf: board private structure |
| 6222 | **/ |
| 6223 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6224 | { |
| 6225 | u32 reset_flags = 0; |
| 6226 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6227 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6228 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6229 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6230 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 6231 | } |
| 6232 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6233 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6234 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6235 | } |
| 6236 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6237 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6238 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 6239 | } |
| 6240 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6241 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6242 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 6243 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6244 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6245 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6246 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 6247 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6248 | |
| 6249 | /* If there's a recovery already waiting, it takes |
| 6250 | * precedence before starting a new reset sequence. |
| 6251 | */ |
| 6252 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 6253 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6254 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6255 | } |
| 6256 | |
| 6257 | /* If we're already down or resetting, just bail */ |
| 6258 | if (reset_flags && |
| 6259 | !test_bit(__I40E_DOWN, &pf->state) && |
| 6260 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6261 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6262 | |
| 6263 | unlock: |
| 6264 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6265 | } |
| 6266 | |
| 6267 | /** |
| 6268 | * i40e_handle_link_event - Handle link event |
| 6269 | * @pf: board private structure |
| 6270 | * @e: event info posted on ARQ |
| 6271 | **/ |
| 6272 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6273 | struct i40e_arq_event_info *e) |
| 6274 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6275 | struct i40e_aqc_get_link_status *status = |
| 6276 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6277 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6278 | /* Do a new status request to re-enable LSE reporting |
| 6279 | * and load new status information into the hw struct |
| 6280 | * This completely ignores any state information |
| 6281 | * in the ARQ event info, instead choosing to always |
| 6282 | * issue the AQ update link status command. |
| 6283 | */ |
| 6284 | i40e_link_event(pf); |
| 6285 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6286 | /* check for unqualified module, if link is down */ |
| 6287 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6288 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6289 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6290 | dev_err(&pf->pdev->dev, |
| 6291 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6292 | } |
| 6293 | |
| 6294 | /** |
| 6295 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6296 | * @pf: board private structure |
| 6297 | **/ |
| 6298 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6299 | { |
| 6300 | struct i40e_arq_event_info event; |
| 6301 | struct i40e_hw *hw = &pf->hw; |
| 6302 | u16 pending, i = 0; |
| 6303 | i40e_status ret; |
| 6304 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6305 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6306 | u32 val; |
| 6307 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6308 | /* Do not run clean AQ when PF reset fails */ |
| 6309 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 6310 | return; |
| 6311 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6312 | /* check for error indications */ |
| 6313 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6314 | oldval = val; |
| 6315 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6316 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6317 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6318 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6319 | } |
| 6320 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6321 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6322 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6323 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6324 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6325 | } |
| 6326 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6327 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6328 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6329 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6330 | } |
| 6331 | if (oldval != val) |
| 6332 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6333 | |
| 6334 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6335 | oldval = val; |
| 6336 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6337 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6338 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6339 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6340 | } |
| 6341 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6342 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6343 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6344 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6345 | } |
| 6346 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6347 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6348 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6349 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6350 | } |
| 6351 | if (oldval != val) |
| 6352 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6353 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6354 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6355 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6356 | if (!event.msg_buf) |
| 6357 | return; |
| 6358 | |
| 6359 | do { |
| 6360 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6361 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6362 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6363 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6364 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6365 | break; |
| 6366 | } |
| 6367 | |
| 6368 | opcode = le16_to_cpu(event.desc.opcode); |
| 6369 | switch (opcode) { |
| 6370 | |
| 6371 | case i40e_aqc_opc_get_link_status: |
| 6372 | i40e_handle_link_event(pf, &event); |
| 6373 | break; |
| 6374 | case i40e_aqc_opc_send_msg_to_pf: |
| 6375 | ret = i40e_vc_process_vf_msg(pf, |
| 6376 | le16_to_cpu(event.desc.retval), |
| 6377 | le32_to_cpu(event.desc.cookie_high), |
| 6378 | le32_to_cpu(event.desc.cookie_low), |
| 6379 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6380 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6381 | break; |
| 6382 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6383 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6384 | #ifdef CONFIG_I40E_DCB |
| 6385 | rtnl_lock(); |
| 6386 | ret = i40e_handle_lldp_event(pf, &event); |
| 6387 | rtnl_unlock(); |
| 6388 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6389 | break; |
| 6390 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6391 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6392 | i40e_handle_lan_overflow_event(pf, &event); |
| 6393 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6394 | case i40e_aqc_opc_send_msg_to_peer: |
| 6395 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6396 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6397 | case i40e_aqc_opc_nvm_erase: |
| 6398 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6399 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 6400 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 6401 | "ARQ NVM operation 0x%04x completed\n", |
| 6402 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6403 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6404 | default: |
| 6405 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 6406 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6407 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6408 | break; |
| 6409 | } |
| 6410 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 6411 | |
| 6412 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 6413 | /* re-enable Admin queue interrupt cause */ |
| 6414 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6415 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6416 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6417 | i40e_flush(hw); |
| 6418 | |
| 6419 | kfree(event.msg_buf); |
| 6420 | } |
| 6421 | |
| 6422 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6423 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6424 | * @pf: board private structure |
| 6425 | **/ |
| 6426 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6427 | { |
| 6428 | int err; |
| 6429 | |
| 6430 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6431 | if (err) { |
| 6432 | /* retry in case of garbage read */ |
| 6433 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6434 | if (err) { |
| 6435 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6436 | err); |
| 6437 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6438 | } |
| 6439 | } |
| 6440 | |
| 6441 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 6442 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 6443 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6444 | } |
| 6445 | } |
| 6446 | |
| 6447 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6448 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6449 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6450 | * |
| 6451 | * enable switch loop back or die - no point in a return value |
| 6452 | **/ |
| 6453 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6454 | { |
| 6455 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6456 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6457 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6458 | |
| 6459 | ctxt.seid = pf->main_vsi_seid; |
| 6460 | ctxt.pf_num = pf->hw.pf_id; |
| 6461 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6462 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6463 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6464 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6465 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6466 | i40e_stat_str(&pf->hw, ret), |
| 6467 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6468 | return; |
| 6469 | } |
| 6470 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6471 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6472 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6473 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6474 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6475 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6476 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6477 | "update vsi switch failed, err %s aq_err %s\n", |
| 6478 | i40e_stat_str(&pf->hw, ret), |
| 6479 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6480 | } |
| 6481 | } |
| 6482 | |
| 6483 | /** |
| 6484 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6485 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6486 | * |
| 6487 | * disable switch loop back or die - no point in a return value |
| 6488 | **/ |
| 6489 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6490 | { |
| 6491 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6492 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6493 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6494 | |
| 6495 | ctxt.seid = pf->main_vsi_seid; |
| 6496 | ctxt.pf_num = pf->hw.pf_id; |
| 6497 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6498 | ret = i40e_aq_get_vsi_params(&pf->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 | "couldn't get PF vsi config, 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 | return; |
| 6505 | } |
| 6506 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6507 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6508 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6509 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6510 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6511 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6512 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6513 | "update vsi switch failed, err %s aq_err %s\n", |
| 6514 | i40e_stat_str(&pf->hw, ret), |
| 6515 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6516 | } |
| 6517 | } |
| 6518 | |
| 6519 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6520 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6521 | * @veb: pointer to the bridge instance |
| 6522 | * |
| 6523 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6524 | * specified HW bridge instance. It is expected this function is called |
| 6525 | * when a new HW bridge is instantiated. |
| 6526 | **/ |
| 6527 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6528 | { |
| 6529 | struct i40e_pf *pf = veb->pf; |
| 6530 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6531 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6532 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6533 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6534 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6535 | i40e_disable_pf_switch_lb(pf); |
| 6536 | else |
| 6537 | i40e_enable_pf_switch_lb(pf); |
| 6538 | } |
| 6539 | |
| 6540 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6541 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6542 | * @veb: pointer to the VEB instance |
| 6543 | * |
| 6544 | * This is a recursive function that first builds the attached VSIs then |
| 6545 | * recurses in to build the next layer of VEB. We track the connections |
| 6546 | * through our own index numbers because the seid's from the HW could |
| 6547 | * change across the reset. |
| 6548 | **/ |
| 6549 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6550 | { |
| 6551 | struct i40e_vsi *ctl_vsi = NULL; |
| 6552 | struct i40e_pf *pf = veb->pf; |
| 6553 | int v, veb_idx; |
| 6554 | int ret; |
| 6555 | |
| 6556 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6557 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6558 | if (pf->vsi[v] && |
| 6559 | pf->vsi[v]->veb_idx == veb->idx && |
| 6560 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6561 | ctl_vsi = pf->vsi[v]; |
| 6562 | break; |
| 6563 | } |
| 6564 | } |
| 6565 | if (!ctl_vsi) { |
| 6566 | dev_info(&pf->pdev->dev, |
| 6567 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6568 | ret = -ENOENT; |
| 6569 | goto end_reconstitute; |
| 6570 | } |
| 6571 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6572 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6573 | ret = i40e_add_vsi(ctl_vsi); |
| 6574 | if (ret) { |
| 6575 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6576 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6577 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6578 | goto end_reconstitute; |
| 6579 | } |
| 6580 | i40e_vsi_reset_stats(ctl_vsi); |
| 6581 | |
| 6582 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6583 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6584 | if (ret) |
| 6585 | goto end_reconstitute; |
| 6586 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6587 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6588 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6589 | else |
| 6590 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6591 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6592 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6593 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6594 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6595 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6596 | continue; |
| 6597 | |
| 6598 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6599 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6600 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6601 | vsi->uplink_seid = veb->seid; |
| 6602 | ret = i40e_add_vsi(vsi); |
| 6603 | if (ret) { |
| 6604 | dev_info(&pf->pdev->dev, |
| 6605 | "rebuild of vsi_idx %d failed: %d\n", |
| 6606 | v, ret); |
| 6607 | goto end_reconstitute; |
| 6608 | } |
| 6609 | i40e_vsi_reset_stats(vsi); |
| 6610 | } |
| 6611 | } |
| 6612 | |
| 6613 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6614 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6615 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6616 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6617 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6618 | if (ret) |
| 6619 | break; |
| 6620 | } |
| 6621 | } |
| 6622 | |
| 6623 | end_reconstitute: |
| 6624 | return ret; |
| 6625 | } |
| 6626 | |
| 6627 | /** |
| 6628 | * i40e_get_capabilities - get info about the HW |
| 6629 | * @pf: the PF struct |
| 6630 | **/ |
| 6631 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6632 | { |
| 6633 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6634 | u16 data_size; |
| 6635 | int buf_len; |
| 6636 | int err; |
| 6637 | |
| 6638 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6639 | do { |
| 6640 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6641 | if (!cap_buf) |
| 6642 | return -ENOMEM; |
| 6643 | |
| 6644 | /* this loads the data into the hw struct for us */ |
| 6645 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6646 | &data_size, |
| 6647 | i40e_aqc_opc_list_func_capabilities, |
| 6648 | NULL); |
| 6649 | /* data loaded, buffer no longer needed */ |
| 6650 | kfree(cap_buf); |
| 6651 | |
| 6652 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6653 | /* retry with a larger buffer */ |
| 6654 | buf_len = data_size; |
| 6655 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6656 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6657 | "capability discovery failed, err %s aq_err %s\n", |
| 6658 | i40e_stat_str(&pf->hw, err), |
| 6659 | i40e_aq_str(&pf->hw, |
| 6660 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6661 | return -ENODEV; |
| 6662 | } |
| 6663 | } while (err); |
| 6664 | |
| 6665 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6666 | dev_info(&pf->pdev->dev, |
| 6667 | "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", |
| 6668 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6669 | pf->hw.func_caps.num_msix_vectors, |
| 6670 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6671 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6672 | pf->hw.func_caps.fd_filters_best_effort, |
| 6673 | pf->hw.func_caps.num_tx_qp, |
| 6674 | pf->hw.func_caps.num_vsis); |
| 6675 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6676 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6677 | + pf->hw.func_caps.num_vfs) |
| 6678 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6679 | dev_info(&pf->pdev->dev, |
| 6680 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6681 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6682 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6683 | } |
| 6684 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6685 | return 0; |
| 6686 | } |
| 6687 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6688 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6689 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6690 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6691 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6692 | * @pf: board private structure |
| 6693 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6694 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6695 | { |
| 6696 | struct i40e_vsi *vsi; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6697 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6698 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6699 | /* quick workaround for an NVM issue that leaves a critical register |
| 6700 | * uninitialized |
| 6701 | */ |
| 6702 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6703 | static const u32 hkey[] = { |
| 6704 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6705 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6706 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6707 | 0x95b3a76d}; |
| 6708 | |
| 6709 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6710 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6711 | } |
| 6712 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6713 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6714 | return; |
| 6715 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6716 | /* find existing VSI and see if it needs configuring */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6717 | vsi = NULL; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6718 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6719 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6720 | vsi = pf->vsi[i]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6721 | break; |
| 6722 | } |
| 6723 | } |
| 6724 | |
| 6725 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6726 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6727 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6728 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6729 | if (!vsi) { |
| 6730 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6731 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6732 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6733 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6734 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6735 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6736 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6737 | } |
| 6738 | |
| 6739 | /** |
| 6740 | * i40e_fdir_teardown - release the Flow Director resources |
| 6741 | * @pf: board private structure |
| 6742 | **/ |
| 6743 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6744 | { |
| 6745 | int i; |
| 6746 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6747 | i40e_fdir_filter_exit(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6748 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6749 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 6750 | i40e_vsi_release(pf->vsi[i]); |
| 6751 | break; |
| 6752 | } |
| 6753 | } |
| 6754 | } |
| 6755 | |
| 6756 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6757 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6758 | * @pf: board private structure |
| 6759 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6760 | * 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] | 6761 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6762 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6763 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6764 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6765 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6766 | u32 v; |
| 6767 | |
| 6768 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6769 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6770 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 6771 | if (i40e_check_asq_alive(&pf->hw)) |
| 6772 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6773 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6774 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6775 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6776 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6777 | i40e_pf_quiesce_all_vsi(pf); |
| 6778 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6779 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6780 | if (pf->vsi[v]) |
| 6781 | pf->vsi[v]->seid = 0; |
| 6782 | } |
| 6783 | |
| 6784 | i40e_shutdown_adminq(&pf->hw); |
| 6785 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6786 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6787 | if (hw->hmc.hmc_obj) { |
| 6788 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6789 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6790 | dev_warn(&pf->pdev->dev, |
| 6791 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6792 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6793 | } |
| 6794 | |
| 6795 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6796 | * i40e_send_version - update firmware with driver version |
| 6797 | * @pf: PF struct |
| 6798 | */ |
| 6799 | static void i40e_send_version(struct i40e_pf *pf) |
| 6800 | { |
| 6801 | struct i40e_driver_version dv; |
| 6802 | |
| 6803 | dv.major_version = DRV_VERSION_MAJOR; |
| 6804 | dv.minor_version = DRV_VERSION_MINOR; |
| 6805 | dv.build_version = DRV_VERSION_BUILD; |
| 6806 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 6807 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6808 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 6809 | } |
| 6810 | |
| 6811 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 6812 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6813 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6814 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6815 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6816 | 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] | 6817 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6818 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6819 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6820 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6821 | u32 val; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6822 | u32 v; |
| 6823 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6824 | /* Now we wait for GRST to settle out. |
| 6825 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 6826 | * because the reset will make them disappear. |
| 6827 | */ |
| 6828 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6829 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6830 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6831 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 6832 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6833 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6834 | pf->pfr_count++; |
| 6835 | |
| 6836 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6837 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6838 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6839 | |
| 6840 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 6841 | ret = i40e_init_adminq(&pf->hw); |
| 6842 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6843 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 6844 | i40e_stat_str(&pf->hw, ret), |
| 6845 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6846 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6847 | } |
| 6848 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6849 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 6850 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6851 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6852 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 6853 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6854 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6855 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6856 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6857 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6858 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 6859 | hw->func_caps.num_rx_qp, |
| 6860 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 6861 | if (ret) { |
| 6862 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 6863 | goto end_core_reset; |
| 6864 | } |
| 6865 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 6866 | if (ret) { |
| 6867 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 6868 | goto end_core_reset; |
| 6869 | } |
| 6870 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6871 | #ifdef CONFIG_I40E_DCB |
| 6872 | ret = i40e_init_pf_dcb(pf); |
| 6873 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6874 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 6875 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 6876 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6877 | } |
| 6878 | #endif /* CONFIG_I40E_DCB */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6879 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 6880 | i40e_init_pf_fcoe(pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6881 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6882 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6883 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6884 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6885 | if (ret) |
| 6886 | goto end_core_reset; |
| 6887 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6888 | /* The driver only wants link up/down and module qualification |
| 6889 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6890 | */ |
| 6891 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6892 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 6893 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6894 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6895 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6896 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 6897 | i40e_stat_str(&pf->hw, ret), |
| 6898 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6899 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6900 | /* make sure our flow control settings are restored */ |
| 6901 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 6902 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 6903 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 6904 | i40e_stat_str(&pf->hw, ret), |
| 6905 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6906 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6907 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 6908 | * They are still in our local switch element arrays, so only |
| 6909 | * need to rebuild the switch model in the HW. |
| 6910 | * |
| 6911 | * If there were VEBs but the reconstitution failed, we'll try |
| 6912 | * try to recover minimal use by getting the basic PF VSI working. |
| 6913 | */ |
| 6914 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6915 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6916 | /* find the one VEB connected to the MAC, and find orphans */ |
| 6917 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6918 | if (!pf->veb[v]) |
| 6919 | continue; |
| 6920 | |
| 6921 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 6922 | pf->veb[v]->uplink_seid == 0) { |
| 6923 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 6924 | |
| 6925 | if (!ret) |
| 6926 | continue; |
| 6927 | |
| 6928 | /* If Main VEB failed, we're in deep doodoo, |
| 6929 | * so give up rebuilding the switch and set up |
| 6930 | * for minimal rebuild of PF VSI. |
| 6931 | * If orphan failed, we'll report the error |
| 6932 | * but try to keep going. |
| 6933 | */ |
| 6934 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 6935 | dev_info(&pf->pdev->dev, |
| 6936 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 6937 | ret); |
| 6938 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 6939 | = pf->mac_seid; |
| 6940 | break; |
| 6941 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 6942 | dev_info(&pf->pdev->dev, |
| 6943 | "rebuild of orphan VEB failed: %d\n", |
| 6944 | ret); |
| 6945 | } |
| 6946 | } |
| 6947 | } |
| 6948 | } |
| 6949 | |
| 6950 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 6951 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6952 | /* no VEB, so rebuild only the Main VSI */ |
| 6953 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 6954 | if (ret) { |
| 6955 | dev_info(&pf->pdev->dev, |
| 6956 | "rebuild of Main VSI failed: %d\n", ret); |
| 6957 | goto end_core_reset; |
| 6958 | } |
| 6959 | } |
| 6960 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6961 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 6962 | * of TSO, so that we avoid the MDD being fired and causing |
| 6963 | * a reset in the case of small MSS+TSO. |
| 6964 | */ |
| 6965 | #define I40E_REG_MSS 0x000E64DC |
| 6966 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 6967 | #define I40E_64BYTE_MSS 0x400000 |
| 6968 | val = rd32(hw, I40E_REG_MSS); |
| 6969 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 6970 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 6971 | val |= I40E_64BYTE_MSS; |
| 6972 | wr32(hw, I40E_REG_MSS, val); |
| 6973 | } |
| 6974 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 6975 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 6976 | msleep(75); |
| 6977 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 6978 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6979 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 6980 | i40e_stat_str(&pf->hw, ret), |
| 6981 | i40e_aq_str(&pf->hw, |
| 6982 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6983 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6984 | /* reinit the misc interrupt */ |
| 6985 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 6986 | ret = i40e_setup_misc_vector(pf); |
| 6987 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 6988 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 6989 | * transmitted. By doing so we stop a malicious VF from sending out |
| 6990 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 6991 | * PF/VF VSIs. |
| 6992 | * The FW can still send Flow control frames if enabled. |
| 6993 | */ |
| 6994 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 6995 | pf->main_vsi_seid); |
| 6996 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6997 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 6998 | i40e_pf_unquiesce_all_vsi(pf); |
| 6999 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 7000 | if (pf->num_alloc_vfs) { |
| 7001 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 7002 | i40e_reset_vf(&pf->vf[v], true); |
| 7003 | } |
| 7004 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7005 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 7006 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7007 | |
| 7008 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 7009 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 7010 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7011 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 7012 | } |
| 7013 | |
| 7014 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7015 | * 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] | 7016 | * @pf: board private structure |
| 7017 | * |
| 7018 | * Close up the VFs and other things in prep for a Core Reset, |
| 7019 | * then get ready to rebuild the world. |
| 7020 | **/ |
| 7021 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 7022 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 7023 | i40e_prep_for_reset(pf); |
| 7024 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7025 | } |
| 7026 | |
| 7027 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7028 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7029 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7030 | * |
| 7031 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 7032 | **/ |
| 7033 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 7034 | { |
| 7035 | struct i40e_hw *hw = &pf->hw; |
| 7036 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7037 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7038 | struct i40e_vf *vf; |
| 7039 | u32 reg; |
| 7040 | int i; |
| 7041 | |
| 7042 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 7043 | return; |
| 7044 | |
| 7045 | /* find what triggered the MDD event */ |
| 7046 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 7047 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7048 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 7049 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7050 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7051 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7052 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7053 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7054 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 7055 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 7056 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7057 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7058 | 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] | 7059 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7060 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 7061 | mdd_detected = true; |
| 7062 | } |
| 7063 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 7064 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7065 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 7066 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7067 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7068 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7069 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 7070 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 7071 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7072 | if (netif_msg_rx_err(pf)) |
| 7073 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 7074 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7075 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 7076 | mdd_detected = true; |
| 7077 | } |
| 7078 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7079 | if (mdd_detected) { |
| 7080 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 7081 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 7082 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7083 | 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] | 7084 | pf_mdd_detected = true; |
| 7085 | } |
| 7086 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 7087 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 7088 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7089 | 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] | 7090 | pf_mdd_detected = true; |
| 7091 | } |
| 7092 | /* Queue belongs to the PF, initiate a reset */ |
| 7093 | if (pf_mdd_detected) { |
| 7094 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 7095 | i40e_service_event_schedule(pf); |
| 7096 | } |
| 7097 | } |
| 7098 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7099 | /* see if one of the VFs needs its hand slapped */ |
| 7100 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7101 | vf = &(pf->vf[i]); |
| 7102 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7103 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7104 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7105 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7106 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7107 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7108 | } |
| 7109 | |
| 7110 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7111 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7112 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7113 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7114 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7115 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7116 | } |
| 7117 | |
| 7118 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7119 | dev_info(&pf->pdev->dev, |
| 7120 | "Too many MDD events on VF %d, disabled\n", i); |
| 7121 | dev_info(&pf->pdev->dev, |
| 7122 | "Use PF Control I/F to re-enable the VF\n"); |
| 7123 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 7124 | } |
| 7125 | } |
| 7126 | |
| 7127 | /* re-enable mdd interrupt cause */ |
| 7128 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 7129 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7130 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7131 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7132 | i40e_flush(hw); |
| 7133 | } |
| 7134 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7135 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7136 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7137 | * @pf: board private structure |
| 7138 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7139 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7140 | { |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7141 | struct i40e_hw *hw = &pf->hw; |
| 7142 | i40e_status ret; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7143 | __be16 port; |
| 7144 | int i; |
| 7145 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7146 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7147 | return; |
| 7148 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7149 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7150 | |
| 7151 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7152 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7153 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
| 7154 | port = pf->udp_ports[i].index; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7155 | if (port) |
| 7156 | ret = i40e_aq_add_udp_tunnel(hw, ntohs(port), |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7157 | pf->udp_ports[i].type, |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7158 | NULL, NULL); |
| 7159 | else |
| 7160 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7161 | |
| 7162 | if (ret) { |
Carolyn Wyborny | 730a8f8 | 2016-02-17 16:12:16 -0800 | [diff] [blame] | 7163 | dev_dbg(&pf->pdev->dev, |
| 7164 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 7165 | pf->udp_ports[i].type ? "vxlan" : "geneve", |
| 7166 | port ? "add" : "delete", |
| 7167 | ntohs(port), i, |
| 7168 | i40e_stat_str(&pf->hw, ret), |
| 7169 | i40e_aq_str(&pf->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7170 | pf->hw.aq.asq_last_status)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7171 | pf->udp_ports[i].index = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7172 | } |
| 7173 | } |
| 7174 | } |
| 7175 | } |
| 7176 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7177 | /** |
| 7178 | * i40e_service_task - Run the driver's async subtasks |
| 7179 | * @work: pointer to work_struct containing our data |
| 7180 | **/ |
| 7181 | static void i40e_service_task(struct work_struct *work) |
| 7182 | { |
| 7183 | struct i40e_pf *pf = container_of(work, |
| 7184 | struct i40e_pf, |
| 7185 | service_task); |
| 7186 | unsigned long start_time = jiffies; |
| 7187 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7188 | /* don't bother with service tasks if a reset is in progress */ |
| 7189 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7190 | i40e_service_event_complete(pf); |
| 7191 | return; |
| 7192 | } |
| 7193 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7194 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 7195 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7196 | i40e_reset_subtask(pf); |
| 7197 | i40e_handle_mdd_event(pf); |
| 7198 | i40e_vc_process_vflr_event(pf); |
| 7199 | i40e_watchdog_subtask(pf); |
| 7200 | i40e_fdir_reinit_subtask(pf); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7201 | i40e_client_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7202 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7203 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7204 | i40e_clean_adminq_subtask(pf); |
| 7205 | |
| 7206 | i40e_service_event_complete(pf); |
| 7207 | |
| 7208 | /* If the tasks have taken longer than one timer cycle or there |
| 7209 | * is more work to be done, reschedule the service task now |
| 7210 | * rather than wait for the timer to tick again. |
| 7211 | */ |
| 7212 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 7213 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 7214 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 7215 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 7216 | i40e_service_event_schedule(pf); |
| 7217 | } |
| 7218 | |
| 7219 | /** |
| 7220 | * i40e_service_timer - timer callback |
| 7221 | * @data: pointer to PF struct |
| 7222 | **/ |
| 7223 | static void i40e_service_timer(unsigned long data) |
| 7224 | { |
| 7225 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7226 | |
| 7227 | mod_timer(&pf->service_timer, |
| 7228 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7229 | i40e_service_event_schedule(pf); |
| 7230 | } |
| 7231 | |
| 7232 | /** |
| 7233 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7234 | * @vsi: the VSI being configured |
| 7235 | **/ |
| 7236 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7237 | { |
| 7238 | struct i40e_pf *pf = vsi->back; |
| 7239 | |
| 7240 | switch (vsi->type) { |
| 7241 | case I40E_VSI_MAIN: |
| 7242 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7243 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7244 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7245 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7246 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7247 | else |
| 7248 | vsi->num_q_vectors = 1; |
| 7249 | |
| 7250 | break; |
| 7251 | |
| 7252 | case I40E_VSI_FDIR: |
| 7253 | vsi->alloc_queue_pairs = 1; |
| 7254 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7255 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7256 | vsi->num_q_vectors = pf->num_fdsb_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7257 | break; |
| 7258 | |
| 7259 | case I40E_VSI_VMDQ2: |
| 7260 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7261 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7262 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7263 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7264 | break; |
| 7265 | |
| 7266 | case I40E_VSI_SRIOV: |
| 7267 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7268 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7269 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7270 | break; |
| 7271 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7272 | #ifdef I40E_FCOE |
| 7273 | case I40E_VSI_FCOE: |
| 7274 | vsi->alloc_queue_pairs = pf->num_fcoe_qps; |
| 7275 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7276 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7277 | vsi->num_q_vectors = pf->num_fcoe_msix; |
| 7278 | break; |
| 7279 | |
| 7280 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7281 | default: |
| 7282 | WARN_ON(1); |
| 7283 | return -ENODATA; |
| 7284 | } |
| 7285 | |
| 7286 | return 0; |
| 7287 | } |
| 7288 | |
| 7289 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7290 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7291 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7292 | * @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] | 7293 | * |
| 7294 | * On error: returns error code (negative) |
| 7295 | * On success: returns 0 |
| 7296 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7297 | 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] | 7298 | { |
| 7299 | int size; |
| 7300 | int ret = 0; |
| 7301 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7302 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7303 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 7304 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7305 | if (!vsi->tx_rings) |
| 7306 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7307 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 7308 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7309 | if (alloc_qvectors) { |
| 7310 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7311 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7312 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7313 | if (!vsi->q_vectors) { |
| 7314 | ret = -ENOMEM; |
| 7315 | goto err_vectors; |
| 7316 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7317 | } |
| 7318 | return ret; |
| 7319 | |
| 7320 | err_vectors: |
| 7321 | kfree(vsi->tx_rings); |
| 7322 | return ret; |
| 7323 | } |
| 7324 | |
| 7325 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7326 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7327 | * @pf: board private structure |
| 7328 | * @type: type of VSI |
| 7329 | * |
| 7330 | * On error: returns error code (negative) |
| 7331 | * On success: returns vsi index in PF (positive) |
| 7332 | **/ |
| 7333 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7334 | { |
| 7335 | int ret = -ENODEV; |
| 7336 | struct i40e_vsi *vsi; |
| 7337 | int vsi_idx; |
| 7338 | int i; |
| 7339 | |
| 7340 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7341 | mutex_lock(&pf->switch_mutex); |
| 7342 | |
| 7343 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7344 | * been happening. We can afford to do a quick scan to look |
| 7345 | * for any free VSIs in the list. |
| 7346 | * |
| 7347 | * find next empty vsi slot, looping back around if necessary |
| 7348 | */ |
| 7349 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7350 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7351 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7352 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7353 | i = 0; |
| 7354 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7355 | i++; |
| 7356 | } |
| 7357 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7358 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7359 | vsi_idx = i; /* Found one! */ |
| 7360 | } else { |
| 7361 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7362 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7363 | } |
| 7364 | pf->next_vsi = ++i; |
| 7365 | |
| 7366 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7367 | if (!vsi) { |
| 7368 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7369 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7370 | } |
| 7371 | vsi->type = type; |
| 7372 | vsi->back = pf; |
| 7373 | set_bit(__I40E_DOWN, &vsi->state); |
| 7374 | vsi->flags = 0; |
| 7375 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7376 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7377 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7378 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7379 | vsi->netdev_registered = false; |
| 7380 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
| 7381 | INIT_LIST_HEAD(&vsi->mac_filter_list); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7382 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7383 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7384 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7385 | if (ret) |
| 7386 | goto err_rings; |
| 7387 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7388 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7389 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7390 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7391 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7392 | /* Setup default MSIX irq handler for VSI */ |
| 7393 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7394 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7395 | /* Initialize VSI lock */ |
| 7396 | spin_lock_init(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7397 | pf->vsi[vsi_idx] = vsi; |
| 7398 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7399 | goto unlock_pf; |
| 7400 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7401 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7402 | pf->next_vsi = i - 1; |
| 7403 | kfree(vsi); |
| 7404 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7405 | mutex_unlock(&pf->switch_mutex); |
| 7406 | return ret; |
| 7407 | } |
| 7408 | |
| 7409 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7410 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7411 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7412 | * @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] | 7413 | * |
| 7414 | * On error: returns error code (negative) |
| 7415 | * On success: returns 0 |
| 7416 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7417 | 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] | 7418 | { |
| 7419 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7420 | if (free_qvectors) { |
| 7421 | kfree(vsi->q_vectors); |
| 7422 | vsi->q_vectors = NULL; |
| 7423 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7424 | kfree(vsi->tx_rings); |
| 7425 | vsi->tx_rings = NULL; |
| 7426 | vsi->rx_rings = NULL; |
| 7427 | } |
| 7428 | |
| 7429 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7430 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7431 | * and lookup table |
| 7432 | * @vsi: Pointer to VSI structure |
| 7433 | */ |
| 7434 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7435 | { |
| 7436 | if (!vsi) |
| 7437 | return; |
| 7438 | |
| 7439 | kfree(vsi->rss_hkey_user); |
| 7440 | vsi->rss_hkey_user = NULL; |
| 7441 | |
| 7442 | kfree(vsi->rss_lut_user); |
| 7443 | vsi->rss_lut_user = NULL; |
| 7444 | } |
| 7445 | |
| 7446 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7447 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7448 | * @vsi: the VSI being un-configured |
| 7449 | **/ |
| 7450 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7451 | { |
| 7452 | struct i40e_pf *pf; |
| 7453 | |
| 7454 | if (!vsi) |
| 7455 | return 0; |
| 7456 | |
| 7457 | if (!vsi->back) |
| 7458 | goto free_vsi; |
| 7459 | pf = vsi->back; |
| 7460 | |
| 7461 | mutex_lock(&pf->switch_mutex); |
| 7462 | if (!pf->vsi[vsi->idx]) { |
| 7463 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7464 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7465 | goto unlock_vsi; |
| 7466 | } |
| 7467 | |
| 7468 | if (pf->vsi[vsi->idx] != vsi) { |
| 7469 | dev_err(&pf->pdev->dev, |
| 7470 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7471 | pf->vsi[vsi->idx]->idx, |
| 7472 | pf->vsi[vsi->idx], |
| 7473 | pf->vsi[vsi->idx]->type, |
| 7474 | vsi->idx, vsi, vsi->type); |
| 7475 | goto unlock_vsi; |
| 7476 | } |
| 7477 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7478 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7479 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7480 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7481 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7482 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7483 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7484 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7485 | pf->vsi[vsi->idx] = NULL; |
| 7486 | if (vsi->idx < pf->next_vsi) |
| 7487 | pf->next_vsi = vsi->idx; |
| 7488 | |
| 7489 | unlock_vsi: |
| 7490 | mutex_unlock(&pf->switch_mutex); |
| 7491 | free_vsi: |
| 7492 | kfree(vsi); |
| 7493 | |
| 7494 | return 0; |
| 7495 | } |
| 7496 | |
| 7497 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7498 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7499 | * @vsi: the VSI being cleaned |
| 7500 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7501 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7502 | { |
| 7503 | int i; |
| 7504 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7505 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7506 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7507 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7508 | vsi->tx_rings[i] = NULL; |
| 7509 | vsi->rx_rings[i] = NULL; |
| 7510 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7511 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7512 | } |
| 7513 | |
| 7514 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7515 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7516 | * @vsi: the VSI being configured |
| 7517 | **/ |
| 7518 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7519 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7520 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7521 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7522 | int i; |
| 7523 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7524 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7525 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7526 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7527 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7528 | if (!tx_ring) |
| 7529 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7530 | |
| 7531 | tx_ring->queue_index = i; |
| 7532 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7533 | tx_ring->ring_active = false; |
| 7534 | tx_ring->vsi = vsi; |
| 7535 | tx_ring->netdev = vsi->netdev; |
| 7536 | tx_ring->dev = &pf->pdev->dev; |
| 7537 | tx_ring->count = vsi->num_desc; |
| 7538 | tx_ring->size = 0; |
| 7539 | tx_ring->dcb_tc = 0; |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 7540 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 7541 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7542 | tx_ring->tx_itr_setting = pf->tx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7543 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7544 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7545 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7546 | rx_ring->queue_index = i; |
| 7547 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7548 | rx_ring->ring_active = false; |
| 7549 | rx_ring->vsi = vsi; |
| 7550 | rx_ring->netdev = vsi->netdev; |
| 7551 | rx_ring->dev = &pf->pdev->dev; |
| 7552 | rx_ring->count = vsi->num_desc; |
| 7553 | rx_ring->size = 0; |
| 7554 | rx_ring->dcb_tc = 0; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7555 | rx_ring->rx_itr_setting = pf->rx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7556 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7557 | } |
| 7558 | |
| 7559 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7560 | |
| 7561 | err_out: |
| 7562 | i40e_vsi_clear_rings(vsi); |
| 7563 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7564 | } |
| 7565 | |
| 7566 | /** |
| 7567 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7568 | * @pf: board private structure |
| 7569 | * @vectors: the number of MSI-X vectors to request |
| 7570 | * |
| 7571 | * Returns the number of vectors reserved, or error |
| 7572 | **/ |
| 7573 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7574 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7575 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7576 | I40E_MIN_MSIX, vectors); |
| 7577 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7578 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7579 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7580 | vectors = 0; |
| 7581 | } |
| 7582 | |
| 7583 | return vectors; |
| 7584 | } |
| 7585 | |
| 7586 | /** |
| 7587 | * i40e_init_msix - Setup the MSIX capability |
| 7588 | * @pf: board private structure |
| 7589 | * |
| 7590 | * Work with the OS to set up the MSIX vectors needed. |
| 7591 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7592 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7593 | **/ |
| 7594 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7595 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7596 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7597 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7598 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7599 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7600 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7601 | |
| 7602 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7603 | return -ENODEV; |
| 7604 | |
| 7605 | /* The number of vectors we'll request will be comprised of: |
| 7606 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7607 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7608 | * - Queues being used for RSS. |
| 7609 | * We don't need as many as max_rss_size vectors. |
| 7610 | * use rss_size instead in the calculation since that |
| 7611 | * is governed by number of cpus in the system. |
| 7612 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7613 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7614 | * - The CPU count within the NUMA node if iWARP is enabled |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7615 | #ifdef I40E_FCOE |
| 7616 | * - The number of FCOE qps. |
| 7617 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7618 | * Once we count this up, try the request. |
| 7619 | * |
| 7620 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7621 | * and try again. If that still fails, we punt. |
| 7622 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7623 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7624 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7625 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7626 | /* reserve one vector for miscellaneous handler */ |
| 7627 | if (vectors_left) { |
| 7628 | v_budget++; |
| 7629 | vectors_left--; |
| 7630 | } |
| 7631 | |
| 7632 | /* reserve vectors for the main PF traffic queues */ |
| 7633 | pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left); |
| 7634 | vectors_left -= pf->num_lan_msix; |
| 7635 | v_budget += pf->num_lan_msix; |
| 7636 | |
| 7637 | /* reserve one vector for sideband flow director */ |
| 7638 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7639 | if (vectors_left) { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7640 | pf->num_fdsb_msix = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7641 | v_budget++; |
| 7642 | vectors_left--; |
| 7643 | } else { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7644 | pf->num_fdsb_msix = 0; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7645 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7646 | } |
| 7647 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7648 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7649 | #ifdef I40E_FCOE |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7650 | /* can we reserve enough for FCoE? */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7651 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7652 | if (!vectors_left) |
| 7653 | pf->num_fcoe_msix = 0; |
| 7654 | else if (vectors_left >= pf->num_fcoe_qps) |
| 7655 | pf->num_fcoe_msix = pf->num_fcoe_qps; |
| 7656 | else |
| 7657 | pf->num_fcoe_msix = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7658 | v_budget += pf->num_fcoe_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7659 | vectors_left -= pf->num_fcoe_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7660 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7661 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7662 | #endif |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7663 | /* can we reserve enough for iWARP? */ |
| 7664 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7665 | if (!vectors_left) |
| 7666 | pf->num_iwarp_msix = 0; |
| 7667 | else if (vectors_left < pf->num_iwarp_msix) |
| 7668 | pf->num_iwarp_msix = 1; |
| 7669 | v_budget += pf->num_iwarp_msix; |
| 7670 | vectors_left -= pf->num_iwarp_msix; |
| 7671 | } |
| 7672 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7673 | /* any vectors left over go for VMDq support */ |
| 7674 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7675 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7676 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7677 | |
| 7678 | /* if we're short on vectors for what's desired, we limit |
| 7679 | * the queues per vmdq. If this is still more than are |
| 7680 | * available, the user will need to change the number of |
| 7681 | * queues/vectors used by the PF later with the ethtool |
| 7682 | * channels command |
| 7683 | */ |
| 7684 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7685 | pf->num_vmdq_qps = 1; |
| 7686 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
| 7687 | |
| 7688 | v_budget += vmdq_vecs; |
| 7689 | vectors_left -= vmdq_vecs; |
| 7690 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7691 | |
| 7692 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7693 | GFP_KERNEL); |
| 7694 | if (!pf->msix_entries) |
| 7695 | return -ENOMEM; |
| 7696 | |
| 7697 | for (i = 0; i < v_budget; i++) |
| 7698 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7699 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7700 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7701 | if (v_actual != v_budget) { |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7702 | /* If we have limited resources, we will start with no vectors |
| 7703 | * for the special features and then allocate vectors to some |
| 7704 | * of these features based on the policy and at the end disable |
| 7705 | * the features that did not get any vectors. |
| 7706 | */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7707 | iwarp_requested = pf->num_iwarp_msix; |
| 7708 | pf->num_iwarp_msix = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7709 | #ifdef I40E_FCOE |
| 7710 | pf->num_fcoe_qps = 0; |
| 7711 | pf->num_fcoe_msix = 0; |
| 7712 | #endif |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7713 | pf->num_vmdq_msix = 0; |
| 7714 | } |
| 7715 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7716 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7717 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7718 | kfree(pf->msix_entries); |
| 7719 | pf->msix_entries = NULL; |
| 7720 | return -ENODEV; |
| 7721 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7722 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7723 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7724 | pf->num_vmdq_vsis = 0; |
| 7725 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7726 | pf->num_lan_qps = 1; |
| 7727 | pf->num_lan_msix = 1; |
| 7728 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7729 | } else if (v_actual != v_budget) { |
| 7730 | int vec; |
| 7731 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7732 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7733 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7734 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7735 | /* Scale vector usage down */ |
| 7736 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7737 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7738 | pf->num_vmdq_qps = 1; |
| 7739 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7740 | |
| 7741 | /* partition out the remaining vectors */ |
| 7742 | switch (vec) { |
| 7743 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7744 | pf->num_lan_msix = 1; |
| 7745 | break; |
| 7746 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7747 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7748 | pf->num_lan_msix = 1; |
| 7749 | pf->num_iwarp_msix = 1; |
| 7750 | } else { |
| 7751 | pf->num_lan_msix = 2; |
| 7752 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7753 | #ifdef I40E_FCOE |
| 7754 | /* give one vector to FCoE */ |
| 7755 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7756 | pf->num_lan_msix = 1; |
| 7757 | pf->num_fcoe_msix = 1; |
| 7758 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7759 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7760 | break; |
| 7761 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7762 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7763 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 7764 | iwarp_requested); |
| 7765 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 7766 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7767 | } else { |
| 7768 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 7769 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7770 | } |
| 7771 | pf->num_lan_msix = min_t(int, |
| 7772 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 7773 | pf->num_lan_msix); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7774 | #ifdef I40E_FCOE |
| 7775 | /* give one vector to FCoE */ |
| 7776 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7777 | pf->num_fcoe_msix = 1; |
| 7778 | vec--; |
| 7779 | } |
| 7780 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7781 | break; |
| 7782 | } |
| 7783 | } |
| 7784 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7785 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7786 | (pf->num_vmdq_msix == 0)) { |
| 7787 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 7788 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 7789 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7790 | |
| 7791 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 7792 | (pf->num_iwarp_msix == 0)) { |
| 7793 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 7794 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 7795 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7796 | #ifdef I40E_FCOE |
| 7797 | |
| 7798 | if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { |
| 7799 | dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n"); |
| 7800 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 7801 | } |
| 7802 | #endif |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7803 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7804 | } |
| 7805 | |
| 7806 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7807 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7808 | * @vsi: the VSI being configured |
| 7809 | * @v_idx: index of the vector in the vsi struct |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7810 | * @cpu: cpu to be used on affinity_mask |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7811 | * |
| 7812 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 7813 | **/ |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7814 | 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] | 7815 | { |
| 7816 | struct i40e_q_vector *q_vector; |
| 7817 | |
| 7818 | /* allocate q_vector */ |
| 7819 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 7820 | if (!q_vector) |
| 7821 | return -ENOMEM; |
| 7822 | |
| 7823 | q_vector->vsi = vsi; |
| 7824 | q_vector->v_idx = v_idx; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7825 | cpumask_set_cpu(cpu, &q_vector->affinity_mask); |
| 7826 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7827 | if (vsi->netdev) |
| 7828 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 7829 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7830 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 7831 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 7832 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 7833 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7834 | /* tie q_vector and vsi together */ |
| 7835 | vsi->q_vectors[v_idx] = q_vector; |
| 7836 | |
| 7837 | return 0; |
| 7838 | } |
| 7839 | |
| 7840 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7841 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7842 | * @vsi: the VSI being configured |
| 7843 | * |
| 7844 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 7845 | * return -ENOMEM. |
| 7846 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7847 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7848 | { |
| 7849 | struct i40e_pf *pf = vsi->back; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7850 | int err, v_idx, num_q_vectors, current_cpu; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7851 | |
| 7852 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 7853 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7854 | num_q_vectors = vsi->num_q_vectors; |
| 7855 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 7856 | num_q_vectors = 1; |
| 7857 | else |
| 7858 | return -EINVAL; |
| 7859 | |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7860 | current_cpu = cpumask_first(cpu_online_mask); |
| 7861 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7862 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7863 | err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7864 | if (err) |
| 7865 | goto err_out; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7866 | current_cpu = cpumask_next(current_cpu, cpu_online_mask); |
| 7867 | if (unlikely(current_cpu >= nr_cpu_ids)) |
| 7868 | current_cpu = cpumask_first(cpu_online_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7869 | } |
| 7870 | |
| 7871 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7872 | |
| 7873 | err_out: |
| 7874 | while (v_idx--) |
| 7875 | i40e_free_q_vector(vsi, v_idx); |
| 7876 | |
| 7877 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7878 | } |
| 7879 | |
| 7880 | /** |
| 7881 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 7882 | * @pf: board private structure to initialize |
| 7883 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7884 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7885 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7886 | int vectors = 0; |
| 7887 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7888 | |
| 7889 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7890 | vectors = i40e_init_msix(pf); |
| 7891 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7892 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7893 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7894 | #ifdef I40E_FCOE |
| 7895 | I40E_FLAG_FCOE_ENABLED | |
| 7896 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7897 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7898 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7899 | I40E_FLAG_SRIOV_ENABLED | |
| 7900 | I40E_FLAG_FD_SB_ENABLED | |
| 7901 | I40E_FLAG_FD_ATR_ENABLED | |
| 7902 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7903 | |
| 7904 | /* rework the queue expectations without MSIX */ |
| 7905 | i40e_determine_queue_usage(pf); |
| 7906 | } |
| 7907 | } |
| 7908 | |
| 7909 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 7910 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7911 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7912 | vectors = pci_enable_msi(pf->pdev); |
| 7913 | if (vectors < 0) { |
| 7914 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 7915 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7916 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 7917 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7918 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7919 | } |
| 7920 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 7921 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7922 | 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] | 7923 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7924 | /* set up vector assignment tracking */ |
| 7925 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 7926 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7927 | if (!pf->irq_pile) { |
| 7928 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 7929 | return -ENOMEM; |
| 7930 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7931 | pf->irq_pile->num_entries = vectors; |
| 7932 | pf->irq_pile->search_hint = 0; |
| 7933 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7934 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7935 | (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] | 7936 | |
| 7937 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7938 | } |
| 7939 | |
| 7940 | /** |
| 7941 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 7942 | * @pf: board private structure |
| 7943 | * |
| 7944 | * This sets up the handler for MSIX 0, which is used to manage the |
| 7945 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 7946 | * when in MSI or Legacy interrupt mode. |
| 7947 | **/ |
| 7948 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 7949 | { |
| 7950 | struct i40e_hw *hw = &pf->hw; |
| 7951 | int err = 0; |
| 7952 | |
| 7953 | /* Only request the irq if this is the first time through, and |
| 7954 | * not when we're rebuilding after a Reset |
| 7955 | */ |
| 7956 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7957 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7958 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7959 | if (err) { |
| 7960 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7961 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7962 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7963 | return -EFAULT; |
| 7964 | } |
| 7965 | } |
| 7966 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 7967 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7968 | |
| 7969 | /* associate no queues to the misc vector */ |
| 7970 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 7971 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 7972 | |
| 7973 | i40e_flush(hw); |
| 7974 | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 7975 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7976 | |
| 7977 | return err; |
| 7978 | } |
| 7979 | |
| 7980 | /** |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7981 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 7982 | * @vsi: vsi structure |
| 7983 | * @seed: RSS hash seed |
| 7984 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7985 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 7986 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7987 | { |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7988 | struct i40e_pf *pf = vsi->back; |
| 7989 | struct i40e_hw *hw = &pf->hw; |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame^] | 7990 | int ret = 0; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7991 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame^] | 7992 | if (seed) { |
| 7993 | struct i40e_aqc_get_set_rss_key_data *seed_dw = |
| 7994 | (struct i40e_aqc_get_set_rss_key_data *)seed; |
| 7995 | ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw); |
| 7996 | if (ret) { |
| 7997 | dev_info(&pf->pdev->dev, |
| 7998 | "Cannot set RSS key, err %s aq_err %s\n", |
| 7999 | i40e_stat_str(hw, ret), |
| 8000 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8001 | return ret; |
| 8002 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8003 | } |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame^] | 8004 | if (lut) { |
| 8005 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8006 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame^] | 8007 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8008 | if (ret) { |
| 8009 | dev_info(&pf->pdev->dev, |
| 8010 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 8011 | i40e_stat_str(hw, ret), |
| 8012 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 8013 | return ret; |
| 8014 | } |
| 8015 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8016 | return ret; |
| 8017 | } |
| 8018 | |
| 8019 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8020 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 8021 | * @vsi: Pointer to vsi structure |
| 8022 | * @seed: Buffter to store the hash keys |
| 8023 | * @lut: Buffer to store the lookup table entries |
| 8024 | * @lut_size: Size of buffer to store the lookup table entries |
| 8025 | * |
| 8026 | * Return 0 on success, negative on failure |
| 8027 | */ |
| 8028 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8029 | u8 *lut, u16 lut_size) |
| 8030 | { |
| 8031 | struct i40e_pf *pf = vsi->back; |
| 8032 | struct i40e_hw *hw = &pf->hw; |
| 8033 | int ret = 0; |
| 8034 | |
| 8035 | if (seed) { |
| 8036 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 8037 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 8038 | if (ret) { |
| 8039 | dev_info(&pf->pdev->dev, |
| 8040 | "Cannot get RSS key, err %s aq_err %s\n", |
| 8041 | i40e_stat_str(&pf->hw, ret), |
| 8042 | i40e_aq_str(&pf->hw, |
| 8043 | pf->hw.aq.asq_last_status)); |
| 8044 | return ret; |
| 8045 | } |
| 8046 | } |
| 8047 | |
| 8048 | if (lut) { |
| 8049 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 8050 | |
| 8051 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8052 | if (ret) { |
| 8053 | dev_info(&pf->pdev->dev, |
| 8054 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 8055 | i40e_stat_str(&pf->hw, ret), |
| 8056 | i40e_aq_str(&pf->hw, |
| 8057 | pf->hw.aq.asq_last_status)); |
| 8058 | return ret; |
| 8059 | } |
| 8060 | } |
| 8061 | |
| 8062 | return ret; |
| 8063 | } |
| 8064 | |
| 8065 | /** |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8066 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 8067 | * @vsi: VSI structure |
| 8068 | **/ |
| 8069 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 8070 | { |
| 8071 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 8072 | struct i40e_pf *pf = vsi->back; |
| 8073 | u8 *lut; |
| 8074 | int ret; |
| 8075 | |
| 8076 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) |
| 8077 | return 0; |
| 8078 | |
| 8079 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8080 | if (!lut) |
| 8081 | return -ENOMEM; |
| 8082 | |
| 8083 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
| 8084 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
| 8085 | vsi->rss_size = min_t(int, pf->alloc_rss_size, vsi->num_queue_pairs); |
| 8086 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 8087 | kfree(lut); |
| 8088 | |
| 8089 | return ret; |
| 8090 | } |
| 8091 | |
| 8092 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8093 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8094 | * @vsi: Pointer to vsi structure |
| 8095 | * @seed: RSS hash seed |
| 8096 | * @lut: Lookup table |
| 8097 | * @lut_size: Lookup table size |
| 8098 | * |
| 8099 | * Returns 0 on success, negative on failure |
| 8100 | **/ |
| 8101 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8102 | const u8 *lut, u16 lut_size) |
| 8103 | { |
| 8104 | struct i40e_pf *pf = vsi->back; |
| 8105 | struct i40e_hw *hw = &pf->hw; |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8106 | u16 vf_id = vsi->vf_id; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8107 | u8 i; |
| 8108 | |
| 8109 | /* Fill out hash function seed */ |
| 8110 | if (seed) { |
| 8111 | u32 *seed_dw = (u32 *)seed; |
| 8112 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8113 | if (vsi->type == I40E_VSI_MAIN) { |
| 8114 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 8115 | i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), |
| 8116 | seed_dw[i]); |
| 8117 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8118 | for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++) |
| 8119 | i40e_write_rx_ctl(hw, |
| 8120 | I40E_VFQF_HKEY1(i, vf_id), |
| 8121 | seed_dw[i]); |
| 8122 | } else { |
| 8123 | dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n"); |
| 8124 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8125 | } |
| 8126 | |
| 8127 | if (lut) { |
| 8128 | u32 *lut_dw = (u32 *)lut; |
| 8129 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8130 | if (vsi->type == I40E_VSI_MAIN) { |
| 8131 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8132 | return -EINVAL; |
| 8133 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8134 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8135 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8136 | if (lut_size != I40E_VF_HLUT_ARRAY_SIZE) |
| 8137 | return -EINVAL; |
| 8138 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8139 | i40e_write_rx_ctl(hw, |
| 8140 | I40E_VFQF_HLUT1(i, vf_id), |
| 8141 | lut_dw[i]); |
| 8142 | } else { |
| 8143 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8144 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8145 | } |
| 8146 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8147 | |
| 8148 | return 0; |
| 8149 | } |
| 8150 | |
| 8151 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8152 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8153 | * @vsi: Pointer to VSI structure |
| 8154 | * @seed: Buffer to store the keys |
| 8155 | * @lut: Buffer to store the lookup table entries |
| 8156 | * @lut_size: Size of buffer to store the lookup table entries |
| 8157 | * |
| 8158 | * Returns 0 on success, negative on failure |
| 8159 | */ |
| 8160 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8161 | u8 *lut, u16 lut_size) |
| 8162 | { |
| 8163 | struct i40e_pf *pf = vsi->back; |
| 8164 | struct i40e_hw *hw = &pf->hw; |
| 8165 | u16 i; |
| 8166 | |
| 8167 | if (seed) { |
| 8168 | u32 *seed_dw = (u32 *)seed; |
| 8169 | |
| 8170 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8171 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8172 | } |
| 8173 | if (lut) { |
| 8174 | u32 *lut_dw = (u32 *)lut; |
| 8175 | |
| 8176 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8177 | return -EINVAL; |
| 8178 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8179 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8180 | } |
| 8181 | |
| 8182 | return 0; |
| 8183 | } |
| 8184 | |
| 8185 | /** |
| 8186 | * i40e_config_rss - Configure RSS keys and lut |
| 8187 | * @vsi: Pointer to VSI structure |
| 8188 | * @seed: RSS hash seed |
| 8189 | * @lut: Lookup table |
| 8190 | * @lut_size: Lookup table size |
| 8191 | * |
| 8192 | * Returns 0 on success, negative on failure |
| 8193 | */ |
| 8194 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8195 | { |
| 8196 | struct i40e_pf *pf = vsi->back; |
| 8197 | |
| 8198 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8199 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8200 | else |
| 8201 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8202 | } |
| 8203 | |
| 8204 | /** |
| 8205 | * i40e_get_rss - Get RSS keys and lut |
| 8206 | * @vsi: Pointer to VSI structure |
| 8207 | * @seed: Buffer to store the keys |
| 8208 | * @lut: Buffer to store the lookup table entries |
| 8209 | * lut_size: Size of buffer to store the lookup table entries |
| 8210 | * |
| 8211 | * Returns 0 on success, negative on failure |
| 8212 | */ |
| 8213 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8214 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8215 | struct i40e_pf *pf = vsi->back; |
| 8216 | |
| 8217 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8218 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8219 | else |
| 8220 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8221 | } |
| 8222 | |
| 8223 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8224 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8225 | * @pf: Pointer to board private structure |
| 8226 | * @lut: Lookup table |
| 8227 | * @rss_table_size: Lookup table size |
| 8228 | * @rss_size: Range of queue number for hashing |
| 8229 | */ |
| 8230 | static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8231 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8232 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8233 | u16 i; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8234 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8235 | for (i = 0; i < rss_table_size; i++) |
| 8236 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8237 | } |
| 8238 | |
| 8239 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8240 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8241 | * @pf: board private structure |
| 8242 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8243 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8244 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8245 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8246 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8247 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8248 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8249 | u32 reg_val; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8250 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8251 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8252 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8253 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8254 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 8255 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8256 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8257 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8258 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8259 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8260 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8261 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8262 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8263 | reg_val = (pf->rss_table_size == 512) ? |
| 8264 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8265 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8266 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8267 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8268 | /* Determine the RSS size of the VSI */ |
| 8269 | if (!vsi->rss_size) |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8270 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8271 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8272 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8273 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8274 | if (!lut) |
| 8275 | return -ENOMEM; |
| 8276 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8277 | /* Use user configured lut if there is one, otherwise use default */ |
| 8278 | if (vsi->rss_lut_user) |
| 8279 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8280 | else |
| 8281 | 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] | 8282 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8283 | /* Use user configured hash key if there is one, otherwise |
| 8284 | * use default. |
| 8285 | */ |
| 8286 | if (vsi->rss_hkey_user) |
| 8287 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8288 | else |
| 8289 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8290 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8291 | kfree(lut); |
| 8292 | |
| 8293 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8294 | } |
| 8295 | |
| 8296 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8297 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8298 | * @pf: board private structure |
| 8299 | * @queue_count: the requested queue count for rss. |
| 8300 | * |
| 8301 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8302 | * count which may be different from the requested queue count. |
| 8303 | **/ |
| 8304 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8305 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8306 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8307 | int new_rss_size; |
| 8308 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8309 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8310 | return 0; |
| 8311 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8312 | 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] | 8313 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8314 | if (queue_count != vsi->num_queue_pairs) { |
| 8315 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8316 | i40e_prep_for_reset(pf); |
| 8317 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8318 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8319 | |
| 8320 | i40e_reset_and_rebuild(pf, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8321 | |
| 8322 | /* Discard the user configured hash keys and lut, if less |
| 8323 | * queues are enabled. |
| 8324 | */ |
| 8325 | if (queue_count < vsi->rss_size) { |
| 8326 | i40e_clear_rss_config_user(vsi); |
| 8327 | dev_dbg(&pf->pdev->dev, |
| 8328 | "discard user configured hash keys and lut\n"); |
| 8329 | } |
| 8330 | |
| 8331 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8332 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8333 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8334 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8335 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8336 | } |
Helin Zhang | e36b0b1 | 2015-10-26 19:44:36 -0400 | [diff] [blame] | 8337 | dev_info(&pf->pdev->dev, "RSS count/HW max RSS count: %d/%d\n", |
| 8338 | pf->alloc_rss_size, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8339 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8340 | } |
| 8341 | |
| 8342 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8343 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 8344 | * @pf: board private structure |
| 8345 | **/ |
| 8346 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 8347 | { |
| 8348 | i40e_status status; |
| 8349 | bool min_valid, max_valid; |
| 8350 | u32 max_bw, min_bw; |
| 8351 | |
| 8352 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8353 | &min_valid, &max_valid); |
| 8354 | |
| 8355 | if (!status) { |
| 8356 | if (min_valid) |
| 8357 | pf->npar_min_bw = min_bw; |
| 8358 | if (max_valid) |
| 8359 | pf->npar_max_bw = max_bw; |
| 8360 | } |
| 8361 | |
| 8362 | return status; |
| 8363 | } |
| 8364 | |
| 8365 | /** |
| 8366 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 8367 | * @pf: board private structure |
| 8368 | **/ |
| 8369 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 8370 | { |
| 8371 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8372 | i40e_status status; |
| 8373 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8374 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8375 | 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] | 8376 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8377 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 8378 | |
| 8379 | /* Set the new bandwidths */ |
| 8380 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8381 | |
| 8382 | return status; |
| 8383 | } |
| 8384 | |
| 8385 | /** |
| 8386 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 8387 | * @pf: board private structure |
| 8388 | **/ |
| 8389 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 8390 | { |
| 8391 | /* Commit temporary BW setting to permanent NVM image */ |
| 8392 | enum i40e_admin_queue_err last_aq_status; |
| 8393 | i40e_status ret; |
| 8394 | u16 nvm_word; |
| 8395 | |
| 8396 | if (pf->hw.partition_id != 1) { |
| 8397 | dev_info(&pf->pdev->dev, |
| 8398 | "Commit BW only works on partition 1! This is partition %d", |
| 8399 | pf->hw.partition_id); |
| 8400 | ret = I40E_NOT_SUPPORTED; |
| 8401 | goto bw_commit_out; |
| 8402 | } |
| 8403 | |
| 8404 | /* Acquire NVM for read access */ |
| 8405 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8406 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8407 | if (ret) { |
| 8408 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8409 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8410 | i40e_stat_str(&pf->hw, ret), |
| 8411 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8412 | goto bw_commit_out; |
| 8413 | } |
| 8414 | |
| 8415 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8416 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8417 | I40E_SR_NVM_CONTROL_WORD, |
| 8418 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8419 | false, NULL); |
| 8420 | /* Save off last admin queue command status before releasing |
| 8421 | * the NVM |
| 8422 | */ |
| 8423 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8424 | i40e_release_nvm(&pf->hw); |
| 8425 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8426 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8427 | i40e_stat_str(&pf->hw, ret), |
| 8428 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8429 | goto bw_commit_out; |
| 8430 | } |
| 8431 | |
| 8432 | /* Wait a bit for NVM release to complete */ |
| 8433 | msleep(50); |
| 8434 | |
| 8435 | /* Acquire NVM for write access */ |
| 8436 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8437 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8438 | if (ret) { |
| 8439 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8440 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8441 | i40e_stat_str(&pf->hw, ret), |
| 8442 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8443 | goto bw_commit_out; |
| 8444 | } |
| 8445 | /* Write it back out unchanged to initiate update NVM, |
| 8446 | * which will force a write of the shadow (alt) RAM to |
| 8447 | * the NVM - thus storing the bandwidth values permanently. |
| 8448 | */ |
| 8449 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8450 | I40E_SR_NVM_CONTROL_WORD, |
| 8451 | 0x10, sizeof(nvm_word), |
| 8452 | &nvm_word, true, NULL); |
| 8453 | /* Save off last admin queue command status before releasing |
| 8454 | * the NVM |
| 8455 | */ |
| 8456 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8457 | i40e_release_nvm(&pf->hw); |
| 8458 | if (ret) |
| 8459 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8460 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8461 | i40e_stat_str(&pf->hw, ret), |
| 8462 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8463 | bw_commit_out: |
| 8464 | |
| 8465 | return ret; |
| 8466 | } |
| 8467 | |
| 8468 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8469 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8470 | * @pf: board private structure to initialize |
| 8471 | * |
| 8472 | * i40e_sw_init initializes the Adapter private data structure. |
| 8473 | * Fields are initialized based on PCI device information and |
| 8474 | * OS network device settings (MTU size). |
| 8475 | **/ |
| 8476 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8477 | { |
| 8478 | int err = 0; |
| 8479 | int size; |
| 8480 | |
| 8481 | pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, |
| 8482 | (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); |
| 8483 | if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { |
| 8484 | if (I40E_DEBUG_USER & debug) |
| 8485 | pf->hw.debug_mask = debug; |
| 8486 | pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), |
| 8487 | I40E_DEFAULT_MSG_ENABLE); |
| 8488 | } |
| 8489 | |
| 8490 | /* Set default capability flags */ |
| 8491 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8492 | I40E_FLAG_MSI_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8493 | I40E_FLAG_MSIX_ENABLED; |
| 8494 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8495 | /* Set default ITR */ |
| 8496 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8497 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8498 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8499 | /* Depending on PF configurations, it is possible that the RSS |
| 8500 | * maximum might end up larger than the available queues |
| 8501 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8502 | 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] | 8503 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8504 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8505 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8506 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8507 | if (pf->hw.func_caps.rss) { |
| 8508 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8509 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8510 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8511 | } |
| 8512 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8513 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8514 | 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] | 8515 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8516 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8517 | if (i40e_get_npar_bw_setting(pf)) |
| 8518 | dev_warn(&pf->pdev->dev, |
| 8519 | "Could not get NPAR bw settings\n"); |
| 8520 | else |
| 8521 | dev_info(&pf->pdev->dev, |
| 8522 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 8523 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8524 | } |
| 8525 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8526 | /* FW/NVM is not yet fixed in this regard */ |
| 8527 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8528 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8529 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8530 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8531 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8532 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8533 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8534 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8535 | else |
| 8536 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8537 | pf->fdir_pf_filter_count = |
| 8538 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8539 | pf->hw.fdir_shared_filter_count = |
| 8540 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8541 | } |
| 8542 | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8543 | if (i40e_is_mac_710(&pf->hw) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8544 | (((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] | 8545 | (pf->hw.aq.fw_maj_ver < 4))) { |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8546 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8547 | /* No DCB support for FW < v4.33 */ |
| 8548 | pf->flags |= I40E_FLAG_NO_DCB_SUPPORT; |
| 8549 | } |
| 8550 | |
| 8551 | /* Disable FW LLDP if FW < v4.3 */ |
| 8552 | if (i40e_is_mac_710(&pf->hw) && |
| 8553 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 8554 | (pf->hw.aq.fw_maj_ver < 4))) |
| 8555 | pf->flags |= I40E_FLAG_STOP_FW_LLDP; |
| 8556 | |
| 8557 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
| 8558 | if (i40e_is_mac_710(&pf->hw) && |
| 8559 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 8560 | (pf->hw.aq.fw_maj_ver >= 5))) |
| 8561 | pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8562 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8563 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8564 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8565 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 8566 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8567 | } |
| 8568 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8569 | if (pf->hw.func_caps.iwarp) { |
| 8570 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 8571 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 8572 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 8573 | } |
| 8574 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8575 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 8576 | i40e_init_pf_fcoe(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8577 | |
| 8578 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8579 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 8580 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8581 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 8582 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 8583 | pf->num_req_vfs = min_t(int, |
| 8584 | pf->hw.func_caps.num_vfs, |
| 8585 | I40E_MAX_VF_COUNT); |
| 8586 | } |
| 8587 | #endif /* CONFIG_PCI_IOV */ |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8588 | if (pf->hw.mac.type == I40E_MAC_X722) { |
| 8589 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE | |
| 8590 | I40E_FLAG_128_QP_RSS_CAPABLE | |
| 8591 | I40E_FLAG_HW_ATR_EVICT_CAPABLE | |
| 8592 | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE | |
| 8593 | I40E_FLAG_WB_ON_ITR_CAPABLE | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8594 | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
Jesse Brandeburg | 8e2cc0e | 2016-02-29 11:00:24 -0800 | [diff] [blame] | 8595 | I40E_FLAG_NO_PCI_LINK_CHECK | |
Catherine Sullivan | f8db54cc | 2015-12-22 14:25:14 -0800 | [diff] [blame] | 8596 | I40E_FLAG_100M_SGMII_CAPABLE | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8597 | I40E_FLAG_USE_SET_LLDP_MIB | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8598 | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8599 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 8600 | ((pf->hw.aq.api_maj_ver == 1) && |
| 8601 | (pf->hw.aq.api_min_ver > 4))) { |
| 8602 | /* Supported in FW API version higher than 1.4 */ |
| 8603 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 8604 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
| 8605 | } else { |
| 8606 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8607 | } |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8608 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8609 | pf->eeprom_version = 0xDEAD; |
| 8610 | pf->lan_veb = I40E_NO_VEB; |
| 8611 | pf->lan_vsi = I40E_NO_VSI; |
| 8612 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 8613 | /* By default FW has this off for performance reasons */ |
| 8614 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 8615 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8616 | /* set up queue assignment tracking */ |
| 8617 | size = sizeof(struct i40e_lump_tracking) |
| 8618 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 8619 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 8620 | if (!pf->qp_pile) { |
| 8621 | err = -ENOMEM; |
| 8622 | goto sw_init_done; |
| 8623 | } |
| 8624 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 8625 | pf->qp_pile->search_hint = 0; |
| 8626 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 8627 | pf->tx_timeout_recovery_level = 1; |
| 8628 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8629 | mutex_init(&pf->switch_mutex); |
| 8630 | |
Greg Rose | c668a12 | 2015-02-26 16:10:39 +0000 | [diff] [blame] | 8631 | /* If NPAR is enabled nudge the Tx scheduler */ |
| 8632 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) |
| 8633 | i40e_set_npar_bw_setting(pf); |
| 8634 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8635 | sw_init_done: |
| 8636 | return err; |
| 8637 | } |
| 8638 | |
| 8639 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8640 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 8641 | * @pf: board private structure to initialize |
| 8642 | * @features: the feature set that the stack is suggesting |
| 8643 | * |
| 8644 | * returns a bool to indicate if reset needs to happen |
| 8645 | **/ |
| 8646 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 8647 | { |
| 8648 | bool need_reset = false; |
| 8649 | |
| 8650 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 8651 | * the state changed, we need to reset. |
| 8652 | */ |
| 8653 | if (features & NETIF_F_NTUPLE) { |
| 8654 | /* Enable filters and mark for reset */ |
| 8655 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 8656 | need_reset = true; |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 8657 | /* enable FD_SB only if there is MSI-X vector */ |
| 8658 | if (pf->num_fdsb_msix > 0) |
| 8659 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8660 | } else { |
| 8661 | /* turn off filters, mark for reset and clear SW filter list */ |
| 8662 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8663 | need_reset = true; |
| 8664 | i40e_fdir_filter_exit(pf); |
| 8665 | } |
| 8666 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8667 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 8668 | /* reset fd counters */ |
| 8669 | pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0; |
| 8670 | pf->fdir_pf_active_filters = 0; |
| 8671 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 8672 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 8673 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8674 | /* if ATR was auto disabled it can be re-enabled. */ |
| 8675 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 8676 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 8677 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8678 | } |
| 8679 | return need_reset; |
| 8680 | } |
| 8681 | |
| 8682 | /** |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8683 | * i40e_clear_rss_lut - clear the rx hash lookup table |
| 8684 | * @vsi: the VSI being configured |
| 8685 | **/ |
| 8686 | static void i40e_clear_rss_lut(struct i40e_vsi *vsi) |
| 8687 | { |
| 8688 | struct i40e_pf *pf = vsi->back; |
| 8689 | struct i40e_hw *hw = &pf->hw; |
| 8690 | u16 vf_id = vsi->vf_id; |
| 8691 | u8 i; |
| 8692 | |
| 8693 | if (vsi->type == I40E_VSI_MAIN) { |
| 8694 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8695 | wr32(hw, I40E_PFQF_HLUT(i), 0); |
| 8696 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8697 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8698 | i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0); |
| 8699 | } else { |
| 8700 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8701 | } |
| 8702 | } |
| 8703 | |
| 8704 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8705 | * i40e_set_features - set the netdev feature flags |
| 8706 | * @netdev: ptr to the netdev being adjusted |
| 8707 | * @features: the feature set that the stack is suggesting |
| 8708 | **/ |
| 8709 | static int i40e_set_features(struct net_device *netdev, |
| 8710 | netdev_features_t features) |
| 8711 | { |
| 8712 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8713 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8714 | struct i40e_pf *pf = vsi->back; |
| 8715 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8716 | |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8717 | if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH)) |
| 8718 | i40e_pf_config_rss(pf); |
| 8719 | else if (!(features & NETIF_F_RXHASH) && |
| 8720 | netdev->features & NETIF_F_RXHASH) |
| 8721 | i40e_clear_rss_lut(vsi); |
| 8722 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8723 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8724 | i40e_vlan_stripping_enable(vsi); |
| 8725 | else |
| 8726 | i40e_vlan_stripping_disable(vsi); |
| 8727 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8728 | need_reset = i40e_set_ntuple(pf, features); |
| 8729 | |
| 8730 | if (need_reset) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8731 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8732 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8733 | return 0; |
| 8734 | } |
| 8735 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8736 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8737 | * 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] | 8738 | * @pf: board private structure |
| 8739 | * @port: The UDP port to look up |
| 8740 | * |
| 8741 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 8742 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8743 | 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] | 8744 | { |
| 8745 | u8 i; |
| 8746 | |
| 8747 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8748 | if (pf->udp_ports[i].index == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8749 | return i; |
| 8750 | } |
| 8751 | |
| 8752 | return i; |
| 8753 | } |
| 8754 | |
| 8755 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8756 | * 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] | 8757 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8758 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8759 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8760 | static void i40e_udp_tunnel_add(struct net_device *netdev, |
| 8761 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8762 | { |
| 8763 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8764 | struct i40e_vsi *vsi = np->vsi; |
| 8765 | struct i40e_pf *pf = vsi->back; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8766 | __be16 port = ti->port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8767 | u8 next_idx; |
| 8768 | u8 idx; |
| 8769 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8770 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8771 | |
| 8772 | /* Check if port already exists */ |
| 8773 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8774 | netdev_info(netdev, "port %d already offloaded\n", |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8775 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8776 | return; |
| 8777 | } |
| 8778 | |
| 8779 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8780 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8781 | |
| 8782 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8783 | 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] | 8784 | ntohs(port)); |
| 8785 | return; |
| 8786 | } |
| 8787 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8788 | switch (ti->type) { |
| 8789 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8790 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 8791 | break; |
| 8792 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8793 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8794 | return; |
| 8795 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 8796 | break; |
| 8797 | default: |
| 8798 | return; |
| 8799 | } |
| 8800 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8801 | /* New port: add it and mark its index in the bitmap */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8802 | pf->udp_ports[next_idx].index = port; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8803 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8804 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8805 | } |
| 8806 | |
| 8807 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8808 | * 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] | 8809 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8810 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8811 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8812 | static void i40e_udp_tunnel_del(struct net_device *netdev, |
| 8813 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8814 | { |
| 8815 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8816 | struct i40e_vsi *vsi = np->vsi; |
| 8817 | struct i40e_pf *pf = vsi->back; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8818 | __be16 port = ti->port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8819 | u8 idx; |
| 8820 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8821 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8822 | |
| 8823 | /* Check if port already exists */ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8824 | if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS) |
| 8825 | goto not_found; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8826 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8827 | switch (ti->type) { |
| 8828 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8829 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN) |
| 8830 | goto not_found; |
| 8831 | break; |
| 8832 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8833 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE) |
| 8834 | goto not_found; |
| 8835 | break; |
| 8836 | default: |
| 8837 | goto not_found; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8838 | } |
| 8839 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8840 | /* if port exists, set it to 0 (mark for deletion) |
| 8841 | * and make it pending |
| 8842 | */ |
| 8843 | pf->udp_ports[idx].index = 0; |
| 8844 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8845 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8846 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8847 | return; |
| 8848 | not_found: |
| 8849 | netdev_warn(netdev, "UDP port %d was not found, not deleting\n", |
| 8850 | ntohs(port)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8851 | } |
| 8852 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8853 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 8854 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8855 | { |
| 8856 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8857 | struct i40e_pf *pf = np->vsi->back; |
| 8858 | struct i40e_hw *hw = &pf->hw; |
| 8859 | |
| 8860 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 8861 | return -EOPNOTSUPP; |
| 8862 | |
| 8863 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 8864 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 8865 | |
| 8866 | return 0; |
| 8867 | } |
| 8868 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 8869 | /** |
| 8870 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 8871 | * @ndm: the input from the stack |
| 8872 | * @tb: pointer to array of nladdr (unused) |
| 8873 | * @dev: the net device pointer |
| 8874 | * @addr: the MAC address entry being added |
| 8875 | * @flags: instructions from stack about fdb operation |
| 8876 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8877 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 8878 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8879 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8880 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8881 | { |
| 8882 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8883 | struct i40e_pf *pf = np->vsi->back; |
| 8884 | int err = 0; |
| 8885 | |
| 8886 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 8887 | return -EOPNOTSUPP; |
| 8888 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 8889 | if (vid) { |
| 8890 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 8891 | return -EINVAL; |
| 8892 | } |
| 8893 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8894 | /* Hardware does not support aging addresses so if a |
| 8895 | * ndm_state is given only allow permanent addresses |
| 8896 | */ |
| 8897 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 8898 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 8899 | return -EINVAL; |
| 8900 | } |
| 8901 | |
| 8902 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 8903 | err = dev_uc_add_excl(dev, addr); |
| 8904 | else if (is_multicast_ether_addr(addr)) |
| 8905 | err = dev_mc_add_excl(dev, addr); |
| 8906 | else |
| 8907 | err = -EINVAL; |
| 8908 | |
| 8909 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 8910 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 8911 | err = 0; |
| 8912 | |
| 8913 | return err; |
| 8914 | } |
| 8915 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8916 | /** |
| 8917 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 8918 | * @dev: the netdev being configured |
| 8919 | * @nlh: RTNL message |
| 8920 | * |
| 8921 | * Inserts a new hardware bridge if not already created and |
| 8922 | * enables the bridging mode requested (VEB or VEPA). If the |
| 8923 | * hardware bridge has already been inserted and the request |
| 8924 | * is to change the mode then that requires a PF reset to |
| 8925 | * allow rebuild of the components with required hardware |
| 8926 | * bridge mode enabled. |
| 8927 | **/ |
| 8928 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 8929 | struct nlmsghdr *nlh, |
| 8930 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8931 | { |
| 8932 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8933 | struct i40e_vsi *vsi = np->vsi; |
| 8934 | struct i40e_pf *pf = vsi->back; |
| 8935 | struct i40e_veb *veb = NULL; |
| 8936 | struct nlattr *attr, *br_spec; |
| 8937 | int i, rem; |
| 8938 | |
| 8939 | /* Only for PF VSI for now */ |
| 8940 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8941 | return -EOPNOTSUPP; |
| 8942 | |
| 8943 | /* Find the HW bridge for PF VSI */ |
| 8944 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8945 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8946 | veb = pf->veb[i]; |
| 8947 | } |
| 8948 | |
| 8949 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 8950 | |
| 8951 | nla_for_each_nested(attr, br_spec, rem) { |
| 8952 | __u16 mode; |
| 8953 | |
| 8954 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 8955 | continue; |
| 8956 | |
| 8957 | mode = nla_get_u16(attr); |
| 8958 | if ((mode != BRIDGE_MODE_VEPA) && |
| 8959 | (mode != BRIDGE_MODE_VEB)) |
| 8960 | return -EINVAL; |
| 8961 | |
| 8962 | /* Insert a new HW bridge */ |
| 8963 | if (!veb) { |
| 8964 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 8965 | vsi->tc_config.enabled_tc); |
| 8966 | if (veb) { |
| 8967 | veb->bridge_mode = mode; |
| 8968 | i40e_config_bridge_mode(veb); |
| 8969 | } else { |
| 8970 | /* No Bridge HW offload available */ |
| 8971 | return -ENOENT; |
| 8972 | } |
| 8973 | break; |
| 8974 | } else if (mode != veb->bridge_mode) { |
| 8975 | /* Existing HW bridge but different mode needs reset */ |
| 8976 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 8977 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 8978 | if (mode == BRIDGE_MODE_VEB) |
| 8979 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 8980 | else |
| 8981 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 8982 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8983 | break; |
| 8984 | } |
| 8985 | } |
| 8986 | |
| 8987 | return 0; |
| 8988 | } |
| 8989 | |
| 8990 | /** |
| 8991 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 8992 | * @skb: skb buff |
| 8993 | * @pid: process id |
| 8994 | * @seq: RTNL message seq # |
| 8995 | * @dev: the netdev being configured |
| 8996 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 8997 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8998 | * |
| 8999 | * Return the mode in which the hardware bridge is operating in |
| 9000 | * i.e VEB or VEPA. |
| 9001 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9002 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 9003 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 9004 | u32 __always_unused filter_mask, |
| 9005 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9006 | { |
| 9007 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9008 | struct i40e_vsi *vsi = np->vsi; |
| 9009 | struct i40e_pf *pf = vsi->back; |
| 9010 | struct i40e_veb *veb = NULL; |
| 9011 | int i; |
| 9012 | |
| 9013 | /* Only for PF VSI for now */ |
| 9014 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9015 | return -EOPNOTSUPP; |
| 9016 | |
| 9017 | /* Find the HW bridge for the PF VSI */ |
| 9018 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9019 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9020 | veb = pf->veb[i]; |
| 9021 | } |
| 9022 | |
| 9023 | if (!veb) |
| 9024 | return 0; |
| 9025 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9026 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 9027 | nlflags, 0, 0, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9028 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9029 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9030 | /* Hardware supports L4 tunnel length of 128B (=2^7) which includes |
| 9031 | * inner mac plus all inner ethertypes. |
| 9032 | */ |
| 9033 | #define I40E_MAX_TUNNEL_HDR_LEN 128 |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9034 | /** |
| 9035 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 9036 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 9037 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9038 | * @features: Offload features that the stack believes apply |
| 9039 | **/ |
| 9040 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 9041 | struct net_device *dev, |
| 9042 | netdev_features_t features) |
| 9043 | { |
| 9044 | if (skb->encapsulation && |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9045 | ((skb_inner_network_header(skb) - skb_transport_header(skb)) > |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9046 | I40E_MAX_TUNNEL_HDR_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 9047 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9048 | |
| 9049 | return features; |
| 9050 | } |
| 9051 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 9052 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9053 | .ndo_open = i40e_open, |
| 9054 | .ndo_stop = i40e_close, |
| 9055 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 9056 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 9057 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 9058 | .ndo_validate_addr = eth_validate_addr, |
| 9059 | .ndo_set_mac_address = i40e_set_mac, |
| 9060 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 9061 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9062 | .ndo_tx_timeout = i40e_tx_timeout, |
| 9063 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 9064 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 9065 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9066 | .ndo_poll_controller = i40e_netpoll, |
| 9067 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9068 | .ndo_setup_tc = __i40e_setup_tc, |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9069 | #ifdef I40E_FCOE |
| 9070 | .ndo_fcoe_enable = i40e_fcoe_enable, |
| 9071 | .ndo_fcoe_disable = i40e_fcoe_disable, |
| 9072 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9073 | .ndo_set_features = i40e_set_features, |
| 9074 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 9075 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9076 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9077 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 9078 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 9079 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Anjali Singhai Jain | c3bbbd2 | 2016-04-01 03:56:07 -0700 | [diff] [blame] | 9080 | .ndo_set_vf_trust = i40e_ndo_set_vf_trust, |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 9081 | .ndo_udp_tunnel_add = i40e_udp_tunnel_add, |
| 9082 | .ndo_udp_tunnel_del = i40e_udp_tunnel_del, |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9083 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9084 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9085 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9086 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 9087 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9088 | }; |
| 9089 | |
| 9090 | /** |
| 9091 | * i40e_config_netdev - Setup the netdev flags |
| 9092 | * @vsi: the VSI being configured |
| 9093 | * |
| 9094 | * Returns 0 on success, negative value on failure |
| 9095 | **/ |
| 9096 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 9097 | { |
| 9098 | struct i40e_pf *pf = vsi->back; |
| 9099 | struct i40e_hw *hw = &pf->hw; |
| 9100 | struct i40e_netdev_priv *np; |
| 9101 | struct net_device *netdev; |
| 9102 | u8 mac_addr[ETH_ALEN]; |
| 9103 | int etherdev_size; |
| 9104 | |
| 9105 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9106 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9107 | if (!netdev) |
| 9108 | return -ENOMEM; |
| 9109 | |
| 9110 | vsi->netdev = netdev; |
| 9111 | np = netdev_priv(netdev); |
| 9112 | np->vsi = vsi; |
| 9113 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9114 | netdev->hw_enc_features |= NETIF_F_SG | |
| 9115 | NETIF_F_IP_CSUM | |
| 9116 | NETIF_F_IPV6_CSUM | |
| 9117 | NETIF_F_HIGHDMA | |
| 9118 | NETIF_F_SOFT_FEATURES | |
| 9119 | NETIF_F_TSO | |
| 9120 | NETIF_F_TSO_ECN | |
| 9121 | NETIF_F_TSO6 | |
| 9122 | NETIF_F_GSO_GRE | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9123 | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 9124 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 9125 | NETIF_F_GSO_IPXIP6 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9126 | NETIF_F_GSO_UDP_TUNNEL | |
| 9127 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9128 | NETIF_F_GSO_PARTIAL | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9129 | NETIF_F_SCTP_CRC | |
| 9130 | NETIF_F_RXHASH | |
| 9131 | NETIF_F_RXCSUM | |
Jesse Brandeburg | 5afdaaa | 2015-12-10 11:38:50 -0800 | [diff] [blame] | 9132 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9133 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9134 | if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)) |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9135 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
| 9136 | |
| 9137 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9138 | |
| 9139 | /* record features VLANs can make use of */ |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9140 | netdev->vlan_features |= netdev->hw_enc_features | |
| 9141 | NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9142 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9143 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9144 | netdev->hw_features |= NETIF_F_NTUPLE; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9145 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9146 | netdev->hw_features |= netdev->hw_enc_features | |
| 9147 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9148 | NETIF_F_HW_VLAN_CTAG_RX; |
| 9149 | |
| 9150 | netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9151 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9152 | |
| 9153 | if (vsi->type == I40E_VSI_MAIN) { |
| 9154 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9155 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9156 | /* The following steps are necessary to prevent reception |
| 9157 | * of tagged packets - some older NVM configurations load a |
| 9158 | * default a MAC-VLAN filter that accepts any tagged packet |
| 9159 | * which must be replaced by a normal filter. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 9160 | */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9161 | i40e_rm_default_mac_filter(vsi, mac_addr); |
| 9162 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 9163 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, true); |
| 9164 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9165 | } else { |
| 9166 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 9167 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 9168 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9169 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9170 | |
| 9171 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9172 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9173 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9174 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9175 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9176 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9177 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9178 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9179 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9180 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9181 | /* Setup netdev TC information */ |
| 9182 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9183 | |
| 9184 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9185 | netdev->watchdog_timeo = 5 * HZ; |
| 9186 | i40e_set_ethtool_ops(netdev); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9187 | #ifdef I40E_FCOE |
| 9188 | i40e_fcoe_config_netdev(netdev, vsi); |
| 9189 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9190 | |
| 9191 | return 0; |
| 9192 | } |
| 9193 | |
| 9194 | /** |
| 9195 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9196 | * @vsi: the VSI being removed |
| 9197 | * |
| 9198 | * Returns 0 on success, negative value on failure |
| 9199 | **/ |
| 9200 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9201 | { |
| 9202 | /* remove default VSI is not allowed */ |
| 9203 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9204 | return; |
| 9205 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9206 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9207 | } |
| 9208 | |
| 9209 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9210 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9211 | * @vsi: the VSI being queried |
| 9212 | * |
| 9213 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9214 | **/ |
| 9215 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9216 | { |
| 9217 | struct i40e_veb *veb; |
| 9218 | struct i40e_pf *pf = vsi->back; |
| 9219 | |
| 9220 | /* Uplink is not a bridge so default to VEB */ |
| 9221 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9222 | return 1; |
| 9223 | |
| 9224 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9225 | if (!veb) { |
| 9226 | dev_info(&pf->pdev->dev, |
| 9227 | "There is no veb associated with the bridge\n"); |
| 9228 | return -ENOENT; |
| 9229 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9230 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9231 | /* Uplink is a bridge in VEPA mode */ |
| 9232 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9233 | return 0; |
| 9234 | } else { |
| 9235 | /* Uplink is a bridge in VEB mode */ |
| 9236 | return 1; |
| 9237 | } |
| 9238 | |
| 9239 | /* VEPA is now default bridge, so return 0 */ |
| 9240 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9241 | } |
| 9242 | |
| 9243 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9244 | * i40e_add_vsi - Add a VSI to the switch |
| 9245 | * @vsi: the VSI being configured |
| 9246 | * |
| 9247 | * This initializes a VSI context depending on the VSI type to be added and |
| 9248 | * passes it down to the add_vsi aq command. |
| 9249 | **/ |
| 9250 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9251 | { |
| 9252 | int ret = -ENODEV; |
Kiran Patil | f6bd096 | 2016-06-20 09:10:34 -0700 | [diff] [blame] | 9253 | i40e_status aq_ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9254 | struct i40e_pf *pf = vsi->back; |
| 9255 | struct i40e_hw *hw = &pf->hw; |
| 9256 | struct i40e_vsi_context ctxt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9257 | struct i40e_mac_filter *f, *ftmp; |
| 9258 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9259 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9260 | int f_count = 0; |
| 9261 | |
| 9262 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9263 | switch (vsi->type) { |
| 9264 | case I40E_VSI_MAIN: |
| 9265 | /* The PF's main VSI is already setup as part of the |
| 9266 | * device initialization, so we'll not bother with |
| 9267 | * the add_vsi call, but we will retrieve the current |
| 9268 | * VSI context. |
| 9269 | */ |
| 9270 | ctxt.seid = pf->main_vsi_seid; |
| 9271 | ctxt.pf_num = pf->hw.pf_id; |
| 9272 | ctxt.vf_num = 0; |
| 9273 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9274 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9275 | if (ret) { |
| 9276 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9277 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9278 | i40e_stat_str(&pf->hw, ret), |
| 9279 | i40e_aq_str(&pf->hw, |
| 9280 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9281 | return -ENOENT; |
| 9282 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9283 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9284 | vsi->info.valid_sections = 0; |
| 9285 | |
| 9286 | vsi->seid = ctxt.seid; |
| 9287 | vsi->id = ctxt.vsi_number; |
| 9288 | |
| 9289 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9290 | |
| 9291 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9292 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9293 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9294 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9295 | ctxt.seid = pf->main_vsi_seid; |
| 9296 | ctxt.pf_num = pf->hw.pf_id; |
| 9297 | ctxt.vf_num = 0; |
| 9298 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9299 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9300 | if (ret) { |
| 9301 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9302 | "update vsi failed, err %s aq_err %s\n", |
| 9303 | i40e_stat_str(&pf->hw, ret), |
| 9304 | i40e_aq_str(&pf->hw, |
| 9305 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9306 | ret = -ENOENT; |
| 9307 | goto err; |
| 9308 | } |
| 9309 | /* update the local VSI info queue map */ |
| 9310 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9311 | vsi->info.valid_sections = 0; |
| 9312 | } else { |
| 9313 | /* Default/Main VSI is only enabled for TC0 |
| 9314 | * reconfigure it to enable all TCs that are |
| 9315 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9316 | * For MFP case the iSCSI PF would use this |
| 9317 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9318 | */ |
| 9319 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9320 | if (ret) { |
| 9321 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9322 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9323 | enabled_tc, |
| 9324 | i40e_stat_str(&pf->hw, ret), |
| 9325 | i40e_aq_str(&pf->hw, |
| 9326 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9327 | ret = -ENOENT; |
| 9328 | } |
| 9329 | } |
| 9330 | break; |
| 9331 | |
| 9332 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9333 | ctxt.pf_num = hw->pf_id; |
| 9334 | ctxt.vf_num = 0; |
| 9335 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9336 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9337 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9338 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9339 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9340 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9341 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9342 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9343 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9344 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9345 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9346 | break; |
| 9347 | |
| 9348 | case I40E_VSI_VMDQ2: |
| 9349 | ctxt.pf_num = hw->pf_id; |
| 9350 | ctxt.vf_num = 0; |
| 9351 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9352 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9353 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9354 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9355 | /* This VSI is connected to VEB so the switch_id |
| 9356 | * should be set to zero by default. |
| 9357 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9358 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9359 | ctxt.info.valid_sections |= |
| 9360 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9361 | ctxt.info.switch_id = |
| 9362 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9363 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9364 | |
| 9365 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9366 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9367 | break; |
| 9368 | |
| 9369 | case I40E_VSI_SRIOV: |
| 9370 | ctxt.pf_num = hw->pf_id; |
| 9371 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9372 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9373 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9374 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9375 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9376 | /* This VSI is connected to VEB so the switch_id |
| 9377 | * should be set to zero by default. |
| 9378 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9379 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9380 | ctxt.info.valid_sections |= |
| 9381 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9382 | ctxt.info.switch_id = |
| 9383 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9384 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9385 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9386 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9387 | ctxt.info.valid_sections |= |
| 9388 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 9389 | ctxt.info.queueing_opt_flags |= |
Ashish Shah | 4b28cdb | 2016-05-03 15:13:17 -0700 | [diff] [blame] | 9390 | (I40E_AQ_VSI_QUE_OPT_TCP_ENA | |
| 9391 | I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9392 | } |
| 9393 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9394 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9395 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9396 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9397 | ctxt.info.valid_sections |= |
| 9398 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9399 | ctxt.info.sec_flags |= |
| 9400 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9401 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9402 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9403 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9404 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9405 | break; |
| 9406 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9407 | #ifdef I40E_FCOE |
| 9408 | case I40E_VSI_FCOE: |
| 9409 | ret = i40e_fcoe_vsi_init(vsi, &ctxt); |
| 9410 | if (ret) { |
| 9411 | dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n"); |
| 9412 | return ret; |
| 9413 | } |
| 9414 | break; |
| 9415 | |
| 9416 | #endif /* I40E_FCOE */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9417 | case I40E_VSI_IWARP: |
| 9418 | /* send down message to iWARP */ |
| 9419 | break; |
| 9420 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9421 | default: |
| 9422 | return -ENODEV; |
| 9423 | } |
| 9424 | |
| 9425 | if (vsi->type != I40E_VSI_MAIN) { |
| 9426 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9427 | if (ret) { |
| 9428 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9429 | "add vsi failed, err %s aq_err %s\n", |
| 9430 | i40e_stat_str(&pf->hw, ret), |
| 9431 | i40e_aq_str(&pf->hw, |
| 9432 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9433 | ret = -ENOENT; |
| 9434 | goto err; |
| 9435 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9436 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9437 | vsi->info.valid_sections = 0; |
| 9438 | vsi->seid = ctxt.seid; |
| 9439 | vsi->id = ctxt.vsi_number; |
| 9440 | } |
Kiran Patil | f6bd096 | 2016-06-20 09:10:34 -0700 | [diff] [blame] | 9441 | /* Except FDIR VSI, for all othet VSI set the broadcast filter */ |
| 9442 | if (vsi->type != I40E_VSI_FDIR) { |
| 9443 | aq_ret = i40e_aq_set_vsi_broadcast(hw, vsi->seid, true, NULL); |
| 9444 | if (aq_ret) { |
| 9445 | ret = i40e_aq_rc_to_posix(aq_ret, |
| 9446 | hw->aq.asq_last_status); |
| 9447 | dev_info(&pf->pdev->dev, |
| 9448 | "set brdcast promisc failed, err %s, aq_err %s\n", |
| 9449 | i40e_stat_str(hw, aq_ret), |
| 9450 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 9451 | } |
| 9452 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9453 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9454 | vsi->active_filters = 0; |
| 9455 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9456 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9457 | /* If macvlan filters already exist, force them to get loaded */ |
| 9458 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9459 | f->state = I40E_FILTER_NEW; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9460 | f_count++; |
| 9461 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9462 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9463 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9464 | if (f_count) { |
| 9465 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 9466 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 9467 | } |
| 9468 | |
| 9469 | /* Update VSI BW information */ |
| 9470 | ret = i40e_vsi_get_bw_info(vsi); |
| 9471 | if (ret) { |
| 9472 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9473 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 9474 | i40e_stat_str(&pf->hw, ret), |
| 9475 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9476 | /* VSI is already added so not tearing that up */ |
| 9477 | ret = 0; |
| 9478 | } |
| 9479 | |
| 9480 | err: |
| 9481 | return ret; |
| 9482 | } |
| 9483 | |
| 9484 | /** |
| 9485 | * i40e_vsi_release - Delete a VSI and free its resources |
| 9486 | * @vsi: the VSI being removed |
| 9487 | * |
| 9488 | * Returns 0 on success or < 0 on error |
| 9489 | **/ |
| 9490 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 9491 | { |
| 9492 | struct i40e_mac_filter *f, *ftmp; |
| 9493 | struct i40e_veb *veb = NULL; |
| 9494 | struct i40e_pf *pf; |
| 9495 | u16 uplink_seid; |
| 9496 | int i, n; |
| 9497 | |
| 9498 | pf = vsi->back; |
| 9499 | |
| 9500 | /* release of a VEB-owner or last VSI is not allowed */ |
| 9501 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 9502 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 9503 | vsi->seid, vsi->uplink_seid); |
| 9504 | return -ENODEV; |
| 9505 | } |
| 9506 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 9507 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 9508 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 9509 | return -ENODEV; |
| 9510 | } |
| 9511 | |
| 9512 | uplink_seid = vsi->uplink_seid; |
| 9513 | if (vsi->type != I40E_VSI_SRIOV) { |
| 9514 | if (vsi->netdev_registered) { |
| 9515 | vsi->netdev_registered = false; |
| 9516 | if (vsi->netdev) { |
| 9517 | /* results in a call to i40e_close() */ |
| 9518 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9519 | } |
| 9520 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 9521 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9522 | } |
| 9523 | i40e_vsi_disable_irq(vsi); |
| 9524 | } |
| 9525 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9526 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9527 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
| 9528 | i40e_del_filter(vsi, f->macaddr, f->vlan, |
| 9529 | f->is_vf, f->is_netdev); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9530 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9531 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 9532 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9533 | |
| 9534 | i40e_vsi_delete(vsi); |
| 9535 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 9536 | if (vsi->netdev) { |
| 9537 | free_netdev(vsi->netdev); |
| 9538 | vsi->netdev = NULL; |
| 9539 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9540 | i40e_vsi_clear_rings(vsi); |
| 9541 | i40e_vsi_clear(vsi); |
| 9542 | |
| 9543 | /* If this was the last thing on the VEB, except for the |
| 9544 | * controlling VSI, remove the VEB, which puts the controlling |
| 9545 | * VSI onto the next level down in the switch. |
| 9546 | * |
| 9547 | * Well, okay, there's one more exception here: don't remove |
| 9548 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 9549 | * from up the network stack. |
| 9550 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9551 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9552 | if (pf->vsi[i] && |
| 9553 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 9554 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9555 | n++; /* count the VSIs */ |
| 9556 | } |
| 9557 | } |
| 9558 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9559 | if (!pf->veb[i]) |
| 9560 | continue; |
| 9561 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 9562 | n++; /* count the VEBs */ |
| 9563 | if (pf->veb[i]->seid == uplink_seid) |
| 9564 | veb = pf->veb[i]; |
| 9565 | } |
| 9566 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 9567 | i40e_veb_release(veb); |
| 9568 | |
| 9569 | return 0; |
| 9570 | } |
| 9571 | |
| 9572 | /** |
| 9573 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 9574 | * @vsi: ptr to the VSI |
| 9575 | * |
| 9576 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 9577 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 9578 | * newly allocated VSI. |
| 9579 | * |
| 9580 | * Returns 0 on success or negative on failure |
| 9581 | **/ |
| 9582 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 9583 | { |
| 9584 | int ret = -ENOENT; |
| 9585 | struct i40e_pf *pf = vsi->back; |
| 9586 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9587 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9588 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 9589 | vsi->seid); |
| 9590 | return -EEXIST; |
| 9591 | } |
| 9592 | |
| 9593 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 9594 | 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] | 9595 | vsi->seid, vsi->base_vector); |
| 9596 | return -EEXIST; |
| 9597 | } |
| 9598 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9599 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9600 | if (ret) { |
| 9601 | dev_info(&pf->pdev->dev, |
| 9602 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 9603 | vsi->num_q_vectors, vsi->seid, ret); |
| 9604 | vsi->num_q_vectors = 0; |
| 9605 | goto vector_setup_out; |
| 9606 | } |
| 9607 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 9608 | /* In Legacy mode, we do not have to get any other vector since we |
| 9609 | * piggyback on the misc/ICR0 for queue interrupts. |
| 9610 | */ |
| 9611 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9612 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9613 | if (vsi->num_q_vectors) |
| 9614 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 9615 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9616 | if (vsi->base_vector < 0) { |
| 9617 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9618 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 9619 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9620 | i40e_vsi_free_q_vectors(vsi); |
| 9621 | ret = -ENOENT; |
| 9622 | goto vector_setup_out; |
| 9623 | } |
| 9624 | |
| 9625 | vector_setup_out: |
| 9626 | return ret; |
| 9627 | } |
| 9628 | |
| 9629 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9630 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 9631 | * @vsi: pointer to the vsi. |
| 9632 | * |
| 9633 | * This re-allocates a vsi's queue resources. |
| 9634 | * |
| 9635 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 9636 | * on success, otherwise returns NULL on failure. |
| 9637 | **/ |
| 9638 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 9639 | { |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9640 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9641 | u8 enabled_tc; |
| 9642 | int ret; |
| 9643 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9644 | if (!vsi) |
| 9645 | return NULL; |
| 9646 | |
| 9647 | pf = vsi->back; |
| 9648 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9649 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9650 | i40e_vsi_clear_rings(vsi); |
| 9651 | |
| 9652 | i40e_vsi_free_arrays(vsi, false); |
| 9653 | i40e_set_num_rings_in_vsi(vsi); |
| 9654 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 9655 | if (ret) |
| 9656 | goto err_vsi; |
| 9657 | |
| 9658 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 9659 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9660 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9661 | "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] | 9662 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9663 | goto err_vsi; |
| 9664 | } |
| 9665 | vsi->base_queue = ret; |
| 9666 | |
| 9667 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 9668 | * layout configurations. |
| 9669 | */ |
| 9670 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9671 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9672 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9673 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9674 | if (vsi->type == I40E_VSI_MAIN) |
| 9675 | i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9676 | |
| 9677 | /* assign it some queues */ |
| 9678 | ret = i40e_alloc_rings(vsi); |
| 9679 | if (ret) |
| 9680 | goto err_rings; |
| 9681 | |
| 9682 | /* map all of the rings to the q_vectors */ |
| 9683 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9684 | return vsi; |
| 9685 | |
| 9686 | err_rings: |
| 9687 | i40e_vsi_free_q_vectors(vsi); |
| 9688 | if (vsi->netdev_registered) { |
| 9689 | vsi->netdev_registered = false; |
| 9690 | unregister_netdev(vsi->netdev); |
| 9691 | free_netdev(vsi->netdev); |
| 9692 | vsi->netdev = NULL; |
| 9693 | } |
| 9694 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9695 | err_vsi: |
| 9696 | i40e_vsi_clear(vsi); |
| 9697 | return NULL; |
| 9698 | } |
| 9699 | |
| 9700 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9701 | * i40e_vsi_setup - Set up a VSI by a given type |
| 9702 | * @pf: board private structure |
| 9703 | * @type: VSI type |
| 9704 | * @uplink_seid: the switch element to link to |
| 9705 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 9706 | * |
| 9707 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 9708 | * to the identified VEB. |
| 9709 | * |
| 9710 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 9711 | * success, otherwise returns NULL on failure. |
| 9712 | **/ |
| 9713 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 9714 | u16 uplink_seid, u32 param1) |
| 9715 | { |
| 9716 | struct i40e_vsi *vsi = NULL; |
| 9717 | struct i40e_veb *veb = NULL; |
| 9718 | int ret, i; |
| 9719 | int v_idx; |
| 9720 | |
| 9721 | /* The requested uplink_seid must be either |
| 9722 | * - the PF's port seid |
| 9723 | * no VEB is needed because this is the PF |
| 9724 | * or this is a Flow Director special case VSI |
| 9725 | * - seid of an existing VEB |
| 9726 | * - seid of a VSI that owns an existing VEB |
| 9727 | * - seid of a VSI that doesn't own a VEB |
| 9728 | * a new VEB is created and the VSI becomes the owner |
| 9729 | * - seid of the PF VSI, which is what creates the first VEB |
| 9730 | * this is a special case of the previous |
| 9731 | * |
| 9732 | * Find which uplink_seid we were given and create a new VEB if needed |
| 9733 | */ |
| 9734 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9735 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 9736 | veb = pf->veb[i]; |
| 9737 | break; |
| 9738 | } |
| 9739 | } |
| 9740 | |
| 9741 | if (!veb && uplink_seid != pf->mac_seid) { |
| 9742 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9743 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9744 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 9745 | vsi = pf->vsi[i]; |
| 9746 | break; |
| 9747 | } |
| 9748 | } |
| 9749 | if (!vsi) { |
| 9750 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 9751 | uplink_seid); |
| 9752 | return NULL; |
| 9753 | } |
| 9754 | |
| 9755 | if (vsi->uplink_seid == pf->mac_seid) |
| 9756 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 9757 | vsi->tc_config.enabled_tc); |
| 9758 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 9759 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9760 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9761 | if (veb) { |
| 9762 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 9763 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 9764 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9765 | return NULL; |
| 9766 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 9767 | /* We come up by default in VEPA mode if SRIOV is not |
| 9768 | * already enabled, in which case we can't force VEPA |
| 9769 | * mode. |
| 9770 | */ |
| 9771 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 9772 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 9773 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9774 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9775 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9776 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9777 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9778 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9779 | veb = pf->veb[i]; |
| 9780 | } |
| 9781 | if (!veb) { |
| 9782 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 9783 | return NULL; |
| 9784 | } |
| 9785 | |
| 9786 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 9787 | uplink_seid = veb->seid; |
| 9788 | } |
| 9789 | |
| 9790 | /* get vsi sw struct */ |
| 9791 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 9792 | if (v_idx < 0) |
| 9793 | goto err_alloc; |
| 9794 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9795 | if (!vsi) |
| 9796 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9797 | vsi->type = type; |
| 9798 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 9799 | |
| 9800 | if (type == I40E_VSI_MAIN) |
| 9801 | pf->lan_vsi = v_idx; |
| 9802 | else if (type == I40E_VSI_SRIOV) |
| 9803 | vsi->vf_id = param1; |
| 9804 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9805 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 9806 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9807 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9808 | dev_info(&pf->pdev->dev, |
| 9809 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 9810 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9811 | goto err_vsi; |
| 9812 | } |
| 9813 | vsi->base_queue = ret; |
| 9814 | |
| 9815 | /* get a VSI from the hardware */ |
| 9816 | vsi->uplink_seid = uplink_seid; |
| 9817 | ret = i40e_add_vsi(vsi); |
| 9818 | if (ret) |
| 9819 | goto err_vsi; |
| 9820 | |
| 9821 | switch (vsi->type) { |
| 9822 | /* setup the netdev if needed */ |
| 9823 | case I40E_VSI_MAIN: |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9824 | /* Apply relevant filters if a platform-specific mac |
| 9825 | * address was selected. |
| 9826 | */ |
| 9827 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 9828 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 9829 | if (ret) { |
| 9830 | dev_warn(&pf->pdev->dev, |
| 9831 | "could not set up macaddr; err %d\n", |
| 9832 | ret); |
| 9833 | } |
| 9834 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9835 | case I40E_VSI_VMDQ2: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9836 | case I40E_VSI_FCOE: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9837 | ret = i40e_config_netdev(vsi); |
| 9838 | if (ret) |
| 9839 | goto err_netdev; |
| 9840 | ret = register_netdev(vsi->netdev); |
| 9841 | if (ret) |
| 9842 | goto err_netdev; |
| 9843 | vsi->netdev_registered = true; |
| 9844 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9845 | #ifdef CONFIG_I40E_DCB |
| 9846 | /* Setup DCB netlink interface */ |
| 9847 | i40e_dcbnl_setup(vsi); |
| 9848 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9849 | /* fall through */ |
| 9850 | |
| 9851 | case I40E_VSI_FDIR: |
| 9852 | /* set up vectors and rings if needed */ |
| 9853 | ret = i40e_vsi_setup_vectors(vsi); |
| 9854 | if (ret) |
| 9855 | goto err_msix; |
| 9856 | |
| 9857 | ret = i40e_alloc_rings(vsi); |
| 9858 | if (ret) |
| 9859 | goto err_rings; |
| 9860 | |
| 9861 | /* map all of the rings to the q_vectors */ |
| 9862 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9863 | |
| 9864 | i40e_vsi_reset_stats(vsi); |
| 9865 | break; |
| 9866 | |
| 9867 | default: |
| 9868 | /* no netdev or rings for the other VSI types */ |
| 9869 | break; |
| 9870 | } |
| 9871 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9872 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
| 9873 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 9874 | ret = i40e_vsi_config_rss(vsi); |
| 9875 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9876 | return vsi; |
| 9877 | |
| 9878 | err_rings: |
| 9879 | i40e_vsi_free_q_vectors(vsi); |
| 9880 | err_msix: |
| 9881 | if (vsi->netdev_registered) { |
| 9882 | vsi->netdev_registered = false; |
| 9883 | unregister_netdev(vsi->netdev); |
| 9884 | free_netdev(vsi->netdev); |
| 9885 | vsi->netdev = NULL; |
| 9886 | } |
| 9887 | err_netdev: |
| 9888 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9889 | err_vsi: |
| 9890 | i40e_vsi_clear(vsi); |
| 9891 | err_alloc: |
| 9892 | return NULL; |
| 9893 | } |
| 9894 | |
| 9895 | /** |
| 9896 | * i40e_veb_get_bw_info - Query VEB BW information |
| 9897 | * @veb: the veb to query |
| 9898 | * |
| 9899 | * Query the Tx scheduler BW configuration data for given VEB |
| 9900 | **/ |
| 9901 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 9902 | { |
| 9903 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 9904 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 9905 | struct i40e_pf *pf = veb->pf; |
| 9906 | struct i40e_hw *hw = &pf->hw; |
| 9907 | u32 tc_bw_max; |
| 9908 | int ret = 0; |
| 9909 | int i; |
| 9910 | |
| 9911 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 9912 | &bw_data, NULL); |
| 9913 | if (ret) { |
| 9914 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9915 | "query veb bw config failed, err %s aq_err %s\n", |
| 9916 | i40e_stat_str(&pf->hw, ret), |
| 9917 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9918 | goto out; |
| 9919 | } |
| 9920 | |
| 9921 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 9922 | &ets_data, NULL); |
| 9923 | if (ret) { |
| 9924 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9925 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 9926 | i40e_stat_str(&pf->hw, ret), |
| 9927 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9928 | goto out; |
| 9929 | } |
| 9930 | |
| 9931 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 9932 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 9933 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 9934 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9935 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 9936 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 9937 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 9938 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 9939 | veb->bw_tc_limit_credits[i] = |
| 9940 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 9941 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 9942 | } |
| 9943 | |
| 9944 | out: |
| 9945 | return ret; |
| 9946 | } |
| 9947 | |
| 9948 | /** |
| 9949 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 9950 | * @pf: board private structure |
| 9951 | * |
| 9952 | * On error: returns error code (negative) |
| 9953 | * On success: returns vsi index in PF (positive) |
| 9954 | **/ |
| 9955 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 9956 | { |
| 9957 | int ret = -ENOENT; |
| 9958 | struct i40e_veb *veb; |
| 9959 | int i; |
| 9960 | |
| 9961 | /* Need to protect the allocation of switch elements at the PF level */ |
| 9962 | mutex_lock(&pf->switch_mutex); |
| 9963 | |
| 9964 | /* VEB list may be fragmented if VEB creation/destruction has |
| 9965 | * been happening. We can afford to do a quick scan to look |
| 9966 | * for any free slots in the list. |
| 9967 | * |
| 9968 | * find next empty veb slot, looping back around if necessary |
| 9969 | */ |
| 9970 | i = 0; |
| 9971 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 9972 | i++; |
| 9973 | if (i >= I40E_MAX_VEB) { |
| 9974 | ret = -ENOMEM; |
| 9975 | goto err_alloc_veb; /* out of VEB slots! */ |
| 9976 | } |
| 9977 | |
| 9978 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 9979 | if (!veb) { |
| 9980 | ret = -ENOMEM; |
| 9981 | goto err_alloc_veb; |
| 9982 | } |
| 9983 | veb->pf = pf; |
| 9984 | veb->idx = i; |
| 9985 | veb->enabled_tc = 1; |
| 9986 | |
| 9987 | pf->veb[i] = veb; |
| 9988 | ret = i; |
| 9989 | err_alloc_veb: |
| 9990 | mutex_unlock(&pf->switch_mutex); |
| 9991 | return ret; |
| 9992 | } |
| 9993 | |
| 9994 | /** |
| 9995 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 9996 | * @branch: where to start deleting |
| 9997 | * |
| 9998 | * This uses recursion to find the tips of the branch to be |
| 9999 | * removed, deleting until we get back to and can delete this VEB. |
| 10000 | **/ |
| 10001 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 10002 | { |
| 10003 | struct i40e_pf *pf = branch->pf; |
| 10004 | u16 branch_seid = branch->seid; |
| 10005 | u16 veb_idx = branch->idx; |
| 10006 | int i; |
| 10007 | |
| 10008 | /* release any VEBs on this VEB - RECURSION */ |
| 10009 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10010 | if (!pf->veb[i]) |
| 10011 | continue; |
| 10012 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 10013 | i40e_switch_branch_release(pf->veb[i]); |
| 10014 | } |
| 10015 | |
| 10016 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 10017 | * |
| 10018 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 10019 | * the VEB itself, so don't use (*branch) after this loop. |
| 10020 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10021 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10022 | if (!pf->vsi[i]) |
| 10023 | continue; |
| 10024 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 10025 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 10026 | i40e_vsi_release(pf->vsi[i]); |
| 10027 | } |
| 10028 | } |
| 10029 | |
| 10030 | /* There's one corner case where the VEB might not have been |
| 10031 | * removed, so double check it here and remove it if needed. |
| 10032 | * This case happens if the veb was created from the debugfs |
| 10033 | * commands and no VSIs were added to it. |
| 10034 | */ |
| 10035 | if (pf->veb[veb_idx]) |
| 10036 | i40e_veb_release(pf->veb[veb_idx]); |
| 10037 | } |
| 10038 | |
| 10039 | /** |
| 10040 | * i40e_veb_clear - remove veb struct |
| 10041 | * @veb: the veb to remove |
| 10042 | **/ |
| 10043 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 10044 | { |
| 10045 | if (!veb) |
| 10046 | return; |
| 10047 | |
| 10048 | if (veb->pf) { |
| 10049 | struct i40e_pf *pf = veb->pf; |
| 10050 | |
| 10051 | mutex_lock(&pf->switch_mutex); |
| 10052 | if (pf->veb[veb->idx] == veb) |
| 10053 | pf->veb[veb->idx] = NULL; |
| 10054 | mutex_unlock(&pf->switch_mutex); |
| 10055 | } |
| 10056 | |
| 10057 | kfree(veb); |
| 10058 | } |
| 10059 | |
| 10060 | /** |
| 10061 | * i40e_veb_release - Delete a VEB and free its resources |
| 10062 | * @veb: the VEB being removed |
| 10063 | **/ |
| 10064 | void i40e_veb_release(struct i40e_veb *veb) |
| 10065 | { |
| 10066 | struct i40e_vsi *vsi = NULL; |
| 10067 | struct i40e_pf *pf; |
| 10068 | int i, n = 0; |
| 10069 | |
| 10070 | pf = veb->pf; |
| 10071 | |
| 10072 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10073 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10074 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 10075 | n++; |
| 10076 | vsi = pf->vsi[i]; |
| 10077 | } |
| 10078 | } |
| 10079 | if (n != 1) { |
| 10080 | dev_info(&pf->pdev->dev, |
| 10081 | "can't remove VEB %d with %d VSIs left\n", |
| 10082 | veb->seid, n); |
| 10083 | return; |
| 10084 | } |
| 10085 | |
| 10086 | /* move the remaining VSI to uplink veb */ |
| 10087 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10088 | if (veb->uplink_seid) { |
| 10089 | vsi->uplink_seid = veb->uplink_seid; |
| 10090 | if (veb->uplink_seid == pf->mac_seid) |
| 10091 | vsi->veb_idx = I40E_NO_VEB; |
| 10092 | else |
| 10093 | vsi->veb_idx = veb->veb_idx; |
| 10094 | } else { |
| 10095 | /* floating VEB */ |
| 10096 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10097 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10098 | } |
| 10099 | |
| 10100 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10101 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10102 | } |
| 10103 | |
| 10104 | /** |
| 10105 | * i40e_add_veb - create the VEB in the switch |
| 10106 | * @veb: the VEB to be instantiated |
| 10107 | * @vsi: the controlling VSI |
| 10108 | **/ |
| 10109 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10110 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10111 | struct i40e_pf *pf = veb->pf; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10112 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10113 | int ret; |
| 10114 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10115 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10116 | veb->enabled_tc, false, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10117 | &veb->seid, enable_stats, NULL); |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10118 | |
| 10119 | /* get a VEB from the hardware */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10120 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10121 | dev_info(&pf->pdev->dev, |
| 10122 | "couldn't add VEB, err %s aq_err %s\n", |
| 10123 | i40e_stat_str(&pf->hw, ret), |
| 10124 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10125 | return -EPERM; |
| 10126 | } |
| 10127 | |
| 10128 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10129 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10130 | &veb->stats_idx, NULL, NULL, NULL); |
| 10131 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10132 | dev_info(&pf->pdev->dev, |
| 10133 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10134 | i40e_stat_str(&pf->hw, ret), |
| 10135 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10136 | return -EPERM; |
| 10137 | } |
| 10138 | ret = i40e_veb_get_bw_info(veb); |
| 10139 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10140 | dev_info(&pf->pdev->dev, |
| 10141 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10142 | i40e_stat_str(&pf->hw, ret), |
| 10143 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10144 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10145 | return -ENOENT; |
| 10146 | } |
| 10147 | |
| 10148 | vsi->uplink_seid = veb->seid; |
| 10149 | vsi->veb_idx = veb->idx; |
| 10150 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10151 | |
| 10152 | return 0; |
| 10153 | } |
| 10154 | |
| 10155 | /** |
| 10156 | * i40e_veb_setup - Set up a VEB |
| 10157 | * @pf: board private structure |
| 10158 | * @flags: VEB setup flags |
| 10159 | * @uplink_seid: the switch element to link to |
| 10160 | * @vsi_seid: the initial VSI seid |
| 10161 | * @enabled_tc: Enabled TC bit-map |
| 10162 | * |
| 10163 | * This allocates the sw VEB structure and links it into the switch |
| 10164 | * It is possible and legal for this to be a duplicate of an already |
| 10165 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10166 | * to be zero, in order to create a floating VEB. |
| 10167 | * |
| 10168 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10169 | * success, otherwise returns NULL on failure. |
| 10170 | **/ |
| 10171 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10172 | u16 uplink_seid, u16 vsi_seid, |
| 10173 | u8 enabled_tc) |
| 10174 | { |
| 10175 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10176 | int vsi_idx, veb_idx; |
| 10177 | int ret; |
| 10178 | |
| 10179 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10180 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10181 | (uplink_seid + vsi_seid != 0)) { |
| 10182 | dev_info(&pf->pdev->dev, |
| 10183 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10184 | uplink_seid, vsi_seid); |
| 10185 | return NULL; |
| 10186 | } |
| 10187 | |
| 10188 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10189 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10190 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10191 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10192 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10193 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10194 | vsi_seid); |
| 10195 | return NULL; |
| 10196 | } |
| 10197 | |
| 10198 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10199 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10200 | if (pf->veb[veb_idx] && |
| 10201 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10202 | uplink_veb = pf->veb[veb_idx]; |
| 10203 | break; |
| 10204 | } |
| 10205 | } |
| 10206 | if (!uplink_veb) { |
| 10207 | dev_info(&pf->pdev->dev, |
| 10208 | "uplink seid %d not found\n", uplink_seid); |
| 10209 | return NULL; |
| 10210 | } |
| 10211 | } |
| 10212 | |
| 10213 | /* get veb sw struct */ |
| 10214 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10215 | if (veb_idx < 0) |
| 10216 | goto err_alloc; |
| 10217 | veb = pf->veb[veb_idx]; |
| 10218 | veb->flags = flags; |
| 10219 | veb->uplink_seid = uplink_seid; |
| 10220 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10221 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10222 | |
| 10223 | /* create the VEB in the switch */ |
| 10224 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10225 | if (ret) |
| 10226 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10227 | if (vsi_idx == pf->lan_vsi) |
| 10228 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10229 | |
| 10230 | return veb; |
| 10231 | |
| 10232 | err_veb: |
| 10233 | i40e_veb_clear(veb); |
| 10234 | err_alloc: |
| 10235 | return NULL; |
| 10236 | } |
| 10237 | |
| 10238 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10239 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10240 | * @pf: board private structure |
| 10241 | * @ele: element we are building info from |
| 10242 | * @num_reported: total number of elements |
| 10243 | * @printconfig: should we print the contents |
| 10244 | * |
| 10245 | * helper function to assist in extracting a few useful SEID values. |
| 10246 | **/ |
| 10247 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10248 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10249 | u16 num_reported, bool printconfig) |
| 10250 | { |
| 10251 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10252 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10253 | u8 element_type = ele->element_type; |
| 10254 | u16 seid = le16_to_cpu(ele->seid); |
| 10255 | |
| 10256 | if (printconfig) |
| 10257 | dev_info(&pf->pdev->dev, |
| 10258 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10259 | element_type, seid, uplink_seid, downlink_seid); |
| 10260 | |
| 10261 | switch (element_type) { |
| 10262 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10263 | pf->mac_seid = seid; |
| 10264 | break; |
| 10265 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10266 | /* Main VEB? */ |
| 10267 | if (uplink_seid != pf->mac_seid) |
| 10268 | break; |
| 10269 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10270 | int v; |
| 10271 | |
| 10272 | /* find existing or else empty VEB */ |
| 10273 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10274 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10275 | pf->lan_veb = v; |
| 10276 | break; |
| 10277 | } |
| 10278 | } |
| 10279 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10280 | v = i40e_veb_mem_alloc(pf); |
| 10281 | if (v < 0) |
| 10282 | break; |
| 10283 | pf->lan_veb = v; |
| 10284 | } |
| 10285 | } |
| 10286 | |
| 10287 | pf->veb[pf->lan_veb]->seid = seid; |
| 10288 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10289 | pf->veb[pf->lan_veb]->pf = pf; |
| 10290 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10291 | break; |
| 10292 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10293 | if (num_reported != 1) |
| 10294 | break; |
| 10295 | /* This is immediately after a reset so we can assume this is |
| 10296 | * the PF's VSI |
| 10297 | */ |
| 10298 | pf->mac_seid = uplink_seid; |
| 10299 | pf->pf_seid = downlink_seid; |
| 10300 | pf->main_vsi_seid = seid; |
| 10301 | if (printconfig) |
| 10302 | dev_info(&pf->pdev->dev, |
| 10303 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10304 | pf->pf_seid, pf->main_vsi_seid); |
| 10305 | break; |
| 10306 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10307 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10308 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10309 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10310 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10311 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10312 | /* ignore these for now */ |
| 10313 | break; |
| 10314 | default: |
| 10315 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10316 | element_type, seid); |
| 10317 | break; |
| 10318 | } |
| 10319 | } |
| 10320 | |
| 10321 | /** |
| 10322 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10323 | * @pf: board private structure |
| 10324 | * @printconfig: should we print the contents |
| 10325 | * |
| 10326 | * Get the current switch configuration from the device and |
| 10327 | * extract a few useful SEID values. |
| 10328 | **/ |
| 10329 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10330 | { |
| 10331 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10332 | u16 next_seid = 0; |
| 10333 | int ret = 0; |
| 10334 | u8 *aq_buf; |
| 10335 | int i; |
| 10336 | |
| 10337 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10338 | if (!aq_buf) |
| 10339 | return -ENOMEM; |
| 10340 | |
| 10341 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10342 | do { |
| 10343 | u16 num_reported, num_total; |
| 10344 | |
| 10345 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10346 | I40E_AQ_LARGE_BUF, |
| 10347 | &next_seid, NULL); |
| 10348 | if (ret) { |
| 10349 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10350 | "get switch config failed err %s aq_err %s\n", |
| 10351 | i40e_stat_str(&pf->hw, ret), |
| 10352 | i40e_aq_str(&pf->hw, |
| 10353 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10354 | kfree(aq_buf); |
| 10355 | return -ENOENT; |
| 10356 | } |
| 10357 | |
| 10358 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10359 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10360 | |
| 10361 | if (printconfig) |
| 10362 | dev_info(&pf->pdev->dev, |
| 10363 | "header: %d reported %d total\n", |
| 10364 | num_reported, num_total); |
| 10365 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10366 | for (i = 0; i < num_reported; i++) { |
| 10367 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10368 | &sw_config->element[i]; |
| 10369 | |
| 10370 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10371 | printconfig); |
| 10372 | } |
| 10373 | } while (next_seid != 0); |
| 10374 | |
| 10375 | kfree(aq_buf); |
| 10376 | return ret; |
| 10377 | } |
| 10378 | |
| 10379 | /** |
| 10380 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10381 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10382 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10383 | * |
| 10384 | * Returns 0 on success, negative value on failure |
| 10385 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10386 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10387 | { |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10388 | u16 flags = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10389 | int ret; |
| 10390 | |
| 10391 | /* find out what's out there already */ |
| 10392 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10393 | if (ret) { |
| 10394 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10395 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10396 | i40e_stat_str(&pf->hw, ret), |
| 10397 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10398 | return ret; |
| 10399 | } |
| 10400 | i40e_pf_reset_stats(pf); |
| 10401 | |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10402 | /* set the switch config bit for the whole device to |
| 10403 | * support limited promisc or true promisc |
| 10404 | * when user requests promisc. The default is limited |
| 10405 | * promisc. |
| 10406 | */ |
| 10407 | |
| 10408 | if ((pf->hw.pf_id == 0) && |
| 10409 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) |
| 10410 | flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10411 | |
| 10412 | if (pf->hw.pf_id == 0) { |
| 10413 | u16 valid_flags; |
| 10414 | |
| 10415 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10416 | ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, |
| 10417 | NULL); |
| 10418 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { |
| 10419 | dev_info(&pf->pdev->dev, |
| 10420 | "couldn't set switch config bits, err %s aq_err %s\n", |
| 10421 | i40e_stat_str(&pf->hw, ret), |
| 10422 | i40e_aq_str(&pf->hw, |
| 10423 | pf->hw.aq.asq_last_status)); |
| 10424 | /* not a fatal problem, just keep going */ |
| 10425 | } |
| 10426 | } |
| 10427 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10428 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10429 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10430 | struct i40e_vsi *vsi = NULL; |
| 10431 | u16 uplink_seid; |
| 10432 | |
| 10433 | /* Set up the PF VSI associated with the PF's main VSI |
| 10434 | * that is already in the HW switch |
| 10435 | */ |
| 10436 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10437 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10438 | else |
| 10439 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10440 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10441 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10442 | else if (reinit) |
| 10443 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10444 | if (!vsi) { |
| 10445 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10446 | i40e_fdir_teardown(pf); |
| 10447 | return -EAGAIN; |
| 10448 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10449 | } else { |
| 10450 | /* force a reset of TC and queue layout configurations */ |
| 10451 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10452 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10453 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10454 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10455 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10456 | } |
| 10457 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 10458 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10459 | i40e_fdir_sb_setup(pf); |
| 10460 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10461 | /* Setup static PF queue filter control settings */ |
| 10462 | ret = i40e_setup_pf_filter_control(pf); |
| 10463 | if (ret) { |
| 10464 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 10465 | ret); |
| 10466 | /* Failure here should not stop continuing other steps */ |
| 10467 | } |
| 10468 | |
| 10469 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 10470 | * the hash |
| 10471 | */ |
| 10472 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 10473 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10474 | |
| 10475 | /* fill in link information and enable LSE reporting */ |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 10476 | i40e_update_link_info(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10477 | i40e_link_event(pf); |
| 10478 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10479 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10480 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 10481 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10482 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10483 | i40e_ptp_init(pf); |
| 10484 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10485 | return ret; |
| 10486 | } |
| 10487 | |
| 10488 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10489 | * i40e_determine_queue_usage - Work out queue distribution |
| 10490 | * @pf: board private structure |
| 10491 | **/ |
| 10492 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 10493 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10494 | int queues_left; |
| 10495 | |
| 10496 | pf->num_lan_qps = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10497 | #ifdef I40E_FCOE |
| 10498 | pf->num_fcoe_qps = 0; |
| 10499 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10500 | |
| 10501 | /* Find the max queues to be put into basic use. We'll always be |
| 10502 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 10503 | * big RSS set. |
| 10504 | */ |
| 10505 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 10506 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10507 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10508 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10509 | /* one qp for PF, no queues for anything else */ |
| 10510 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10511 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10512 | |
| 10513 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10514 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10515 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10516 | #ifdef I40E_FCOE |
| 10517 | I40E_FLAG_FCOE_ENABLED | |
| 10518 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10519 | I40E_FLAG_FD_SB_ENABLED | |
| 10520 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10521 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10522 | I40E_FLAG_SRIOV_ENABLED | |
| 10523 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10524 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 10525 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 10526 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10527 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10528 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10529 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10530 | queues_left -= pf->num_lan_qps; |
| 10531 | |
| 10532 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10533 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10534 | #ifdef I40E_FCOE |
| 10535 | I40E_FLAG_FCOE_ENABLED | |
| 10536 | #endif |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10537 | I40E_FLAG_FD_SB_ENABLED | |
| 10538 | I40E_FLAG_FD_ATR_ENABLED | |
| 10539 | I40E_FLAG_DCB_ENABLED | |
| 10540 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10541 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10542 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10543 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10544 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10545 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10546 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 10547 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 10548 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 10549 | num_online_cpus()); |
| 10550 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 10551 | pf->hw.func_caps.num_tx_qp); |
| 10552 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10553 | queues_left -= pf->num_lan_qps; |
| 10554 | } |
| 10555 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10556 | #ifdef I40E_FCOE |
| 10557 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 10558 | if (I40E_DEFAULT_FCOE <= queues_left) { |
| 10559 | pf->num_fcoe_qps = I40E_DEFAULT_FCOE; |
| 10560 | } else if (I40E_MINIMUM_FCOE <= queues_left) { |
| 10561 | pf->num_fcoe_qps = I40E_MINIMUM_FCOE; |
| 10562 | } else { |
| 10563 | pf->num_fcoe_qps = 0; |
| 10564 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 10565 | dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n"); |
| 10566 | } |
| 10567 | |
| 10568 | queues_left -= pf->num_fcoe_qps; |
| 10569 | } |
| 10570 | |
| 10571 | #endif |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10572 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10573 | if (queues_left > 1) { |
| 10574 | queues_left -= 1; /* save 1 queue for FD */ |
| 10575 | } else { |
| 10576 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 10577 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 10578 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10579 | } |
| 10580 | |
| 10581 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10582 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10583 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 10584 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10585 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 10586 | } |
| 10587 | |
| 10588 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 10589 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 10590 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 10591 | (queues_left / pf->num_vmdq_qps)); |
| 10592 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 10593 | } |
| 10594 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10595 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10596 | dev_dbg(&pf->pdev->dev, |
| 10597 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 10598 | pf->hw.func_caps.num_tx_qp, |
| 10599 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10600 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 10601 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 10602 | queues_left); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10603 | #ifdef I40E_FCOE |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10604 | 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] | 10605 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10606 | } |
| 10607 | |
| 10608 | /** |
| 10609 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 10610 | * @pf: PF to be setup |
| 10611 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10612 | * 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] | 10613 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 10614 | * based filter sizes required for them. It also enables Flow director, |
| 10615 | * ethertype and macvlan type filter settings for the pf. |
| 10616 | * |
| 10617 | * Returns 0 on success, negative on failure |
| 10618 | **/ |
| 10619 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 10620 | { |
| 10621 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 10622 | |
| 10623 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 10624 | |
| 10625 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10626 | 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] | 10627 | settings->enable_fdir = true; |
| 10628 | |
| 10629 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 10630 | settings->enable_ethtype = true; |
| 10631 | settings->enable_macvlan = true; |
| 10632 | |
| 10633 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 10634 | return -ENOENT; |
| 10635 | |
| 10636 | return 0; |
| 10637 | } |
| 10638 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10639 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10640 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10641 | static void i40e_print_features(struct i40e_pf *pf) |
| 10642 | { |
| 10643 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10644 | char *buf; |
| 10645 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10646 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10647 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 10648 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10649 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10650 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10651 | 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] | 10652 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10653 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10654 | #endif |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10655 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10656 | pf->hw.func_caps.num_vsis, |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10657 | pf->vsi[pf->lan_vsi]->num_queue_pairs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10658 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10659 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10660 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10661 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10662 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10663 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 10664 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10665 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10666 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10667 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10668 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10669 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10670 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10671 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10672 | #ifdef I40E_FCOE |
| 10673 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10674 | i += snprintf(&buf[i], REMAIN(i), " FCOE"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10675 | #endif |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10676 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10677 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10678 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10679 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10680 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10681 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 10682 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10683 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10684 | } |
| 10685 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10686 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10687 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
| 10688 | * |
| 10689 | * @pdev: PCI device information struct |
| 10690 | * @pf: board private structure |
| 10691 | * |
| 10692 | * Look up the MAC address in Open Firmware on systems that support it, |
| 10693 | * and use IDPROM on SPARC if no OF address is found. On return, the |
| 10694 | * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value |
| 10695 | * has been selected. |
| 10696 | **/ |
| 10697 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 10698 | { |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10699 | pf->flags &= ~I40E_FLAG_PF_MAC; |
Sowmini Varadhan | ba94272 | 2016-01-12 19:32:31 -0800 | [diff] [blame] | 10700 | if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10701 | pf->flags |= I40E_FLAG_PF_MAC; |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10702 | } |
| 10703 | |
| 10704 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10705 | * i40e_probe - Device initialization routine |
| 10706 | * @pdev: PCI device information struct |
| 10707 | * @ent: entry in i40e_pci_tbl |
| 10708 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10709 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 10710 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10711 | * and a hardware reset occur. |
| 10712 | * |
| 10713 | * Returns 0 on success, negative on failure |
| 10714 | **/ |
| 10715 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 10716 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 10717 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10718 | struct i40e_pf *pf; |
| 10719 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10720 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10721 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10722 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 10723 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10724 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10725 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10726 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10727 | |
| 10728 | err = pci_enable_device_mem(pdev); |
| 10729 | if (err) |
| 10730 | return err; |
| 10731 | |
| 10732 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10733 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10734 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 10735 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10736 | if (err) { |
| 10737 | dev_err(&pdev->dev, |
| 10738 | "DMA configuration failed: 0x%x\n", err); |
| 10739 | goto err_dma; |
| 10740 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10741 | } |
| 10742 | |
| 10743 | /* set up pci connections */ |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10744 | err = pci_request_mem_regions(pdev, i40e_driver_name); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10745 | if (err) { |
| 10746 | dev_info(&pdev->dev, |
| 10747 | "pci_request_selected_regions failed %d\n", err); |
| 10748 | goto err_pci_reg; |
| 10749 | } |
| 10750 | |
| 10751 | pci_enable_pcie_error_reporting(pdev); |
| 10752 | pci_set_master(pdev); |
| 10753 | |
| 10754 | /* Now that we have a PCI connection, we need to do the |
| 10755 | * low level device setup. This is primarily setting up |
| 10756 | * the Admin Queue structures and then querying for the |
| 10757 | * device's current profile information. |
| 10758 | */ |
| 10759 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 10760 | if (!pf) { |
| 10761 | err = -ENOMEM; |
| 10762 | goto err_pf_alloc; |
| 10763 | } |
| 10764 | pf->next_vsi = 0; |
| 10765 | pf->pdev = pdev; |
| 10766 | set_bit(__I40E_DOWN, &pf->state); |
| 10767 | |
| 10768 | hw = &pf->hw; |
| 10769 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10770 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10771 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 10772 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10773 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10774 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10775 | if (!hw->hw_addr) { |
| 10776 | err = -EIO; |
| 10777 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 10778 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10779 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10780 | goto err_ioremap; |
| 10781 | } |
| 10782 | hw->vendor_id = pdev->vendor; |
| 10783 | hw->device_id = pdev->device; |
| 10784 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 10785 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 10786 | hw->subsystem_device_id = pdev->subsystem_device; |
| 10787 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 10788 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10789 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10790 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 10791 | /* set up the locks for the AQ, do this only once in probe |
| 10792 | * and destroy them only once in remove |
| 10793 | */ |
| 10794 | mutex_init(&hw->aq.asq_mutex); |
| 10795 | mutex_init(&hw->aq.arq_mutex); |
| 10796 | |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 10797 | if (debug != -1) { |
| 10798 | pf->msg_enable = pf->hw.debug_mask; |
| 10799 | pf->msg_enable = debug; |
| 10800 | } |
| 10801 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10802 | /* do a special CORER for clearing PXE mode once at init */ |
| 10803 | if (hw->revision_id == 0 && |
| 10804 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 10805 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 10806 | i40e_flush(hw); |
| 10807 | msleep(200); |
| 10808 | pf->corer_count++; |
| 10809 | |
| 10810 | i40e_clear_pxe_mode(hw); |
| 10811 | } |
| 10812 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10813 | /* 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] | 10814 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10815 | err = i40e_pf_reset(hw); |
| 10816 | if (err) { |
| 10817 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 10818 | goto err_pf_reset; |
| 10819 | } |
| 10820 | pf->pfr_count++; |
| 10821 | |
| 10822 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 10823 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 10824 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10825 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10826 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10827 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 10828 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10829 | "%s-%s:misc", |
| 10830 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10831 | |
| 10832 | err = i40e_init_shared_code(hw); |
| 10833 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 10834 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 10835 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10836 | goto err_pf_reset; |
| 10837 | } |
| 10838 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10839 | /* set up a default setting for link flow control */ |
| 10840 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 10841 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10842 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 10843 | if (err) { |
| 10844 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 10845 | dev_info(&pdev->dev, |
| 10846 | "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"); |
| 10847 | else |
| 10848 | dev_info(&pdev->dev, |
| 10849 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 10850 | |
| 10851 | goto err_pf_reset; |
| 10852 | } |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10853 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10854 | /* provide nvm, fw, api versions */ |
| 10855 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 10856 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 10857 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 10858 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10859 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10860 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 10861 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10862 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10863 | "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"); |
| 10864 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 10865 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10866 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10867 | "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] | 10868 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 10869 | i40e_verify_eeprom(pf); |
| 10870 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 10871 | /* Rev 0 hardware was never productized */ |
| 10872 | if (hw->revision_id < 1) |
| 10873 | 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"); |
| 10874 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 10875 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10876 | err = i40e_get_capabilities(pf); |
| 10877 | if (err) |
| 10878 | goto err_adminq_setup; |
| 10879 | |
| 10880 | err = i40e_sw_init(pf); |
| 10881 | if (err) { |
| 10882 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 10883 | goto err_sw_init; |
| 10884 | } |
| 10885 | |
| 10886 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 10887 | hw->func_caps.num_rx_qp, |
| 10888 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 10889 | if (err) { |
| 10890 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 10891 | goto err_init_lan_hmc; |
| 10892 | } |
| 10893 | |
| 10894 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 10895 | if (err) { |
| 10896 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 10897 | err = -ENOENT; |
| 10898 | goto err_configure_lan_hmc; |
| 10899 | } |
| 10900 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10901 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 10902 | * Ignore error return codes because if it was already disabled via |
| 10903 | * hardware settings this will fail |
| 10904 | */ |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 10905 | if (pf->flags & I40E_FLAG_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10906 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 10907 | i40e_aq_stop_lldp(hw, true, NULL); |
| 10908 | } |
| 10909 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10910 | i40e_get_mac_addr(hw, hw->mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10911 | /* allow a platform config to override the HW addr */ |
| 10912 | i40e_get_platform_mac_addr(pdev, pf); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 10913 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10914 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 10915 | err = -EIO; |
| 10916 | goto err_mac_addr; |
| 10917 | } |
| 10918 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 10919 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10920 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 10921 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 10922 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10923 | #ifdef I40E_FCOE |
| 10924 | err = i40e_get_san_mac_addr(hw, hw->mac.san_addr); |
| 10925 | if (err) |
| 10926 | dev_info(&pdev->dev, |
| 10927 | "(non-fatal) SAN MAC retrieval failed: %d\n", err); |
| 10928 | if (!is_valid_ether_addr(hw->mac.san_addr)) { |
| 10929 | dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n", |
| 10930 | hw->mac.san_addr); |
| 10931 | ether_addr_copy(hw->mac.san_addr, hw->mac.addr); |
| 10932 | } |
| 10933 | dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr); |
| 10934 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10935 | |
| 10936 | pci_set_drvdata(pdev, pf); |
| 10937 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10938 | #ifdef CONFIG_I40E_DCB |
| 10939 | err = i40e_init_pf_dcb(pf); |
| 10940 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 10941 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10942 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 10943 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10944 | } |
| 10945 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10946 | |
| 10947 | /* set up periodic task facility */ |
| 10948 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 10949 | pf->service_timer_period = HZ; |
| 10950 | |
| 10951 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 10952 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 10953 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10954 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10955 | /* NVM bit on means WoL disabled for the port */ |
| 10956 | 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] | 10957 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10958 | pf->wol_en = false; |
| 10959 | else |
| 10960 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 10961 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 10962 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10963 | /* set up the main switch operations */ |
| 10964 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 10965 | err = i40e_init_interrupt_scheme(pf); |
| 10966 | if (err) |
| 10967 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10968 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10969 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 10970 | * to us; HW supports far more and we share the remaining pool with |
| 10971 | * the other PFs. We allocate space for more than the guarantee with |
| 10972 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10973 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10974 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 10975 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 10976 | else |
| 10977 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 10978 | |
| 10979 | /* 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] | 10980 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 10981 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 10982 | if (!pf->vsi) { |
| 10983 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10984 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 10985 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10986 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 10987 | #ifdef CONFIG_PCI_IOV |
| 10988 | /* prep for VF support */ |
| 10989 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10990 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 10991 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 10992 | if (pci_num_vf(pdev)) |
| 10993 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 10994 | } |
| 10995 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10996 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10997 | if (err) { |
| 10998 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 10999 | goto err_vsis; |
| 11000 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11001 | |
| 11002 | /* Make sure flow control is set according to current settings */ |
| 11003 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 11004 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 11005 | dev_dbg(&pf->pdev->dev, |
| 11006 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 11007 | i40e_stat_str(hw, err), |
| 11008 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11009 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 11010 | dev_dbg(&pf->pdev->dev, |
| 11011 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 11012 | i40e_stat_str(hw, err), |
| 11013 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11014 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 11015 | dev_dbg(&pf->pdev->dev, |
| 11016 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 11017 | i40e_stat_str(hw, err), |
| 11018 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11019 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11020 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11021 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11022 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 11023 | i40e_vsi_open(pf->vsi[i]); |
| 11024 | break; |
| 11025 | } |
| 11026 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11027 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11028 | /* The driver only wants link up/down and module qualification |
| 11029 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11030 | */ |
| 11031 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11032 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 11033 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11034 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11035 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11036 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 11037 | i40e_stat_str(&pf->hw, err), |
| 11038 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11039 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11040 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 11041 | * of TSO, so that we avoid the MDD being fired and causing |
| 11042 | * a reset in the case of small MSS+TSO. |
| 11043 | */ |
| 11044 | val = rd32(hw, I40E_REG_MSS); |
| 11045 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 11046 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 11047 | val |= I40E_64BYTE_MSS; |
| 11048 | wr32(hw, I40E_REG_MSS, val); |
| 11049 | } |
| 11050 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 11051 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 11052 | msleep(75); |
| 11053 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 11054 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11055 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 11056 | i40e_stat_str(&pf->hw, err), |
| 11057 | i40e_aq_str(&pf->hw, |
| 11058 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 11059 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11060 | /* The main driver is (mostly) up and happy. We need to set this state |
| 11061 | * before setting up the misc vector or we get a race and the vector |
| 11062 | * ends up disabled forever. |
| 11063 | */ |
| 11064 | clear_bit(__I40E_DOWN, &pf->state); |
| 11065 | |
| 11066 | /* In case of MSIX we are going to setup the misc vector right here |
| 11067 | * to handle admin queue events etc. In case of legacy and MSI |
| 11068 | * the misc functionality and queue processing is combined in |
| 11069 | * the same vector and that gets setup at open. |
| 11070 | */ |
| 11071 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 11072 | err = i40e_setup_misc_vector(pf); |
| 11073 | if (err) { |
| 11074 | dev_info(&pdev->dev, |
| 11075 | "setup of misc vector failed: %d\n", err); |
| 11076 | goto err_vsis; |
| 11077 | } |
| 11078 | } |
| 11079 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11080 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11081 | /* prep for VF support */ |
| 11082 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11083 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11084 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11085 | /* disable link interrupts for VFs */ |
| 11086 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11087 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11088 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11089 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11090 | |
| 11091 | if (pci_num_vf(pdev)) { |
| 11092 | dev_info(&pdev->dev, |
| 11093 | "Active VFs found, allocating resources.\n"); |
| 11094 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11095 | if (err) |
| 11096 | dev_info(&pdev->dev, |
| 11097 | "Error %d allocating resources for existing VFs\n", |
| 11098 | err); |
| 11099 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11100 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11101 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11102 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11103 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11104 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11105 | pf->num_iwarp_msix, |
| 11106 | I40E_IWARP_IRQ_PILE_ID); |
| 11107 | if (pf->iwarp_base_vector < 0) { |
| 11108 | dev_info(&pdev->dev, |
| 11109 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 11110 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 11111 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 11112 | } |
| 11113 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11114 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11115 | i40e_dbg_pf_init(pf); |
| 11116 | |
| 11117 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11118 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11119 | |
| 11120 | /* since everything's happy, start the service_task timer */ |
| 11121 | mod_timer(&pf->service_timer, |
| 11122 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11123 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11124 | /* add this PF to client device list and launch a client service task */ |
| 11125 | err = i40e_lan_add_device(pf); |
| 11126 | if (err) |
| 11127 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 11128 | err); |
| 11129 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11130 | #ifdef I40E_FCOE |
| 11131 | /* create FCoE interface */ |
| 11132 | i40e_fcoe_vsi_setup(pf); |
| 11133 | |
| 11134 | #endif |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11135 | #define PCI_SPEED_SIZE 8 |
| 11136 | #define PCI_WIDTH_SIZE 8 |
| 11137 | /* Devices on the IOSF bus do not have this information |
| 11138 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11139 | * checking them. |
| 11140 | */ |
| 11141 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { |
| 11142 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11143 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11144 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11145 | /* Get the negotiated link width and speed from PCI config |
| 11146 | * space |
| 11147 | */ |
| 11148 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11149 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11150 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11151 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11152 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11153 | switch (hw->bus.speed) { |
| 11154 | case i40e_bus_speed_8000: |
| 11155 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11156 | case i40e_bus_speed_5000: |
| 11157 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11158 | case i40e_bus_speed_2500: |
| 11159 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11160 | default: |
| 11161 | break; |
| 11162 | } |
| 11163 | switch (hw->bus.width) { |
| 11164 | case i40e_bus_width_pcie_x8: |
| 11165 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11166 | case i40e_bus_width_pcie_x4: |
| 11167 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11168 | case i40e_bus_width_pcie_x2: |
| 11169 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11170 | case i40e_bus_width_pcie_x1: |
| 11171 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11172 | default: |
| 11173 | break; |
| 11174 | } |
| 11175 | |
| 11176 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11177 | speed, width); |
| 11178 | |
| 11179 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11180 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11181 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11182 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11183 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11184 | } |
| 11185 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11186 | /* get the requested speeds from the fw */ |
| 11187 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11188 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11189 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11190 | i40e_stat_str(&pf->hw, err), |
| 11191 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11192 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11193 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11194 | /* get the supported phy types from the fw */ |
| 11195 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11196 | if (err) |
| 11197 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11198 | i40e_stat_str(&pf->hw, err), |
| 11199 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 11200 | pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type); |
| 11201 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11202 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11203 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11204 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11205 | * PF/VF VSIs. |
| 11206 | * The FW can still send Flow control frames if enabled. |
| 11207 | */ |
| 11208 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11209 | pf->main_vsi_seid); |
| 11210 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 11211 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
| 11212 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
| 11213 | pf->flags |= I40E_FLAG_HAVE_10GBASET_PHY; |
| 11214 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11215 | /* print a string summarizing features */ |
| 11216 | i40e_print_features(pf); |
| 11217 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11218 | return 0; |
| 11219 | |
| 11220 | /* Unwind what we've done if something failed in the setup */ |
| 11221 | err_vsis: |
| 11222 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11223 | i40e_clear_interrupt_scheme(pf); |
| 11224 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11225 | err_switch_setup: |
| 11226 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11227 | del_timer_sync(&pf->service_timer); |
| 11228 | err_mac_addr: |
| 11229 | err_configure_lan_hmc: |
| 11230 | (void)i40e_shutdown_lan_hmc(hw); |
| 11231 | err_init_lan_hmc: |
| 11232 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11233 | err_sw_init: |
| 11234 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11235 | err_pf_reset: |
| 11236 | iounmap(hw->hw_addr); |
| 11237 | err_ioremap: |
| 11238 | kfree(pf); |
| 11239 | err_pf_alloc: |
| 11240 | pci_disable_pcie_error_reporting(pdev); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11241 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11242 | err_pci_reg: |
| 11243 | err_dma: |
| 11244 | pci_disable_device(pdev); |
| 11245 | return err; |
| 11246 | } |
| 11247 | |
| 11248 | /** |
| 11249 | * i40e_remove - Device removal routine |
| 11250 | * @pdev: PCI device information struct |
| 11251 | * |
| 11252 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11253 | * that is should release a PCI device. This could be caused by a |
| 11254 | * Hot-Plug event, or because the driver is going to be removed from |
| 11255 | * memory. |
| 11256 | **/ |
| 11257 | static void i40e_remove(struct pci_dev *pdev) |
| 11258 | { |
| 11259 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11260 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11261 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11262 | int i; |
| 11263 | |
| 11264 | i40e_dbg_pf_exit(pf); |
| 11265 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11266 | i40e_ptp_stop(pf); |
| 11267 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11268 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 11269 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 11270 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11271 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11272 | /* no more scheduling of any task */ |
Pandi Kumar Maharajan | a4618ec | 2016-02-18 09:19:25 -0800 | [diff] [blame] | 11273 | set_bit(__I40E_SUSPENDED, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11274 | set_bit(__I40E_DOWN, &pf->state); |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 11275 | if (pf->service_timer.data) |
| 11276 | del_timer_sync(&pf->service_timer); |
| 11277 | if (pf->service_task.func) |
| 11278 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11279 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11280 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11281 | i40e_free_vfs(pf); |
| 11282 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11283 | } |
| 11284 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11285 | i40e_fdir_teardown(pf); |
| 11286 | |
| 11287 | /* If there is a switch structure or any orphans, remove them. |
| 11288 | * This will leave only the PF's VSI remaining. |
| 11289 | */ |
| 11290 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11291 | if (!pf->veb[i]) |
| 11292 | continue; |
| 11293 | |
| 11294 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11295 | pf->veb[i]->uplink_seid == 0) |
| 11296 | i40e_switch_branch_release(pf->veb[i]); |
| 11297 | } |
| 11298 | |
| 11299 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11300 | * adminq and hmc. |
| 11301 | */ |
| 11302 | if (pf->vsi[pf->lan_vsi]) |
| 11303 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11304 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11305 | /* remove attached clients */ |
| 11306 | ret_code = i40e_lan_del_device(pf); |
| 11307 | if (ret_code) { |
| 11308 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 11309 | ret_code); |
| 11310 | } |
| 11311 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11312 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11313 | if (hw->hmc.hmc_obj) { |
| 11314 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11315 | if (ret_code) |
| 11316 | dev_warn(&pdev->dev, |
| 11317 | "Failed to destroy the HMC resources: %d\n", |
| 11318 | ret_code); |
| 11319 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11320 | |
| 11321 | /* shutdown the adminq */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11322 | ret_code = i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11323 | if (ret_code) |
| 11324 | dev_warn(&pdev->dev, |
| 11325 | "Failed to destroy the Admin Queue resources: %d\n", |
| 11326 | ret_code); |
| 11327 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11328 | /* destroy the locks only once, here */ |
| 11329 | mutex_destroy(&hw->aq.arq_mutex); |
| 11330 | mutex_destroy(&hw->aq.asq_mutex); |
| 11331 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11332 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11333 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11334 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11335 | if (pf->vsi[i]) { |
| 11336 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11337 | i40e_vsi_clear(pf->vsi[i]); |
| 11338 | pf->vsi[i] = NULL; |
| 11339 | } |
| 11340 | } |
| 11341 | |
| 11342 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11343 | kfree(pf->veb[i]); |
| 11344 | pf->veb[i] = NULL; |
| 11345 | } |
| 11346 | |
| 11347 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11348 | kfree(pf->vsi); |
| 11349 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11350 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11351 | kfree(pf); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11352 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11353 | |
| 11354 | pci_disable_pcie_error_reporting(pdev); |
| 11355 | pci_disable_device(pdev); |
| 11356 | } |
| 11357 | |
| 11358 | /** |
| 11359 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11360 | * @pdev: PCI device information struct |
| 11361 | * |
| 11362 | * Called to warn that something happened and the error handling steps |
| 11363 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11364 | * remediation. |
| 11365 | **/ |
| 11366 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11367 | enum pci_channel_state error) |
| 11368 | { |
| 11369 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11370 | |
| 11371 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11372 | |
| 11373 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11374 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11375 | rtnl_lock(); |
| 11376 | i40e_prep_for_reset(pf); |
| 11377 | rtnl_unlock(); |
| 11378 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11379 | |
| 11380 | /* Request a slot reset */ |
| 11381 | return PCI_ERS_RESULT_NEED_RESET; |
| 11382 | } |
| 11383 | |
| 11384 | /** |
| 11385 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11386 | * @pdev: PCI device information struct |
| 11387 | * |
| 11388 | * Called to find if the driver can work with the device now that |
| 11389 | * the pci slot has been reset. If a basic connection seems good |
| 11390 | * (registers are readable and have sane content) then return a |
| 11391 | * happy little PCI_ERS_RESULT_xxx. |
| 11392 | **/ |
| 11393 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11394 | { |
| 11395 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11396 | pci_ers_result_t result; |
| 11397 | int err; |
| 11398 | u32 reg; |
| 11399 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11400 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11401 | if (pci_enable_device_mem(pdev)) { |
| 11402 | dev_info(&pdev->dev, |
| 11403 | "Cannot re-enable PCI device after reset.\n"); |
| 11404 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11405 | } else { |
| 11406 | pci_set_master(pdev); |
| 11407 | pci_restore_state(pdev); |
| 11408 | pci_save_state(pdev); |
| 11409 | pci_wake_from_d3(pdev, false); |
| 11410 | |
| 11411 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11412 | if (reg == 0) |
| 11413 | result = PCI_ERS_RESULT_RECOVERED; |
| 11414 | else |
| 11415 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11416 | } |
| 11417 | |
| 11418 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11419 | if (err) { |
| 11420 | dev_info(&pdev->dev, |
| 11421 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11422 | err); |
| 11423 | /* non-fatal, continue */ |
| 11424 | } |
| 11425 | |
| 11426 | return result; |
| 11427 | } |
| 11428 | |
| 11429 | /** |
| 11430 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11431 | * @pdev: PCI device information struct |
| 11432 | * |
| 11433 | * Called to allow the driver to bring things back up after PCI error |
| 11434 | * and/or reset recovery has finished. |
| 11435 | **/ |
| 11436 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11437 | { |
| 11438 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11439 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11440 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11441 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 11442 | return; |
| 11443 | |
| 11444 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11445 | i40e_handle_reset_warning(pf); |
Vasily Averin | 4c4935a | 2015-07-08 15:04:26 +0300 | [diff] [blame] | 11446 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11447 | } |
| 11448 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11449 | /** |
| 11450 | * i40e_shutdown - PCI callback for shutting down |
| 11451 | * @pdev: PCI device information struct |
| 11452 | **/ |
| 11453 | static void i40e_shutdown(struct pci_dev *pdev) |
| 11454 | { |
| 11455 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11456 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11457 | |
| 11458 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11459 | set_bit(__I40E_DOWN, &pf->state); |
| 11460 | rtnl_lock(); |
| 11461 | i40e_prep_for_reset(pf); |
| 11462 | rtnl_unlock(); |
| 11463 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11464 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11465 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11466 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11467 | del_timer_sync(&pf->service_timer); |
| 11468 | cancel_work_sync(&pf->service_task); |
| 11469 | i40e_fdir_teardown(pf); |
| 11470 | |
| 11471 | rtnl_lock(); |
| 11472 | i40e_prep_for_reset(pf); |
| 11473 | rtnl_unlock(); |
| 11474 | |
| 11475 | wr32(hw, I40E_PFPM_APM, |
| 11476 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11477 | wr32(hw, I40E_PFPM_WUFC, |
| 11478 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11479 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 11480 | i40e_clear_interrupt_scheme(pf); |
| 11481 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11482 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11483 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11484 | pci_set_power_state(pdev, PCI_D3hot); |
| 11485 | } |
| 11486 | } |
| 11487 | |
| 11488 | #ifdef CONFIG_PM |
| 11489 | /** |
| 11490 | * i40e_suspend - PCI callback for moving to D3 |
| 11491 | * @pdev: PCI device information struct |
| 11492 | **/ |
| 11493 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11494 | { |
| 11495 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11496 | struct i40e_hw *hw = &pf->hw; |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11497 | int retval = 0; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11498 | |
| 11499 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11500 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 11501 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11502 | rtnl_lock(); |
| 11503 | i40e_prep_for_reset(pf); |
| 11504 | rtnl_unlock(); |
| 11505 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11506 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11507 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11508 | |
Greg Rose | b33d3b7 | 2016-05-16 10:26:37 -0700 | [diff] [blame] | 11509 | i40e_stop_misc_vector(pf); |
| 11510 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11511 | retval = pci_save_state(pdev); |
| 11512 | if (retval) |
| 11513 | return retval; |
| 11514 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11515 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11516 | pci_set_power_state(pdev, PCI_D3hot); |
| 11517 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11518 | return retval; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11519 | } |
| 11520 | |
| 11521 | /** |
| 11522 | * i40e_resume - PCI callback for waking up from D3 |
| 11523 | * @pdev: PCI device information struct |
| 11524 | **/ |
| 11525 | static int i40e_resume(struct pci_dev *pdev) |
| 11526 | { |
| 11527 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11528 | u32 err; |
| 11529 | |
| 11530 | pci_set_power_state(pdev, PCI_D0); |
| 11531 | pci_restore_state(pdev); |
| 11532 | /* pci_restore_state() clears dev->state_saves, so |
| 11533 | * call pci_save_state() again to restore it. |
| 11534 | */ |
| 11535 | pci_save_state(pdev); |
| 11536 | |
| 11537 | err = pci_enable_device_mem(pdev); |
| 11538 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11539 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11540 | return err; |
| 11541 | } |
| 11542 | pci_set_master(pdev); |
| 11543 | |
| 11544 | /* no wakeup events while running */ |
| 11545 | pci_wake_from_d3(pdev, false); |
| 11546 | |
| 11547 | /* handling the reset will rebuild the device state */ |
| 11548 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11549 | clear_bit(__I40E_DOWN, &pf->state); |
| 11550 | rtnl_lock(); |
| 11551 | i40e_reset_and_rebuild(pf, false); |
| 11552 | rtnl_unlock(); |
| 11553 | } |
| 11554 | |
| 11555 | return 0; |
| 11556 | } |
| 11557 | |
| 11558 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11559 | static const struct pci_error_handlers i40e_err_handler = { |
| 11560 | .error_detected = i40e_pci_error_detected, |
| 11561 | .slot_reset = i40e_pci_error_slot_reset, |
| 11562 | .resume = i40e_pci_error_resume, |
| 11563 | }; |
| 11564 | |
| 11565 | static struct pci_driver i40e_driver = { |
| 11566 | .name = i40e_driver_name, |
| 11567 | .id_table = i40e_pci_tbl, |
| 11568 | .probe = i40e_probe, |
| 11569 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11570 | #ifdef CONFIG_PM |
| 11571 | .suspend = i40e_suspend, |
| 11572 | .resume = i40e_resume, |
| 11573 | #endif |
| 11574 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11575 | .err_handler = &i40e_err_handler, |
| 11576 | .sriov_configure = i40e_pci_sriov_configure, |
| 11577 | }; |
| 11578 | |
| 11579 | /** |
| 11580 | * i40e_init_module - Driver registration routine |
| 11581 | * |
| 11582 | * i40e_init_module is the first routine called when the driver is |
| 11583 | * loaded. All it does is register with the PCI subsystem. |
| 11584 | **/ |
| 11585 | static int __init i40e_init_module(void) |
| 11586 | { |
| 11587 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 11588 | i40e_driver_string, i40e_driver_version_str); |
| 11589 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 11590 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11591 | /* we will see if single thread per module is enough for now, |
| 11592 | * it can't be any worse than using the system workqueue which |
| 11593 | * was already single threaded |
| 11594 | */ |
| 11595 | i40e_wq = create_singlethread_workqueue(i40e_driver_name); |
| 11596 | if (!i40e_wq) { |
| 11597 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 11598 | return -ENOMEM; |
| 11599 | } |
| 11600 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11601 | i40e_dbg_init(); |
| 11602 | return pci_register_driver(&i40e_driver); |
| 11603 | } |
| 11604 | module_init(i40e_init_module); |
| 11605 | |
| 11606 | /** |
| 11607 | * i40e_exit_module - Driver exit cleanup routine |
| 11608 | * |
| 11609 | * i40e_exit_module is called just before the driver is removed |
| 11610 | * from memory. |
| 11611 | **/ |
| 11612 | static void __exit i40e_exit_module(void) |
| 11613 | { |
| 11614 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11615 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11616 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11617 | } |
| 11618 | module_exit(i40e_exit_module); |