Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2016 Intel Corporation. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 27 | #include <linux/etherdevice.h> |
| 28 | #include <linux/of_net.h> |
| 29 | #include <linux/pci.h> |
| 30 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 31 | /* Local includes */ |
| 32 | #include "i40e.h" |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 33 | #include "i40e_diag.h" |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 34 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 35 | #include <net/vxlan.h> |
| 36 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 37 | #if IS_ENABLED(CONFIG_GENEVE) |
| 38 | #include <net/geneve.h> |
| 39 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 40 | |
| 41 | const char i40e_driver_name[] = "i40e"; |
| 42 | static const char i40e_driver_string[] = |
| 43 | "Intel(R) Ethernet Connection XL710 Network Driver"; |
| 44 | |
| 45 | #define DRV_KERN "-k" |
| 46 | |
Catherine Sullivan | e8e724d | 2014-07-10 07:58:26 +0000 | [diff] [blame] | 47 | #define DRV_VERSION_MAJOR 1 |
Catherine Sullivan | 50f26a5 | 2016-03-10 14:59:51 -0800 | [diff] [blame] | 48 | #define DRV_VERSION_MINOR 5 |
Harshitha Ramamurthy | 5a6fc25 | 2016-04-13 03:08:32 -0700 | [diff] [blame] | 49 | #define DRV_VERSION_BUILD 10 |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 50 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 51 | __stringify(DRV_VERSION_MINOR) "." \ |
| 52 | __stringify(DRV_VERSION_BUILD) DRV_KERN |
| 53 | const char i40e_driver_version_str[] = DRV_VERSION; |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 54 | static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation."; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 55 | |
| 56 | /* a bit of forward declarations */ |
| 57 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); |
| 58 | static void i40e_handle_reset_warning(struct i40e_pf *pf); |
| 59 | static int i40e_add_vsi(struct i40e_vsi *vsi); |
| 60 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 61 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 62 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
| 63 | static void i40e_determine_queue_usage(struct i40e_pf *pf); |
| 64 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 65 | static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 66 | u16 rss_table_size, u16 rss_size); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 67 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 68 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 69 | |
| 70 | /* i40e_pci_tbl - PCI Device ID Table |
| 71 | * |
| 72 | * Last entry must be all 0s |
| 73 | * |
| 74 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 75 | * Class, Class Mask, private data (not used) } |
| 76 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 77 | static const struct pci_device_id i40e_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 78 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 79 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 80 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, |
| 81 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 82 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, |
| 83 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, |
| 84 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 85 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0}, |
Shannon Nelson | bc5166b9 | 2015-08-26 15:14:10 -0400 | [diff] [blame] | 86 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0}, |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 87 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
Anjali Singhai Jain | 35dae51 | 2015-12-22 14:25:03 -0800 | [diff] [blame] | 88 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0}, |
| 89 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame] | 90 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0}, |
| 91 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0}, |
| 92 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0}, |
Catherine Sullivan | d6bf58c | 2016-03-18 12:18:08 -0700 | [diff] [blame] | 93 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0}, |
Catherine Sullivan | a3aa503 | 2016-04-13 03:08:31 -0700 | [diff] [blame] | 94 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_I_X722), 0}, |
Shannon Nelson | 48a3b51 | 2015-07-23 16:54:39 -0400 | [diff] [blame] | 95 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
| 96 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 97 | /* required last entry */ |
| 98 | {0, } |
| 99 | }; |
| 100 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 101 | |
| 102 | #define I40E_MAX_VF_COUNT 128 |
| 103 | static int debug = -1; |
| 104 | module_param(debug, int, 0); |
| 105 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 106 | |
| 107 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 108 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 109 | MODULE_LICENSE("GPL"); |
| 110 | MODULE_VERSION(DRV_VERSION); |
| 111 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 112 | static struct workqueue_struct *i40e_wq; |
| 113 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 114 | /** |
| 115 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 116 | * @hw: pointer to the HW structure |
| 117 | * @mem: ptr to mem struct to fill out |
| 118 | * @size: size of memory requested |
| 119 | * @alignment: what to align the allocation to |
| 120 | **/ |
| 121 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 122 | u64 size, u32 alignment) |
| 123 | { |
| 124 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 125 | |
| 126 | mem->size = ALIGN(size, alignment); |
| 127 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 128 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 129 | if (!mem->va) |
| 130 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 131 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 132 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /** |
| 136 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 137 | * @hw: pointer to the HW structure |
| 138 | * @mem: ptr to mem struct to free |
| 139 | **/ |
| 140 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 141 | { |
| 142 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 143 | |
| 144 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 145 | mem->va = NULL; |
| 146 | mem->pa = 0; |
| 147 | mem->size = 0; |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 154 | * @hw: pointer to the HW structure |
| 155 | * @mem: ptr to mem struct to fill out |
| 156 | * @size: size of memory requested |
| 157 | **/ |
| 158 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 159 | u32 size) |
| 160 | { |
| 161 | mem->size = size; |
| 162 | mem->va = kzalloc(size, GFP_KERNEL); |
| 163 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 164 | if (!mem->va) |
| 165 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 166 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 167 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /** |
| 171 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 172 | * @hw: pointer to the HW structure |
| 173 | * @mem: ptr to mem struct to free |
| 174 | **/ |
| 175 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 176 | { |
| 177 | /* it's ok to kfree a NULL pointer */ |
| 178 | kfree(mem->va); |
| 179 | mem->va = NULL; |
| 180 | mem->size = 0; |
| 181 | |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * i40e_get_lump - find a lump of free generic resource |
| 187 | * @pf: board private structure |
| 188 | * @pile: the pile of resource to search |
| 189 | * @needed: the number of items needed |
| 190 | * @id: an owner id to stick on the items assigned |
| 191 | * |
| 192 | * Returns the base item index of the lump, or negative for error |
| 193 | * |
| 194 | * The search_hint trick and lack of advanced fit-finding only work |
| 195 | * because we're highly likely to have all the same size lump requests. |
| 196 | * Linear search time and any fragmentation should be minimal. |
| 197 | **/ |
| 198 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 199 | u16 needed, u16 id) |
| 200 | { |
| 201 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 202 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 203 | |
| 204 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 205 | dev_info(&pf->pdev->dev, |
| 206 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 207 | pile, needed, id); |
| 208 | return -EINVAL; |
| 209 | } |
| 210 | |
| 211 | /* start the linear search with an imperfect hint */ |
| 212 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 213 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 214 | /* skip already allocated entries */ |
| 215 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 216 | i++; |
| 217 | continue; |
| 218 | } |
| 219 | |
| 220 | /* do we have enough in this lump? */ |
| 221 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 222 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 223 | break; |
| 224 | } |
| 225 | |
| 226 | if (j == needed) { |
| 227 | /* there was enough, so assign it to the requestor */ |
| 228 | for (j = 0; j < needed; j++) |
| 229 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 230 | ret = i; |
| 231 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 232 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 233 | } |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 234 | |
| 235 | /* not enough, so skip over it and continue looking */ |
| 236 | i += j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | return ret; |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * i40e_put_lump - return a lump of generic resource |
| 244 | * @pile: the pile of resource to search |
| 245 | * @index: the base item index |
| 246 | * @id: the owner id of the items assigned |
| 247 | * |
| 248 | * Returns the count of items in the lump |
| 249 | **/ |
| 250 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 251 | { |
| 252 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 253 | int count = 0; |
| 254 | int i; |
| 255 | |
| 256 | if (!pile || index >= pile->num_entries) |
| 257 | return -EINVAL; |
| 258 | |
| 259 | for (i = index; |
| 260 | i < pile->num_entries && pile->list[i] == valid_id; |
| 261 | i++) { |
| 262 | pile->list[i] = 0; |
| 263 | count++; |
| 264 | } |
| 265 | |
| 266 | if (count && index < pile->search_hint) |
| 267 | pile->search_hint = index; |
| 268 | |
| 269 | return count; |
| 270 | } |
| 271 | |
| 272 | /** |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 273 | * i40e_find_vsi_from_id - searches for the vsi with the given id |
| 274 | * @pf - the pf structure to search for the vsi |
| 275 | * @id - id of the vsi it is searching for |
| 276 | **/ |
| 277 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) |
| 278 | { |
| 279 | int i; |
| 280 | |
| 281 | for (i = 0; i < pf->num_alloc_vsi; i++) |
| 282 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) |
| 283 | return pf->vsi[i]; |
| 284 | |
| 285 | return NULL; |
| 286 | } |
| 287 | |
| 288 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 289 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 290 | * @pf: board private structure |
| 291 | * |
| 292 | * If not already scheduled, this puts the task into the work queue |
| 293 | **/ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 294 | void i40e_service_event_schedule(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 295 | { |
| 296 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 297 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && |
| 298 | !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 299 | queue_work(i40e_wq, &pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /** |
| 303 | * i40e_tx_timeout - Respond to a Tx Hang |
| 304 | * @netdev: network interface device structure |
| 305 | * |
| 306 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 307 | * device is munged, not just the one netdev port, so go for the full |
| 308 | * reset. |
| 309 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 310 | #ifdef I40E_FCOE |
| 311 | void i40e_tx_timeout(struct net_device *netdev) |
| 312 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 313 | static void i40e_tx_timeout(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 314 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 315 | { |
| 316 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 317 | struct i40e_vsi *vsi = np->vsi; |
| 318 | struct i40e_pf *pf = vsi->back; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 319 | struct i40e_ring *tx_ring = NULL; |
| 320 | unsigned int i, hung_queue = 0; |
| 321 | u32 head, val; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 322 | |
| 323 | pf->tx_timeout_count++; |
| 324 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 325 | /* find the stopped queue the same way the stack does */ |
| 326 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 327 | struct netdev_queue *q; |
| 328 | unsigned long trans_start; |
| 329 | |
| 330 | q = netdev_get_tx_queue(netdev, i); |
| 331 | trans_start = q->trans_start ? : netdev->trans_start; |
| 332 | if (netif_xmit_stopped(q) && |
| 333 | time_after(jiffies, |
| 334 | (trans_start + netdev->watchdog_timeo))) { |
| 335 | hung_queue = i; |
| 336 | break; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | if (i == netdev->num_tx_queues) { |
| 341 | netdev_info(netdev, "tx_timeout: no netdev hung queue found\n"); |
| 342 | } else { |
| 343 | /* now that we have an index, find the tx_ring struct */ |
| 344 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 345 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 346 | if (hung_queue == |
| 347 | vsi->tx_rings[i]->queue_index) { |
| 348 | tx_ring = vsi->tx_rings[i]; |
| 349 | break; |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 355 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 356 | pf->tx_timeout_recovery_level = 1; /* reset after some time */ |
| 357 | else if (time_before(jiffies, |
| 358 | (pf->tx_timeout_last_recovery + netdev->watchdog_timeo))) |
| 359 | return; /* don't do any new action before the next timeout */ |
| 360 | |
| 361 | if (tx_ring) { |
| 362 | head = i40e_get_head(tx_ring); |
| 363 | /* Read interrupt register */ |
| 364 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 365 | val = rd32(&pf->hw, |
| 366 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 367 | tx_ring->vsi->base_vector - 1)); |
| 368 | else |
| 369 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 370 | |
| 371 | 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", |
| 372 | vsi->seid, hung_queue, tx_ring->next_to_clean, |
| 373 | head, tx_ring->next_to_use, |
| 374 | readl(tx_ring->tail), val); |
| 375 | } |
| 376 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 377 | pf->tx_timeout_last_recovery = jiffies; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 378 | netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n", |
| 379 | pf->tx_timeout_recovery_level, hung_queue); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 380 | |
| 381 | switch (pf->tx_timeout_recovery_level) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 382 | case 1: |
| 383 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 384 | break; |
| 385 | case 2: |
| 386 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 387 | break; |
| 388 | case 3: |
| 389 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 390 | break; |
| 391 | default: |
| 392 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 393 | break; |
| 394 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 395 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 396 | i40e_service_event_schedule(pf); |
| 397 | pf->tx_timeout_recovery_level++; |
| 398 | } |
| 399 | |
| 400 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 401 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 402 | * @vsi: the VSI we care about |
| 403 | * |
| 404 | * Returns the address of the device statistics structure. |
| 405 | * The statistics are actually updated from the service task. |
| 406 | **/ |
| 407 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 408 | { |
| 409 | return &vsi->net_stats; |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 414 | * @netdev: network interface device structure |
| 415 | * |
| 416 | * Returns the address of the device statistics structure. |
| 417 | * The statistics are actually updated from the service task. |
| 418 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 419 | #ifdef I40E_FCOE |
| 420 | struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 421 | struct net_device *netdev, |
| 422 | struct rtnl_link_stats64 *stats) |
| 423 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 424 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 425 | struct net_device *netdev, |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 426 | struct rtnl_link_stats64 *stats) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 427 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 428 | { |
| 429 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 430 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 431 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 432 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 433 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 434 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 435 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 436 | return stats; |
| 437 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 438 | if (!vsi->tx_rings) |
| 439 | return stats; |
| 440 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 441 | rcu_read_lock(); |
| 442 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 443 | u64 bytes, packets; |
| 444 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 445 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 446 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 447 | if (!tx_ring) |
| 448 | continue; |
| 449 | |
| 450 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 451 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 452 | packets = tx_ring->stats.packets; |
| 453 | bytes = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 454 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 455 | |
| 456 | stats->tx_packets += packets; |
| 457 | stats->tx_bytes += bytes; |
| 458 | rx_ring = &tx_ring[1]; |
| 459 | |
| 460 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 461 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 462 | packets = rx_ring->stats.packets; |
| 463 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 464 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 465 | |
| 466 | stats->rx_packets += packets; |
| 467 | stats->rx_bytes += bytes; |
| 468 | } |
| 469 | rcu_read_unlock(); |
| 470 | |
Akeem G Abodunrin | a5282f4 | 2014-05-10 04:49:03 +0000 | [diff] [blame] | 471 | /* following stats updated by i40e_watchdog_subtask() */ |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 472 | stats->multicast = vsi_stats->multicast; |
| 473 | stats->tx_errors = vsi_stats->tx_errors; |
| 474 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 475 | stats->rx_errors = vsi_stats->rx_errors; |
Jesse Brandeburg | d8201e2 | 2015-07-23 16:54:35 -0400 | [diff] [blame] | 476 | stats->rx_dropped = vsi_stats->rx_dropped; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 477 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 478 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
| 479 | |
| 480 | return stats; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | /** |
| 484 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 485 | * @vsi: the VSI to have its stats reset |
| 486 | **/ |
| 487 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 488 | { |
| 489 | struct rtnl_link_stats64 *ns; |
| 490 | int i; |
| 491 | |
| 492 | if (!vsi) |
| 493 | return; |
| 494 | |
| 495 | ns = i40e_get_vsi_stats_struct(vsi); |
| 496 | memset(ns, 0, sizeof(*ns)); |
| 497 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 498 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 499 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 500 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 501 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 502 | memset(&vsi->rx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 503 | sizeof(vsi->rx_rings[i]->stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 504 | memset(&vsi->rx_rings[i]->rx_stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 505 | sizeof(vsi->rx_rings[i]->rx_stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 506 | memset(&vsi->tx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 507 | sizeof(vsi->tx_rings[i]->stats)); |
| 508 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 509 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 510 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 511 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 512 | vsi->stat_offsets_loaded = false; |
| 513 | } |
| 514 | |
| 515 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 516 | * 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] | 517 | * @pf: the PF to be reset |
| 518 | **/ |
| 519 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 520 | { |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 521 | int i; |
| 522 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 523 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 524 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 525 | pf->stat_offsets_loaded = false; |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 526 | |
| 527 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 528 | if (pf->veb[i]) { |
| 529 | memset(&pf->veb[i]->stats, 0, |
| 530 | sizeof(pf->veb[i]->stats)); |
| 531 | memset(&pf->veb[i]->stats_offsets, 0, |
| 532 | sizeof(pf->veb[i]->stats_offsets)); |
| 533 | pf->veb[i]->stat_offsets_loaded = false; |
| 534 | } |
| 535 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | /** |
| 539 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 540 | * @hw: ptr to the hardware info |
| 541 | * @hireg: the high 32 bit reg to read |
| 542 | * @loreg: the low 32 bit reg to read |
| 543 | * @offset_loaded: has the initial offset been loaded yet |
| 544 | * @offset: ptr to current offset value |
| 545 | * @stat: ptr to the stat |
| 546 | * |
| 547 | * Since the device stats are not reset at PFReset, they likely will not |
| 548 | * be zeroed when the driver starts. We'll save the first values read |
| 549 | * and use them as offsets to be subtracted from the raw values in order |
| 550 | * to report stats that count from zero. In the process, we also manage |
| 551 | * the potential roll-over. |
| 552 | **/ |
| 553 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 554 | bool offset_loaded, u64 *offset, u64 *stat) |
| 555 | { |
| 556 | u64 new_data; |
| 557 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 558 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 559 | new_data = rd32(hw, loreg); |
| 560 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 561 | } else { |
| 562 | new_data = rd64(hw, loreg); |
| 563 | } |
| 564 | if (!offset_loaded) |
| 565 | *offset = new_data; |
| 566 | if (likely(new_data >= *offset)) |
| 567 | *stat = new_data - *offset; |
| 568 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 569 | *stat = (new_data + BIT_ULL(48)) - *offset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 570 | *stat &= 0xFFFFFFFFFFFFULL; |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 575 | * @hw: ptr to the hardware info |
| 576 | * @reg: the hw reg to read |
| 577 | * @offset_loaded: has the initial offset been loaded yet |
| 578 | * @offset: ptr to current offset value |
| 579 | * @stat: ptr to the stat |
| 580 | **/ |
| 581 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 582 | bool offset_loaded, u64 *offset, u64 *stat) |
| 583 | { |
| 584 | u32 new_data; |
| 585 | |
| 586 | new_data = rd32(hw, reg); |
| 587 | if (!offset_loaded) |
| 588 | *offset = new_data; |
| 589 | if (likely(new_data >= *offset)) |
| 590 | *stat = (u32)(new_data - *offset); |
| 591 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 592 | *stat = (u32)((new_data + BIT_ULL(32)) - *offset); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | /** |
| 596 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 597 | * @vsi: the VSI to be updated |
| 598 | **/ |
| 599 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 600 | { |
| 601 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 602 | struct i40e_pf *pf = vsi->back; |
| 603 | struct i40e_hw *hw = &pf->hw; |
| 604 | struct i40e_eth_stats *oes; |
| 605 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 606 | |
| 607 | es = &vsi->eth_stats; |
| 608 | oes = &vsi->eth_stats_offsets; |
| 609 | |
| 610 | /* Gather up the stats that the hw collects */ |
| 611 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 612 | vsi->stat_offsets_loaded, |
| 613 | &oes->tx_errors, &es->tx_errors); |
| 614 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 615 | vsi->stat_offsets_loaded, |
| 616 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 617 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 618 | vsi->stat_offsets_loaded, |
| 619 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 620 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 621 | vsi->stat_offsets_loaded, |
| 622 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 623 | |
| 624 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 625 | I40E_GLV_GORCL(stat_idx), |
| 626 | vsi->stat_offsets_loaded, |
| 627 | &oes->rx_bytes, &es->rx_bytes); |
| 628 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 629 | I40E_GLV_UPRCL(stat_idx), |
| 630 | vsi->stat_offsets_loaded, |
| 631 | &oes->rx_unicast, &es->rx_unicast); |
| 632 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 633 | I40E_GLV_MPRCL(stat_idx), |
| 634 | vsi->stat_offsets_loaded, |
| 635 | &oes->rx_multicast, &es->rx_multicast); |
| 636 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 637 | I40E_GLV_BPRCL(stat_idx), |
| 638 | vsi->stat_offsets_loaded, |
| 639 | &oes->rx_broadcast, &es->rx_broadcast); |
| 640 | |
| 641 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 642 | I40E_GLV_GOTCL(stat_idx), |
| 643 | vsi->stat_offsets_loaded, |
| 644 | &oes->tx_bytes, &es->tx_bytes); |
| 645 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 646 | I40E_GLV_UPTCL(stat_idx), |
| 647 | vsi->stat_offsets_loaded, |
| 648 | &oes->tx_unicast, &es->tx_unicast); |
| 649 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 650 | I40E_GLV_MPTCL(stat_idx), |
| 651 | vsi->stat_offsets_loaded, |
| 652 | &oes->tx_multicast, &es->tx_multicast); |
| 653 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 654 | I40E_GLV_BPTCL(stat_idx), |
| 655 | vsi->stat_offsets_loaded, |
| 656 | &oes->tx_broadcast, &es->tx_broadcast); |
| 657 | vsi->stat_offsets_loaded = true; |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * i40e_update_veb_stats - Update Switch component statistics |
| 662 | * @veb: the VEB being updated |
| 663 | **/ |
| 664 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 665 | { |
| 666 | struct i40e_pf *pf = veb->pf; |
| 667 | struct i40e_hw *hw = &pf->hw; |
| 668 | struct i40e_eth_stats *oes; |
| 669 | struct i40e_eth_stats *es; /* device's eth stats */ |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 670 | struct i40e_veb_tc_stats *veb_oes; |
| 671 | struct i40e_veb_tc_stats *veb_es; |
| 672 | int i, idx = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 673 | |
| 674 | idx = veb->stats_idx; |
| 675 | es = &veb->stats; |
| 676 | oes = &veb->stats_offsets; |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 677 | veb_es = &veb->tc_stats; |
| 678 | veb_oes = &veb->tc_stats_offsets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 679 | |
| 680 | /* Gather up the stats that the hw collects */ |
| 681 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 682 | veb->stat_offsets_loaded, |
| 683 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 684 | if (hw->revision_id > 0) |
| 685 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 686 | veb->stat_offsets_loaded, |
| 687 | &oes->rx_unknown_protocol, |
| 688 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 689 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 690 | veb->stat_offsets_loaded, |
| 691 | &oes->rx_bytes, &es->rx_bytes); |
| 692 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 693 | veb->stat_offsets_loaded, |
| 694 | &oes->rx_unicast, &es->rx_unicast); |
| 695 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 696 | veb->stat_offsets_loaded, |
| 697 | &oes->rx_multicast, &es->rx_multicast); |
| 698 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 699 | veb->stat_offsets_loaded, |
| 700 | &oes->rx_broadcast, &es->rx_broadcast); |
| 701 | |
| 702 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 703 | veb->stat_offsets_loaded, |
| 704 | &oes->tx_bytes, &es->tx_bytes); |
| 705 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 706 | veb->stat_offsets_loaded, |
| 707 | &oes->tx_unicast, &es->tx_unicast); |
| 708 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 709 | veb->stat_offsets_loaded, |
| 710 | &oes->tx_multicast, &es->tx_multicast); |
| 711 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 712 | veb->stat_offsets_loaded, |
| 713 | &oes->tx_broadcast, &es->tx_broadcast); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 714 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 715 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), |
| 716 | I40E_GLVEBTC_RPCL(i, idx), |
| 717 | veb->stat_offsets_loaded, |
| 718 | &veb_oes->tc_rx_packets[i], |
| 719 | &veb_es->tc_rx_packets[i]); |
| 720 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), |
| 721 | I40E_GLVEBTC_RBCL(i, idx), |
| 722 | veb->stat_offsets_loaded, |
| 723 | &veb_oes->tc_rx_bytes[i], |
| 724 | &veb_es->tc_rx_bytes[i]); |
| 725 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), |
| 726 | I40E_GLVEBTC_TPCL(i, idx), |
| 727 | veb->stat_offsets_loaded, |
| 728 | &veb_oes->tc_tx_packets[i], |
| 729 | &veb_es->tc_tx_packets[i]); |
| 730 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), |
| 731 | I40E_GLVEBTC_TBCL(i, idx), |
| 732 | veb->stat_offsets_loaded, |
| 733 | &veb_oes->tc_tx_bytes[i], |
| 734 | &veb_es->tc_tx_bytes[i]); |
| 735 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 736 | veb->stat_offsets_loaded = true; |
| 737 | } |
| 738 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 739 | #ifdef I40E_FCOE |
| 740 | /** |
| 741 | * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters. |
| 742 | * @vsi: the VSI that is capable of doing FCoE |
| 743 | **/ |
| 744 | static void i40e_update_fcoe_stats(struct i40e_vsi *vsi) |
| 745 | { |
| 746 | struct i40e_pf *pf = vsi->back; |
| 747 | struct i40e_hw *hw = &pf->hw; |
| 748 | struct i40e_fcoe_stats *ofs; |
| 749 | struct i40e_fcoe_stats *fs; /* device's eth stats */ |
| 750 | int idx; |
| 751 | |
| 752 | if (vsi->type != I40E_VSI_FCOE) |
| 753 | return; |
| 754 | |
Kiran Patil | 4147e2c | 2016-01-15 14:33:14 -0800 | [diff] [blame] | 755 | idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 756 | fs = &vsi->fcoe_stats; |
| 757 | ofs = &vsi->fcoe_stats_offsets; |
| 758 | |
| 759 | i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx), |
| 760 | vsi->fcoe_stat_offsets_loaded, |
| 761 | &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets); |
| 762 | i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx), |
| 763 | vsi->fcoe_stat_offsets_loaded, |
| 764 | &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords); |
| 765 | i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx), |
| 766 | vsi->fcoe_stat_offsets_loaded, |
| 767 | &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped); |
| 768 | i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx), |
| 769 | vsi->fcoe_stat_offsets_loaded, |
| 770 | &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets); |
| 771 | i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx), |
| 772 | vsi->fcoe_stat_offsets_loaded, |
| 773 | &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords); |
| 774 | i40e_stat_update32(hw, I40E_GL_FCOECRC(idx), |
| 775 | vsi->fcoe_stat_offsets_loaded, |
| 776 | &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc); |
| 777 | i40e_stat_update32(hw, I40E_GL_FCOELAST(idx), |
| 778 | vsi->fcoe_stat_offsets_loaded, |
| 779 | &ofs->fcoe_last_error, &fs->fcoe_last_error); |
| 780 | i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx), |
| 781 | vsi->fcoe_stat_offsets_loaded, |
| 782 | &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count); |
| 783 | |
| 784 | vsi->fcoe_stat_offsets_loaded = true; |
| 785 | } |
| 786 | |
| 787 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 788 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 789 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 790 | * @vsi: the VSI to be updated |
| 791 | * |
| 792 | * There are a few instances where we store the same stat in a |
| 793 | * couple of different structs. This is partly because we have |
| 794 | * the netdev stats that need to be filled out, which is slightly |
| 795 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 796 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 797 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 798 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 799 | { |
| 800 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 801 | struct rtnl_link_stats64 *ons; |
| 802 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 803 | struct i40e_eth_stats *oes; |
| 804 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 805 | u32 tx_restart, tx_busy; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 806 | u64 tx_lost_interrupt; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 807 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 808 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 809 | u64 bytes, packets; |
| 810 | unsigned int start; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 811 | u64 tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 812 | u64 tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 813 | u64 rx_p, rx_b; |
| 814 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 815 | u16 q; |
| 816 | |
| 817 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 818 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 819 | return; |
| 820 | |
| 821 | ns = i40e_get_vsi_stats_struct(vsi); |
| 822 | ons = &vsi->net_stats_offsets; |
| 823 | es = &vsi->eth_stats; |
| 824 | oes = &vsi->eth_stats_offsets; |
| 825 | |
| 826 | /* Gather up the netdev and vsi stats that the driver collects |
| 827 | * on the fly during packet processing |
| 828 | */ |
| 829 | rx_b = rx_p = 0; |
| 830 | tx_b = tx_p = 0; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 831 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 832 | tx_lost_interrupt = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 833 | rx_page = 0; |
| 834 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 835 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 836 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 837 | /* locate Tx ring */ |
| 838 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 839 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 840 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 841 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 842 | packets = p->stats.packets; |
| 843 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 844 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 845 | tx_b += bytes; |
| 846 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 847 | tx_restart += p->tx_stats.restart_queue; |
| 848 | tx_busy += p->tx_stats.tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 849 | tx_linearize += p->tx_stats.tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 850 | tx_force_wb += p->tx_stats.tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 851 | tx_lost_interrupt += p->tx_stats.tx_lost_interrupt; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 852 | |
| 853 | /* Rx queue is part of the same block as Tx queue */ |
| 854 | p = &p[1]; |
| 855 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 856 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 857 | packets = p->stats.packets; |
| 858 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 859 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 860 | rx_b += bytes; |
| 861 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 862 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 863 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 864 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 865 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 866 | vsi->tx_restart = tx_restart; |
| 867 | vsi->tx_busy = tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 868 | vsi->tx_linearize = tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 869 | vsi->tx_force_wb = tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 870 | vsi->tx_lost_interrupt = tx_lost_interrupt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 871 | vsi->rx_page_failed = rx_page; |
| 872 | vsi->rx_buf_failed = rx_buf; |
| 873 | |
| 874 | ns->rx_packets = rx_p; |
| 875 | ns->rx_bytes = rx_b; |
| 876 | ns->tx_packets = tx_p; |
| 877 | ns->tx_bytes = tx_b; |
| 878 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 879 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 880 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 881 | ons->tx_errors = oes->tx_errors; |
| 882 | ns->tx_errors = es->tx_errors; |
| 883 | ons->multicast = oes->rx_multicast; |
| 884 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 885 | ons->rx_dropped = oes->rx_discards; |
| 886 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 887 | ons->tx_dropped = oes->tx_discards; |
| 888 | ns->tx_dropped = es->tx_discards; |
| 889 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 890 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 891 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 892 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 893 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 894 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 895 | } |
| 896 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 897 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 898 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 899 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 900 | * @pf: the PF to be updated |
| 901 | **/ |
| 902 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 903 | { |
| 904 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 905 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 906 | struct i40e_hw *hw = &pf->hw; |
| 907 | u32 val; |
| 908 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 909 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 910 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 911 | I40E_GLPRT_GORCL(hw->port), |
| 912 | pf->stat_offsets_loaded, |
| 913 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 914 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 915 | I40E_GLPRT_GOTCL(hw->port), |
| 916 | pf->stat_offsets_loaded, |
| 917 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 918 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 919 | pf->stat_offsets_loaded, |
| 920 | &osd->eth.rx_discards, |
| 921 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 922 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 923 | I40E_GLPRT_UPRCL(hw->port), |
| 924 | pf->stat_offsets_loaded, |
| 925 | &osd->eth.rx_unicast, |
| 926 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 927 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 928 | I40E_GLPRT_MPRCL(hw->port), |
| 929 | pf->stat_offsets_loaded, |
| 930 | &osd->eth.rx_multicast, |
| 931 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 932 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 933 | I40E_GLPRT_BPRCL(hw->port), |
| 934 | pf->stat_offsets_loaded, |
| 935 | &osd->eth.rx_broadcast, |
| 936 | &nsd->eth.rx_broadcast); |
| 937 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 938 | I40E_GLPRT_UPTCL(hw->port), |
| 939 | pf->stat_offsets_loaded, |
| 940 | &osd->eth.tx_unicast, |
| 941 | &nsd->eth.tx_unicast); |
| 942 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 943 | I40E_GLPRT_MPTCL(hw->port), |
| 944 | pf->stat_offsets_loaded, |
| 945 | &osd->eth.tx_multicast, |
| 946 | &nsd->eth.tx_multicast); |
| 947 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 948 | I40E_GLPRT_BPTCL(hw->port), |
| 949 | pf->stat_offsets_loaded, |
| 950 | &osd->eth.tx_broadcast, |
| 951 | &nsd->eth.tx_broadcast); |
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_TDOLD(hw->port), |
| 954 | pf->stat_offsets_loaded, |
| 955 | &osd->tx_dropped_link_down, |
| 956 | &nsd->tx_dropped_link_down); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 957 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 958 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 959 | pf->stat_offsets_loaded, |
| 960 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 961 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 962 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 963 | pf->stat_offsets_loaded, |
| 964 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 965 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 966 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 967 | pf->stat_offsets_loaded, |
| 968 | &osd->mac_local_faults, |
| 969 | &nsd->mac_local_faults); |
| 970 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 971 | pf->stat_offsets_loaded, |
| 972 | &osd->mac_remote_faults, |
| 973 | &nsd->mac_remote_faults); |
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_RLEC(hw->port), |
| 976 | pf->stat_offsets_loaded, |
| 977 | &osd->rx_length_errors, |
| 978 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 979 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 980 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 981 | pf->stat_offsets_loaded, |
| 982 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 983 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 984 | pf->stat_offsets_loaded, |
| 985 | &osd->link_xon_tx, &nsd->link_xon_tx); |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 986 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 987 | pf->stat_offsets_loaded, |
| 988 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 989 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 990 | pf->stat_offsets_loaded, |
| 991 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 992 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 993 | for (i = 0; i < 8; i++) { |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 994 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 995 | pf->stat_offsets_loaded, |
| 996 | &osd->priority_xoff_rx[i], |
| 997 | &nsd->priority_xoff_rx[i]); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 998 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 999 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1000 | &osd->priority_xon_rx[i], |
| 1001 | &nsd->priority_xon_rx[i]); |
| 1002 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1003 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1004 | &osd->priority_xon_tx[i], |
| 1005 | &nsd->priority_xon_tx[i]); |
| 1006 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(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_xoff_tx[i], |
| 1009 | &nsd->priority_xoff_tx[i]); |
| 1010 | i40e_stat_update32(hw, |
| 1011 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1012 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1013 | &osd->priority_xon_2_xoff[i], |
| 1014 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1017 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 1018 | I40E_GLPRT_PRC64L(hw->port), |
| 1019 | pf->stat_offsets_loaded, |
| 1020 | &osd->rx_size_64, &nsd->rx_size_64); |
| 1021 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 1022 | I40E_GLPRT_PRC127L(hw->port), |
| 1023 | pf->stat_offsets_loaded, |
| 1024 | &osd->rx_size_127, &nsd->rx_size_127); |
| 1025 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 1026 | I40E_GLPRT_PRC255L(hw->port), |
| 1027 | pf->stat_offsets_loaded, |
| 1028 | &osd->rx_size_255, &nsd->rx_size_255); |
| 1029 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 1030 | I40E_GLPRT_PRC511L(hw->port), |
| 1031 | pf->stat_offsets_loaded, |
| 1032 | &osd->rx_size_511, &nsd->rx_size_511); |
| 1033 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 1034 | I40E_GLPRT_PRC1023L(hw->port), |
| 1035 | pf->stat_offsets_loaded, |
| 1036 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 1037 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 1038 | I40E_GLPRT_PRC1522L(hw->port), |
| 1039 | pf->stat_offsets_loaded, |
| 1040 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 1041 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 1042 | I40E_GLPRT_PRC9522L(hw->port), |
| 1043 | pf->stat_offsets_loaded, |
| 1044 | &osd->rx_size_big, &nsd->rx_size_big); |
| 1045 | |
| 1046 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 1047 | I40E_GLPRT_PTC64L(hw->port), |
| 1048 | pf->stat_offsets_loaded, |
| 1049 | &osd->tx_size_64, &nsd->tx_size_64); |
| 1050 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 1051 | I40E_GLPRT_PTC127L(hw->port), |
| 1052 | pf->stat_offsets_loaded, |
| 1053 | &osd->tx_size_127, &nsd->tx_size_127); |
| 1054 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 1055 | I40E_GLPRT_PTC255L(hw->port), |
| 1056 | pf->stat_offsets_loaded, |
| 1057 | &osd->tx_size_255, &nsd->tx_size_255); |
| 1058 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 1059 | I40E_GLPRT_PTC511L(hw->port), |
| 1060 | pf->stat_offsets_loaded, |
| 1061 | &osd->tx_size_511, &nsd->tx_size_511); |
| 1062 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 1063 | I40E_GLPRT_PTC1023L(hw->port), |
| 1064 | pf->stat_offsets_loaded, |
| 1065 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 1066 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 1067 | I40E_GLPRT_PTC1522L(hw->port), |
| 1068 | pf->stat_offsets_loaded, |
| 1069 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1070 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1071 | I40E_GLPRT_PTC9522L(hw->port), |
| 1072 | pf->stat_offsets_loaded, |
| 1073 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1074 | |
| 1075 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1076 | pf->stat_offsets_loaded, |
| 1077 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1078 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1079 | pf->stat_offsets_loaded, |
| 1080 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1081 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1082 | pf->stat_offsets_loaded, |
| 1083 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1084 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1085 | pf->stat_offsets_loaded, |
| 1086 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1087 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1088 | /* FDIR stats */ |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1089 | i40e_stat_update32(hw, |
| 1090 | 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] | 1091 | pf->stat_offsets_loaded, |
| 1092 | &osd->fd_atr_match, &nsd->fd_atr_match); |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1093 | i40e_stat_update32(hw, |
| 1094 | 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] | 1095 | pf->stat_offsets_loaded, |
| 1096 | &osd->fd_sb_match, &nsd->fd_sb_match); |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 1097 | i40e_stat_update32(hw, |
| 1098 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), |
| 1099 | pf->stat_offsets_loaded, |
| 1100 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1101 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1102 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1103 | nsd->tx_lpi_status = |
| 1104 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1105 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1106 | nsd->rx_lpi_status = |
| 1107 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1108 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1109 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1110 | pf->stat_offsets_loaded, |
| 1111 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1112 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1113 | pf->stat_offsets_loaded, |
| 1114 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1115 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1116 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
| 1117 | !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) |
| 1118 | nsd->fd_sb_status = true; |
| 1119 | else |
| 1120 | nsd->fd_sb_status = false; |
| 1121 | |
| 1122 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
| 1123 | !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 1124 | nsd->fd_atr_status = true; |
| 1125 | else |
| 1126 | nsd->fd_atr_status = false; |
| 1127 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1128 | pf->stat_offsets_loaded = true; |
| 1129 | } |
| 1130 | |
| 1131 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1132 | * i40e_update_stats - Update the various statistics counters. |
| 1133 | * @vsi: the VSI to be updated |
| 1134 | * |
| 1135 | * Update the various stats for this VSI and its related entities. |
| 1136 | **/ |
| 1137 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1138 | { |
| 1139 | struct i40e_pf *pf = vsi->back; |
| 1140 | |
| 1141 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1142 | i40e_update_pf_stats(pf); |
| 1143 | |
| 1144 | i40e_update_vsi_stats(vsi); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1145 | #ifdef I40E_FCOE |
| 1146 | i40e_update_fcoe_stats(vsi); |
| 1147 | #endif |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1151 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1152 | * @vsi: the VSI to be searched |
| 1153 | * @macaddr: the MAC address |
| 1154 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1155 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1156 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1157 | * |
| 1158 | * Returns ptr to the filter object or NULL |
| 1159 | **/ |
| 1160 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
| 1161 | u8 *macaddr, s16 vlan, |
| 1162 | bool is_vf, bool is_netdev) |
| 1163 | { |
| 1164 | struct i40e_mac_filter *f; |
| 1165 | |
| 1166 | if (!vsi || !macaddr) |
| 1167 | return NULL; |
| 1168 | |
| 1169 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1170 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1171 | (vlan == f->vlan) && |
| 1172 | (!is_vf || f->is_vf) && |
| 1173 | (!is_netdev || f->is_netdev)) |
| 1174 | return f; |
| 1175 | } |
| 1176 | return NULL; |
| 1177 | } |
| 1178 | |
| 1179 | /** |
| 1180 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1181 | * @vsi: the VSI to be searched |
| 1182 | * @macaddr: the MAC address we are searching for |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1183 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1184 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1185 | * |
| 1186 | * Returns the first filter with the provided MAC address or NULL if |
| 1187 | * MAC address was not found |
| 1188 | **/ |
| 1189 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr, |
| 1190 | bool is_vf, bool is_netdev) |
| 1191 | { |
| 1192 | struct i40e_mac_filter *f; |
| 1193 | |
| 1194 | if (!vsi || !macaddr) |
| 1195 | return NULL; |
| 1196 | |
| 1197 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1198 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1199 | (!is_vf || f->is_vf) && |
| 1200 | (!is_netdev || f->is_netdev)) |
| 1201 | return f; |
| 1202 | } |
| 1203 | return NULL; |
| 1204 | } |
| 1205 | |
| 1206 | /** |
| 1207 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1208 | * @vsi: the VSI to be searched |
| 1209 | * |
| 1210 | * Returns true if VSI is in vlan mode or false otherwise |
| 1211 | **/ |
| 1212 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1213 | { |
| 1214 | struct i40e_mac_filter *f; |
| 1215 | |
| 1216 | /* Only -1 for all the filters denotes not in vlan mode |
| 1217 | * so we have to go through all the list in order to make sure |
| 1218 | */ |
| 1219 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Greg Rose | d9b68f8 | 2015-07-23 16:54:31 -0400 | [diff] [blame] | 1220 | if (f->vlan >= 0 || vsi->info.pvid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1221 | return true; |
| 1222 | } |
| 1223 | |
| 1224 | return false; |
| 1225 | } |
| 1226 | |
| 1227 | /** |
| 1228 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1229 | * @vsi: the VSI to be searched |
| 1230 | * @macaddr: the mac address to be filtered |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1231 | * @is_vf: true if it is a VF |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1232 | * @is_netdev: true if it is a netdev |
| 1233 | * |
| 1234 | * Goes through all the macvlan filters and adds a |
| 1235 | * macvlan filter for each unique vlan that already exists |
| 1236 | * |
| 1237 | * Returns first filter found on success, else NULL |
| 1238 | **/ |
| 1239 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1240 | bool is_vf, bool is_netdev) |
| 1241 | { |
| 1242 | struct i40e_mac_filter *f; |
| 1243 | |
| 1244 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Mitch Williams | ecbb44e | 2015-07-10 19:35:56 -0400 | [diff] [blame] | 1245 | if (vsi->info.pvid) |
| 1246 | f->vlan = le16_to_cpu(vsi->info.pvid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1247 | if (!i40e_find_filter(vsi, macaddr, f->vlan, |
| 1248 | is_vf, is_netdev)) { |
| 1249 | if (!i40e_add_filter(vsi, macaddr, f->vlan, |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 1250 | is_vf, is_netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1251 | return NULL; |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | return list_first_entry_or_null(&vsi->mac_filter_list, |
| 1256 | struct i40e_mac_filter, list); |
| 1257 | } |
| 1258 | |
| 1259 | /** |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1260 | * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS |
| 1261 | * @vsi: the VSI to be searched |
| 1262 | * @macaddr: the mac address to be removed |
| 1263 | * @is_vf: true if it is a VF |
| 1264 | * @is_netdev: true if it is a netdev |
| 1265 | * |
| 1266 | * Removes a given MAC address from a VSI, regardless of VLAN |
| 1267 | * |
| 1268 | * Returns 0 for success, or error |
| 1269 | **/ |
| 1270 | int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1271 | bool is_vf, bool is_netdev) |
| 1272 | { |
| 1273 | struct i40e_mac_filter *f = NULL; |
| 1274 | int changed = 0; |
| 1275 | |
| 1276 | WARN(!spin_is_locked(&vsi->mac_filter_list_lock), |
| 1277 | "Missing mac_filter_list_lock\n"); |
| 1278 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1279 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1280 | (is_vf == f->is_vf) && |
| 1281 | (is_netdev == f->is_netdev)) { |
| 1282 | f->counter--; |
| 1283 | f->changed = true; |
| 1284 | changed = 1; |
| 1285 | } |
| 1286 | } |
| 1287 | if (changed) { |
| 1288 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1289 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1290 | return 0; |
| 1291 | } |
| 1292 | return -ENOENT; |
| 1293 | } |
| 1294 | |
| 1295 | /** |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1296 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM |
| 1297 | * @vsi: the PF Main VSI - inappropriate for any other VSI |
| 1298 | * @macaddr: the MAC address |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1299 | * |
| 1300 | * Some older firmware configurations set up a default promiscuous VLAN |
| 1301 | * filter that needs to be removed. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1302 | **/ |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1303 | static int i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr) |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1304 | { |
| 1305 | struct i40e_aqc_remove_macvlan_element_data element; |
| 1306 | struct i40e_pf *pf = vsi->back; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1307 | i40e_status ret; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1308 | |
| 1309 | /* Only appropriate for the PF main VSI */ |
| 1310 | if (vsi->type != I40E_VSI_MAIN) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1311 | return -EINVAL; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1312 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1313 | memset(&element, 0, sizeof(element)); |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1314 | ether_addr_copy(element.mac_addr, macaddr); |
| 1315 | element.vlan_tag = 0; |
| 1316 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | |
| 1317 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1318 | ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1319 | if (ret) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1320 | return -ENOENT; |
| 1321 | |
| 1322 | return 0; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1326 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1327 | * @vsi: the VSI to be searched |
| 1328 | * @macaddr: the MAC address |
| 1329 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1330 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1331 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1332 | * |
| 1333 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1334 | * |
| 1335 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1336 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1337 | **/ |
| 1338 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
| 1339 | u8 *macaddr, s16 vlan, |
| 1340 | bool is_vf, bool is_netdev) |
| 1341 | { |
| 1342 | struct i40e_mac_filter *f; |
| 1343 | |
| 1344 | if (!vsi || !macaddr) |
| 1345 | return NULL; |
| 1346 | |
| 1347 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1348 | if (!f) { |
| 1349 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1350 | if (!f) |
| 1351 | goto add_filter_out; |
| 1352 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1353 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1354 | f->vlan = vlan; |
| 1355 | f->changed = true; |
| 1356 | |
| 1357 | INIT_LIST_HEAD(&f->list); |
Kiran Patil | 04d5a21 | 2015-12-09 15:50:23 -0800 | [diff] [blame] | 1358 | list_add_tail(&f->list, &vsi->mac_filter_list); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | /* increment counter and add a new flag if needed */ |
| 1362 | if (is_vf) { |
| 1363 | if (!f->is_vf) { |
| 1364 | f->is_vf = true; |
| 1365 | f->counter++; |
| 1366 | } |
| 1367 | } else if (is_netdev) { |
| 1368 | if (!f->is_netdev) { |
| 1369 | f->is_netdev = true; |
| 1370 | f->counter++; |
| 1371 | } |
| 1372 | } else { |
| 1373 | f->counter++; |
| 1374 | } |
| 1375 | |
| 1376 | /* changed tells sync_filters_subtask to |
| 1377 | * push the filter down to the firmware |
| 1378 | */ |
| 1379 | if (f->changed) { |
| 1380 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1381 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1382 | } |
| 1383 | |
| 1384 | add_filter_out: |
| 1385 | return f; |
| 1386 | } |
| 1387 | |
| 1388 | /** |
| 1389 | * i40e_del_filter - Remove a mac/vlan filter from the VSI |
| 1390 | * @vsi: the VSI to be searched |
| 1391 | * @macaddr: the MAC address |
| 1392 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1393 | * @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] | 1394 | * @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] | 1395 | * |
| 1396 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1397 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1398 | **/ |
| 1399 | void i40e_del_filter(struct i40e_vsi *vsi, |
| 1400 | u8 *macaddr, s16 vlan, |
| 1401 | bool is_vf, bool is_netdev) |
| 1402 | { |
| 1403 | struct i40e_mac_filter *f; |
| 1404 | |
| 1405 | if (!vsi || !macaddr) |
| 1406 | return; |
| 1407 | |
| 1408 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1409 | if (!f || f->counter == 0) |
| 1410 | return; |
| 1411 | |
| 1412 | if (is_vf) { |
| 1413 | if (f->is_vf) { |
| 1414 | f->is_vf = false; |
| 1415 | f->counter--; |
| 1416 | } |
| 1417 | } else if (is_netdev) { |
| 1418 | if (f->is_netdev) { |
| 1419 | f->is_netdev = false; |
| 1420 | f->counter--; |
| 1421 | } |
| 1422 | } else { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1423 | /* 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] | 1424 | int min_f = 0; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1425 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1426 | min_f += (f->is_vf ? 1 : 0); |
| 1427 | min_f += (f->is_netdev ? 1 : 0); |
| 1428 | |
| 1429 | if (f->counter > min_f) |
| 1430 | f->counter--; |
| 1431 | } |
| 1432 | |
| 1433 | /* counter == 0 tells sync_filters_subtask to |
| 1434 | * remove the filter from the firmware's list |
| 1435 | */ |
| 1436 | if (f->counter == 0) { |
| 1437 | f->changed = true; |
| 1438 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1439 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | /** |
| 1444 | * i40e_set_mac - NDO callback to set mac address |
| 1445 | * @netdev: network interface device structure |
| 1446 | * @p: pointer to an address structure |
| 1447 | * |
| 1448 | * Returns 0 on success, negative on failure |
| 1449 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1450 | #ifdef I40E_FCOE |
| 1451 | int i40e_set_mac(struct net_device *netdev, void *p) |
| 1452 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1453 | static int i40e_set_mac(struct net_device *netdev, void *p) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1454 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1455 | { |
| 1456 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1457 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1458 | struct i40e_pf *pf = vsi->back; |
| 1459 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1460 | struct sockaddr *addr = p; |
| 1461 | struct i40e_mac_filter *f; |
| 1462 | |
| 1463 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1464 | return -EADDRNOTAVAIL; |
| 1465 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1466 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1467 | netdev_info(netdev, "already using mac address %pM\n", |
| 1468 | addr->sa_data); |
| 1469 | return 0; |
| 1470 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1471 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1472 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1473 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1474 | return -EADDRNOTAVAIL; |
| 1475 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1476 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1477 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1478 | hw->mac.addr); |
| 1479 | else |
| 1480 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1481 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1482 | if (vsi->type == I40E_VSI_MAIN) { |
| 1483 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1484 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1485 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1486 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1487 | addr->sa_data, NULL); |
| 1488 | if (ret) { |
| 1489 | netdev_info(netdev, |
| 1490 | "Addr change for Main VSI failed: %d\n", |
| 1491 | ret); |
| 1492 | return -EADDRNOTAVAIL; |
| 1493 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1496 | if (ether_addr_equal(netdev->dev_addr, hw->mac.addr)) { |
| 1497 | struct i40e_aqc_remove_macvlan_element_data element; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1498 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1499 | memset(&element, 0, sizeof(element)); |
| 1500 | ether_addr_copy(element.mac_addr, netdev->dev_addr); |
| 1501 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1502 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1503 | } else { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1504 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1505 | i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 1506 | false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1507 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1510 | if (ether_addr_equal(addr->sa_data, hw->mac.addr)) { |
| 1511 | struct i40e_aqc_add_macvlan_element_data element; |
| 1512 | |
| 1513 | memset(&element, 0, sizeof(element)); |
| 1514 | ether_addr_copy(element.mac_addr, hw->mac.addr); |
| 1515 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 1516 | i40e_aq_add_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1517 | } else { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1518 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1519 | f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, |
| 1520 | false, false); |
| 1521 | if (f) |
| 1522 | f->is_laa = true; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1523 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1526 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1527 | |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1528 | /* schedule our worker thread which will take care of |
| 1529 | * applying the new filter changes |
| 1530 | */ |
| 1531 | i40e_service_event_schedule(vsi->back); |
| 1532 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | /** |
| 1536 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1537 | * @vsi: the VSI being setup |
| 1538 | * @ctxt: VSI context structure |
| 1539 | * @enabled_tc: Enabled TCs bitmap |
| 1540 | * @is_add: True if called before Add VSI |
| 1541 | * |
| 1542 | * Setup VSI queue mapping for enabled traffic classes. |
| 1543 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1544 | #ifdef I40E_FCOE |
| 1545 | void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1546 | struct i40e_vsi_context *ctxt, |
| 1547 | u8 enabled_tc, |
| 1548 | bool is_add) |
| 1549 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1550 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1551 | struct i40e_vsi_context *ctxt, |
| 1552 | u8 enabled_tc, |
| 1553 | bool is_add) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1554 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1555 | { |
| 1556 | struct i40e_pf *pf = vsi->back; |
| 1557 | u16 sections = 0; |
| 1558 | u8 netdev_tc = 0; |
| 1559 | u16 numtc = 0; |
| 1560 | u16 qcount; |
| 1561 | u8 offset; |
| 1562 | u16 qmap; |
| 1563 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1564 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1565 | |
| 1566 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1567 | offset = 0; |
| 1568 | |
| 1569 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1570 | /* Find numtc from enabled TC bitmap */ |
| 1571 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1572 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1573 | numtc++; |
| 1574 | } |
| 1575 | if (!numtc) { |
| 1576 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1577 | numtc = 1; |
| 1578 | } |
| 1579 | } else { |
| 1580 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1581 | numtc = 1; |
| 1582 | } |
| 1583 | |
| 1584 | vsi->tc_config.numtc = numtc; |
| 1585 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1586 | /* Number of queues per enabled TC */ |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1587 | /* In MFP case we can have a much lower count of MSIx |
| 1588 | * vectors available and so we need to lower the used |
| 1589 | * q count. |
| 1590 | */ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1591 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 1592 | qcount = min_t(int, vsi->alloc_queue_pairs, pf->num_lan_msix); |
| 1593 | else |
| 1594 | qcount = vsi->alloc_queue_pairs; |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1595 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1596 | 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] | 1597 | |
| 1598 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1599 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1600 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1601 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1602 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1603 | int pow, num_qps; |
| 1604 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1605 | switch (vsi->type) { |
| 1606 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1607 | qcount = min_t(int, pf->alloc_rss_size, |
| 1608 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1609 | break; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1610 | #ifdef I40E_FCOE |
| 1611 | case I40E_VSI_FCOE: |
| 1612 | qcount = num_tc_qps; |
| 1613 | break; |
| 1614 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1615 | case I40E_VSI_FDIR: |
| 1616 | case I40E_VSI_SRIOV: |
| 1617 | case I40E_VSI_VMDQ2: |
| 1618 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1619 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1620 | WARN_ON(i != 0); |
| 1621 | break; |
| 1622 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1623 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1624 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1625 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1626 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1627 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1628 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1629 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1630 | pow++; |
| 1631 | num_qps >>= 1; |
| 1632 | } |
| 1633 | |
| 1634 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1635 | qmap = |
| 1636 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1637 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1638 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1639 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1640 | } else { |
| 1641 | /* TC is not enabled so set the offset to |
| 1642 | * default queue and allocate one queue |
| 1643 | * for the given TC. |
| 1644 | */ |
| 1645 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1646 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1647 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1648 | |
| 1649 | qmap = 0; |
| 1650 | } |
| 1651 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1652 | } |
| 1653 | |
| 1654 | /* Set actual Tx/Rx queue pairs */ |
| 1655 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1656 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1657 | if (vsi->req_queue_pairs > 0) |
| 1658 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1659 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1660 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1661 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1662 | |
| 1663 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1664 | if (is_add) { |
| 1665 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1666 | |
| 1667 | ctxt->info.up_enable_bits = enabled_tc; |
| 1668 | } |
| 1669 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1670 | ctxt->info.mapping_flags |= |
| 1671 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1672 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1673 | ctxt->info.queue_mapping[i] = |
| 1674 | cpu_to_le16(vsi->base_queue + i); |
| 1675 | } else { |
| 1676 | ctxt->info.mapping_flags |= |
| 1677 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1678 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1679 | } |
| 1680 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1681 | } |
| 1682 | |
| 1683 | /** |
| 1684 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1685 | * @netdev: network interface device structure |
| 1686 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1687 | #ifdef I40E_FCOE |
| 1688 | void i40e_set_rx_mode(struct net_device *netdev) |
| 1689 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1690 | static void i40e_set_rx_mode(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1691 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1692 | { |
| 1693 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1694 | struct i40e_mac_filter *f, *ftmp; |
| 1695 | struct i40e_vsi *vsi = np->vsi; |
| 1696 | struct netdev_hw_addr *uca; |
| 1697 | struct netdev_hw_addr *mca; |
| 1698 | struct netdev_hw_addr *ha; |
| 1699 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1700 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1701 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1702 | /* add addr if not already in the filter list */ |
| 1703 | netdev_for_each_uc_addr(uca, netdev) { |
| 1704 | if (!i40e_find_mac(vsi, uca->addr, false, true)) { |
| 1705 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1706 | i40e_put_mac_in_vlan(vsi, uca->addr, |
| 1707 | false, true); |
| 1708 | else |
| 1709 | i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY, |
| 1710 | false, true); |
| 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | netdev_for_each_mc_addr(mca, netdev) { |
| 1715 | if (!i40e_find_mac(vsi, mca->addr, false, true)) { |
| 1716 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1717 | i40e_put_mac_in_vlan(vsi, mca->addr, |
| 1718 | false, true); |
| 1719 | else |
| 1720 | i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY, |
| 1721 | false, true); |
| 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | /* remove filter if not in netdev list */ |
| 1726 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1727 | |
| 1728 | if (!f->is_netdev) |
| 1729 | continue; |
| 1730 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1731 | netdev_for_each_mc_addr(mca, netdev) |
| 1732 | if (ether_addr_equal(mca->addr, f->macaddr)) |
| 1733 | goto bottom_of_search_loop; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1734 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1735 | netdev_for_each_uc_addr(uca, netdev) |
| 1736 | if (ether_addr_equal(uca->addr, f->macaddr)) |
| 1737 | goto bottom_of_search_loop; |
| 1738 | |
| 1739 | for_each_dev_addr(netdev, ha) |
| 1740 | if (ether_addr_equal(ha->addr, f->macaddr)) |
| 1741 | goto bottom_of_search_loop; |
| 1742 | |
| 1743 | /* f->macaddr wasn't found in uc, mc, or ha list so delete it */ |
| 1744 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true); |
| 1745 | |
| 1746 | bottom_of_search_loop: |
| 1747 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1748 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1749 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1750 | |
| 1751 | /* check for other flag changes */ |
| 1752 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1753 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1754 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1755 | } |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1756 | |
| 1757 | /* schedule our worker thread which will take care of |
| 1758 | * applying the new filter changes |
| 1759 | */ |
| 1760 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | /** |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1764 | * i40e_mac_filter_entry_clone - Clones a MAC filter entry |
| 1765 | * @src: source MAC filter entry to be clones |
| 1766 | * |
| 1767 | * Returns the pointer to newly cloned MAC filter entry or NULL |
| 1768 | * in case of error |
| 1769 | **/ |
| 1770 | static struct i40e_mac_filter *i40e_mac_filter_entry_clone( |
| 1771 | struct i40e_mac_filter *src) |
| 1772 | { |
| 1773 | struct i40e_mac_filter *f; |
| 1774 | |
| 1775 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1776 | if (!f) |
| 1777 | return NULL; |
| 1778 | *f = *src; |
| 1779 | |
| 1780 | INIT_LIST_HEAD(&f->list); |
| 1781 | |
| 1782 | return f; |
| 1783 | } |
| 1784 | |
| 1785 | /** |
| 1786 | * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries |
| 1787 | * @vsi: pointer to vsi struct |
| 1788 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1789 | * those entries needs to be undone. |
| 1790 | * |
| 1791 | * MAC filter entries from list were slated to be removed from device. |
| 1792 | **/ |
| 1793 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1794 | struct list_head *from) |
| 1795 | { |
| 1796 | struct i40e_mac_filter *f, *ftmp; |
| 1797 | |
| 1798 | list_for_each_entry_safe(f, ftmp, from, list) { |
| 1799 | f->changed = true; |
| 1800 | /* Move the element back into MAC filter list*/ |
| 1801 | list_move_tail(&f->list, &vsi->mac_filter_list); |
| 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | /** |
| 1806 | * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries |
| 1807 | * @vsi: pointer to vsi struct |
| 1808 | * |
| 1809 | * MAC filter entries from list were slated to be added from device. |
| 1810 | **/ |
| 1811 | static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi) |
| 1812 | { |
| 1813 | struct i40e_mac_filter *f, *ftmp; |
| 1814 | |
| 1815 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1816 | if (!f->changed && f->counter) |
| 1817 | f->changed = true; |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | /** |
| 1822 | * i40e_cleanup_add_list - Deletes the element from add list and release |
| 1823 | * memory |
| 1824 | * @add_list: Pointer to list which contains MAC filter entries |
| 1825 | **/ |
| 1826 | static void i40e_cleanup_add_list(struct list_head *add_list) |
| 1827 | { |
| 1828 | struct i40e_mac_filter *f, *ftmp; |
| 1829 | |
| 1830 | list_for_each_entry_safe(f, ftmp, add_list, list) { |
| 1831 | list_del(&f->list); |
| 1832 | kfree(f); |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1837 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1838 | * @vsi: ptr to the VSI |
| 1839 | * |
| 1840 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1841 | * |
| 1842 | * Returns 0 or error value |
| 1843 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 1844 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1845 | { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1846 | struct list_head tmp_del_list, tmp_add_list; |
| 1847 | struct i40e_mac_filter *f, *ftmp, *fclone; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1848 | bool promisc_forced_on = false; |
| 1849 | bool add_happened = false; |
| 1850 | int filter_list_len = 0; |
| 1851 | u32 changed_flags = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1852 | i40e_status aq_ret = 0; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1853 | bool err_cond = false; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1854 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1855 | struct i40e_pf *pf; |
| 1856 | int num_add = 0; |
| 1857 | int num_del = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1858 | int aq_err = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1859 | u16 cmd_flags; |
| 1860 | |
| 1861 | /* empty array typed pointers, kcalloc later */ |
| 1862 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1863 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1864 | |
| 1865 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1866 | usleep_range(1000, 2000); |
| 1867 | pf = vsi->back; |
| 1868 | |
| 1869 | if (vsi->netdev) { |
| 1870 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1871 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1872 | } |
| 1873 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1874 | INIT_LIST_HEAD(&tmp_del_list); |
| 1875 | INIT_LIST_HEAD(&tmp_add_list); |
| 1876 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1877 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1878 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1879 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1880 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1881 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1882 | if (!f->changed) |
| 1883 | continue; |
| 1884 | |
| 1885 | if (f->counter != 0) |
| 1886 | continue; |
| 1887 | f->changed = false; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1888 | |
| 1889 | /* Move the element into temporary del_list */ |
| 1890 | list_move_tail(&f->list, &tmp_del_list); |
| 1891 | } |
| 1892 | |
| 1893 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1894 | if (!f->changed) |
| 1895 | continue; |
| 1896 | |
| 1897 | if (f->counter == 0) |
| 1898 | continue; |
| 1899 | f->changed = false; |
| 1900 | |
| 1901 | /* Clone MAC filter entry and add into temporary list */ |
| 1902 | fclone = i40e_mac_filter_entry_clone(f); |
| 1903 | if (!fclone) { |
| 1904 | err_cond = true; |
| 1905 | break; |
| 1906 | } |
| 1907 | list_add_tail(&fclone->list, &tmp_add_list); |
| 1908 | } |
| 1909 | |
| 1910 | /* if failed to clone MAC filter entry - undo */ |
| 1911 | if (err_cond) { |
| 1912 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 1913 | i40e_undo_add_filter_entries(vsi); |
| 1914 | } |
| 1915 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 1916 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1917 | if (err_cond) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1918 | i40e_cleanup_add_list(&tmp_add_list); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1919 | retval = -ENOMEM; |
| 1920 | goto out; |
| 1921 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | /* Now process 'del_list' outside the lock */ |
| 1925 | if (!list_empty(&tmp_del_list)) { |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1926 | int del_list_size; |
| 1927 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1928 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 1929 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1930 | del_list_size = filter_list_len * |
| 1931 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Jesse Brandeburg | 38c3cec | 2016-01-04 10:33:05 -0800 | [diff] [blame] | 1932 | del_list = kzalloc(del_list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1933 | if (!del_list) { |
| 1934 | i40e_cleanup_add_list(&tmp_add_list); |
| 1935 | |
| 1936 | /* Undo VSI's MAC filter entry element updates */ |
| 1937 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1938 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 1939 | i40e_undo_add_filter_entries(vsi); |
| 1940 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1941 | retval = -ENOMEM; |
| 1942 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1946 | cmd_flags = 0; |
| 1947 | |
| 1948 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1949 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1950 | del_list[num_del].vlan_tag = |
| 1951 | cpu_to_le16((u16)(f->vlan == |
| 1952 | I40E_VLAN_ANY ? 0 : f->vlan)); |
| 1953 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1954 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1955 | del_list[num_del].flags = cmd_flags; |
| 1956 | num_del++; |
| 1957 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1958 | /* flush a full buffer */ |
| 1959 | if (num_del == filter_list_len) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1960 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, |
| 1961 | vsi->seid, |
| 1962 | del_list, |
| 1963 | num_del, |
| 1964 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1965 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1966 | num_del = 0; |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1967 | memset(del_list, 0, del_list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1968 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1969 | if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) { |
| 1970 | retval = -EIO; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1971 | dev_err(&pf->pdev->dev, |
| 1972 | "ignoring delete macvlan error, err %s, aq_err %s while flushing a full buffer\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1973 | i40e_stat_str(&pf->hw, aq_ret), |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1974 | i40e_aq_str(&pf->hw, aq_err)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1975 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1976 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1977 | /* Release memory for MAC filter entries which were |
| 1978 | * synced up with HW. |
| 1979 | */ |
| 1980 | list_del(&f->list); |
| 1981 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1982 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1983 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1984 | if (num_del) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1985 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, |
| 1986 | del_list, num_del, |
| 1987 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1988 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1989 | num_del = 0; |
| 1990 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1991 | if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1992 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1993 | "ignoring delete macvlan error, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1994 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1995 | i40e_aq_str(&pf->hw, aq_err)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | kfree(del_list); |
| 1999 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | if (!list_empty(&tmp_add_list)) { |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2003 | int add_list_size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2004 | |
| 2005 | /* do all the adds now */ |
| 2006 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 2007 | sizeof(struct i40e_aqc_add_macvlan_element_data), |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2008 | add_list_size = filter_list_len * |
| 2009 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Jesse Brandeburg | 38c3cec | 2016-01-04 10:33:05 -0800 | [diff] [blame] | 2010 | add_list = kzalloc(add_list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2011 | if (!add_list) { |
| 2012 | /* Purge element from temporary lists */ |
| 2013 | i40e_cleanup_add_list(&tmp_add_list); |
| 2014 | |
| 2015 | /* Undo add filter entries from VSI MAC filter list */ |
| 2016 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2017 | i40e_undo_add_filter_entries(vsi); |
| 2018 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2019 | retval = -ENOMEM; |
| 2020 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2021 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2022 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2023 | list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2024 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2025 | add_happened = true; |
| 2026 | cmd_flags = 0; |
| 2027 | |
| 2028 | /* add to add array */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2029 | ether_addr_copy(add_list[num_add].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2030 | add_list[num_add].vlan_tag = |
| 2031 | cpu_to_le16( |
| 2032 | (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan)); |
| 2033 | add_list[num_add].queue_number = 0; |
| 2034 | |
| 2035 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2036 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2037 | num_add++; |
| 2038 | |
| 2039 | /* flush a full buffer */ |
| 2040 | if (num_add == filter_list_len) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2041 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 2042 | add_list, num_add, |
| 2043 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2044 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2045 | num_add = 0; |
| 2046 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2047 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2048 | break; |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2049 | memset(add_list, 0, add_list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2050 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2051 | /* Entries from tmp_add_list were cloned from MAC |
| 2052 | * filter list, hence clean those cloned entries |
| 2053 | */ |
| 2054 | list_del(&f->list); |
| 2055 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2056 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2057 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2058 | if (num_add) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2059 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 2060 | add_list, num_add, NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2061 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2062 | num_add = 0; |
| 2063 | } |
| 2064 | kfree(add_list); |
| 2065 | add_list = NULL; |
| 2066 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2067 | if (add_happened && aq_ret && aq_err != I40E_AQ_RC_EINVAL) { |
| 2068 | retval = i40e_aq_rc_to_posix(aq_ret, aq_err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2069 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2070 | "add filter failed, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2071 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2072 | i40e_aq_str(&pf->hw, aq_err)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2073 | if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) && |
| 2074 | !test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2075 | &vsi->state)) { |
| 2076 | promisc_forced_on = true; |
| 2077 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2078 | &vsi->state); |
| 2079 | dev_info(&pf->pdev->dev, "promiscuous mode forced on\n"); |
| 2080 | } |
| 2081 | } |
| 2082 | } |
| 2083 | |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2084 | /* if the VF is not trusted do not do promisc */ |
| 2085 | if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) { |
| 2086 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2087 | goto out; |
| 2088 | } |
| 2089 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2090 | /* check for changes in promiscuous modes */ |
| 2091 | if (changed_flags & IFF_ALLMULTI) { |
| 2092 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2093 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2094 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2095 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2096 | vsi->seid, |
| 2097 | cur_multipromisc, |
| 2098 | NULL); |
| 2099 | if (aq_ret) { |
| 2100 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2101 | pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2102 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2103 | "set multi promisc failed, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2104 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2105 | i40e_aq_str(&pf->hw, |
| 2106 | pf->hw.aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2107 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2108 | } |
| 2109 | if ((changed_flags & IFF_PROMISC) || promisc_forced_on) { |
| 2110 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2111 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2112 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 2113 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2114 | &vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2115 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2116 | (pf->lan_veb != I40E_NO_VEB) && |
| 2117 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2118 | /* set defport ON for Main VSI instead of true promisc |
| 2119 | * this way we will get all unicast/multicast and VLAN |
| 2120 | * promisc behavior but will not get VF or VMDq traffic |
| 2121 | * replicated on the Main VSI. |
| 2122 | */ |
| 2123 | if (pf->cur_promisc != cur_promisc) { |
| 2124 | pf->cur_promisc = cur_promisc; |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2125 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2126 | } |
| 2127 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2128 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2129 | &vsi->back->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2130 | vsi->seid, |
| 2131 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2132 | if (aq_ret) { |
| 2133 | retval = |
| 2134 | i40e_aq_rc_to_posix(aq_ret, |
| 2135 | pf->hw.aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2136 | dev_info(&pf->pdev->dev, |
| 2137 | "set unicast promisc failed, err %d, aq_err %d\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2138 | aq_ret, pf->hw.aq.asq_last_status); |
| 2139 | } |
| 2140 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2141 | &vsi->back->hw, |
| 2142 | vsi->seid, |
| 2143 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2144 | if (aq_ret) { |
| 2145 | retval = |
| 2146 | i40e_aq_rc_to_posix(aq_ret, |
| 2147 | pf->hw.aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2148 | dev_info(&pf->pdev->dev, |
| 2149 | "set multicast promisc failed, err %d, aq_err %d\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2150 | aq_ret, pf->hw.aq.asq_last_status); |
| 2151 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2152 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2153 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2154 | vsi->seid, |
| 2155 | cur_promisc, NULL); |
| 2156 | if (aq_ret) { |
| 2157 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2158 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2159 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2160 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2161 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2162 | i40e_aq_str(&pf->hw, |
| 2163 | pf->hw.aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2164 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2165 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2166 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2167 | /* if something went wrong then set the changed flag so we try again */ |
| 2168 | if (retval) |
| 2169 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2170 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2171 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2172 | return retval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | /** |
| 2176 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2177 | * @pf: board private structure |
| 2178 | **/ |
| 2179 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2180 | { |
| 2181 | int v; |
| 2182 | |
| 2183 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2184 | return; |
| 2185 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2186 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2187 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2188 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2189 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2190 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2191 | |
| 2192 | if (ret) { |
| 2193 | /* come back and try again later */ |
| 2194 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2195 | break; |
| 2196 | } |
| 2197 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2198 | } |
| 2199 | } |
| 2200 | |
| 2201 | /** |
| 2202 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2203 | * @netdev: network interface device structure |
| 2204 | * @new_mtu: new value for maximum frame size |
| 2205 | * |
| 2206 | * Returns 0 on success, negative on failure |
| 2207 | **/ |
| 2208 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2209 | { |
| 2210 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 61a46a4 | 2014-04-23 04:50:05 +0000 | [diff] [blame] | 2211 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2212 | struct i40e_vsi *vsi = np->vsi; |
| 2213 | |
| 2214 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 2215 | if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) |
| 2216 | return -EINVAL; |
| 2217 | |
| 2218 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2219 | netdev->mtu, new_mtu); |
| 2220 | netdev->mtu = new_mtu; |
| 2221 | if (netif_running(netdev)) |
| 2222 | i40e_vsi_reinit_locked(vsi); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 2223 | i40e_notify_client_of_l2_param_changes(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2224 | return 0; |
| 2225 | } |
| 2226 | |
| 2227 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2228 | * i40e_ioctl - Access the hwtstamp interface |
| 2229 | * @netdev: network interface device structure |
| 2230 | * @ifr: interface request data |
| 2231 | * @cmd: ioctl command |
| 2232 | **/ |
| 2233 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2234 | { |
| 2235 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2236 | struct i40e_pf *pf = np->vsi->back; |
| 2237 | |
| 2238 | switch (cmd) { |
| 2239 | case SIOCGHWTSTAMP: |
| 2240 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2241 | case SIOCSHWTSTAMP: |
| 2242 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2243 | default: |
| 2244 | return -EOPNOTSUPP; |
| 2245 | } |
| 2246 | } |
| 2247 | |
| 2248 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2249 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2250 | * @vsi: the vsi being adjusted |
| 2251 | **/ |
| 2252 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2253 | { |
| 2254 | struct i40e_vsi_context ctxt; |
| 2255 | i40e_status ret; |
| 2256 | |
| 2257 | if ((vsi->info.valid_sections & |
| 2258 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2259 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2260 | return; /* already enabled */ |
| 2261 | |
| 2262 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2263 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2264 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2265 | |
| 2266 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2267 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2268 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2269 | if (ret) { |
| 2270 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2271 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2272 | i40e_stat_str(&vsi->back->hw, ret), |
| 2273 | i40e_aq_str(&vsi->back->hw, |
| 2274 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2275 | } |
| 2276 | } |
| 2277 | |
| 2278 | /** |
| 2279 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2280 | * @vsi: the vsi being adjusted |
| 2281 | **/ |
| 2282 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2283 | { |
| 2284 | struct i40e_vsi_context ctxt; |
| 2285 | i40e_status ret; |
| 2286 | |
| 2287 | if ((vsi->info.valid_sections & |
| 2288 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2289 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2290 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2291 | return; /* already disabled */ |
| 2292 | |
| 2293 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2294 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2295 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2296 | |
| 2297 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2298 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2299 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2300 | if (ret) { |
| 2301 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2302 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2303 | i40e_stat_str(&vsi->back->hw, ret), |
| 2304 | i40e_aq_str(&vsi->back->hw, |
| 2305 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2306 | } |
| 2307 | } |
| 2308 | |
| 2309 | /** |
| 2310 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2311 | * @netdev: network interface to be adjusted |
| 2312 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2313 | **/ |
| 2314 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2315 | { |
| 2316 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2317 | struct i40e_vsi *vsi = np->vsi; |
| 2318 | |
| 2319 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2320 | i40e_vlan_stripping_enable(vsi); |
| 2321 | else |
| 2322 | i40e_vlan_stripping_disable(vsi); |
| 2323 | } |
| 2324 | |
| 2325 | /** |
| 2326 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 2327 | * @vsi: the vsi being configured |
| 2328 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 2329 | **/ |
| 2330 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2331 | { |
| 2332 | struct i40e_mac_filter *f, *add_f; |
| 2333 | bool is_netdev, is_vf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2334 | |
| 2335 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2336 | is_netdev = !!(vsi->netdev); |
| 2337 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2338 | /* Locked once because all functions invoked below iterates list*/ |
| 2339 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2340 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2341 | if (is_netdev) { |
| 2342 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid, |
| 2343 | is_vf, is_netdev); |
| 2344 | if (!add_f) { |
| 2345 | dev_info(&vsi->back->pdev->dev, |
| 2346 | "Could not add vlan filter %d for %pM\n", |
| 2347 | vid, vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2348 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2349 | return -ENOMEM; |
| 2350 | } |
| 2351 | } |
| 2352 | |
| 2353 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2354 | add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2355 | if (!add_f) { |
| 2356 | dev_info(&vsi->back->pdev->dev, |
| 2357 | "Could not add vlan filter %d for %pM\n", |
| 2358 | vid, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2359 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2360 | return -ENOMEM; |
| 2361 | } |
| 2362 | } |
| 2363 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2364 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 2365 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 2366 | * with 0, so we now accept untagged and specified tagged traffic |
| 2367 | * (and not any taged and untagged) |
| 2368 | */ |
| 2369 | if (vid > 0) { |
| 2370 | if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 2371 | I40E_VLAN_ANY, |
| 2372 | is_vf, is_netdev)) { |
| 2373 | i40e_del_filter(vsi, vsi->netdev->dev_addr, |
| 2374 | I40E_VLAN_ANY, is_vf, is_netdev); |
| 2375 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0, |
| 2376 | is_vf, is_netdev); |
| 2377 | if (!add_f) { |
| 2378 | dev_info(&vsi->back->pdev->dev, |
| 2379 | "Could not add filter 0 for %pM\n", |
| 2380 | 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 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2385 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2386 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2387 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
| 2388 | if (vid > 0 && !vsi->info.pvid) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2389 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2390 | if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2391 | is_vf, is_netdev)) |
| 2392 | continue; |
| 2393 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2394 | is_vf, is_netdev); |
| 2395 | add_f = i40e_add_filter(vsi, f->macaddr, |
| 2396 | 0, is_vf, is_netdev); |
| 2397 | if (!add_f) { |
| 2398 | dev_info(&vsi->back->pdev->dev, |
| 2399 | "Could not add filter 0 for %pM\n", |
| 2400 | f->macaddr); |
| 2401 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2402 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2403 | } |
| 2404 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2407 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2408 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2409 | /* schedule our worker thread which will take care of |
| 2410 | * applying the new filter changes |
| 2411 | */ |
| 2412 | i40e_service_event_schedule(vsi->back); |
| 2413 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | /** |
| 2417 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 2418 | * @vsi: the vsi being configured |
| 2419 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2420 | * |
| 2421 | * Return: 0 on success or negative otherwise |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2422 | **/ |
| 2423 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2424 | { |
| 2425 | struct net_device *netdev = vsi->netdev; |
| 2426 | struct i40e_mac_filter *f, *add_f; |
| 2427 | bool is_vf, is_netdev; |
| 2428 | int filter_count = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2429 | |
| 2430 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2431 | is_netdev = !!(netdev); |
| 2432 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2433 | /* Locked once because all functions invoked below iterates list */ |
| 2434 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2435 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2436 | if (is_netdev) |
| 2437 | i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev); |
| 2438 | |
| 2439 | list_for_each_entry(f, &vsi->mac_filter_list, list) |
| 2440 | i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2441 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2442 | /* go through all the filters for this VSI and if there is only |
| 2443 | * vid == 0 it means there are no other filters, so vid 0 must |
| 2444 | * be replaced with -1. This signifies that we should from now |
| 2445 | * on accept any traffic (with any tag present, or untagged) |
| 2446 | */ |
| 2447 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2448 | if (is_netdev) { |
| 2449 | if (f->vlan && |
| 2450 | ether_addr_equal(netdev->dev_addr, f->macaddr)) |
| 2451 | filter_count++; |
| 2452 | } |
| 2453 | |
| 2454 | if (f->vlan) |
| 2455 | filter_count++; |
| 2456 | } |
| 2457 | |
| 2458 | if (!filter_count && is_netdev) { |
| 2459 | i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev); |
| 2460 | f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 2461 | is_vf, is_netdev); |
| 2462 | if (!f) { |
| 2463 | dev_info(&vsi->back->pdev->dev, |
| 2464 | "Could not add filter %d for %pM\n", |
| 2465 | I40E_VLAN_ANY, netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2466 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2467 | return -ENOMEM; |
| 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | if (!filter_count) { |
| 2472 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2473 | i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev); |
| 2474 | add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2475 | is_vf, is_netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2476 | if (!add_f) { |
| 2477 | dev_info(&vsi->back->pdev->dev, |
| 2478 | "Could not add filter %d for %pM\n", |
| 2479 | I40E_VLAN_ANY, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2480 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2481 | return -ENOMEM; |
| 2482 | } |
| 2483 | } |
| 2484 | } |
| 2485 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2486 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2487 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2488 | /* schedule our worker thread which will take care of |
| 2489 | * applying the new filter changes |
| 2490 | */ |
| 2491 | i40e_service_event_schedule(vsi->back); |
| 2492 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | /** |
| 2496 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2497 | * @netdev: network interface to be adjusted |
| 2498 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2499 | * |
| 2500 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2501 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2502 | #ifdef I40E_FCOE |
| 2503 | int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2504 | __always_unused __be16 proto, u16 vid) |
| 2505 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2506 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2507 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2508 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2509 | { |
| 2510 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2511 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2512 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2513 | |
| 2514 | if (vid > 4095) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2515 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2516 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2517 | netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid); |
| 2518 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2519 | /* If the network stack called us with vid = 0 then |
| 2520 | * it is asking to receive priority tagged packets with |
| 2521 | * vlan id 0. Our HW receives them by default when configured |
| 2522 | * to receive untagged packets so there is no need to add an |
| 2523 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2524 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2525 | if (vid) |
| 2526 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2527 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2528 | if (!ret && (vid < VLAN_N_VID)) |
| 2529 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2530 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2531 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | /** |
| 2535 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2536 | * @netdev: network interface to be adjusted |
| 2537 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2538 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2539 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2540 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2541 | #ifdef I40E_FCOE |
| 2542 | int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2543 | __always_unused __be16 proto, u16 vid) |
| 2544 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2545 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2546 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2547 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2548 | { |
| 2549 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2550 | struct i40e_vsi *vsi = np->vsi; |
| 2551 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2552 | netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid); |
| 2553 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2554 | /* return code is ignored as there is nothing a user |
| 2555 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2556 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2557 | */ |
| 2558 | i40e_vsi_kill_vlan(vsi, vid); |
| 2559 | |
| 2560 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2561 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2562 | return 0; |
| 2563 | } |
| 2564 | |
| 2565 | /** |
| 2566 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2567 | * @vsi: the vsi being brought back up |
| 2568 | **/ |
| 2569 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2570 | { |
| 2571 | u16 vid; |
| 2572 | |
| 2573 | if (!vsi->netdev) |
| 2574 | return; |
| 2575 | |
| 2576 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2577 | |
| 2578 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2579 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2580 | vid); |
| 2581 | } |
| 2582 | |
| 2583 | /** |
| 2584 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2585 | * @vsi: the vsi being adjusted |
| 2586 | * @vid: the vlan id to set as a PVID |
| 2587 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2588 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2589 | { |
| 2590 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2591 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2592 | |
| 2593 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2594 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2595 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2596 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2597 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2598 | |
| 2599 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2600 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2601 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2602 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2603 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2604 | "add pvid failed, err %s aq_err %s\n", |
| 2605 | i40e_stat_str(&vsi->back->hw, ret), |
| 2606 | i40e_aq_str(&vsi->back->hw, |
| 2607 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2608 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2609 | } |
| 2610 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2611 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | /** |
| 2615 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2616 | * @vsi: the vsi being adjusted |
| 2617 | * |
| 2618 | * Just use the vlan_rx_register() service to put it back to normal |
| 2619 | **/ |
| 2620 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2621 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2622 | i40e_vlan_stripping_disable(vsi); |
| 2623 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2624 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | /** |
| 2628 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2629 | * @vsi: ptr to the VSI |
| 2630 | * |
| 2631 | * If this function returns with an error, then it's possible one or |
| 2632 | * more of the rings is populated (while the rest are not). It is the |
| 2633 | * callers duty to clean those orphaned rings. |
| 2634 | * |
| 2635 | * Return 0 on success, negative on failure |
| 2636 | **/ |
| 2637 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2638 | { |
| 2639 | int i, err = 0; |
| 2640 | |
| 2641 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2642 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2643 | |
| 2644 | return err; |
| 2645 | } |
| 2646 | |
| 2647 | /** |
| 2648 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2649 | * @vsi: ptr to the VSI |
| 2650 | * |
| 2651 | * Free VSI's transmit software resources |
| 2652 | **/ |
| 2653 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2654 | { |
| 2655 | int i; |
| 2656 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2657 | if (!vsi->tx_rings) |
| 2658 | return; |
| 2659 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2660 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2661 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2662 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | /** |
| 2666 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2667 | * @vsi: ptr to the VSI |
| 2668 | * |
| 2669 | * If this function returns with an error, then it's possible one or |
| 2670 | * more of the rings is populated (while the rest are not). It is the |
| 2671 | * callers duty to clean those orphaned rings. |
| 2672 | * |
| 2673 | * Return 0 on success, negative on failure |
| 2674 | **/ |
| 2675 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2676 | { |
| 2677 | int i, err = 0; |
| 2678 | |
| 2679 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2680 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2681 | #ifdef I40E_FCOE |
| 2682 | i40e_fcoe_setup_ddp_resources(vsi); |
| 2683 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2684 | return err; |
| 2685 | } |
| 2686 | |
| 2687 | /** |
| 2688 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2689 | * @vsi: ptr to the VSI |
| 2690 | * |
| 2691 | * Free all receive software resources |
| 2692 | **/ |
| 2693 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2694 | { |
| 2695 | int i; |
| 2696 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2697 | if (!vsi->rx_rings) |
| 2698 | return; |
| 2699 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2700 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2701 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2702 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2703 | #ifdef I40E_FCOE |
| 2704 | i40e_fcoe_free_ddp_resources(vsi); |
| 2705 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2709 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2710 | * @ring: The Tx ring to configure |
| 2711 | * |
| 2712 | * This enables/disables XPS for a given Tx descriptor ring |
| 2713 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2714 | **/ |
| 2715 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2716 | { |
| 2717 | struct i40e_vsi *vsi = ring->vsi; |
| 2718 | cpumask_var_t mask; |
| 2719 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2720 | if (!ring->q_vector || !ring->netdev) |
| 2721 | return; |
| 2722 | |
| 2723 | /* Single TC mode enable XPS */ |
| 2724 | if (vsi->tc_config.numtc <= 1) { |
| 2725 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2726 | netif_set_xps_queue(ring->netdev, |
| 2727 | &ring->q_vector->affinity_mask, |
| 2728 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2729 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2730 | /* Disable XPS to allow selection based on TC */ |
| 2731 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2732 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2733 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2734 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2735 | |
| 2736 | /* schedule our worker thread which will take care of |
| 2737 | * applying the new filter changes |
| 2738 | */ |
| 2739 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2740 | } |
| 2741 | |
| 2742 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2743 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2744 | * @ring: The Tx ring to configure |
| 2745 | * |
| 2746 | * Configure the Tx descriptor ring in the HMC context. |
| 2747 | **/ |
| 2748 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2749 | { |
| 2750 | struct i40e_vsi *vsi = ring->vsi; |
| 2751 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2752 | struct i40e_hw *hw = &vsi->back->hw; |
| 2753 | struct i40e_hmc_obj_txq tx_ctx; |
| 2754 | i40e_status err = 0; |
| 2755 | u32 qtx_ctl = 0; |
| 2756 | |
| 2757 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2758 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2759 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2760 | ring->atr_count = 0; |
| 2761 | } else { |
| 2762 | ring->atr_sample_rate = 0; |
| 2763 | } |
| 2764 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2765 | /* configure XPS */ |
| 2766 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2767 | |
| 2768 | /* clear the context structure first */ |
| 2769 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2770 | |
| 2771 | tx_ctx.new_context = 1; |
| 2772 | tx_ctx.base = (ring->dma / 128); |
| 2773 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2774 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2775 | I40E_FLAG_FD_ATR_ENABLED)); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2776 | #ifdef I40E_FCOE |
| 2777 | tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2778 | #endif |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2779 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2780 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2781 | if (vsi->type != I40E_VSI_FDIR) |
| 2782 | tx_ctx.head_wb_ena = 1; |
| 2783 | tx_ctx.head_wb_addr = ring->dma + |
| 2784 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2785 | |
| 2786 | /* As part of VSI creation/update, FW allocates certain |
| 2787 | * Tx arbitration queue sets for each TC enabled for |
| 2788 | * the VSI. The FW returns the handles to these queue |
| 2789 | * sets as part of the response buffer to Add VSI, |
| 2790 | * Update VSI, etc. AQ commands. It is expected that |
| 2791 | * these queue set handles be associated with the Tx |
| 2792 | * queues by the driver as part of the TX queue context |
| 2793 | * initialization. This has to be done regardless of |
| 2794 | * DCB as by default everything is mapped to TC0. |
| 2795 | */ |
| 2796 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2797 | tx_ctx.rdylist_act = 0; |
| 2798 | |
| 2799 | /* clear the context in the HMC */ |
| 2800 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2801 | if (err) { |
| 2802 | dev_info(&vsi->back->pdev->dev, |
| 2803 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2804 | ring->queue_index, pf_q, err); |
| 2805 | return -ENOMEM; |
| 2806 | } |
| 2807 | |
| 2808 | /* set the context in the HMC */ |
| 2809 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2810 | if (err) { |
| 2811 | dev_info(&vsi->back->pdev->dev, |
| 2812 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2813 | ring->queue_index, pf_q, err); |
| 2814 | return -ENOMEM; |
| 2815 | } |
| 2816 | |
| 2817 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2818 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2819 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2820 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2821 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2822 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2823 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2824 | } |
| 2825 | |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2826 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2827 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2828 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2829 | i40e_flush(hw); |
| 2830 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2831 | /* cache tail off for easier writes later */ |
| 2832 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2833 | |
| 2834 | return 0; |
| 2835 | } |
| 2836 | |
| 2837 | /** |
| 2838 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2839 | * @ring: The Rx ring to configure |
| 2840 | * |
| 2841 | * Configure the Rx descriptor ring in the HMC context. |
| 2842 | **/ |
| 2843 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2844 | { |
| 2845 | struct i40e_vsi *vsi = ring->vsi; |
| 2846 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2847 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2848 | struct i40e_hw *hw = &vsi->back->hw; |
| 2849 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2850 | i40e_status err = 0; |
| 2851 | |
| 2852 | ring->state = 0; |
| 2853 | |
| 2854 | /* clear the context structure first */ |
| 2855 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2856 | |
| 2857 | ring->rx_buf_len = vsi->rx_buf_len; |
| 2858 | ring->rx_hdr_len = vsi->rx_hdr_len; |
| 2859 | |
| 2860 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
| 2861 | rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT; |
| 2862 | |
| 2863 | rx_ctx.base = (ring->dma / 128); |
| 2864 | rx_ctx.qlen = ring->count; |
| 2865 | |
| 2866 | if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) { |
| 2867 | set_ring_16byte_desc_enabled(ring); |
| 2868 | rx_ctx.dsize = 0; |
| 2869 | } else { |
| 2870 | rx_ctx.dsize = 1; |
| 2871 | } |
| 2872 | |
| 2873 | rx_ctx.dtype = vsi->dtype; |
| 2874 | if (vsi->dtype) { |
| 2875 | set_ring_ps_enabled(ring); |
| 2876 | rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 | |
| 2877 | I40E_RX_SPLIT_IP | |
| 2878 | I40E_RX_SPLIT_TCP_UDP | |
| 2879 | I40E_RX_SPLIT_SCTP; |
| 2880 | } else { |
| 2881 | rx_ctx.hsplit_0 = 0; |
| 2882 | } |
| 2883 | |
| 2884 | rx_ctx.rxmax = min_t(u16, vsi->max_frame, |
| 2885 | (chain_len * ring->rx_buf_len)); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 2886 | if (hw->revision_id == 0) |
| 2887 | rx_ctx.lrxqthresh = 0; |
| 2888 | else |
| 2889 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2890 | rx_ctx.crcstrip = 1; |
| 2891 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 2892 | /* this controls whether VLAN is stripped from inner headers */ |
| 2893 | rx_ctx.showiv = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2894 | #ifdef I40E_FCOE |
| 2895 | rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2896 | #endif |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 2897 | /* set the prefena field to 1 because the manual says to */ |
| 2898 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2899 | |
| 2900 | /* clear the context in the HMC */ |
| 2901 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 2902 | if (err) { |
| 2903 | dev_info(&vsi->back->pdev->dev, |
| 2904 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2905 | ring->queue_index, pf_q, err); |
| 2906 | return -ENOMEM; |
| 2907 | } |
| 2908 | |
| 2909 | /* set the context in the HMC */ |
| 2910 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 2911 | if (err) { |
| 2912 | dev_info(&vsi->back->pdev->dev, |
| 2913 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2914 | ring->queue_index, pf_q, err); |
| 2915 | return -ENOMEM; |
| 2916 | } |
| 2917 | |
| 2918 | /* cache tail for quicker writes, and clear the reg before use */ |
| 2919 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 2920 | writel(0, ring->tail); |
| 2921 | |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 2922 | if (ring_is_ps_enabled(ring)) { |
| 2923 | i40e_alloc_rx_headers(ring); |
| 2924 | i40e_alloc_rx_buffers_ps(ring, I40E_DESC_UNUSED(ring)); |
| 2925 | } else { |
| 2926 | i40e_alloc_rx_buffers_1buf(ring, I40E_DESC_UNUSED(ring)); |
| 2927 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2928 | |
| 2929 | return 0; |
| 2930 | } |
| 2931 | |
| 2932 | /** |
| 2933 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 2934 | * @vsi: VSI structure describing this set of rings and resources |
| 2935 | * |
| 2936 | * Configure the Tx VSI for operation. |
| 2937 | **/ |
| 2938 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 2939 | { |
| 2940 | int err = 0; |
| 2941 | u16 i; |
| 2942 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2943 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 2944 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2945 | |
| 2946 | return err; |
| 2947 | } |
| 2948 | |
| 2949 | /** |
| 2950 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 2951 | * @vsi: the VSI being configured |
| 2952 | * |
| 2953 | * Configure the Rx VSI for operation. |
| 2954 | **/ |
| 2955 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 2956 | { |
| 2957 | int err = 0; |
| 2958 | u16 i; |
| 2959 | |
| 2960 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 2961 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 2962 | + ETH_FCS_LEN + VLAN_HLEN; |
| 2963 | else |
| 2964 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 2965 | |
| 2966 | /* figure out correct receive buffer length */ |
| 2967 | switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED | |
| 2968 | I40E_FLAG_RX_PS_ENABLED)) { |
| 2969 | case I40E_FLAG_RX_1BUF_ENABLED: |
| 2970 | vsi->rx_hdr_len = 0; |
| 2971 | vsi->rx_buf_len = vsi->max_frame; |
| 2972 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 2973 | break; |
| 2974 | case I40E_FLAG_RX_PS_ENABLED: |
| 2975 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2976 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2977 | vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT; |
| 2978 | break; |
| 2979 | default: |
| 2980 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2981 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2982 | vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS; |
| 2983 | break; |
| 2984 | } |
| 2985 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2986 | #ifdef I40E_FCOE |
| 2987 | /* setup rx buffer for FCoE */ |
| 2988 | if ((vsi->type == I40E_VSI_FCOE) && |
| 2989 | (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) { |
| 2990 | vsi->rx_hdr_len = 0; |
| 2991 | vsi->rx_buf_len = I40E_RXBUFFER_3072; |
| 2992 | vsi->max_frame = I40E_RXBUFFER_3072; |
| 2993 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 2994 | } |
| 2995 | |
| 2996 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2997 | /* round up for the chip's needs */ |
| 2998 | vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2999 | BIT_ULL(I40E_RXQ_CTX_HBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3000 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3001 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3002 | |
| 3003 | /* set up individual rings */ |
| 3004 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3005 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3006 | |
| 3007 | return err; |
| 3008 | } |
| 3009 | |
| 3010 | /** |
| 3011 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3012 | * @vsi: ptr to the VSI |
| 3013 | **/ |
| 3014 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3015 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3016 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3017 | u16 qoffset, qcount; |
| 3018 | int i, n; |
| 3019 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3020 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3021 | /* Reset the TC information */ |
| 3022 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3023 | rx_ring = vsi->rx_rings[i]; |
| 3024 | tx_ring = vsi->tx_rings[i]; |
| 3025 | rx_ring->dcb_tc = 0; |
| 3026 | tx_ring->dcb_tc = 0; |
| 3027 | } |
| 3028 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3029 | |
| 3030 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3031 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3032 | continue; |
| 3033 | |
| 3034 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3035 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3036 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3037 | rx_ring = vsi->rx_rings[i]; |
| 3038 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3039 | rx_ring->dcb_tc = n; |
| 3040 | tx_ring->dcb_tc = n; |
| 3041 | } |
| 3042 | } |
| 3043 | } |
| 3044 | |
| 3045 | /** |
| 3046 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3047 | * @vsi: ptr to the VSI |
| 3048 | **/ |
| 3049 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3050 | { |
| 3051 | if (vsi->netdev) |
| 3052 | i40e_set_rx_mode(vsi->netdev); |
| 3053 | } |
| 3054 | |
| 3055 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3056 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3057 | * @vsi: Pointer to the targeted VSI |
| 3058 | * |
| 3059 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3060 | * filters were saved. |
| 3061 | **/ |
| 3062 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3063 | { |
| 3064 | struct i40e_fdir_filter *filter; |
| 3065 | struct i40e_pf *pf = vsi->back; |
| 3066 | struct hlist_node *node; |
| 3067 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3068 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3069 | return; |
| 3070 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3071 | hlist_for_each_entry_safe(filter, node, |
| 3072 | &pf->fdir_filter_list, fdir_node) { |
| 3073 | i40e_add_del_fdir(vsi, filter, true); |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3078 | * i40e_vsi_configure - Set up the VSI for action |
| 3079 | * @vsi: the VSI being configured |
| 3080 | **/ |
| 3081 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3082 | { |
| 3083 | int err; |
| 3084 | |
| 3085 | i40e_set_vsi_rx_mode(vsi); |
| 3086 | i40e_restore_vlan(vsi); |
| 3087 | i40e_vsi_config_dcb_rings(vsi); |
| 3088 | err = i40e_vsi_configure_tx(vsi); |
| 3089 | if (!err) |
| 3090 | err = i40e_vsi_configure_rx(vsi); |
| 3091 | |
| 3092 | return err; |
| 3093 | } |
| 3094 | |
| 3095 | /** |
| 3096 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3097 | * @vsi: the VSI being configured |
| 3098 | **/ |
| 3099 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3100 | { |
| 3101 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3102 | struct i40e_hw *hw = &pf->hw; |
| 3103 | u16 vector; |
| 3104 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3105 | u32 qp; |
| 3106 | |
| 3107 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3108 | * and PFINT_LNKLSTn registers, e.g.: |
| 3109 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3110 | */ |
| 3111 | qp = vsi->base_queue; |
| 3112 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3113 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3114 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3115 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3116 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3117 | 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] | 3118 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3119 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3120 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3121 | 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] | 3122 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3123 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3124 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3125 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
| 3126 | INTRL_USEC_TO_REG(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3127 | |
| 3128 | /* Linked list for the queuepairs assigned to this vector */ |
| 3129 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3130 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3131 | u32 val; |
| 3132 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3133 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3134 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3135 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3136 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 3137 | (I40E_QUEUE_TYPE_TX |
| 3138 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 3139 | |
| 3140 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3141 | |
| 3142 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3143 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3144 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3145 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 3146 | (I40E_QUEUE_TYPE_RX |
| 3147 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3148 | |
| 3149 | /* Terminate the linked list */ |
| 3150 | if (q == (q_vector->num_ringpairs - 1)) |
| 3151 | val |= (I40E_QUEUE_END_OF_LIST |
| 3152 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3153 | |
| 3154 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3155 | qp++; |
| 3156 | } |
| 3157 | } |
| 3158 | |
| 3159 | i40e_flush(hw); |
| 3160 | } |
| 3161 | |
| 3162 | /** |
| 3163 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3164 | * @hw: ptr to the hardware info |
| 3165 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3166 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3167 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3168 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3169 | u32 val; |
| 3170 | |
| 3171 | /* clear things first */ |
| 3172 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3173 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3174 | |
| 3175 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3176 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3177 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3178 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3179 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3180 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3181 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3182 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3183 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3184 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3185 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3186 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3187 | if (pf->flags & I40E_FLAG_PTP) |
| 3188 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3189 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3190 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3191 | |
| 3192 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3193 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3194 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3195 | |
| 3196 | /* OTHER_ITR_IDX = 0 */ |
| 3197 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3198 | } |
| 3199 | |
| 3200 | /** |
| 3201 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3202 | * @vsi: the VSI being configured |
| 3203 | **/ |
| 3204 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3205 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3206 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3207 | struct i40e_pf *pf = vsi->back; |
| 3208 | struct i40e_hw *hw = &pf->hw; |
| 3209 | u32 val; |
| 3210 | |
| 3211 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3212 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3213 | 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] | 3214 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3215 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3216 | 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] | 3217 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3218 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3219 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3220 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3221 | |
| 3222 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3223 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3224 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3225 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3226 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3227 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3228 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3229 | |
| 3230 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3231 | |
| 3232 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3233 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3234 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3235 | |
| 3236 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3237 | i40e_flush(hw); |
| 3238 | } |
| 3239 | |
| 3240 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3241 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3242 | * @pf: board private structure |
| 3243 | **/ |
| 3244 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3245 | { |
| 3246 | struct i40e_hw *hw = &pf->hw; |
| 3247 | |
| 3248 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3249 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3250 | i40e_flush(hw); |
| 3251 | } |
| 3252 | |
| 3253 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3254 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3255 | * @pf: board private structure |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3256 | * @clearpba: true when all pending interrupt events should be cleared |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3257 | **/ |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3258 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3259 | { |
| 3260 | struct i40e_hw *hw = &pf->hw; |
| 3261 | u32 val; |
| 3262 | |
| 3263 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3264 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3265 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3266 | |
| 3267 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3268 | i40e_flush(hw); |
| 3269 | } |
| 3270 | |
| 3271 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3272 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3273 | * @irq: interrupt number |
| 3274 | * @data: pointer to a q_vector |
| 3275 | **/ |
| 3276 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3277 | { |
| 3278 | struct i40e_q_vector *q_vector = data; |
| 3279 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3280 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3281 | return IRQ_HANDLED; |
| 3282 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3283 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3284 | |
| 3285 | return IRQ_HANDLED; |
| 3286 | } |
| 3287 | |
| 3288 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3289 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3290 | * @vsi: the VSI being configured |
| 3291 | * @basename: name for the vector |
| 3292 | * |
| 3293 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3294 | **/ |
| 3295 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3296 | { |
| 3297 | int q_vectors = vsi->num_q_vectors; |
| 3298 | struct i40e_pf *pf = vsi->back; |
| 3299 | int base = vsi->base_vector; |
| 3300 | int rx_int_idx = 0; |
| 3301 | int tx_int_idx = 0; |
| 3302 | int vector, err; |
| 3303 | |
| 3304 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3305 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3306 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3307 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3308 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3309 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3310 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3311 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3312 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3313 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3314 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3315 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3316 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3317 | } else { |
| 3318 | /* skip this unused q_vector */ |
| 3319 | continue; |
| 3320 | } |
| 3321 | err = request_irq(pf->msix_entries[base + vector].vector, |
| 3322 | vsi->irq_handler, |
| 3323 | 0, |
| 3324 | q_vector->name, |
| 3325 | q_vector); |
| 3326 | if (err) { |
| 3327 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3328 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3329 | goto free_queue_irqs; |
| 3330 | } |
| 3331 | /* assign the mask for this irq */ |
| 3332 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3333 | &q_vector->affinity_mask); |
| 3334 | } |
| 3335 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3336 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3337 | return 0; |
| 3338 | |
| 3339 | free_queue_irqs: |
| 3340 | while (vector) { |
| 3341 | vector--; |
| 3342 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3343 | NULL); |
| 3344 | free_irq(pf->msix_entries[base + vector].vector, |
| 3345 | &(vsi->q_vectors[vector])); |
| 3346 | } |
| 3347 | return err; |
| 3348 | } |
| 3349 | |
| 3350 | /** |
| 3351 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3352 | * @vsi: the VSI being un-configured |
| 3353 | **/ |
| 3354 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3355 | { |
| 3356 | struct i40e_pf *pf = vsi->back; |
| 3357 | struct i40e_hw *hw = &pf->hw; |
| 3358 | int base = vsi->base_vector; |
| 3359 | int i; |
| 3360 | |
| 3361 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3362 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3363 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3367 | for (i = vsi->base_vector; |
| 3368 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3369 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3370 | |
| 3371 | i40e_flush(hw); |
| 3372 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3373 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3374 | } else { |
| 3375 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3376 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3377 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3378 | i40e_flush(hw); |
| 3379 | synchronize_irq(pf->pdev->irq); |
| 3380 | } |
| 3381 | } |
| 3382 | |
| 3383 | /** |
| 3384 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3385 | * @vsi: the VSI being configured |
| 3386 | **/ |
| 3387 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3388 | { |
| 3389 | struct i40e_pf *pf = vsi->back; |
| 3390 | int i; |
| 3391 | |
| 3392 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3393 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3394 | i40e_irq_dynamic_enable(vsi, i); |
| 3395 | } else { |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3396 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3397 | } |
| 3398 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3399 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3400 | return 0; |
| 3401 | } |
| 3402 | |
| 3403 | /** |
| 3404 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3405 | * @pf: board private structure |
| 3406 | **/ |
| 3407 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3408 | { |
| 3409 | /* Disable ICR 0 */ |
| 3410 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3411 | i40e_flush(&pf->hw); |
| 3412 | } |
| 3413 | |
| 3414 | /** |
| 3415 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3416 | * @irq: interrupt number |
| 3417 | * @data: pointer to a q_vector |
| 3418 | * |
| 3419 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3420 | * with both queue and non-queue interrupts. This is also used in |
| 3421 | * MSIX mode to handle the non-queue interrupts. |
| 3422 | **/ |
| 3423 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3424 | { |
| 3425 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3426 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3427 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3428 | u32 icr0, icr0_remaining; |
| 3429 | u32 val, ena_mask; |
| 3430 | |
| 3431 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3432 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3433 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3434 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3435 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3436 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3437 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3438 | /* if interrupt but no bits showing, must be SWINT */ |
| 3439 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3440 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3441 | pf->sw_int_count++; |
| 3442 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3443 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 3444 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
| 3445 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3446 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3447 | dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
| 3448 | } |
| 3449 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3450 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3451 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3452 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3453 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3454 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3455 | /* We do not have a way to disarm Queue causes while leaving |
| 3456 | * interrupt enabled for all other causes, ideally |
| 3457 | * interrupt should be disabled while we are in NAPI but |
| 3458 | * this is not a performance path and napi_schedule() |
| 3459 | * can deal with rescheduling. |
| 3460 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3461 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3462 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3463 | } |
| 3464 | |
| 3465 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3466 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3467 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3468 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3472 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3473 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3474 | } |
| 3475 | |
| 3476 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3477 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3478 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3479 | } |
| 3480 | |
| 3481 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3482 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3483 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3484 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3485 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3486 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3487 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3488 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3489 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3490 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3491 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3492 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3493 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3494 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3495 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3496 | } |
| 3497 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3498 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3499 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3500 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3501 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3502 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3503 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3504 | } |
| 3505 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3506 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3507 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3508 | |
| 3509 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3510 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3511 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3512 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3513 | } |
| 3514 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3515 | /* If a critical error is pending we have no choice but to reset the |
| 3516 | * device. |
| 3517 | * Report and mask out any remaining unexpected interrupts. |
| 3518 | */ |
| 3519 | icr0_remaining = icr0 & ena_mask; |
| 3520 | if (icr0_remaining) { |
| 3521 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3522 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3523 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3524 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3525 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3526 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3527 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3528 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3529 | } |
| 3530 | ena_mask &= ~icr0_remaining; |
| 3531 | } |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3532 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3533 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3534 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3535 | /* re-enable interrupt causes */ |
| 3536 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3537 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3538 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3539 | i40e_irq_dynamic_enable_icr0(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3540 | } |
| 3541 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3542 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3546 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3547 | * @tx_ring: tx ring to clean |
| 3548 | * @budget: how many cleans we're allowed |
| 3549 | * |
| 3550 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3551 | **/ |
| 3552 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3553 | { |
| 3554 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3555 | u16 i = tx_ring->next_to_clean; |
| 3556 | struct i40e_tx_buffer *tx_buf; |
| 3557 | struct i40e_tx_desc *tx_desc; |
| 3558 | |
| 3559 | tx_buf = &tx_ring->tx_bi[i]; |
| 3560 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3561 | i -= tx_ring->count; |
| 3562 | |
| 3563 | do { |
| 3564 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3565 | |
| 3566 | /* if next_to_watch is not set then there is no work pending */ |
| 3567 | if (!eop_desc) |
| 3568 | break; |
| 3569 | |
| 3570 | /* prevent any other reads prior to eop_desc */ |
| 3571 | read_barrier_depends(); |
| 3572 | |
| 3573 | /* if the descriptor isn't done, no work yet to do */ |
| 3574 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3575 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3576 | break; |
| 3577 | |
| 3578 | /* clear next_to_watch to prevent false hangs */ |
| 3579 | tx_buf->next_to_watch = NULL; |
| 3580 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3581 | tx_desc->buffer_addr = 0; |
| 3582 | tx_desc->cmd_type_offset_bsz = 0; |
| 3583 | /* move past filter desc */ |
| 3584 | tx_buf++; |
| 3585 | tx_desc++; |
| 3586 | i++; |
| 3587 | if (unlikely(!i)) { |
| 3588 | i -= tx_ring->count; |
| 3589 | tx_buf = tx_ring->tx_bi; |
| 3590 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3591 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3592 | /* unmap skb header data */ |
| 3593 | dma_unmap_single(tx_ring->dev, |
| 3594 | dma_unmap_addr(tx_buf, dma), |
| 3595 | dma_unmap_len(tx_buf, len), |
| 3596 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3597 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3598 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3599 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3600 | tx_buf->raw_buf = NULL; |
| 3601 | tx_buf->tx_flags = 0; |
| 3602 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3603 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3604 | tx_desc->buffer_addr = 0; |
| 3605 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3606 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3607 | /* 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] | 3608 | tx_buf++; |
| 3609 | tx_desc++; |
| 3610 | i++; |
| 3611 | if (unlikely(!i)) { |
| 3612 | i -= tx_ring->count; |
| 3613 | tx_buf = tx_ring->tx_bi; |
| 3614 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3615 | } |
| 3616 | |
| 3617 | /* update budget accounting */ |
| 3618 | budget--; |
| 3619 | } while (likely(budget)); |
| 3620 | |
| 3621 | i += tx_ring->count; |
| 3622 | tx_ring->next_to_clean = i; |
| 3623 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3624 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3625 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3626 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3627 | return budget > 0; |
| 3628 | } |
| 3629 | |
| 3630 | /** |
| 3631 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3632 | * @irq: interrupt number |
| 3633 | * @data: pointer to a q_vector |
| 3634 | **/ |
| 3635 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3636 | { |
| 3637 | struct i40e_q_vector *q_vector = data; |
| 3638 | struct i40e_vsi *vsi; |
| 3639 | |
| 3640 | if (!q_vector->tx.ring) |
| 3641 | return IRQ_HANDLED; |
| 3642 | |
| 3643 | vsi = q_vector->tx.ring->vsi; |
| 3644 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3645 | |
| 3646 | return IRQ_HANDLED; |
| 3647 | } |
| 3648 | |
| 3649 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3650 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3651 | * @vsi: the VSI being configured |
| 3652 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3653 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3654 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3655 | 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] | 3656 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3657 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3658 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3659 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3660 | |
| 3661 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3662 | tx_ring->next = q_vector->tx.ring; |
| 3663 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3664 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3665 | |
| 3666 | rx_ring->q_vector = q_vector; |
| 3667 | rx_ring->next = q_vector->rx.ring; |
| 3668 | q_vector->rx.ring = rx_ring; |
| 3669 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | /** |
| 3673 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3674 | * @vsi: the VSI being configured |
| 3675 | * |
| 3676 | * This function maps descriptor rings to the queue-specific vectors |
| 3677 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3678 | * one vector per queue pair, but on a constrained vector budget, we |
| 3679 | * group the queue pairs as "efficiently" as possible. |
| 3680 | **/ |
| 3681 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3682 | { |
| 3683 | int qp_remaining = vsi->num_queue_pairs; |
| 3684 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3685 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3686 | int v_start = 0; |
| 3687 | int qp_idx = 0; |
| 3688 | |
| 3689 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3690 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3691 | * It is also important to go through all the vectors available to be |
| 3692 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3693 | * are cleared. This is especially important when decreasing the |
| 3694 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3695 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3696 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3697 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3698 | |
| 3699 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3700 | |
| 3701 | q_vector->num_ringpairs = num_ringpairs; |
| 3702 | |
| 3703 | q_vector->rx.count = 0; |
| 3704 | q_vector->tx.count = 0; |
| 3705 | q_vector->rx.ring = NULL; |
| 3706 | q_vector->tx.ring = NULL; |
| 3707 | |
| 3708 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3709 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3710 | qp_idx++; |
| 3711 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3712 | } |
| 3713 | } |
| 3714 | } |
| 3715 | |
| 3716 | /** |
| 3717 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3718 | * @vsi: the VSI being configured |
| 3719 | * @basename: name for the vector |
| 3720 | **/ |
| 3721 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3722 | { |
| 3723 | struct i40e_pf *pf = vsi->back; |
| 3724 | int err; |
| 3725 | |
| 3726 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3727 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3728 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3729 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3730 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3731 | else |
| 3732 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3733 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3734 | |
| 3735 | if (err) |
| 3736 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3737 | |
| 3738 | return err; |
| 3739 | } |
| 3740 | |
| 3741 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3742 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3743 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3744 | * @netdev: network interface device structure |
| 3745 | * |
| 3746 | * This is used by netconsole to send skbs without having to re-enable |
| 3747 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3748 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3749 | #ifdef I40E_FCOE |
| 3750 | void i40e_netpoll(struct net_device *netdev) |
| 3751 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3752 | static void i40e_netpoll(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3753 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3754 | { |
| 3755 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3756 | struct i40e_vsi *vsi = np->vsi; |
| 3757 | struct i40e_pf *pf = vsi->back; |
| 3758 | int i; |
| 3759 | |
| 3760 | /* if interface is down do nothing */ |
| 3761 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3762 | return; |
| 3763 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3764 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3765 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3766 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3767 | } else { |
| 3768 | i40e_intr(pf->pdev->irq, netdev); |
| 3769 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3770 | } |
| 3771 | #endif |
| 3772 | |
| 3773 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3774 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3775 | * @pf: the PF being configured |
| 3776 | * @pf_q: the PF queue |
| 3777 | * @enable: enable or disable state of the queue |
| 3778 | * |
| 3779 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3780 | * enabled or disabled state. |
| 3781 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3782 | * multiple retries; else will return 0 in case of success. |
| 3783 | **/ |
| 3784 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3785 | { |
| 3786 | int i; |
| 3787 | u32 tx_reg; |
| 3788 | |
| 3789 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3790 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3791 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3792 | break; |
| 3793 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3794 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3795 | } |
| 3796 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3797 | return -ETIMEDOUT; |
| 3798 | |
| 3799 | return 0; |
| 3800 | } |
| 3801 | |
| 3802 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3803 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3804 | * @vsi: the VSI being configured |
| 3805 | * @enable: start or stop the rings |
| 3806 | **/ |
| 3807 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3808 | { |
| 3809 | struct i40e_pf *pf = vsi->back; |
| 3810 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3811 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3812 | u32 tx_reg; |
| 3813 | |
| 3814 | pf_q = vsi->base_queue; |
| 3815 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3816 | |
| 3817 | /* warn the TX unit of coming changes */ |
| 3818 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3819 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3820 | usleep_range(10, 20); |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3821 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3822 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3823 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3824 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3825 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3826 | break; |
| 3827 | usleep_range(1000, 2000); |
| 3828 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3829 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3830 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3831 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3832 | |
| 3833 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3834 | if (enable) { |
| 3835 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3836 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3837 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3838 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3839 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3840 | |
| 3841 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 3842 | /* No waiting for the Tx queue to disable */ |
| 3843 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3844 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3845 | |
| 3846 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3847 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 3848 | if (ret) { |
| 3849 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3850 | "VSI seid %d Tx ring %d %sable timeout\n", |
| 3851 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3852 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3853 | } |
| 3854 | } |
| 3855 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3856 | if (hw->revision_id == 0) |
| 3857 | mdelay(50); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3858 | return ret; |
| 3859 | } |
| 3860 | |
| 3861 | /** |
| 3862 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 3863 | * @pf: the PF being configured |
| 3864 | * @pf_q: the PF queue |
| 3865 | * @enable: enable or disable state of the queue |
| 3866 | * |
| 3867 | * This routine will wait for the given Rx queue of the PF to reach the |
| 3868 | * enabled or disabled state. |
| 3869 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3870 | * multiple retries; else will return 0 in case of success. |
| 3871 | **/ |
| 3872 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3873 | { |
| 3874 | int i; |
| 3875 | u32 rx_reg; |
| 3876 | |
| 3877 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3878 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 3879 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3880 | break; |
| 3881 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3882 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3883 | } |
| 3884 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3885 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3886 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3887 | return 0; |
| 3888 | } |
| 3889 | |
| 3890 | /** |
| 3891 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 3892 | * @vsi: the VSI being configured |
| 3893 | * @enable: start or stop the rings |
| 3894 | **/ |
| 3895 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 3896 | { |
| 3897 | struct i40e_pf *pf = vsi->back; |
| 3898 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3899 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3900 | u32 rx_reg; |
| 3901 | |
| 3902 | pf_q = vsi->base_queue; |
| 3903 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3904 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3905 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3906 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3907 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3908 | break; |
| 3909 | usleep_range(1000, 2000); |
| 3910 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3911 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3912 | /* Skip if the queue is already in the requested state */ |
| 3913 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3914 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3915 | |
| 3916 | /* turn on/off the queue */ |
| 3917 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3918 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3919 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3920 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3921 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 3922 | /* No waiting for the Tx queue to disable */ |
| 3923 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3924 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3925 | |
| 3926 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3927 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 3928 | if (ret) { |
| 3929 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3930 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 3931 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3932 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3933 | } |
| 3934 | } |
| 3935 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3936 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | /** |
| 3940 | * i40e_vsi_control_rings - Start or stop a VSI's rings |
| 3941 | * @vsi: the VSI being configured |
| 3942 | * @enable: start or stop the rings |
| 3943 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 3944 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3945 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3946 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3947 | |
| 3948 | /* do rx first for enable and last for disable */ |
| 3949 | if (request) { |
| 3950 | ret = i40e_vsi_control_rx(vsi, request); |
| 3951 | if (ret) |
| 3952 | return ret; |
| 3953 | ret = i40e_vsi_control_tx(vsi, request); |
| 3954 | } else { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3955 | /* Ignore return value, we need to shutdown whatever we can */ |
| 3956 | i40e_vsi_control_tx(vsi, request); |
| 3957 | i40e_vsi_control_rx(vsi, request); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3958 | } |
| 3959 | |
| 3960 | return ret; |
| 3961 | } |
| 3962 | |
| 3963 | /** |
| 3964 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 3965 | * @vsi: the VSI being configured |
| 3966 | **/ |
| 3967 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 3968 | { |
| 3969 | struct i40e_pf *pf = vsi->back; |
| 3970 | struct i40e_hw *hw = &pf->hw; |
| 3971 | int base = vsi->base_vector; |
| 3972 | u32 val, qp; |
| 3973 | int i; |
| 3974 | |
| 3975 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3976 | if (!vsi->q_vectors) |
| 3977 | return; |
| 3978 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3979 | if (!vsi->irqs_ready) |
| 3980 | return; |
| 3981 | |
| 3982 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3983 | for (i = 0; i < vsi->num_q_vectors; i++) { |
| 3984 | u16 vector = i + base; |
| 3985 | |
| 3986 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 3987 | if (!vsi->q_vectors[i] || |
| 3988 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3989 | continue; |
| 3990 | |
| 3991 | /* clear the affinity_mask in the IRQ descriptor */ |
| 3992 | irq_set_affinity_hint(pf->msix_entries[vector].vector, |
| 3993 | NULL); |
| 3994 | free_irq(pf->msix_entries[vector].vector, |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3995 | vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3996 | |
| 3997 | /* Tear down the interrupt queue link list |
| 3998 | * |
| 3999 | * We know that they come in pairs and always |
| 4000 | * the Rx first, then the Tx. To clear the |
| 4001 | * link list, stick the EOL value into the |
| 4002 | * next_q field of the registers. |
| 4003 | */ |
| 4004 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4005 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4006 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4007 | val |= I40E_QUEUE_END_OF_LIST |
| 4008 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4009 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4010 | |
| 4011 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4012 | u32 next; |
| 4013 | |
| 4014 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4015 | |
| 4016 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4017 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4018 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4019 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4020 | |
| 4021 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4022 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4023 | |
| 4024 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4025 | |
| 4026 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4027 | |
| 4028 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4029 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4030 | |
| 4031 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4032 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4033 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4034 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4035 | |
| 4036 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4037 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4038 | |
| 4039 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4040 | qp = next; |
| 4041 | } |
| 4042 | } |
| 4043 | } else { |
| 4044 | free_irq(pf->pdev->irq, pf); |
| 4045 | |
| 4046 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4047 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4048 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4049 | val |= I40E_QUEUE_END_OF_LIST |
| 4050 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4051 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4052 | |
| 4053 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4054 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4055 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4056 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4057 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4058 | |
| 4059 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4060 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4061 | |
| 4062 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4063 | |
| 4064 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4065 | |
| 4066 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4067 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4068 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4069 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4070 | |
| 4071 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4072 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4073 | |
| 4074 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4075 | } |
| 4076 | } |
| 4077 | |
| 4078 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4079 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4080 | * @vsi: the VSI being configured |
| 4081 | * @v_idx: Index of vector to be freed |
| 4082 | * |
| 4083 | * This function frees the memory allocated to the q_vector. In addition if |
| 4084 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4085 | * to freeing the q_vector. |
| 4086 | **/ |
| 4087 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4088 | { |
| 4089 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4090 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4091 | |
| 4092 | if (!q_vector) |
| 4093 | return; |
| 4094 | |
| 4095 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4096 | i40e_for_each_ring(ring, q_vector->tx) |
| 4097 | ring->q_vector = NULL; |
| 4098 | |
| 4099 | i40e_for_each_ring(ring, q_vector->rx) |
| 4100 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4101 | |
| 4102 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4103 | if (vsi->netdev) |
| 4104 | netif_napi_del(&q_vector->napi); |
| 4105 | |
| 4106 | vsi->q_vectors[v_idx] = NULL; |
| 4107 | |
| 4108 | kfree_rcu(q_vector, rcu); |
| 4109 | } |
| 4110 | |
| 4111 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4112 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4113 | * @vsi: the VSI being un-configured |
| 4114 | * |
| 4115 | * This frees the memory allocated to the q_vectors and |
| 4116 | * deletes references to the NAPI struct. |
| 4117 | **/ |
| 4118 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4119 | { |
| 4120 | int v_idx; |
| 4121 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4122 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4123 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | /** |
| 4127 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4128 | * @pf: board private structure |
| 4129 | **/ |
| 4130 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4131 | { |
| 4132 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4133 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4134 | pci_disable_msix(pf->pdev); |
| 4135 | kfree(pf->msix_entries); |
| 4136 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4137 | kfree(pf->irq_pile); |
| 4138 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4139 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4140 | pci_disable_msi(pf->pdev); |
| 4141 | } |
| 4142 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4143 | } |
| 4144 | |
| 4145 | /** |
| 4146 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4147 | * @pf: board private structure |
| 4148 | * |
| 4149 | * We go through and clear interrupt specific resources and reset the structure |
| 4150 | * to pre-load conditions |
| 4151 | **/ |
| 4152 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4153 | { |
| 4154 | int i; |
| 4155 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4156 | i40e_stop_misc_vector(pf); |
Shannon Nelson | 6927839 | 2016-03-10 14:59:43 -0800 | [diff] [blame] | 4157 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4158 | synchronize_irq(pf->msix_entries[0].vector); |
| 4159 | free_irq(pf->msix_entries[0].vector, pf); |
| 4160 | } |
| 4161 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4162 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4163 | I40E_IWARP_IRQ_PILE_ID); |
| 4164 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4165 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4166 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4167 | if (pf->vsi[i]) |
| 4168 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4169 | i40e_reset_interrupt_capability(pf); |
| 4170 | } |
| 4171 | |
| 4172 | /** |
| 4173 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4174 | * @vsi: the VSI being configured |
| 4175 | **/ |
| 4176 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4177 | { |
| 4178 | int q_idx; |
| 4179 | |
| 4180 | if (!vsi->netdev) |
| 4181 | return; |
| 4182 | |
| 4183 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4184 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4185 | } |
| 4186 | |
| 4187 | /** |
| 4188 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4189 | * @vsi: the VSI being configured |
| 4190 | **/ |
| 4191 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4192 | { |
| 4193 | int q_idx; |
| 4194 | |
| 4195 | if (!vsi->netdev) |
| 4196 | return; |
| 4197 | |
| 4198 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4199 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4200 | } |
| 4201 | |
| 4202 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4203 | * i40e_vsi_close - Shut down a VSI |
| 4204 | * @vsi: the vsi to be quelled |
| 4205 | **/ |
| 4206 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4207 | { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4208 | bool reset = false; |
| 4209 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4210 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4211 | i40e_down(vsi); |
| 4212 | i40e_vsi_free_irq(vsi); |
| 4213 | i40e_vsi_free_tx_resources(vsi); |
| 4214 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4215 | vsi->current_netdev_flags = 0; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4216 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4217 | reset = true; |
| 4218 | i40e_notify_client_of_netdev_close(vsi, reset); |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4222 | * i40e_quiesce_vsi - Pause a given VSI |
| 4223 | * @vsi: the VSI being paused |
| 4224 | **/ |
| 4225 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4226 | { |
| 4227 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4228 | return; |
| 4229 | |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4230 | /* No need to disable FCoE VSI when Tx suspended */ |
| 4231 | if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) && |
| 4232 | vsi->type == I40E_VSI_FCOE) { |
| 4233 | dev_dbg(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4234 | "VSI seid %d skipping FCoE VSI disable\n", vsi->seid); |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4235 | return; |
| 4236 | } |
| 4237 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4238 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4239 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4240 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4241 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4242 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4243 | } |
| 4244 | |
| 4245 | /** |
| 4246 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4247 | * @vsi: the VSI being resumed |
| 4248 | **/ |
| 4249 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4250 | { |
| 4251 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 4252 | return; |
| 4253 | |
| 4254 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4255 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4256 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4257 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4258 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | /** |
| 4262 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4263 | * @pf: the PF |
| 4264 | **/ |
| 4265 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4266 | { |
| 4267 | int v; |
| 4268 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4269 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4270 | if (pf->vsi[v]) |
| 4271 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4272 | } |
| 4273 | } |
| 4274 | |
| 4275 | /** |
| 4276 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4277 | * @pf: the PF |
| 4278 | **/ |
| 4279 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4280 | { |
| 4281 | int v; |
| 4282 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4283 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4284 | if (pf->vsi[v]) |
| 4285 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4286 | } |
| 4287 | } |
| 4288 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4289 | #ifdef CONFIG_I40E_DCB |
| 4290 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4291 | * 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] | 4292 | * @vsi: the VSI being configured |
| 4293 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4294 | * This function waits for the given VSI's queues to be disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4295 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4296 | static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4297 | { |
| 4298 | struct i40e_pf *pf = vsi->back; |
| 4299 | int i, pf_q, ret; |
| 4300 | |
| 4301 | pf_q = vsi->base_queue; |
| 4302 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4303 | /* Check and wait for the disable status of the queue */ |
| 4304 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4305 | if (ret) { |
| 4306 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4307 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4308 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4309 | return ret; |
| 4310 | } |
| 4311 | } |
| 4312 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4313 | pf_q = vsi->base_queue; |
| 4314 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4315 | /* Check and wait for the disable status of the queue */ |
| 4316 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4317 | if (ret) { |
| 4318 | dev_info(&pf->pdev->dev, |
| 4319 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4320 | vsi->seid, pf_q); |
| 4321 | return ret; |
| 4322 | } |
| 4323 | } |
| 4324 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4325 | return 0; |
| 4326 | } |
| 4327 | |
| 4328 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4329 | * 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] | 4330 | * @pf: the PF |
| 4331 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4332 | * 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] | 4333 | * VSIs that are managed by this PF. |
| 4334 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4335 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4336 | { |
| 4337 | int v, ret = 0; |
| 4338 | |
| 4339 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4340 | /* No need to wait for FCoE VSI queues */ |
| 4341 | if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4342 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4343 | if (ret) |
| 4344 | break; |
| 4345 | } |
| 4346 | } |
| 4347 | |
| 4348 | return ret; |
| 4349 | } |
| 4350 | |
| 4351 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4352 | |
| 4353 | /** |
| 4354 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4355 | * @q_idx: TX queue number |
| 4356 | * @vsi: Pointer to VSI struct |
| 4357 | * |
| 4358 | * This function checks specified queue for given VSI. Detects hung condition. |
| 4359 | * Sets hung bit since it is two step process. Before next run of service task |
| 4360 | * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not, |
| 4361 | * hung condition remain unchanged and during subsequent run, this function |
| 4362 | * issues SW interrupt to recover from hung condition. |
| 4363 | **/ |
| 4364 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4365 | { |
| 4366 | struct i40e_ring *tx_ring = NULL; |
| 4367 | struct i40e_pf *pf; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4368 | u32 head, val, tx_pending_hw; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4369 | int i; |
| 4370 | |
| 4371 | pf = vsi->back; |
| 4372 | |
| 4373 | /* now that we have an index, find the tx_ring struct */ |
| 4374 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4375 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4376 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4377 | tx_ring = vsi->tx_rings[i]; |
| 4378 | break; |
| 4379 | } |
| 4380 | } |
| 4381 | } |
| 4382 | |
| 4383 | if (!tx_ring) |
| 4384 | return; |
| 4385 | |
| 4386 | /* Read interrupt register */ |
| 4387 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4388 | val = rd32(&pf->hw, |
| 4389 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4390 | tx_ring->vsi->base_vector - 1)); |
| 4391 | else |
| 4392 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4393 | |
| 4394 | head = i40e_get_head(tx_ring); |
| 4395 | |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4396 | tx_pending_hw = i40e_get_tx_pending(tx_ring, false); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4397 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4398 | /* HW is done executing descriptors, updated HEAD write back, |
| 4399 | * but SW hasn't processed those descriptors. If interrupt is |
| 4400 | * not generated from this point ON, it could result into |
| 4401 | * dev_watchdog detecting timeout on those netdev_queue, |
| 4402 | * hence proactively trigger SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4403 | */ |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4404 | if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4405 | /* NAPI Poll didn't run and clear since it was set */ |
| 4406 | if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4407 | &tx_ring->q_vector->hung_detected)) { |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4408 | 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", |
| 4409 | vsi->seid, q_idx, tx_pending_hw, |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4410 | tx_ring->next_to_clean, head, |
| 4411 | tx_ring->next_to_use, |
| 4412 | readl(tx_ring->tail)); |
| 4413 | netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n", |
| 4414 | vsi->seid, q_idx, val); |
| 4415 | i40e_force_wb(vsi, tx_ring->q_vector); |
| 4416 | } else { |
| 4417 | /* First Chance - detected possible hung */ |
| 4418 | set_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4419 | &tx_ring->q_vector->hung_detected); |
| 4420 | } |
| 4421 | } |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4422 | |
| 4423 | /* This is the case where we have interrupts missing, |
| 4424 | * so the tx_pending in HW will most likely be 0, but we |
| 4425 | * will have tx_pending in SW since the WB happened but the |
| 4426 | * interrupt got lost. |
| 4427 | */ |
| 4428 | if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) && |
| 4429 | (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
| 4430 | if (napi_reschedule(&tx_ring->q_vector->napi)) |
| 4431 | tx_ring->tx_stats.tx_lost_interrupt++; |
| 4432 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4433 | } |
| 4434 | |
| 4435 | /** |
| 4436 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4437 | * @pf: pointer to PF struct |
| 4438 | * |
| 4439 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4440 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4441 | * SW interrupt. |
| 4442 | **/ |
| 4443 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4444 | { |
| 4445 | struct net_device *netdev; |
| 4446 | struct i40e_vsi *vsi; |
| 4447 | int i; |
| 4448 | |
| 4449 | /* Only for LAN VSI */ |
| 4450 | vsi = pf->vsi[pf->lan_vsi]; |
| 4451 | |
| 4452 | if (!vsi) |
| 4453 | return; |
| 4454 | |
| 4455 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
| 4456 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 4457 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4458 | return; |
| 4459 | |
| 4460 | /* Make sure type is MAIN VSI */ |
| 4461 | if (vsi->type != I40E_VSI_MAIN) |
| 4462 | return; |
| 4463 | |
| 4464 | netdev = vsi->netdev; |
| 4465 | if (!netdev) |
| 4466 | return; |
| 4467 | |
| 4468 | /* Bail out if netif_carrier is not OK */ |
| 4469 | if (!netif_carrier_ok(netdev)) |
| 4470 | return; |
| 4471 | |
| 4472 | /* Go thru' TX queues for netdev */ |
| 4473 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4474 | struct netdev_queue *q; |
| 4475 | |
| 4476 | q = netdev_get_tx_queue(netdev, i); |
| 4477 | if (q) |
| 4478 | i40e_detect_recover_hung_queue(i, vsi); |
| 4479 | } |
| 4480 | } |
| 4481 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4482 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4483 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4484 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4485 | * |
| 4486 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4487 | * and LAN TC. |
| 4488 | **/ |
| 4489 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4490 | { |
| 4491 | struct i40e_dcb_app_priority_table app; |
| 4492 | struct i40e_hw *hw = &pf->hw; |
| 4493 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4494 | u8 tc, i; |
| 4495 | /* Get the iSCSI APP TLV */ |
| 4496 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4497 | |
| 4498 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4499 | app = dcbcfg->app[i]; |
| 4500 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4501 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4502 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4503 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4504 | break; |
| 4505 | } |
| 4506 | } |
| 4507 | |
| 4508 | return enabled_tc; |
| 4509 | } |
| 4510 | |
| 4511 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4512 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4513 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4514 | * |
| 4515 | * Return the number of TCs from given DCBx configuration |
| 4516 | **/ |
| 4517 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4518 | { |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4519 | u8 num_tc = 0; |
| 4520 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4521 | |
| 4522 | /* Scan the ETS Config Priority Table to find |
| 4523 | * traffic class enabled for a given priority |
| 4524 | * and use the traffic class index to get the |
| 4525 | * number of traffic classes enabled |
| 4526 | */ |
| 4527 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4528 | if (dcbcfg->etscfg.prioritytable[i] > num_tc) |
| 4529 | num_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4530 | } |
| 4531 | |
| 4532 | /* Traffic class index starts from zero so |
| 4533 | * increment to return the actual count |
| 4534 | */ |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4535 | return num_tc + 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4536 | } |
| 4537 | |
| 4538 | /** |
| 4539 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4540 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4541 | * |
| 4542 | * Query the current DCB configuration and return the number of |
| 4543 | * traffic classes enabled from the given DCBX config |
| 4544 | **/ |
| 4545 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4546 | { |
| 4547 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4548 | u8 enabled_tc = 1; |
| 4549 | u8 i; |
| 4550 | |
| 4551 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4552 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4553 | |
| 4554 | return enabled_tc; |
| 4555 | } |
| 4556 | |
| 4557 | /** |
| 4558 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4559 | * @pf: PF being queried |
| 4560 | * |
| 4561 | * Return number of traffic classes enabled for the given PF |
| 4562 | **/ |
| 4563 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4564 | { |
| 4565 | struct i40e_hw *hw = &pf->hw; |
| 4566 | u8 i, enabled_tc; |
| 4567 | u8 num_tc = 0; |
| 4568 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4569 | |
| 4570 | /* If DCB is not enabled then always in single TC */ |
| 4571 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4572 | return 1; |
| 4573 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4574 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4575 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4576 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4577 | |
| 4578 | /* MFP mode return count of enabled TCs for this PF */ |
| 4579 | if (pf->hw.func_caps.iscsi) |
| 4580 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4581 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4582 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4583 | |
| 4584 | /* At least have TC0 */ |
| 4585 | enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 4586 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4587 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4588 | num_tc++; |
| 4589 | } |
| 4590 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4591 | } |
| 4592 | |
| 4593 | /** |
| 4594 | * i40e_pf_get_default_tc - Get bitmap for first enabled TC |
| 4595 | * @pf: PF being queried |
| 4596 | * |
| 4597 | * Return a bitmap for first enabled traffic class for this PF. |
| 4598 | **/ |
| 4599 | static u8 i40e_pf_get_default_tc(struct i40e_pf *pf) |
| 4600 | { |
| 4601 | u8 enabled_tc = pf->hw.func_caps.enabled_tcmap; |
| 4602 | u8 i = 0; |
| 4603 | |
| 4604 | if (!enabled_tc) |
| 4605 | return 0x1; /* TC0 */ |
| 4606 | |
| 4607 | /* Find the first enabled TC */ |
| 4608 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4609 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4610 | break; |
| 4611 | } |
| 4612 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4613 | return BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4614 | } |
| 4615 | |
| 4616 | /** |
| 4617 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4618 | * @pf: PF being queried |
| 4619 | * |
| 4620 | * Return a bitmap for enabled traffic classes for this PF. |
| 4621 | **/ |
| 4622 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4623 | { |
| 4624 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4625 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4626 | return i40e_pf_get_default_tc(pf); |
| 4627 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4628 | /* SFP mode we want PF to be enabled for all TCs */ |
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_enabled_tc(&pf->hw.local_dcbx_config); |
| 4631 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4632 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4633 | if (pf->hw.func_caps.iscsi) |
| 4634 | return i40e_get_iscsi_tc_map(pf); |
| 4635 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4636 | return i40e_pf_get_default_tc(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | /** |
| 4640 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4641 | * @vsi: the VSI being queried |
| 4642 | * |
| 4643 | * Returns 0 on success, negative value on failure |
| 4644 | **/ |
| 4645 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4646 | { |
| 4647 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4648 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4649 | struct i40e_pf *pf = vsi->back; |
| 4650 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4651 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4652 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4653 | int i; |
| 4654 | |
| 4655 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4656 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4657 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4658 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4659 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4660 | i40e_stat_str(&pf->hw, ret), |
| 4661 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4662 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4666 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4667 | NULL); |
| 4668 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4669 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4670 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4671 | i40e_stat_str(&pf->hw, ret), |
| 4672 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4673 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4674 | } |
| 4675 | |
| 4676 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4677 | dev_info(&pf->pdev->dev, |
| 4678 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4679 | bw_config.tc_valid_bits, |
| 4680 | bw_ets_config.tc_valid_bits); |
| 4681 | /* Still continuing */ |
| 4682 | } |
| 4683 | |
| 4684 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4685 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4686 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4687 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4688 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4689 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4690 | vsi->bw_ets_limit_credits[i] = |
| 4691 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4692 | /* 3 bits out of 4 for each TC */ |
| 4693 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4694 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4695 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4696 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | /** |
| 4700 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4701 | * @vsi: the VSI being configured |
| 4702 | * @enabled_tc: TC bitmap |
| 4703 | * @bw_credits: BW shared credits per TC |
| 4704 | * |
| 4705 | * Returns 0 on success, negative value on failure |
| 4706 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4707 | 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] | 4708 | u8 *bw_share) |
| 4709 | { |
| 4710 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4711 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4712 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4713 | |
| 4714 | bw_data.tc_valid_bits = enabled_tc; |
| 4715 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4716 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4717 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4718 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4719 | NULL); |
| 4720 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4721 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4722 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4723 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4724 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4728 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4729 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4730 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4731 | } |
| 4732 | |
| 4733 | /** |
| 4734 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4735 | * @vsi: the VSI being configured |
| 4736 | * @enabled_tc: TC map to be enabled |
| 4737 | * |
| 4738 | **/ |
| 4739 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4740 | { |
| 4741 | struct net_device *netdev = vsi->netdev; |
| 4742 | struct i40e_pf *pf = vsi->back; |
| 4743 | struct i40e_hw *hw = &pf->hw; |
| 4744 | u8 netdev_tc = 0; |
| 4745 | int i; |
| 4746 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4747 | |
| 4748 | if (!netdev) |
| 4749 | return; |
| 4750 | |
| 4751 | if (!enabled_tc) { |
| 4752 | netdev_reset_tc(netdev); |
| 4753 | return; |
| 4754 | } |
| 4755 | |
| 4756 | /* Set up actual enabled TCs on the VSI */ |
| 4757 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 4758 | return; |
| 4759 | |
| 4760 | /* set per TC queues for the VSI */ |
| 4761 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4762 | /* Only set TC queues for enabled tcs |
| 4763 | * |
| 4764 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 4765 | * enabled_tc bitmap would be 0x00001001; the driver |
| 4766 | * will set the numtc for netdev as 2 that will be |
| 4767 | * referenced by the netdev layer as TC 0 and 1. |
| 4768 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4769 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4770 | netdev_set_tc_queue(netdev, |
| 4771 | vsi->tc_config.tc_info[i].netdev_tc, |
| 4772 | vsi->tc_config.tc_info[i].qcount, |
| 4773 | vsi->tc_config.tc_info[i].qoffset); |
| 4774 | } |
| 4775 | |
| 4776 | /* Assign UP2TC map for the VSI */ |
| 4777 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4778 | /* Get the actual TC# for the UP */ |
| 4779 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4780 | /* Get the mapped netdev TC# for the UP */ |
| 4781 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 4782 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 4783 | } |
| 4784 | } |
| 4785 | |
| 4786 | /** |
| 4787 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 4788 | * @vsi: the VSI being configured |
| 4789 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 4790 | **/ |
| 4791 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 4792 | struct i40e_vsi_context *ctxt) |
| 4793 | { |
| 4794 | /* copy just the sections touched not the entire info |
| 4795 | * since not all sections are valid as returned by |
| 4796 | * update vsi params |
| 4797 | */ |
| 4798 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 4799 | memcpy(&vsi->info.queue_mapping, |
| 4800 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 4801 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 4802 | sizeof(vsi->info.tc_mapping)); |
| 4803 | } |
| 4804 | |
| 4805 | /** |
| 4806 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 4807 | * @vsi: VSI to be configured |
| 4808 | * @enabled_tc: TC bitmap |
| 4809 | * |
| 4810 | * This configures a particular VSI for TCs that are mapped to the |
| 4811 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 4812 | * VSIs to configure TC for a particular VSI. |
| 4813 | * |
| 4814 | * NOTE: |
| 4815 | * It is expected that the VSI queues have been quisced before calling |
| 4816 | * this function. |
| 4817 | **/ |
| 4818 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4819 | { |
| 4820 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 4821 | struct i40e_vsi_context ctxt; |
| 4822 | int ret = 0; |
| 4823 | int i; |
| 4824 | |
| 4825 | /* Check if enabled_tc is same as existing or new TCs */ |
| 4826 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 4827 | return ret; |
| 4828 | |
| 4829 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 4830 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4831 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4832 | bw_share[i] = 1; |
| 4833 | } |
| 4834 | |
| 4835 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 4836 | if (ret) { |
| 4837 | dev_info(&vsi->back->pdev->dev, |
| 4838 | "Failed configuring TC map %d for VSI %d\n", |
| 4839 | enabled_tc, vsi->seid); |
| 4840 | goto out; |
| 4841 | } |
| 4842 | |
| 4843 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 4844 | ctxt.seid = vsi->seid; |
| 4845 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 4846 | ctxt.vf_num = 0; |
| 4847 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 4848 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4849 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 4850 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4851 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 4852 | ctxt.info.valid_sections |= |
| 4853 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 4854 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 4855 | } |
| 4856 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4857 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 4858 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 4859 | if (ret) { |
| 4860 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4861 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 4862 | i40e_stat_str(&vsi->back->hw, ret), |
| 4863 | i40e_aq_str(&vsi->back->hw, |
| 4864 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4865 | goto out; |
| 4866 | } |
| 4867 | /* update the local VSI info with updated queue map */ |
| 4868 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 4869 | vsi->info.valid_sections = 0; |
| 4870 | |
| 4871 | /* Update current VSI BW information */ |
| 4872 | ret = i40e_vsi_get_bw_info(vsi); |
| 4873 | if (ret) { |
| 4874 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4875 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 4876 | i40e_stat_str(&vsi->back->hw, ret), |
| 4877 | i40e_aq_str(&vsi->back->hw, |
| 4878 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4879 | goto out; |
| 4880 | } |
| 4881 | |
| 4882 | /* Update the netdev TC setup */ |
| 4883 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 4884 | out: |
| 4885 | return ret; |
| 4886 | } |
| 4887 | |
| 4888 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4889 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 4890 | * @veb: given VEB |
| 4891 | * @enabled_tc: TC bitmap |
| 4892 | * |
| 4893 | * Configures given TC bitmap for VEB (switching) element |
| 4894 | **/ |
| 4895 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 4896 | { |
| 4897 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 4898 | struct i40e_pf *pf = veb->pf; |
| 4899 | int ret = 0; |
| 4900 | int i; |
| 4901 | |
| 4902 | /* No TCs or already enabled TCs just return */ |
| 4903 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 4904 | return ret; |
| 4905 | |
| 4906 | bw_data.tc_valid_bits = enabled_tc; |
| 4907 | /* bw_data.absolute_credits is not set (relative) */ |
| 4908 | |
| 4909 | /* Enable ETS TCs with equal BW Share for now */ |
| 4910 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4911 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4912 | bw_data.tc_bw_share_credits[i] = 1; |
| 4913 | } |
| 4914 | |
| 4915 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 4916 | &bw_data, NULL); |
| 4917 | if (ret) { |
| 4918 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4919 | "VEB bw config failed, err %s aq_err %s\n", |
| 4920 | i40e_stat_str(&pf->hw, ret), |
| 4921 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4922 | goto out; |
| 4923 | } |
| 4924 | |
| 4925 | /* Update the BW information */ |
| 4926 | ret = i40e_veb_get_bw_info(veb); |
| 4927 | if (ret) { |
| 4928 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4929 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 4930 | i40e_stat_str(&pf->hw, ret), |
| 4931 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | out: |
| 4935 | return ret; |
| 4936 | } |
| 4937 | |
| 4938 | #ifdef CONFIG_I40E_DCB |
| 4939 | /** |
| 4940 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 4941 | * @pf: PF struct |
| 4942 | * |
| 4943 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 4944 | * the caller would've quiesce all the VSIs before calling |
| 4945 | * this function |
| 4946 | **/ |
| 4947 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 4948 | { |
| 4949 | u8 tc_map = 0; |
| 4950 | int ret; |
| 4951 | u8 v; |
| 4952 | |
| 4953 | /* Enable the TCs available on PF to all VEBs */ |
| 4954 | tc_map = i40e_pf_get_tc_map(pf); |
| 4955 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 4956 | if (!pf->veb[v]) |
| 4957 | continue; |
| 4958 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 4959 | if (ret) { |
| 4960 | dev_info(&pf->pdev->dev, |
| 4961 | "Failed configuring TC for VEB seid=%d\n", |
| 4962 | pf->veb[v]->seid); |
| 4963 | /* Will try to configure as many components */ |
| 4964 | } |
| 4965 | } |
| 4966 | |
| 4967 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4968 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4969 | if (!pf->vsi[v]) |
| 4970 | continue; |
| 4971 | |
| 4972 | /* - Enable all TCs for the LAN VSI |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4973 | #ifdef I40E_FCOE |
| 4974 | * - For FCoE VSI only enable the TC configured |
| 4975 | * as per the APP TLV |
| 4976 | #endif |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4977 | * - For all others keep them at TC0 for now |
| 4978 | */ |
| 4979 | if (v == pf->lan_vsi) |
| 4980 | tc_map = i40e_pf_get_tc_map(pf); |
| 4981 | else |
| 4982 | tc_map = i40e_pf_get_default_tc(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4983 | #ifdef I40E_FCOE |
| 4984 | if (pf->vsi[v]->type == I40E_VSI_FCOE) |
| 4985 | tc_map = i40e_get_fcoe_tc_map(pf); |
| 4986 | #endif /* #ifdef I40E_FCOE */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4987 | |
| 4988 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 4989 | if (ret) { |
| 4990 | dev_info(&pf->pdev->dev, |
| 4991 | "Failed configuring TC for VSI seid=%d\n", |
| 4992 | pf->vsi[v]->seid); |
| 4993 | /* Will try to configure as many components */ |
| 4994 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 4995 | /* Re-configure VSI vectors based on updated TC map */ |
| 4996 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4997 | if (pf->vsi[v]->netdev) |
| 4998 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 4999 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5000 | i40e_notify_client_of_l2_param_changes(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5001 | } |
| 5002 | } |
| 5003 | |
| 5004 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5005 | * i40e_resume_port_tx - Resume port Tx |
| 5006 | * @pf: PF struct |
| 5007 | * |
| 5008 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 5009 | * resume. |
| 5010 | **/ |
| 5011 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 5012 | { |
| 5013 | struct i40e_hw *hw = &pf->hw; |
| 5014 | int ret; |
| 5015 | |
| 5016 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 5017 | if (ret) { |
| 5018 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5019 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 5020 | i40e_stat_str(&pf->hw, ret), |
| 5021 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5022 | /* Schedule PF reset to recover */ |
| 5023 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5024 | i40e_service_event_schedule(pf); |
| 5025 | } |
| 5026 | |
| 5027 | return ret; |
| 5028 | } |
| 5029 | |
| 5030 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5031 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 5032 | * @pf: PF being configured |
| 5033 | * |
| 5034 | * Query the current DCB configuration and cache it |
| 5035 | * in the hardware structure |
| 5036 | **/ |
| 5037 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 5038 | { |
| 5039 | struct i40e_hw *hw = &pf->hw; |
| 5040 | int err = 0; |
| 5041 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5042 | /* 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] | 5043 | if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5044 | goto out; |
| 5045 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5046 | /* Get the initial DCB configuration */ |
| 5047 | err = i40e_init_dcb(hw); |
| 5048 | if (!err) { |
| 5049 | /* Device/Function is not DCBX capable */ |
| 5050 | if ((!hw->func_caps.dcb) || |
| 5051 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5052 | dev_info(&pf->pdev->dev, |
| 5053 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 5054 | |
| 5055 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 5056 | goto out; |
| 5057 | |
| 5058 | } else { |
| 5059 | /* When status is not DISABLED then DCBX in FW */ |
| 5060 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5061 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5062 | |
| 5063 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
| 5064 | /* Enable DCB tagging only when more than one TC */ |
| 5065 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5066 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5067 | dev_dbg(&pf->pdev->dev, |
| 5068 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5069 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5070 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5071 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5072 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5073 | i40e_stat_str(&pf->hw, err), |
| 5074 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5075 | } |
| 5076 | |
| 5077 | out: |
| 5078 | return err; |
| 5079 | } |
| 5080 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5081 | #define SPEED_SIZE 14 |
| 5082 | #define FC_SIZE 8 |
| 5083 | /** |
| 5084 | * i40e_print_link_message - print link up or down |
| 5085 | * @vsi: the VSI for which link needs a message |
| 5086 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5087 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5088 | { |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5089 | char *speed = "Unknown"; |
| 5090 | char *fc = "Unknown"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5091 | |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5092 | if (vsi->current_isup == isup) |
| 5093 | return; |
| 5094 | vsi->current_isup = isup; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5095 | if (!isup) { |
| 5096 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5097 | return; |
| 5098 | } |
| 5099 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5100 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5101 | * least 10GB |
| 5102 | */ |
| 5103 | if (vsi->back->hw.func_caps.npar_enable && |
| 5104 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5105 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5106 | netdev_warn(vsi->netdev, |
| 5107 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5108 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5109 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5110 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5111 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5112 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5113 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5114 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5115 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5116 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5117 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5118 | break; |
| 5119 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5120 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5121 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5122 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5123 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5124 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5125 | default: |
| 5126 | break; |
| 5127 | } |
| 5128 | |
| 5129 | switch (vsi->back->hw.fc.current_mode) { |
| 5130 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5131 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5132 | break; |
| 5133 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5134 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5135 | break; |
| 5136 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5137 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5138 | break; |
| 5139 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5140 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5141 | break; |
| 5142 | } |
| 5143 | |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5144 | 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] | 5145 | speed, fc); |
| 5146 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5147 | |
| 5148 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5149 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5150 | * @vsi: the VSI being configured |
| 5151 | **/ |
| 5152 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5153 | { |
| 5154 | struct i40e_pf *pf = vsi->back; |
| 5155 | int err; |
| 5156 | |
| 5157 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5158 | i40e_vsi_configure_msix(vsi); |
| 5159 | else |
| 5160 | i40e_configure_msi_and_legacy(vsi); |
| 5161 | |
| 5162 | /* start rings */ |
| 5163 | err = i40e_vsi_control_rings(vsi, true); |
| 5164 | if (err) |
| 5165 | return err; |
| 5166 | |
| 5167 | clear_bit(__I40E_DOWN, &vsi->state); |
| 5168 | i40e_napi_enable_all(vsi); |
| 5169 | i40e_vsi_enable_irq(vsi); |
| 5170 | |
| 5171 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5172 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5173 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5174 | netif_tx_start_all_queues(vsi->netdev); |
| 5175 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5176 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5177 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5178 | /* need to check for qualified module here*/ |
| 5179 | if ((pf->hw.phy.link_info.link_info & |
| 5180 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5181 | (!(pf->hw.phy.link_info.an_info & |
| 5182 | I40E_AQ_QUALIFIED_MODULE))) |
| 5183 | netdev_err(vsi->netdev, |
| 5184 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5185 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5186 | |
| 5187 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5188 | if (vsi->type == I40E_VSI_FDIR) { |
| 5189 | /* reset fd counters */ |
| 5190 | pf->fd_add_err = pf->fd_atr_cnt = 0; |
| 5191 | if (pf->fd_tcp_rule > 0) { |
| 5192 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5193 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5194 | 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] | 5195 | pf->fd_tcp_rule = 0; |
| 5196 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5197 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5198 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5199 | |
| 5200 | /* On the next run of the service_task, notify any clients of the new |
| 5201 | * opened netdev |
| 5202 | */ |
| 5203 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5204 | i40e_service_event_schedule(pf); |
| 5205 | |
| 5206 | return 0; |
| 5207 | } |
| 5208 | |
| 5209 | /** |
| 5210 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5211 | * @vsi: the VSI being configured |
| 5212 | * |
| 5213 | * Rebuild the ring structs after some configuration |
| 5214 | * has changed, e.g. MTU size. |
| 5215 | **/ |
| 5216 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5217 | { |
| 5218 | struct i40e_pf *pf = vsi->back; |
| 5219 | |
| 5220 | WARN_ON(in_interrupt()); |
| 5221 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5222 | usleep_range(1000, 2000); |
| 5223 | i40e_down(vsi); |
| 5224 | |
| 5225 | /* Give a VF some time to respond to the reset. The |
| 5226 | * two second wait is based upon the watchdog cycle in |
| 5227 | * the VF driver. |
| 5228 | */ |
| 5229 | if (vsi->type == I40E_VSI_SRIOV) |
| 5230 | msleep(2000); |
| 5231 | i40e_up(vsi); |
| 5232 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 5233 | } |
| 5234 | |
| 5235 | /** |
| 5236 | * i40e_up - Bring the connection back up after being down |
| 5237 | * @vsi: the VSI being configured |
| 5238 | **/ |
| 5239 | int i40e_up(struct i40e_vsi *vsi) |
| 5240 | { |
| 5241 | int err; |
| 5242 | |
| 5243 | err = i40e_vsi_configure(vsi); |
| 5244 | if (!err) |
| 5245 | err = i40e_up_complete(vsi); |
| 5246 | |
| 5247 | return err; |
| 5248 | } |
| 5249 | |
| 5250 | /** |
| 5251 | * i40e_down - Shutdown the connection processing |
| 5252 | * @vsi: the VSI being stopped |
| 5253 | **/ |
| 5254 | void i40e_down(struct i40e_vsi *vsi) |
| 5255 | { |
| 5256 | int i; |
| 5257 | |
| 5258 | /* It is assumed that the caller of this function |
| 5259 | * sets the vsi->state __I40E_DOWN bit. |
| 5260 | */ |
| 5261 | if (vsi->netdev) { |
| 5262 | netif_carrier_off(vsi->netdev); |
| 5263 | netif_tx_disable(vsi->netdev); |
| 5264 | } |
| 5265 | i40e_vsi_disable_irq(vsi); |
| 5266 | i40e_vsi_control_rings(vsi, false); |
| 5267 | i40e_napi_disable_all(vsi); |
| 5268 | |
| 5269 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5270 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 5271 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5272 | } |
| 5273 | } |
| 5274 | |
| 5275 | /** |
| 5276 | * i40e_setup_tc - configure multiple traffic classes |
| 5277 | * @netdev: net device to configure |
| 5278 | * @tc: number of traffic classes to enable |
| 5279 | **/ |
| 5280 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5281 | { |
| 5282 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5283 | struct i40e_vsi *vsi = np->vsi; |
| 5284 | struct i40e_pf *pf = vsi->back; |
| 5285 | u8 enabled_tc = 0; |
| 5286 | int ret = -EINVAL; |
| 5287 | int i; |
| 5288 | |
| 5289 | /* Check if DCB enabled to continue */ |
| 5290 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5291 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5292 | goto exit; |
| 5293 | } |
| 5294 | |
| 5295 | /* Check if MFP enabled */ |
| 5296 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5297 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5298 | goto exit; |
| 5299 | } |
| 5300 | |
| 5301 | /* Check whether tc count is within enabled limit */ |
| 5302 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5303 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5304 | goto exit; |
| 5305 | } |
| 5306 | |
| 5307 | /* Generate TC map for number of tc requested */ |
| 5308 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5309 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5310 | |
| 5311 | /* Requesting same TC configuration as already enabled */ |
| 5312 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5313 | return 0; |
| 5314 | |
| 5315 | /* Quiesce VSI queues */ |
| 5316 | i40e_quiesce_vsi(vsi); |
| 5317 | |
| 5318 | /* Configure VSI for enabled TCs */ |
| 5319 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5320 | if (ret) { |
| 5321 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5322 | vsi->seid); |
| 5323 | goto exit; |
| 5324 | } |
| 5325 | |
| 5326 | /* Unquiesce VSI */ |
| 5327 | i40e_unquiesce_vsi(vsi); |
| 5328 | |
| 5329 | exit: |
| 5330 | return ret; |
| 5331 | } |
| 5332 | |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5333 | #ifdef I40E_FCOE |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5334 | int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5335 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5336 | #else |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5337 | static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5338 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5339 | #endif |
| 5340 | { |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5341 | if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5342 | return -EINVAL; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5343 | return i40e_setup_tc(netdev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5344 | } |
| 5345 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5346 | /** |
| 5347 | * i40e_open - Called when a network interface is made active |
| 5348 | * @netdev: network interface device structure |
| 5349 | * |
| 5350 | * The open entry point is called when a network interface is made |
| 5351 | * active by the system (IFF_UP). At this point all resources needed |
| 5352 | * for transmit and receive operations are allocated, the interrupt |
| 5353 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5354 | * enabled, and the stack is notified that the interface is ready. |
| 5355 | * |
| 5356 | * Returns 0 on success, negative value on failure |
| 5357 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5358 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5359 | { |
| 5360 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5361 | struct i40e_vsi *vsi = np->vsi; |
| 5362 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5363 | int err; |
| 5364 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5365 | /* disallow open during test or if eeprom is broken */ |
| 5366 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 5367 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5368 | return -EBUSY; |
| 5369 | |
| 5370 | netif_carrier_off(netdev); |
| 5371 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5372 | err = i40e_vsi_open(vsi); |
| 5373 | if (err) |
| 5374 | return err; |
| 5375 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5376 | /* configure global TSO hardware offload settings */ |
| 5377 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5378 | TCP_FLAG_FIN) >> 16); |
| 5379 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5380 | TCP_FLAG_FIN | |
| 5381 | TCP_FLAG_CWR) >> 16); |
| 5382 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5383 | |
Singhai, Anjali | 6633d38 | 2015-12-03 23:49:31 -0800 | [diff] [blame] | 5384 | #ifdef CONFIG_I40E_VXLAN |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5385 | vxlan_get_rx_port(netdev); |
| 5386 | #endif |
Singhai, Anjali | cd86660 | 2015-12-14 12:21:21 -0800 | [diff] [blame] | 5387 | #ifdef CONFIG_I40E_GENEVE |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 5388 | if (pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE) |
| 5389 | geneve_get_rx_port(netdev); |
Singhai, Anjali | cd86660 | 2015-12-14 12:21:21 -0800 | [diff] [blame] | 5390 | #endif |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5391 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5392 | i40e_notify_client_of_netdev_open(vsi); |
| 5393 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5394 | return 0; |
| 5395 | } |
| 5396 | |
| 5397 | /** |
| 5398 | * i40e_vsi_open - |
| 5399 | * @vsi: the VSI to open |
| 5400 | * |
| 5401 | * Finish initialization of the VSI. |
| 5402 | * |
| 5403 | * Returns 0 on success, negative value on failure |
| 5404 | **/ |
| 5405 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5406 | { |
| 5407 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5408 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5409 | int err; |
| 5410 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5411 | /* allocate descriptors */ |
| 5412 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5413 | if (err) |
| 5414 | goto err_setup_tx; |
| 5415 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5416 | if (err) |
| 5417 | goto err_setup_rx; |
| 5418 | |
| 5419 | err = i40e_vsi_configure(vsi); |
| 5420 | if (err) |
| 5421 | goto err_setup_rx; |
| 5422 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5423 | if (vsi->netdev) { |
| 5424 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5425 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5426 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5427 | if (err) |
| 5428 | goto err_setup_rx; |
| 5429 | |
| 5430 | /* Notify the stack of the actual queue counts. */ |
| 5431 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5432 | vsi->num_queue_pairs); |
| 5433 | if (err) |
| 5434 | goto err_set_queues; |
| 5435 | |
| 5436 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5437 | vsi->num_queue_pairs); |
| 5438 | if (err) |
| 5439 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5440 | |
| 5441 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5442 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5443 | dev_driver_string(&pf->pdev->dev), |
| 5444 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5445 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5446 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5447 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5448 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5449 | goto err_setup_rx; |
| 5450 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5451 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5452 | err = i40e_up_complete(vsi); |
| 5453 | if (err) |
| 5454 | goto err_up_complete; |
| 5455 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5456 | return 0; |
| 5457 | |
| 5458 | err_up_complete: |
| 5459 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5460 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5461 | i40e_vsi_free_irq(vsi); |
| 5462 | err_setup_rx: |
| 5463 | i40e_vsi_free_rx_resources(vsi); |
| 5464 | err_setup_tx: |
| 5465 | i40e_vsi_free_tx_resources(vsi); |
| 5466 | if (vsi == pf->vsi[pf->lan_vsi]) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5467 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5468 | |
| 5469 | return err; |
| 5470 | } |
| 5471 | |
| 5472 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5473 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5474 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5475 | * |
| 5476 | * This function destroys the hlist where all the Flow Director |
| 5477 | * filters were saved. |
| 5478 | **/ |
| 5479 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5480 | { |
| 5481 | struct i40e_fdir_filter *filter; |
| 5482 | struct hlist_node *node2; |
| 5483 | |
| 5484 | hlist_for_each_entry_safe(filter, node2, |
| 5485 | &pf->fdir_filter_list, fdir_node) { |
| 5486 | hlist_del(&filter->fdir_node); |
| 5487 | kfree(filter); |
| 5488 | } |
| 5489 | pf->fdir_pf_active_filters = 0; |
| 5490 | } |
| 5491 | |
| 5492 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5493 | * i40e_close - Disables a network interface |
| 5494 | * @netdev: network interface device structure |
| 5495 | * |
| 5496 | * The close entry point is called when an interface is de-activated |
| 5497 | * by the OS. The hardware is still under the driver's control, but |
| 5498 | * this netdev interface is disabled. |
| 5499 | * |
| 5500 | * Returns 0, this is not allowed to fail |
| 5501 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5502 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5503 | { |
| 5504 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5505 | struct i40e_vsi *vsi = np->vsi; |
| 5506 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5507 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5508 | |
| 5509 | return 0; |
| 5510 | } |
| 5511 | |
| 5512 | /** |
| 5513 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5514 | * @pf: board private structure |
| 5515 | * @reset_flags: which reset is requested |
| 5516 | * |
| 5517 | * The essential difference in resets is that the PF Reset |
| 5518 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5519 | * firmware, and doesn't bother the other PFs on the chip. |
| 5520 | **/ |
| 5521 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5522 | { |
| 5523 | u32 val; |
| 5524 | |
| 5525 | WARN_ON(in_interrupt()); |
| 5526 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5527 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5528 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5529 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5530 | |
| 5531 | /* Request a Global Reset |
| 5532 | * |
| 5533 | * This will start the chip's countdown to the actual full |
| 5534 | * chip reset event, and a warning interrupt to be sent |
| 5535 | * to all PFs, including the requestor. Our handler |
| 5536 | * for the warning interrupt will deal with the shutdown |
| 5537 | * and recovery of the switch setup. |
| 5538 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5539 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5540 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5541 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5542 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5543 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5544 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5545 | |
| 5546 | /* Request a Core Reset |
| 5547 | * |
| 5548 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5549 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5550 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5551 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5552 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5553 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5554 | i40e_flush(&pf->hw); |
| 5555 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5556 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5557 | |
| 5558 | /* Request a PF Reset |
| 5559 | * |
| 5560 | * Resets only the PF-specific registers |
| 5561 | * |
| 5562 | * This goes directly to the tear-down and rebuild of |
| 5563 | * the switch, since we need to do all the recovery as |
| 5564 | * for the Core Reset. |
| 5565 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5566 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5567 | i40e_handle_reset_warning(pf); |
| 5568 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5569 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5570 | int v; |
| 5571 | |
| 5572 | /* Find the VSI(s) that requested a re-init */ |
| 5573 | dev_info(&pf->pdev->dev, |
| 5574 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5575 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5576 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5577 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5578 | if (vsi != NULL && |
| 5579 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5580 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5581 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5582 | } |
| 5583 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5584 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5585 | int v; |
| 5586 | |
| 5587 | /* Find the VSI(s) that needs to be brought down */ |
| 5588 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5589 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5590 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5591 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5592 | if (vsi != NULL && |
| 5593 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5594 | set_bit(__I40E_DOWN, &vsi->state); |
| 5595 | i40e_down(vsi); |
| 5596 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5597 | } |
| 5598 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5599 | } else { |
| 5600 | dev_info(&pf->pdev->dev, |
| 5601 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5602 | } |
| 5603 | } |
| 5604 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5605 | #ifdef CONFIG_I40E_DCB |
| 5606 | /** |
| 5607 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5608 | * @pf: board private structure |
| 5609 | * @old_cfg: current DCB config |
| 5610 | * @new_cfg: new DCB config |
| 5611 | **/ |
| 5612 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5613 | struct i40e_dcbx_config *old_cfg, |
| 5614 | struct i40e_dcbx_config *new_cfg) |
| 5615 | { |
| 5616 | bool need_reconfig = false; |
| 5617 | |
| 5618 | /* Check if ETS configuration has changed */ |
| 5619 | if (memcmp(&new_cfg->etscfg, |
| 5620 | &old_cfg->etscfg, |
| 5621 | sizeof(new_cfg->etscfg))) { |
| 5622 | /* If Priority Table has changed reconfig is needed */ |
| 5623 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5624 | &old_cfg->etscfg.prioritytable, |
| 5625 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5626 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5627 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5631 | &old_cfg->etscfg.tcbwtable, |
| 5632 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5633 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5634 | |
| 5635 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5636 | &old_cfg->etscfg.tsatable, |
| 5637 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5638 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | /* Check if PFC configuration has changed */ |
| 5642 | if (memcmp(&new_cfg->pfc, |
| 5643 | &old_cfg->pfc, |
| 5644 | sizeof(new_cfg->pfc))) { |
| 5645 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5646 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5647 | } |
| 5648 | |
| 5649 | /* Check if APP Table has changed */ |
| 5650 | if (memcmp(&new_cfg->app, |
| 5651 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5652 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5653 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5654 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5655 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5656 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5657 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5658 | return need_reconfig; |
| 5659 | } |
| 5660 | |
| 5661 | /** |
| 5662 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5663 | * @pf: board private structure |
| 5664 | * @e: event info posted on ARQ |
| 5665 | **/ |
| 5666 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5667 | struct i40e_arq_event_info *e) |
| 5668 | { |
| 5669 | struct i40e_aqc_lldp_get_mib *mib = |
| 5670 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5671 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5672 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5673 | bool need_reconfig = false; |
| 5674 | int ret = 0; |
| 5675 | u8 type; |
| 5676 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5677 | /* Not DCB capable or capability disabled */ |
| 5678 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
| 5679 | return ret; |
| 5680 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5681 | /* Ignore if event is not for Nearest Bridge */ |
| 5682 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5683 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5684 | 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] | 5685 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5686 | return ret; |
| 5687 | |
| 5688 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5689 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5690 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5691 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5692 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5693 | /* Update the remote cached instance and return */ |
| 5694 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5695 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5696 | &hw->remote_dcbx_config); |
| 5697 | goto exit; |
| 5698 | } |
| 5699 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5700 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5701 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5702 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5703 | /* Reset the old DCBx configuration data */ |
| 5704 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5705 | /* Get updated DCBX data from firmware */ |
| 5706 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5707 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5708 | dev_info(&pf->pdev->dev, |
| 5709 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 5710 | i40e_stat_str(&pf->hw, ret), |
| 5711 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5712 | goto exit; |
| 5713 | } |
| 5714 | |
| 5715 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5716 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5717 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5718 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5719 | goto exit; |
| 5720 | } |
| 5721 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5722 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5723 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5724 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5725 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5726 | |
| 5727 | if (!need_reconfig) |
| 5728 | goto exit; |
| 5729 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5730 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5731 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5732 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5733 | else |
| 5734 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5735 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5736 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5737 | /* Reconfiguration needed quiesce all VSIs */ |
| 5738 | i40e_pf_quiesce_all_vsi(pf); |
| 5739 | |
| 5740 | /* Changes in configuration update VEB/VSI */ |
| 5741 | i40e_dcb_reconfigure(pf); |
| 5742 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5743 | ret = i40e_resume_port_tx(pf); |
| 5744 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5745 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5746 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5747 | if (ret) |
| 5748 | goto exit; |
| 5749 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 5750 | /* Wait for the PF's queues to be disabled */ |
| 5751 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5752 | if (ret) { |
| 5753 | /* Schedule PF reset to recover */ |
| 5754 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5755 | i40e_service_event_schedule(pf); |
| 5756 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5757 | i40e_pf_unquiesce_all_vsi(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5758 | } |
| 5759 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5760 | exit: |
| 5761 | return ret; |
| 5762 | } |
| 5763 | #endif /* CONFIG_I40E_DCB */ |
| 5764 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5765 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5766 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 5767 | * @pf: board private structure |
| 5768 | * @reset_flags: which reset is requested |
| 5769 | * |
| 5770 | **/ |
| 5771 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 5772 | { |
| 5773 | rtnl_lock(); |
| 5774 | i40e_do_reset(pf, reset_flags); |
| 5775 | rtnl_unlock(); |
| 5776 | } |
| 5777 | |
| 5778 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5779 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 5780 | * @pf: board private structure |
| 5781 | * @e: event info posted on ARQ |
| 5782 | * |
| 5783 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 5784 | * and VF queues |
| 5785 | **/ |
| 5786 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 5787 | struct i40e_arq_event_info *e) |
| 5788 | { |
| 5789 | struct i40e_aqc_lan_overflow *data = |
| 5790 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 5791 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 5792 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 5793 | struct i40e_hw *hw = &pf->hw; |
| 5794 | struct i40e_vf *vf; |
| 5795 | u16 vf_id; |
| 5796 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5797 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 5798 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5799 | |
| 5800 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 5801 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 5802 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 5803 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 5804 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 5805 | vf_id -= hw->func_caps.vf_base_id; |
| 5806 | vf = &pf->vf[vf_id]; |
| 5807 | i40e_vc_notify_vf_reset(vf); |
| 5808 | /* Allow VF to process pending reset notification */ |
| 5809 | msleep(20); |
| 5810 | i40e_reset_vf(vf, false); |
| 5811 | } |
| 5812 | } |
| 5813 | |
| 5814 | /** |
| 5815 | * i40e_service_event_complete - Finish up the service event |
| 5816 | * @pf: board private structure |
| 5817 | **/ |
| 5818 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 5819 | { |
Shannon Nelson | b875f99 | 2015-10-21 19:47:03 -0400 | [diff] [blame] | 5820 | WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5821 | |
| 5822 | /* flush memory to make sure state is correct before next watchog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5823 | smp_mb__before_atomic(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5824 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 5825 | } |
| 5826 | |
| 5827 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5828 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 5829 | * @pf: board private structure |
| 5830 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5831 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5832 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5833 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5834 | |
| 5835 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5836 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 5837 | return fcnt_prog; |
| 5838 | } |
| 5839 | |
| 5840 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5841 | * 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] | 5842 | * @pf: board private structure |
| 5843 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5844 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5845 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5846 | u32 val, fcnt_prog; |
| 5847 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5848 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5849 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 5850 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 5851 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 5852 | return fcnt_prog; |
| 5853 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5854 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5855 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5856 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 5857 | * @pf: board private structure |
| 5858 | **/ |
| 5859 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 5860 | { |
| 5861 | u32 val, fcnt_prog; |
| 5862 | |
| 5863 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 5864 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 5865 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 5866 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 5867 | return fcnt_prog; |
| 5868 | } |
| 5869 | |
| 5870 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5871 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 5872 | * @pf: board private structure |
| 5873 | **/ |
| 5874 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 5875 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5876 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5877 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5878 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5879 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5880 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 5881 | return; |
| 5882 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5883 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 5884 | * to re-enable |
| 5885 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5886 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5887 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5888 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 5889 | (pf->fd_add_err == 0) || |
| 5890 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5891 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 5892 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 5893 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5894 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5895 | 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] | 5896 | } |
| 5897 | } |
| 5898 | /* Wait for some more space to be available to turn on ATR */ |
| 5899 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 5900 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 5901 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
| 5902 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5903 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5904 | 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] | 5905 | } |
| 5906 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5907 | |
| 5908 | /* if hw had a problem adding a filter, delete it */ |
| 5909 | if (pf->fd_inv > 0) { |
| 5910 | hlist_for_each_entry_safe(filter, node, |
| 5911 | &pf->fdir_filter_list, fdir_node) { |
| 5912 | if (filter->fd_id == pf->fd_inv) { |
| 5913 | hlist_del(&filter->fdir_node); |
| 5914 | kfree(filter); |
| 5915 | pf->fdir_pf_active_filters--; |
| 5916 | } |
| 5917 | } |
| 5918 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5919 | } |
| 5920 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5921 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5922 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5923 | /** |
| 5924 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 5925 | * @pf: board private structure |
| 5926 | **/ |
| 5927 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 5928 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5929 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5930 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5931 | bool disable_atr = false; |
| 5932 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5933 | int reg; |
| 5934 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 5935 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 5936 | return; |
| 5937 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5938 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 5939 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 5940 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5941 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5942 | /* If the flush is happening too quick and we have mostly SB rules we |
| 5943 | * should not re-enable ATR for some time. |
| 5944 | */ |
| 5945 | min_flush_time = pf->fd_flush_timestamp + |
| 5946 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 5947 | 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] | 5948 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5949 | if (!(time_after(jiffies, min_flush_time)) && |
| 5950 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 5951 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5952 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 5953 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5954 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5955 | |
| 5956 | pf->fd_flush_timestamp = jiffies; |
| 5957 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
| 5958 | /* flush all filters */ |
| 5959 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 5960 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 5961 | i40e_flush(&pf->hw); |
| 5962 | pf->fd_flush_cnt++; |
| 5963 | pf->fd_add_err = 0; |
| 5964 | do { |
| 5965 | /* Check FD flush status every 5-6msec */ |
| 5966 | usleep_range(5000, 6000); |
| 5967 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 5968 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 5969 | break; |
| 5970 | } while (flush_wait_retry--); |
| 5971 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 5972 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 5973 | } else { |
| 5974 | /* replay sideband filters */ |
| 5975 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
| 5976 | if (!disable_atr) |
| 5977 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 5978 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
| 5979 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5980 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 5981 | } |
| 5982 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5983 | } |
| 5984 | |
| 5985 | /** |
| 5986 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 5987 | * @pf: board private structure |
| 5988 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5989 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5990 | { |
| 5991 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 5992 | } |
| 5993 | |
| 5994 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 5995 | * being applied really fast; before we see the first |
| 5996 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 5997 | * reacting will make sure we don't cause flush too often. |
| 5998 | */ |
| 5999 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 6000 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6001 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6002 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 6003 | * @pf: board private structure |
| 6004 | **/ |
| 6005 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 6006 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6007 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6008 | /* if interface is down do nothing */ |
| 6009 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 6010 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6011 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 6012 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 6013 | return; |
| 6014 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6015 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6016 | i40e_fdir_flush_and_replay(pf); |
| 6017 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6018 | i40e_fdir_check_and_reenable(pf); |
| 6019 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | /** |
| 6023 | * i40e_vsi_link_event - notify VSI of a link event |
| 6024 | * @vsi: vsi to be notified |
| 6025 | * @link_up: link up or down |
| 6026 | **/ |
| 6027 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 6028 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 6029 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6030 | return; |
| 6031 | |
| 6032 | switch (vsi->type) { |
| 6033 | case I40E_VSI_MAIN: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6034 | #ifdef I40E_FCOE |
| 6035 | case I40E_VSI_FCOE: |
| 6036 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6037 | if (!vsi->netdev || !vsi->netdev_registered) |
| 6038 | break; |
| 6039 | |
| 6040 | if (link_up) { |
| 6041 | netif_carrier_on(vsi->netdev); |
| 6042 | netif_tx_wake_all_queues(vsi->netdev); |
| 6043 | } else { |
| 6044 | netif_carrier_off(vsi->netdev); |
| 6045 | netif_tx_stop_all_queues(vsi->netdev); |
| 6046 | } |
| 6047 | break; |
| 6048 | |
| 6049 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6050 | case I40E_VSI_VMDQ2: |
| 6051 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6052 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6053 | case I40E_VSI_MIRROR: |
| 6054 | default: |
| 6055 | /* there is no notification for other VSIs */ |
| 6056 | break; |
| 6057 | } |
| 6058 | } |
| 6059 | |
| 6060 | /** |
| 6061 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6062 | * @veb: veb to be notified |
| 6063 | * @link_up: link up or down |
| 6064 | **/ |
| 6065 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6066 | { |
| 6067 | struct i40e_pf *pf; |
| 6068 | int i; |
| 6069 | |
| 6070 | if (!veb || !veb->pf) |
| 6071 | return; |
| 6072 | pf = veb->pf; |
| 6073 | |
| 6074 | /* depth first... */ |
| 6075 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6076 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6077 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6078 | |
| 6079 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6080 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6081 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6082 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6083 | } |
| 6084 | |
| 6085 | /** |
| 6086 | * i40e_link_event - Update netif_carrier status |
| 6087 | * @pf: board private structure |
| 6088 | **/ |
| 6089 | static void i40e_link_event(struct i40e_pf *pf) |
| 6090 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6091 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6092 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6093 | i40e_status status; |
| 6094 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6095 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6096 | /* save off old link status information */ |
| 6097 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6098 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6099 | /* set this to force the get_link_status call to refresh state */ |
| 6100 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6101 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6102 | 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] | 6103 | |
| 6104 | status = i40e_get_link_status(&pf->hw, &new_link); |
| 6105 | if (status) { |
| 6106 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6107 | status); |
| 6108 | return; |
| 6109 | } |
| 6110 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6111 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6112 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6113 | |
| 6114 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6115 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6116 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 6117 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6118 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6119 | |
| 6120 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 6121 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6122 | |
| 6123 | /* Notify the base of the switch tree connected to |
| 6124 | * the link. Floating VEBs are not notified. |
| 6125 | */ |
| 6126 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6127 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6128 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6129 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6130 | |
| 6131 | if (pf->vf) |
| 6132 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6133 | |
| 6134 | if (pf->flags & I40E_FLAG_PTP) |
| 6135 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6136 | } |
| 6137 | |
| 6138 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6139 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6140 | * @pf: board private structure |
| 6141 | **/ |
| 6142 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6143 | { |
| 6144 | int i; |
| 6145 | |
| 6146 | /* if interface is down do nothing */ |
| 6147 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 6148 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6149 | return; |
| 6150 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6151 | /* make sure we don't do these things too often */ |
| 6152 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6153 | pf->service_timer_period))) |
| 6154 | return; |
| 6155 | pf->service_timer_previous = jiffies; |
| 6156 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6157 | if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) |
| 6158 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6159 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6160 | /* Update the stats for active netdevs so the network stack |
| 6161 | * can look at updated numbers whenever it cares to |
| 6162 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6163 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6164 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6165 | i40e_update_stats(pf->vsi[i]); |
| 6166 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6167 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6168 | /* Update the stats for the active switching components */ |
| 6169 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6170 | if (pf->veb[i]) |
| 6171 | i40e_update_veb_stats(pf->veb[i]); |
| 6172 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6173 | |
| 6174 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6175 | } |
| 6176 | |
| 6177 | /** |
| 6178 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6179 | * @pf: board private structure |
| 6180 | **/ |
| 6181 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6182 | { |
| 6183 | u32 reset_flags = 0; |
| 6184 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6185 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6186 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6187 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6188 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 6189 | } |
| 6190 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6191 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6192 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6193 | } |
| 6194 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6195 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6196 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 6197 | } |
| 6198 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6199 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6200 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 6201 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6202 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6203 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6204 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 6205 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6206 | |
| 6207 | /* If there's a recovery already waiting, it takes |
| 6208 | * precedence before starting a new reset sequence. |
| 6209 | */ |
| 6210 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 6211 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6212 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6213 | } |
| 6214 | |
| 6215 | /* If we're already down or resetting, just bail */ |
| 6216 | if (reset_flags && |
| 6217 | !test_bit(__I40E_DOWN, &pf->state) && |
| 6218 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6219 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6220 | |
| 6221 | unlock: |
| 6222 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | /** |
| 6226 | * i40e_handle_link_event - Handle link event |
| 6227 | * @pf: board private structure |
| 6228 | * @e: event info posted on ARQ |
| 6229 | **/ |
| 6230 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6231 | struct i40e_arq_event_info *e) |
| 6232 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6233 | struct i40e_aqc_get_link_status *status = |
| 6234 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6235 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6236 | /* Do a new status request to re-enable LSE reporting |
| 6237 | * and load new status information into the hw struct |
| 6238 | * This completely ignores any state information |
| 6239 | * in the ARQ event info, instead choosing to always |
| 6240 | * issue the AQ update link status command. |
| 6241 | */ |
| 6242 | i40e_link_event(pf); |
| 6243 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6244 | /* check for unqualified module, if link is down */ |
| 6245 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6246 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6247 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6248 | dev_err(&pf->pdev->dev, |
| 6249 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6250 | } |
| 6251 | |
| 6252 | /** |
| 6253 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6254 | * @pf: board private structure |
| 6255 | **/ |
| 6256 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6257 | { |
| 6258 | struct i40e_arq_event_info event; |
| 6259 | struct i40e_hw *hw = &pf->hw; |
| 6260 | u16 pending, i = 0; |
| 6261 | i40e_status ret; |
| 6262 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6263 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6264 | u32 val; |
| 6265 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6266 | /* Do not run clean AQ when PF reset fails */ |
| 6267 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 6268 | return; |
| 6269 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6270 | /* check for error indications */ |
| 6271 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6272 | oldval = val; |
| 6273 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6274 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6275 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6276 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6277 | } |
| 6278 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6279 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6280 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6281 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6282 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6283 | } |
| 6284 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6285 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6286 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6287 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6288 | } |
| 6289 | if (oldval != val) |
| 6290 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6291 | |
| 6292 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6293 | oldval = val; |
| 6294 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6295 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6296 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6297 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6298 | } |
| 6299 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6300 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6301 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6302 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6303 | } |
| 6304 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6305 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6306 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6307 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6308 | } |
| 6309 | if (oldval != val) |
| 6310 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6311 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6312 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6313 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6314 | if (!event.msg_buf) |
| 6315 | return; |
| 6316 | |
| 6317 | do { |
| 6318 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6319 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6320 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6321 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6322 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6323 | break; |
| 6324 | } |
| 6325 | |
| 6326 | opcode = le16_to_cpu(event.desc.opcode); |
| 6327 | switch (opcode) { |
| 6328 | |
| 6329 | case i40e_aqc_opc_get_link_status: |
| 6330 | i40e_handle_link_event(pf, &event); |
| 6331 | break; |
| 6332 | case i40e_aqc_opc_send_msg_to_pf: |
| 6333 | ret = i40e_vc_process_vf_msg(pf, |
| 6334 | le16_to_cpu(event.desc.retval), |
| 6335 | le32_to_cpu(event.desc.cookie_high), |
| 6336 | le32_to_cpu(event.desc.cookie_low), |
| 6337 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6338 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6339 | break; |
| 6340 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6341 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6342 | #ifdef CONFIG_I40E_DCB |
| 6343 | rtnl_lock(); |
| 6344 | ret = i40e_handle_lldp_event(pf, &event); |
| 6345 | rtnl_unlock(); |
| 6346 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6347 | break; |
| 6348 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6349 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6350 | i40e_handle_lan_overflow_event(pf, &event); |
| 6351 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6352 | case i40e_aqc_opc_send_msg_to_peer: |
| 6353 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6354 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6355 | case i40e_aqc_opc_nvm_erase: |
| 6356 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6357 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 6358 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 6359 | "ARQ NVM operation 0x%04x completed\n", |
| 6360 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6361 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6362 | default: |
| 6363 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 6364 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6365 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6366 | break; |
| 6367 | } |
| 6368 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 6369 | |
| 6370 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 6371 | /* re-enable Admin queue interrupt cause */ |
| 6372 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6373 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6374 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6375 | i40e_flush(hw); |
| 6376 | |
| 6377 | kfree(event.msg_buf); |
| 6378 | } |
| 6379 | |
| 6380 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6381 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6382 | * @pf: board private structure |
| 6383 | **/ |
| 6384 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6385 | { |
| 6386 | int err; |
| 6387 | |
| 6388 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6389 | if (err) { |
| 6390 | /* retry in case of garbage read */ |
| 6391 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6392 | if (err) { |
| 6393 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6394 | err); |
| 6395 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6396 | } |
| 6397 | } |
| 6398 | |
| 6399 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 6400 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 6401 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6402 | } |
| 6403 | } |
| 6404 | |
| 6405 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6406 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6407 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6408 | * |
| 6409 | * enable switch loop back or die - no point in a return value |
| 6410 | **/ |
| 6411 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6412 | { |
| 6413 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6414 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6415 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6416 | |
| 6417 | ctxt.seid = pf->main_vsi_seid; |
| 6418 | ctxt.pf_num = pf->hw.pf_id; |
| 6419 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6420 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6421 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6422 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6423 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6424 | i40e_stat_str(&pf->hw, ret), |
| 6425 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6426 | return; |
| 6427 | } |
| 6428 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6429 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6430 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6431 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6432 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6433 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6434 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6435 | "update vsi switch failed, err %s aq_err %s\n", |
| 6436 | i40e_stat_str(&pf->hw, ret), |
| 6437 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6438 | } |
| 6439 | } |
| 6440 | |
| 6441 | /** |
| 6442 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6443 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6444 | * |
| 6445 | * disable switch loop back or die - no point in a return value |
| 6446 | **/ |
| 6447 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6448 | { |
| 6449 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6450 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6451 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6452 | |
| 6453 | ctxt.seid = pf->main_vsi_seid; |
| 6454 | ctxt.pf_num = pf->hw.pf_id; |
| 6455 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6456 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6457 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6458 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6459 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6460 | i40e_stat_str(&pf->hw, ret), |
| 6461 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6462 | return; |
| 6463 | } |
| 6464 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6465 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6466 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6467 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6468 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6469 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6470 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6471 | "update vsi switch failed, err %s aq_err %s\n", |
| 6472 | i40e_stat_str(&pf->hw, ret), |
| 6473 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6474 | } |
| 6475 | } |
| 6476 | |
| 6477 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6478 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6479 | * @veb: pointer to the bridge instance |
| 6480 | * |
| 6481 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6482 | * specified HW bridge instance. It is expected this function is called |
| 6483 | * when a new HW bridge is instantiated. |
| 6484 | **/ |
| 6485 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6486 | { |
| 6487 | struct i40e_pf *pf = veb->pf; |
| 6488 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6489 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6490 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6491 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6492 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6493 | i40e_disable_pf_switch_lb(pf); |
| 6494 | else |
| 6495 | i40e_enable_pf_switch_lb(pf); |
| 6496 | } |
| 6497 | |
| 6498 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6499 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6500 | * @veb: pointer to the VEB instance |
| 6501 | * |
| 6502 | * This is a recursive function that first builds the attached VSIs then |
| 6503 | * recurses in to build the next layer of VEB. We track the connections |
| 6504 | * through our own index numbers because the seid's from the HW could |
| 6505 | * change across the reset. |
| 6506 | **/ |
| 6507 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6508 | { |
| 6509 | struct i40e_vsi *ctl_vsi = NULL; |
| 6510 | struct i40e_pf *pf = veb->pf; |
| 6511 | int v, veb_idx; |
| 6512 | int ret; |
| 6513 | |
| 6514 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6515 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6516 | if (pf->vsi[v] && |
| 6517 | pf->vsi[v]->veb_idx == veb->idx && |
| 6518 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6519 | ctl_vsi = pf->vsi[v]; |
| 6520 | break; |
| 6521 | } |
| 6522 | } |
| 6523 | if (!ctl_vsi) { |
| 6524 | dev_info(&pf->pdev->dev, |
| 6525 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6526 | ret = -ENOENT; |
| 6527 | goto end_reconstitute; |
| 6528 | } |
| 6529 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6530 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6531 | ret = i40e_add_vsi(ctl_vsi); |
| 6532 | if (ret) { |
| 6533 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6534 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6535 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6536 | goto end_reconstitute; |
| 6537 | } |
| 6538 | i40e_vsi_reset_stats(ctl_vsi); |
| 6539 | |
| 6540 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6541 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6542 | if (ret) |
| 6543 | goto end_reconstitute; |
| 6544 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6545 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6546 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6547 | else |
| 6548 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6549 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6550 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6551 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6552 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6553 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6554 | continue; |
| 6555 | |
| 6556 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6557 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6558 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6559 | vsi->uplink_seid = veb->seid; |
| 6560 | ret = i40e_add_vsi(vsi); |
| 6561 | if (ret) { |
| 6562 | dev_info(&pf->pdev->dev, |
| 6563 | "rebuild of vsi_idx %d failed: %d\n", |
| 6564 | v, ret); |
| 6565 | goto end_reconstitute; |
| 6566 | } |
| 6567 | i40e_vsi_reset_stats(vsi); |
| 6568 | } |
| 6569 | } |
| 6570 | |
| 6571 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6572 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6573 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6574 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6575 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6576 | if (ret) |
| 6577 | break; |
| 6578 | } |
| 6579 | } |
| 6580 | |
| 6581 | end_reconstitute: |
| 6582 | return ret; |
| 6583 | } |
| 6584 | |
| 6585 | /** |
| 6586 | * i40e_get_capabilities - get info about the HW |
| 6587 | * @pf: the PF struct |
| 6588 | **/ |
| 6589 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6590 | { |
| 6591 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6592 | u16 data_size; |
| 6593 | int buf_len; |
| 6594 | int err; |
| 6595 | |
| 6596 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6597 | do { |
| 6598 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6599 | if (!cap_buf) |
| 6600 | return -ENOMEM; |
| 6601 | |
| 6602 | /* this loads the data into the hw struct for us */ |
| 6603 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6604 | &data_size, |
| 6605 | i40e_aqc_opc_list_func_capabilities, |
| 6606 | NULL); |
| 6607 | /* data loaded, buffer no longer needed */ |
| 6608 | kfree(cap_buf); |
| 6609 | |
| 6610 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6611 | /* retry with a larger buffer */ |
| 6612 | buf_len = data_size; |
| 6613 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6614 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6615 | "capability discovery failed, err %s aq_err %s\n", |
| 6616 | i40e_stat_str(&pf->hw, err), |
| 6617 | i40e_aq_str(&pf->hw, |
| 6618 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6619 | return -ENODEV; |
| 6620 | } |
| 6621 | } while (err); |
| 6622 | |
| 6623 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6624 | dev_info(&pf->pdev->dev, |
| 6625 | "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", |
| 6626 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6627 | pf->hw.func_caps.num_msix_vectors, |
| 6628 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6629 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6630 | pf->hw.func_caps.fd_filters_best_effort, |
| 6631 | pf->hw.func_caps.num_tx_qp, |
| 6632 | pf->hw.func_caps.num_vsis); |
| 6633 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6634 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6635 | + pf->hw.func_caps.num_vfs) |
| 6636 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6637 | dev_info(&pf->pdev->dev, |
| 6638 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6639 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6640 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6641 | } |
| 6642 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6643 | return 0; |
| 6644 | } |
| 6645 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6646 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6647 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6648 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6649 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6650 | * @pf: board private structure |
| 6651 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6652 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6653 | { |
| 6654 | struct i40e_vsi *vsi; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6655 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6656 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6657 | /* quick workaround for an NVM issue that leaves a critical register |
| 6658 | * uninitialized |
| 6659 | */ |
| 6660 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6661 | static const u32 hkey[] = { |
| 6662 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6663 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6664 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6665 | 0x95b3a76d}; |
| 6666 | |
| 6667 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6668 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6669 | } |
| 6670 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6671 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6672 | return; |
| 6673 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6674 | /* find existing VSI and see if it needs configuring */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6675 | vsi = NULL; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6676 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6677 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6678 | vsi = pf->vsi[i]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6679 | break; |
| 6680 | } |
| 6681 | } |
| 6682 | |
| 6683 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6684 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6685 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6686 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6687 | if (!vsi) { |
| 6688 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6689 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6690 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6691 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6692 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6693 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6694 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6695 | } |
| 6696 | |
| 6697 | /** |
| 6698 | * i40e_fdir_teardown - release the Flow Director resources |
| 6699 | * @pf: board private structure |
| 6700 | **/ |
| 6701 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6702 | { |
| 6703 | int i; |
| 6704 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6705 | i40e_fdir_filter_exit(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6706 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6707 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 6708 | i40e_vsi_release(pf->vsi[i]); |
| 6709 | break; |
| 6710 | } |
| 6711 | } |
| 6712 | } |
| 6713 | |
| 6714 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6715 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6716 | * @pf: board private structure |
| 6717 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6718 | * 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] | 6719 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6720 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6721 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6722 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6723 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6724 | u32 v; |
| 6725 | |
| 6726 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6727 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6728 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 6729 | if (i40e_check_asq_alive(&pf->hw)) |
| 6730 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6731 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6732 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
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 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6735 | i40e_pf_quiesce_all_vsi(pf); |
| 6736 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6737 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6738 | if (pf->vsi[v]) |
| 6739 | pf->vsi[v]->seid = 0; |
| 6740 | } |
| 6741 | |
| 6742 | i40e_shutdown_adminq(&pf->hw); |
| 6743 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6744 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6745 | if (hw->hmc.hmc_obj) { |
| 6746 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6747 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6748 | dev_warn(&pf->pdev->dev, |
| 6749 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6750 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6751 | } |
| 6752 | |
| 6753 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6754 | * i40e_send_version - update firmware with driver version |
| 6755 | * @pf: PF struct |
| 6756 | */ |
| 6757 | static void i40e_send_version(struct i40e_pf *pf) |
| 6758 | { |
| 6759 | struct i40e_driver_version dv; |
| 6760 | |
| 6761 | dv.major_version = DRV_VERSION_MAJOR; |
| 6762 | dv.minor_version = DRV_VERSION_MINOR; |
| 6763 | dv.build_version = DRV_VERSION_BUILD; |
| 6764 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 6765 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6766 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 6767 | } |
| 6768 | |
| 6769 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 6770 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6771 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6772 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6773 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6774 | 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] | 6775 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6776 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6777 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6778 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6779 | u32 val; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6780 | u32 v; |
| 6781 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6782 | /* Now we wait for GRST to settle out. |
| 6783 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 6784 | * because the reset will make them disappear. |
| 6785 | */ |
| 6786 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6787 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6788 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6789 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 6790 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6791 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6792 | pf->pfr_count++; |
| 6793 | |
| 6794 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6795 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6796 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6797 | |
| 6798 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 6799 | ret = i40e_init_adminq(&pf->hw); |
| 6800 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6801 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 6802 | i40e_stat_str(&pf->hw, ret), |
| 6803 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6804 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6805 | } |
| 6806 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6807 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 6808 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6809 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6810 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 6811 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6812 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6813 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6814 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6815 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6816 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 6817 | hw->func_caps.num_rx_qp, |
| 6818 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 6819 | if (ret) { |
| 6820 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 6821 | goto end_core_reset; |
| 6822 | } |
| 6823 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 6824 | if (ret) { |
| 6825 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 6826 | goto end_core_reset; |
| 6827 | } |
| 6828 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6829 | #ifdef CONFIG_I40E_DCB |
| 6830 | ret = i40e_init_pf_dcb(pf); |
| 6831 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6832 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 6833 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 6834 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6835 | } |
| 6836 | #endif /* CONFIG_I40E_DCB */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6837 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 6838 | i40e_init_pf_fcoe(pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6839 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6840 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6841 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6842 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6843 | if (ret) |
| 6844 | goto end_core_reset; |
| 6845 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6846 | /* The driver only wants link up/down and module qualification |
| 6847 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6848 | */ |
| 6849 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6850 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 6851 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6852 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6853 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6854 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 6855 | i40e_stat_str(&pf->hw, ret), |
| 6856 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6857 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6858 | /* make sure our flow control settings are restored */ |
| 6859 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 6860 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 6861 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 6862 | i40e_stat_str(&pf->hw, ret), |
| 6863 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6864 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6865 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 6866 | * They are still in our local switch element arrays, so only |
| 6867 | * need to rebuild the switch model in the HW. |
| 6868 | * |
| 6869 | * If there were VEBs but the reconstitution failed, we'll try |
| 6870 | * try to recover minimal use by getting the basic PF VSI working. |
| 6871 | */ |
| 6872 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6873 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6874 | /* find the one VEB connected to the MAC, and find orphans */ |
| 6875 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6876 | if (!pf->veb[v]) |
| 6877 | continue; |
| 6878 | |
| 6879 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 6880 | pf->veb[v]->uplink_seid == 0) { |
| 6881 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 6882 | |
| 6883 | if (!ret) |
| 6884 | continue; |
| 6885 | |
| 6886 | /* If Main VEB failed, we're in deep doodoo, |
| 6887 | * so give up rebuilding the switch and set up |
| 6888 | * for minimal rebuild of PF VSI. |
| 6889 | * If orphan failed, we'll report the error |
| 6890 | * but try to keep going. |
| 6891 | */ |
| 6892 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 6893 | dev_info(&pf->pdev->dev, |
| 6894 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 6895 | ret); |
| 6896 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 6897 | = pf->mac_seid; |
| 6898 | break; |
| 6899 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 6900 | dev_info(&pf->pdev->dev, |
| 6901 | "rebuild of orphan VEB failed: %d\n", |
| 6902 | ret); |
| 6903 | } |
| 6904 | } |
| 6905 | } |
| 6906 | } |
| 6907 | |
| 6908 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 6909 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6910 | /* no VEB, so rebuild only the Main VSI */ |
| 6911 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 6912 | if (ret) { |
| 6913 | dev_info(&pf->pdev->dev, |
| 6914 | "rebuild of Main VSI failed: %d\n", ret); |
| 6915 | goto end_core_reset; |
| 6916 | } |
| 6917 | } |
| 6918 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6919 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 6920 | * of TSO, so that we avoid the MDD being fired and causing |
| 6921 | * a reset in the case of small MSS+TSO. |
| 6922 | */ |
| 6923 | #define I40E_REG_MSS 0x000E64DC |
| 6924 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 6925 | #define I40E_64BYTE_MSS 0x400000 |
| 6926 | val = rd32(hw, I40E_REG_MSS); |
| 6927 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 6928 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 6929 | val |= I40E_64BYTE_MSS; |
| 6930 | wr32(hw, I40E_REG_MSS, val); |
| 6931 | } |
| 6932 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 6933 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 6934 | msleep(75); |
| 6935 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 6936 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6937 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 6938 | i40e_stat_str(&pf->hw, ret), |
| 6939 | i40e_aq_str(&pf->hw, |
| 6940 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6941 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6942 | /* reinit the misc interrupt */ |
| 6943 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 6944 | ret = i40e_setup_misc_vector(pf); |
| 6945 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 6946 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 6947 | * transmitted. By doing so we stop a malicious VF from sending out |
| 6948 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 6949 | * PF/VF VSIs. |
| 6950 | * The FW can still send Flow control frames if enabled. |
| 6951 | */ |
| 6952 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 6953 | pf->main_vsi_seid); |
| 6954 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6955 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 6956 | i40e_pf_unquiesce_all_vsi(pf); |
| 6957 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 6958 | if (pf->num_alloc_vfs) { |
| 6959 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 6960 | i40e_reset_vf(&pf->vf[v], true); |
| 6961 | } |
| 6962 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6963 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6964 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6965 | |
| 6966 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6967 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 6968 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6969 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 6970 | } |
| 6971 | |
| 6972 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6973 | * 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] | 6974 | * @pf: board private structure |
| 6975 | * |
| 6976 | * Close up the VFs and other things in prep for a Core Reset, |
| 6977 | * then get ready to rebuild the world. |
| 6978 | **/ |
| 6979 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 6980 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6981 | i40e_prep_for_reset(pf); |
| 6982 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6983 | } |
| 6984 | |
| 6985 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6986 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6987 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6988 | * |
| 6989 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 6990 | **/ |
| 6991 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 6992 | { |
| 6993 | struct i40e_hw *hw = &pf->hw; |
| 6994 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 6995 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6996 | struct i40e_vf *vf; |
| 6997 | u32 reg; |
| 6998 | int i; |
| 6999 | |
| 7000 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 7001 | return; |
| 7002 | |
| 7003 | /* find what triggered the MDD event */ |
| 7004 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 7005 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7006 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 7007 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7008 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7009 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7010 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7011 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7012 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 7013 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 7014 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7015 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7016 | 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] | 7017 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7018 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 7019 | mdd_detected = true; |
| 7020 | } |
| 7021 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 7022 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7023 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 7024 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7025 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7026 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7027 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 7028 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 7029 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7030 | if (netif_msg_rx_err(pf)) |
| 7031 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 7032 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7033 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 7034 | mdd_detected = true; |
| 7035 | } |
| 7036 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7037 | if (mdd_detected) { |
| 7038 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 7039 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 7040 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7041 | 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] | 7042 | pf_mdd_detected = true; |
| 7043 | } |
| 7044 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 7045 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 7046 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7047 | 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] | 7048 | pf_mdd_detected = true; |
| 7049 | } |
| 7050 | /* Queue belongs to the PF, initiate a reset */ |
| 7051 | if (pf_mdd_detected) { |
| 7052 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 7053 | i40e_service_event_schedule(pf); |
| 7054 | } |
| 7055 | } |
| 7056 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7057 | /* see if one of the VFs needs its hand slapped */ |
| 7058 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7059 | vf = &(pf->vf[i]); |
| 7060 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7061 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7062 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7063 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7064 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7065 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7066 | } |
| 7067 | |
| 7068 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7069 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7070 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7071 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7072 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7073 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7074 | } |
| 7075 | |
| 7076 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7077 | dev_info(&pf->pdev->dev, |
| 7078 | "Too many MDD events on VF %d, disabled\n", i); |
| 7079 | dev_info(&pf->pdev->dev, |
| 7080 | "Use PF Control I/F to re-enable the VF\n"); |
| 7081 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 7082 | } |
| 7083 | } |
| 7084 | |
| 7085 | /* re-enable mdd interrupt cause */ |
| 7086 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 7087 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7088 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7089 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7090 | i40e_flush(hw); |
| 7091 | } |
| 7092 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7093 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7094 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7095 | * @pf: board private structure |
| 7096 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7097 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7098 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7099 | #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7100 | struct i40e_hw *hw = &pf->hw; |
| 7101 | i40e_status ret; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7102 | __be16 port; |
| 7103 | int i; |
| 7104 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7105 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7106 | return; |
| 7107 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7108 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7109 | |
| 7110 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7111 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7112 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
| 7113 | port = pf->udp_ports[i].index; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7114 | if (port) |
| 7115 | ret = i40e_aq_add_udp_tunnel(hw, ntohs(port), |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7116 | pf->udp_ports[i].type, |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7117 | NULL, NULL); |
| 7118 | else |
| 7119 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7120 | |
| 7121 | if (ret) { |
Carolyn Wyborny | 730a8f8 | 2016-02-17 16:12:16 -0800 | [diff] [blame] | 7122 | dev_dbg(&pf->pdev->dev, |
| 7123 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 7124 | pf->udp_ports[i].type ? "vxlan" : "geneve", |
| 7125 | port ? "add" : "delete", |
| 7126 | ntohs(port), i, |
| 7127 | i40e_stat_str(&pf->hw, ret), |
| 7128 | i40e_aq_str(&pf->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7129 | pf->hw.aq.asq_last_status)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7130 | pf->udp_ports[i].index = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7131 | } |
| 7132 | } |
| 7133 | } |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7134 | #endif |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7135 | } |
| 7136 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7137 | /** |
| 7138 | * i40e_service_task - Run the driver's async subtasks |
| 7139 | * @work: pointer to work_struct containing our data |
| 7140 | **/ |
| 7141 | static void i40e_service_task(struct work_struct *work) |
| 7142 | { |
| 7143 | struct i40e_pf *pf = container_of(work, |
| 7144 | struct i40e_pf, |
| 7145 | service_task); |
| 7146 | unsigned long start_time = jiffies; |
| 7147 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7148 | /* don't bother with service tasks if a reset is in progress */ |
| 7149 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7150 | i40e_service_event_complete(pf); |
| 7151 | return; |
| 7152 | } |
| 7153 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7154 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 7155 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7156 | i40e_reset_subtask(pf); |
| 7157 | i40e_handle_mdd_event(pf); |
| 7158 | i40e_vc_process_vflr_event(pf); |
| 7159 | i40e_watchdog_subtask(pf); |
| 7160 | i40e_fdir_reinit_subtask(pf); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7161 | i40e_client_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7162 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7163 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7164 | i40e_clean_adminq_subtask(pf); |
| 7165 | |
| 7166 | i40e_service_event_complete(pf); |
| 7167 | |
| 7168 | /* If the tasks have taken longer than one timer cycle or there |
| 7169 | * is more work to be done, reschedule the service task now |
| 7170 | * rather than wait for the timer to tick again. |
| 7171 | */ |
| 7172 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 7173 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 7174 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 7175 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 7176 | i40e_service_event_schedule(pf); |
| 7177 | } |
| 7178 | |
| 7179 | /** |
| 7180 | * i40e_service_timer - timer callback |
| 7181 | * @data: pointer to PF struct |
| 7182 | **/ |
| 7183 | static void i40e_service_timer(unsigned long data) |
| 7184 | { |
| 7185 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7186 | |
| 7187 | mod_timer(&pf->service_timer, |
| 7188 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7189 | i40e_service_event_schedule(pf); |
| 7190 | } |
| 7191 | |
| 7192 | /** |
| 7193 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7194 | * @vsi: the VSI being configured |
| 7195 | **/ |
| 7196 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7197 | { |
| 7198 | struct i40e_pf *pf = vsi->back; |
| 7199 | |
| 7200 | switch (vsi->type) { |
| 7201 | case I40E_VSI_MAIN: |
| 7202 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7203 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7204 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7205 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7206 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7207 | else |
| 7208 | vsi->num_q_vectors = 1; |
| 7209 | |
| 7210 | break; |
| 7211 | |
| 7212 | case I40E_VSI_FDIR: |
| 7213 | vsi->alloc_queue_pairs = 1; |
| 7214 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7215 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7216 | vsi->num_q_vectors = 1; |
| 7217 | break; |
| 7218 | |
| 7219 | case I40E_VSI_VMDQ2: |
| 7220 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7221 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7222 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7223 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7224 | break; |
| 7225 | |
| 7226 | case I40E_VSI_SRIOV: |
| 7227 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7228 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7229 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7230 | break; |
| 7231 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7232 | #ifdef I40E_FCOE |
| 7233 | case I40E_VSI_FCOE: |
| 7234 | vsi->alloc_queue_pairs = pf->num_fcoe_qps; |
| 7235 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7236 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7237 | vsi->num_q_vectors = pf->num_fcoe_msix; |
| 7238 | break; |
| 7239 | |
| 7240 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7241 | default: |
| 7242 | WARN_ON(1); |
| 7243 | return -ENODATA; |
| 7244 | } |
| 7245 | |
| 7246 | return 0; |
| 7247 | } |
| 7248 | |
| 7249 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7250 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7251 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7252 | * @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] | 7253 | * |
| 7254 | * On error: returns error code (negative) |
| 7255 | * On success: returns 0 |
| 7256 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7257 | 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] | 7258 | { |
| 7259 | int size; |
| 7260 | int ret = 0; |
| 7261 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7262 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7263 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 7264 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7265 | if (!vsi->tx_rings) |
| 7266 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7267 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 7268 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7269 | if (alloc_qvectors) { |
| 7270 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7271 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7272 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7273 | if (!vsi->q_vectors) { |
| 7274 | ret = -ENOMEM; |
| 7275 | goto err_vectors; |
| 7276 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7277 | } |
| 7278 | return ret; |
| 7279 | |
| 7280 | err_vectors: |
| 7281 | kfree(vsi->tx_rings); |
| 7282 | return ret; |
| 7283 | } |
| 7284 | |
| 7285 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7286 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7287 | * @pf: board private structure |
| 7288 | * @type: type of VSI |
| 7289 | * |
| 7290 | * On error: returns error code (negative) |
| 7291 | * On success: returns vsi index in PF (positive) |
| 7292 | **/ |
| 7293 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7294 | { |
| 7295 | int ret = -ENODEV; |
| 7296 | struct i40e_vsi *vsi; |
| 7297 | int vsi_idx; |
| 7298 | int i; |
| 7299 | |
| 7300 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7301 | mutex_lock(&pf->switch_mutex); |
| 7302 | |
| 7303 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7304 | * been happening. We can afford to do a quick scan to look |
| 7305 | * for any free VSIs in the list. |
| 7306 | * |
| 7307 | * find next empty vsi slot, looping back around if necessary |
| 7308 | */ |
| 7309 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7310 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7311 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7312 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7313 | i = 0; |
| 7314 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7315 | i++; |
| 7316 | } |
| 7317 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7318 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7319 | vsi_idx = i; /* Found one! */ |
| 7320 | } else { |
| 7321 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7322 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7323 | } |
| 7324 | pf->next_vsi = ++i; |
| 7325 | |
| 7326 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7327 | if (!vsi) { |
| 7328 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7329 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7330 | } |
| 7331 | vsi->type = type; |
| 7332 | vsi->back = pf; |
| 7333 | set_bit(__I40E_DOWN, &vsi->state); |
| 7334 | vsi->flags = 0; |
| 7335 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7336 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7337 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7338 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7339 | vsi->netdev_registered = false; |
| 7340 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
| 7341 | INIT_LIST_HEAD(&vsi->mac_filter_list); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7342 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7343 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7344 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7345 | if (ret) |
| 7346 | goto err_rings; |
| 7347 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7348 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7349 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7350 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7351 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7352 | /* Setup default MSIX irq handler for VSI */ |
| 7353 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7354 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7355 | /* Initialize VSI lock */ |
| 7356 | spin_lock_init(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7357 | pf->vsi[vsi_idx] = vsi; |
| 7358 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7359 | goto unlock_pf; |
| 7360 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7361 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7362 | pf->next_vsi = i - 1; |
| 7363 | kfree(vsi); |
| 7364 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7365 | mutex_unlock(&pf->switch_mutex); |
| 7366 | return ret; |
| 7367 | } |
| 7368 | |
| 7369 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7370 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7371 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7372 | * @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] | 7373 | * |
| 7374 | * On error: returns error code (negative) |
| 7375 | * On success: returns 0 |
| 7376 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7377 | 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] | 7378 | { |
| 7379 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7380 | if (free_qvectors) { |
| 7381 | kfree(vsi->q_vectors); |
| 7382 | vsi->q_vectors = NULL; |
| 7383 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7384 | kfree(vsi->tx_rings); |
| 7385 | vsi->tx_rings = NULL; |
| 7386 | vsi->rx_rings = NULL; |
| 7387 | } |
| 7388 | |
| 7389 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7390 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7391 | * and lookup table |
| 7392 | * @vsi: Pointer to VSI structure |
| 7393 | */ |
| 7394 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7395 | { |
| 7396 | if (!vsi) |
| 7397 | return; |
| 7398 | |
| 7399 | kfree(vsi->rss_hkey_user); |
| 7400 | vsi->rss_hkey_user = NULL; |
| 7401 | |
| 7402 | kfree(vsi->rss_lut_user); |
| 7403 | vsi->rss_lut_user = NULL; |
| 7404 | } |
| 7405 | |
| 7406 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7407 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7408 | * @vsi: the VSI being un-configured |
| 7409 | **/ |
| 7410 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7411 | { |
| 7412 | struct i40e_pf *pf; |
| 7413 | |
| 7414 | if (!vsi) |
| 7415 | return 0; |
| 7416 | |
| 7417 | if (!vsi->back) |
| 7418 | goto free_vsi; |
| 7419 | pf = vsi->back; |
| 7420 | |
| 7421 | mutex_lock(&pf->switch_mutex); |
| 7422 | if (!pf->vsi[vsi->idx]) { |
| 7423 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7424 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7425 | goto unlock_vsi; |
| 7426 | } |
| 7427 | |
| 7428 | if (pf->vsi[vsi->idx] != vsi) { |
| 7429 | dev_err(&pf->pdev->dev, |
| 7430 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7431 | pf->vsi[vsi->idx]->idx, |
| 7432 | pf->vsi[vsi->idx], |
| 7433 | pf->vsi[vsi->idx]->type, |
| 7434 | vsi->idx, vsi, vsi->type); |
| 7435 | goto unlock_vsi; |
| 7436 | } |
| 7437 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7438 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7439 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7440 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7441 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7442 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7443 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7444 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7445 | pf->vsi[vsi->idx] = NULL; |
| 7446 | if (vsi->idx < pf->next_vsi) |
| 7447 | pf->next_vsi = vsi->idx; |
| 7448 | |
| 7449 | unlock_vsi: |
| 7450 | mutex_unlock(&pf->switch_mutex); |
| 7451 | free_vsi: |
| 7452 | kfree(vsi); |
| 7453 | |
| 7454 | return 0; |
| 7455 | } |
| 7456 | |
| 7457 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7458 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7459 | * @vsi: the VSI being cleaned |
| 7460 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7461 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7462 | { |
| 7463 | int i; |
| 7464 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7465 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7466 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7467 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7468 | vsi->tx_rings[i] = NULL; |
| 7469 | vsi->rx_rings[i] = NULL; |
| 7470 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7471 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7472 | } |
| 7473 | |
| 7474 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7475 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7476 | * @vsi: the VSI being configured |
| 7477 | **/ |
| 7478 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7479 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7480 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7481 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7482 | int i; |
| 7483 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7484 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7485 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7486 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7487 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7488 | if (!tx_ring) |
| 7489 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7490 | |
| 7491 | tx_ring->queue_index = i; |
| 7492 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7493 | tx_ring->ring_active = false; |
| 7494 | tx_ring->vsi = vsi; |
| 7495 | tx_ring->netdev = vsi->netdev; |
| 7496 | tx_ring->dev = &pf->pdev->dev; |
| 7497 | tx_ring->count = vsi->num_desc; |
| 7498 | tx_ring->size = 0; |
| 7499 | tx_ring->dcb_tc = 0; |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 7500 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 7501 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7502 | tx_ring->tx_itr_setting = pf->tx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7503 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7504 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7505 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7506 | rx_ring->queue_index = i; |
| 7507 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7508 | rx_ring->ring_active = false; |
| 7509 | rx_ring->vsi = vsi; |
| 7510 | rx_ring->netdev = vsi->netdev; |
| 7511 | rx_ring->dev = &pf->pdev->dev; |
| 7512 | rx_ring->count = vsi->num_desc; |
| 7513 | rx_ring->size = 0; |
| 7514 | rx_ring->dcb_tc = 0; |
| 7515 | if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) |
| 7516 | set_ring_16byte_desc_enabled(rx_ring); |
| 7517 | else |
| 7518 | clear_ring_16byte_desc_enabled(rx_ring); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7519 | rx_ring->rx_itr_setting = pf->rx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7520 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7521 | } |
| 7522 | |
| 7523 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7524 | |
| 7525 | err_out: |
| 7526 | i40e_vsi_clear_rings(vsi); |
| 7527 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7528 | } |
| 7529 | |
| 7530 | /** |
| 7531 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7532 | * @pf: board private structure |
| 7533 | * @vectors: the number of MSI-X vectors to request |
| 7534 | * |
| 7535 | * Returns the number of vectors reserved, or error |
| 7536 | **/ |
| 7537 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7538 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7539 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7540 | I40E_MIN_MSIX, vectors); |
| 7541 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7542 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7543 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7544 | vectors = 0; |
| 7545 | } |
| 7546 | |
| 7547 | return vectors; |
| 7548 | } |
| 7549 | |
| 7550 | /** |
| 7551 | * i40e_init_msix - Setup the MSIX capability |
| 7552 | * @pf: board private structure |
| 7553 | * |
| 7554 | * Work with the OS to set up the MSIX vectors needed. |
| 7555 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7556 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7557 | **/ |
| 7558 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7559 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7560 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7561 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7562 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7563 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7564 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7565 | |
| 7566 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7567 | return -ENODEV; |
| 7568 | |
| 7569 | /* The number of vectors we'll request will be comprised of: |
| 7570 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7571 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7572 | * - Queues being used for RSS. |
| 7573 | * We don't need as many as max_rss_size vectors. |
| 7574 | * use rss_size instead in the calculation since that |
| 7575 | * is governed by number of cpus in the system. |
| 7576 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7577 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7578 | * - The CPU count within the NUMA node if iWARP is enabled |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7579 | #ifdef I40E_FCOE |
| 7580 | * - The number of FCOE qps. |
| 7581 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7582 | * Once we count this up, try the request. |
| 7583 | * |
| 7584 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7585 | * and try again. If that still fails, we punt. |
| 7586 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7587 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7588 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7589 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7590 | /* reserve one vector for miscellaneous handler */ |
| 7591 | if (vectors_left) { |
| 7592 | v_budget++; |
| 7593 | vectors_left--; |
| 7594 | } |
| 7595 | |
| 7596 | /* reserve vectors for the main PF traffic queues */ |
| 7597 | pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left); |
| 7598 | vectors_left -= pf->num_lan_msix; |
| 7599 | v_budget += pf->num_lan_msix; |
| 7600 | |
| 7601 | /* reserve one vector for sideband flow director */ |
| 7602 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7603 | if (vectors_left) { |
| 7604 | v_budget++; |
| 7605 | vectors_left--; |
| 7606 | } else { |
| 7607 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7608 | } |
| 7609 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7610 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7611 | #ifdef I40E_FCOE |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7612 | /* can we reserve enough for FCoE? */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7613 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7614 | if (!vectors_left) |
| 7615 | pf->num_fcoe_msix = 0; |
| 7616 | else if (vectors_left >= pf->num_fcoe_qps) |
| 7617 | pf->num_fcoe_msix = pf->num_fcoe_qps; |
| 7618 | else |
| 7619 | pf->num_fcoe_msix = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7620 | v_budget += pf->num_fcoe_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7621 | vectors_left -= pf->num_fcoe_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7622 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7623 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7624 | #endif |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7625 | /* can we reserve enough for iWARP? */ |
| 7626 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7627 | if (!vectors_left) |
| 7628 | pf->num_iwarp_msix = 0; |
| 7629 | else if (vectors_left < pf->num_iwarp_msix) |
| 7630 | pf->num_iwarp_msix = 1; |
| 7631 | v_budget += pf->num_iwarp_msix; |
| 7632 | vectors_left -= pf->num_iwarp_msix; |
| 7633 | } |
| 7634 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7635 | /* any vectors left over go for VMDq support */ |
| 7636 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7637 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7638 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7639 | |
| 7640 | /* if we're short on vectors for what's desired, we limit |
| 7641 | * the queues per vmdq. If this is still more than are |
| 7642 | * available, the user will need to change the number of |
| 7643 | * queues/vectors used by the PF later with the ethtool |
| 7644 | * channels command |
| 7645 | */ |
| 7646 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7647 | pf->num_vmdq_qps = 1; |
| 7648 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
| 7649 | |
| 7650 | v_budget += vmdq_vecs; |
| 7651 | vectors_left -= vmdq_vecs; |
| 7652 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7653 | |
| 7654 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7655 | GFP_KERNEL); |
| 7656 | if (!pf->msix_entries) |
| 7657 | return -ENOMEM; |
| 7658 | |
| 7659 | for (i = 0; i < v_budget; i++) |
| 7660 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7661 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7662 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7663 | if (v_actual != v_budget) { |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7664 | /* If we have limited resources, we will start with no vectors |
| 7665 | * for the special features and then allocate vectors to some |
| 7666 | * of these features based on the policy and at the end disable |
| 7667 | * the features that did not get any vectors. |
| 7668 | */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7669 | iwarp_requested = pf->num_iwarp_msix; |
| 7670 | pf->num_iwarp_msix = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7671 | #ifdef I40E_FCOE |
| 7672 | pf->num_fcoe_qps = 0; |
| 7673 | pf->num_fcoe_msix = 0; |
| 7674 | #endif |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7675 | pf->num_vmdq_msix = 0; |
| 7676 | } |
| 7677 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7678 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7679 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7680 | kfree(pf->msix_entries); |
| 7681 | pf->msix_entries = NULL; |
| 7682 | return -ENODEV; |
| 7683 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7684 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7685 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7686 | pf->num_vmdq_vsis = 0; |
| 7687 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7688 | pf->num_lan_qps = 1; |
| 7689 | pf->num_lan_msix = 1; |
| 7690 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7691 | } else if (v_actual != v_budget) { |
| 7692 | int vec; |
| 7693 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7694 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7695 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7696 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7697 | /* Scale vector usage down */ |
| 7698 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7699 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7700 | pf->num_vmdq_qps = 1; |
| 7701 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7702 | |
| 7703 | /* partition out the remaining vectors */ |
| 7704 | switch (vec) { |
| 7705 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7706 | pf->num_lan_msix = 1; |
| 7707 | break; |
| 7708 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7709 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7710 | pf->num_lan_msix = 1; |
| 7711 | pf->num_iwarp_msix = 1; |
| 7712 | } else { |
| 7713 | pf->num_lan_msix = 2; |
| 7714 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7715 | #ifdef I40E_FCOE |
| 7716 | /* give one vector to FCoE */ |
| 7717 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7718 | pf->num_lan_msix = 1; |
| 7719 | pf->num_fcoe_msix = 1; |
| 7720 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7721 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7722 | break; |
| 7723 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7724 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7725 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 7726 | iwarp_requested); |
| 7727 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 7728 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7729 | } else { |
| 7730 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 7731 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7732 | } |
| 7733 | pf->num_lan_msix = min_t(int, |
| 7734 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 7735 | pf->num_lan_msix); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7736 | #ifdef I40E_FCOE |
| 7737 | /* give one vector to FCoE */ |
| 7738 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7739 | pf->num_fcoe_msix = 1; |
| 7740 | vec--; |
| 7741 | } |
| 7742 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7743 | break; |
| 7744 | } |
| 7745 | } |
| 7746 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7747 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7748 | (pf->num_vmdq_msix == 0)) { |
| 7749 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 7750 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 7751 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7752 | |
| 7753 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 7754 | (pf->num_iwarp_msix == 0)) { |
| 7755 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 7756 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 7757 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7758 | #ifdef I40E_FCOE |
| 7759 | |
| 7760 | if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { |
| 7761 | dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n"); |
| 7762 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 7763 | } |
| 7764 | #endif |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7765 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7766 | } |
| 7767 | |
| 7768 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7769 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7770 | * @vsi: the VSI being configured |
| 7771 | * @v_idx: index of the vector in the vsi struct |
| 7772 | * |
| 7773 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 7774 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7775 | static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7776 | { |
| 7777 | struct i40e_q_vector *q_vector; |
| 7778 | |
| 7779 | /* allocate q_vector */ |
| 7780 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 7781 | if (!q_vector) |
| 7782 | return -ENOMEM; |
| 7783 | |
| 7784 | q_vector->vsi = vsi; |
| 7785 | q_vector->v_idx = v_idx; |
| 7786 | cpumask_set_cpu(v_idx, &q_vector->affinity_mask); |
| 7787 | if (vsi->netdev) |
| 7788 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 7789 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7790 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 7791 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 7792 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 7793 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7794 | /* tie q_vector and vsi together */ |
| 7795 | vsi->q_vectors[v_idx] = q_vector; |
| 7796 | |
| 7797 | return 0; |
| 7798 | } |
| 7799 | |
| 7800 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7801 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7802 | * @vsi: the VSI being configured |
| 7803 | * |
| 7804 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 7805 | * return -ENOMEM. |
| 7806 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7807 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7808 | { |
| 7809 | struct i40e_pf *pf = vsi->back; |
| 7810 | int v_idx, num_q_vectors; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7811 | int err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7812 | |
| 7813 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 7814 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7815 | num_q_vectors = vsi->num_q_vectors; |
| 7816 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 7817 | num_q_vectors = 1; |
| 7818 | else |
| 7819 | return -EINVAL; |
| 7820 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7821 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7822 | err = i40e_vsi_alloc_q_vector(vsi, v_idx); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7823 | if (err) |
| 7824 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7825 | } |
| 7826 | |
| 7827 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7828 | |
| 7829 | err_out: |
| 7830 | while (v_idx--) |
| 7831 | i40e_free_q_vector(vsi, v_idx); |
| 7832 | |
| 7833 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7834 | } |
| 7835 | |
| 7836 | /** |
| 7837 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 7838 | * @pf: board private structure to initialize |
| 7839 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7840 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7841 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7842 | int vectors = 0; |
| 7843 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7844 | |
| 7845 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7846 | vectors = i40e_init_msix(pf); |
| 7847 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7848 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7849 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7850 | #ifdef I40E_FCOE |
| 7851 | I40E_FLAG_FCOE_ENABLED | |
| 7852 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7853 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7854 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7855 | I40E_FLAG_SRIOV_ENABLED | |
| 7856 | I40E_FLAG_FD_SB_ENABLED | |
| 7857 | I40E_FLAG_FD_ATR_ENABLED | |
| 7858 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7859 | |
| 7860 | /* rework the queue expectations without MSIX */ |
| 7861 | i40e_determine_queue_usage(pf); |
| 7862 | } |
| 7863 | } |
| 7864 | |
| 7865 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 7866 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7867 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7868 | vectors = pci_enable_msi(pf->pdev); |
| 7869 | if (vectors < 0) { |
| 7870 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 7871 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7872 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 7873 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7874 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7875 | } |
| 7876 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 7877 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7878 | 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] | 7879 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7880 | /* set up vector assignment tracking */ |
| 7881 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 7882 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7883 | if (!pf->irq_pile) { |
| 7884 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 7885 | return -ENOMEM; |
| 7886 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7887 | pf->irq_pile->num_entries = vectors; |
| 7888 | pf->irq_pile->search_hint = 0; |
| 7889 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7890 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7891 | (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] | 7892 | |
| 7893 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7894 | } |
| 7895 | |
| 7896 | /** |
| 7897 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 7898 | * @pf: board private structure |
| 7899 | * |
| 7900 | * This sets up the handler for MSIX 0, which is used to manage the |
| 7901 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 7902 | * when in MSI or Legacy interrupt mode. |
| 7903 | **/ |
| 7904 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 7905 | { |
| 7906 | struct i40e_hw *hw = &pf->hw; |
| 7907 | int err = 0; |
| 7908 | |
| 7909 | /* Only request the irq if this is the first time through, and |
| 7910 | * not when we're rebuilding after a Reset |
| 7911 | */ |
| 7912 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7913 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7914 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7915 | if (err) { |
| 7916 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7917 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7918 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7919 | return -EFAULT; |
| 7920 | } |
| 7921 | } |
| 7922 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 7923 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7924 | |
| 7925 | /* associate no queues to the misc vector */ |
| 7926 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 7927 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 7928 | |
| 7929 | i40e_flush(hw); |
| 7930 | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 7931 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7932 | |
| 7933 | return err; |
| 7934 | } |
| 7935 | |
| 7936 | /** |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7937 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 7938 | * @vsi: vsi structure |
| 7939 | * @seed: RSS hash seed |
| 7940 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7941 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 7942 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7943 | { |
| 7944 | struct i40e_aqc_get_set_rss_key_data rss_key; |
| 7945 | struct i40e_pf *pf = vsi->back; |
| 7946 | struct i40e_hw *hw = &pf->hw; |
| 7947 | bool pf_lut = false; |
| 7948 | u8 *rss_lut; |
| 7949 | int ret, i; |
| 7950 | |
| 7951 | memset(&rss_key, 0, sizeof(rss_key)); |
| 7952 | memcpy(&rss_key, seed, sizeof(rss_key)); |
| 7953 | |
| 7954 | rss_lut = kzalloc(pf->rss_table_size, GFP_KERNEL); |
| 7955 | if (!rss_lut) |
| 7956 | return -ENOMEM; |
| 7957 | |
| 7958 | /* Populate the LUT with max no. of queues in round robin fashion */ |
| 7959 | for (i = 0; i < vsi->rss_table_size; i++) |
| 7960 | rss_lut[i] = i % vsi->rss_size; |
| 7961 | |
| 7962 | ret = i40e_aq_set_rss_key(hw, vsi->id, &rss_key); |
| 7963 | if (ret) { |
| 7964 | dev_info(&pf->pdev->dev, |
| 7965 | "Cannot set RSS key, err %s aq_err %s\n", |
| 7966 | i40e_stat_str(&pf->hw, ret), |
| 7967 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai | 126b63d | 2015-08-24 13:26:53 -0700 | [diff] [blame] | 7968 | goto config_rss_aq_out; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7969 | } |
| 7970 | |
| 7971 | if (vsi->type == I40E_VSI_MAIN) |
| 7972 | pf_lut = true; |
| 7973 | |
| 7974 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, rss_lut, |
| 7975 | vsi->rss_table_size); |
| 7976 | if (ret) |
| 7977 | dev_info(&pf->pdev->dev, |
| 7978 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 7979 | i40e_stat_str(&pf->hw, ret), |
| 7980 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 7981 | |
Anjali Singhai | 126b63d | 2015-08-24 13:26:53 -0700 | [diff] [blame] | 7982 | config_rss_aq_out: |
| 7983 | kfree(rss_lut); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7984 | return ret; |
| 7985 | } |
| 7986 | |
| 7987 | /** |
| 7988 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 7989 | * @vsi: VSI structure |
| 7990 | **/ |
| 7991 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 7992 | { |
| 7993 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 7994 | struct i40e_pf *pf = vsi->back; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7995 | u8 *lut; |
| 7996 | int ret; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7997 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7998 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) |
| 7999 | return 0; |
| 8000 | |
| 8001 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8002 | if (!lut) |
| 8003 | return -ENOMEM; |
| 8004 | |
| 8005 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8006 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8007 | vsi->rss_size = min_t(int, pf->alloc_rss_size, vsi->num_queue_pairs); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8008 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 8009 | kfree(lut); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8010 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8011 | return ret; |
| 8012 | } |
| 8013 | |
| 8014 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8015 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 8016 | * @vsi: Pointer to vsi structure |
| 8017 | * @seed: Buffter to store the hash keys |
| 8018 | * @lut: Buffer to store the lookup table entries |
| 8019 | * @lut_size: Size of buffer to store the lookup table entries |
| 8020 | * |
| 8021 | * Return 0 on success, negative on failure |
| 8022 | */ |
| 8023 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8024 | u8 *lut, u16 lut_size) |
| 8025 | { |
| 8026 | struct i40e_pf *pf = vsi->back; |
| 8027 | struct i40e_hw *hw = &pf->hw; |
| 8028 | int ret = 0; |
| 8029 | |
| 8030 | if (seed) { |
| 8031 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 8032 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 8033 | if (ret) { |
| 8034 | dev_info(&pf->pdev->dev, |
| 8035 | "Cannot get RSS key, err %s aq_err %s\n", |
| 8036 | i40e_stat_str(&pf->hw, ret), |
| 8037 | i40e_aq_str(&pf->hw, |
| 8038 | pf->hw.aq.asq_last_status)); |
| 8039 | return ret; |
| 8040 | } |
| 8041 | } |
| 8042 | |
| 8043 | if (lut) { |
| 8044 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 8045 | |
| 8046 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8047 | if (ret) { |
| 8048 | dev_info(&pf->pdev->dev, |
| 8049 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 8050 | i40e_stat_str(&pf->hw, ret), |
| 8051 | i40e_aq_str(&pf->hw, |
| 8052 | pf->hw.aq.asq_last_status)); |
| 8053 | return ret; |
| 8054 | } |
| 8055 | } |
| 8056 | |
| 8057 | return ret; |
| 8058 | } |
| 8059 | |
| 8060 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8061 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8062 | * @vsi: Pointer to vsi structure |
| 8063 | * @seed: RSS hash seed |
| 8064 | * @lut: Lookup table |
| 8065 | * @lut_size: Lookup table size |
| 8066 | * |
| 8067 | * Returns 0 on success, negative on failure |
| 8068 | **/ |
| 8069 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8070 | const u8 *lut, u16 lut_size) |
| 8071 | { |
| 8072 | struct i40e_pf *pf = vsi->back; |
| 8073 | struct i40e_hw *hw = &pf->hw; |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8074 | u16 vf_id = vsi->vf_id; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8075 | u8 i; |
| 8076 | |
| 8077 | /* Fill out hash function seed */ |
| 8078 | if (seed) { |
| 8079 | u32 *seed_dw = (u32 *)seed; |
| 8080 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8081 | if (vsi->type == I40E_VSI_MAIN) { |
| 8082 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 8083 | i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), |
| 8084 | seed_dw[i]); |
| 8085 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8086 | for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++) |
| 8087 | i40e_write_rx_ctl(hw, |
| 8088 | I40E_VFQF_HKEY1(i, vf_id), |
| 8089 | seed_dw[i]); |
| 8090 | } else { |
| 8091 | dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n"); |
| 8092 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8093 | } |
| 8094 | |
| 8095 | if (lut) { |
| 8096 | u32 *lut_dw = (u32 *)lut; |
| 8097 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8098 | if (vsi->type == I40E_VSI_MAIN) { |
| 8099 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8100 | return -EINVAL; |
| 8101 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8102 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8103 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8104 | if (lut_size != I40E_VF_HLUT_ARRAY_SIZE) |
| 8105 | return -EINVAL; |
| 8106 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8107 | i40e_write_rx_ctl(hw, |
| 8108 | I40E_VFQF_HLUT1(i, vf_id), |
| 8109 | lut_dw[i]); |
| 8110 | } else { |
| 8111 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8112 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8113 | } |
| 8114 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8115 | |
| 8116 | return 0; |
| 8117 | } |
| 8118 | |
| 8119 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8120 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8121 | * @vsi: Pointer to VSI structure |
| 8122 | * @seed: Buffer to store the keys |
| 8123 | * @lut: Buffer to store the lookup table entries |
| 8124 | * @lut_size: Size of buffer to store the lookup table entries |
| 8125 | * |
| 8126 | * Returns 0 on success, negative on failure |
| 8127 | */ |
| 8128 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8129 | u8 *lut, u16 lut_size) |
| 8130 | { |
| 8131 | struct i40e_pf *pf = vsi->back; |
| 8132 | struct i40e_hw *hw = &pf->hw; |
| 8133 | u16 i; |
| 8134 | |
| 8135 | if (seed) { |
| 8136 | u32 *seed_dw = (u32 *)seed; |
| 8137 | |
| 8138 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8139 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8140 | } |
| 8141 | if (lut) { |
| 8142 | u32 *lut_dw = (u32 *)lut; |
| 8143 | |
| 8144 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8145 | return -EINVAL; |
| 8146 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8147 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8148 | } |
| 8149 | |
| 8150 | return 0; |
| 8151 | } |
| 8152 | |
| 8153 | /** |
| 8154 | * i40e_config_rss - Configure RSS keys and lut |
| 8155 | * @vsi: Pointer to VSI structure |
| 8156 | * @seed: RSS hash seed |
| 8157 | * @lut: Lookup table |
| 8158 | * @lut_size: Lookup table size |
| 8159 | * |
| 8160 | * Returns 0 on success, negative on failure |
| 8161 | */ |
| 8162 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8163 | { |
| 8164 | struct i40e_pf *pf = vsi->back; |
| 8165 | |
| 8166 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8167 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8168 | else |
| 8169 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8170 | } |
| 8171 | |
| 8172 | /** |
| 8173 | * i40e_get_rss - Get RSS keys and lut |
| 8174 | * @vsi: Pointer to VSI structure |
| 8175 | * @seed: Buffer to store the keys |
| 8176 | * @lut: Buffer to store the lookup table entries |
| 8177 | * lut_size: Size of buffer to store the lookup table entries |
| 8178 | * |
| 8179 | * Returns 0 on success, negative on failure |
| 8180 | */ |
| 8181 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8182 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8183 | struct i40e_pf *pf = vsi->back; |
| 8184 | |
| 8185 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8186 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8187 | else |
| 8188 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8189 | } |
| 8190 | |
| 8191 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8192 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8193 | * @pf: Pointer to board private structure |
| 8194 | * @lut: Lookup table |
| 8195 | * @rss_table_size: Lookup table size |
| 8196 | * @rss_size: Range of queue number for hashing |
| 8197 | */ |
| 8198 | static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8199 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8200 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8201 | u16 i; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8202 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8203 | for (i = 0; i < rss_table_size; i++) |
| 8204 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8205 | } |
| 8206 | |
| 8207 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8208 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8209 | * @pf: board private structure |
| 8210 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8211 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8212 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8213 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8214 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8215 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8216 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8217 | u32 reg_val; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8218 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8219 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8220 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8221 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8222 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 8223 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8224 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8225 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8226 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8227 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8228 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8229 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8230 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8231 | reg_val = (pf->rss_table_size == 512) ? |
| 8232 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8233 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8234 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8235 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8236 | /* Determine the RSS size of the VSI */ |
| 8237 | if (!vsi->rss_size) |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8238 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8239 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8240 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8241 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8242 | if (!lut) |
| 8243 | return -ENOMEM; |
| 8244 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8245 | /* Use user configured lut if there is one, otherwise use default */ |
| 8246 | if (vsi->rss_lut_user) |
| 8247 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8248 | else |
| 8249 | 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] | 8250 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8251 | /* Use user configured hash key if there is one, otherwise |
| 8252 | * use default. |
| 8253 | */ |
| 8254 | if (vsi->rss_hkey_user) |
| 8255 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8256 | else |
| 8257 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8258 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8259 | kfree(lut); |
| 8260 | |
| 8261 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8262 | } |
| 8263 | |
| 8264 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8265 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8266 | * @pf: board private structure |
| 8267 | * @queue_count: the requested queue count for rss. |
| 8268 | * |
| 8269 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8270 | * count which may be different from the requested queue count. |
| 8271 | **/ |
| 8272 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8273 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8274 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8275 | int new_rss_size; |
| 8276 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8277 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8278 | return 0; |
| 8279 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8280 | 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] | 8281 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8282 | if (queue_count != vsi->num_queue_pairs) { |
| 8283 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8284 | i40e_prep_for_reset(pf); |
| 8285 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8286 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8287 | |
| 8288 | i40e_reset_and_rebuild(pf, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8289 | |
| 8290 | /* Discard the user configured hash keys and lut, if less |
| 8291 | * queues are enabled. |
| 8292 | */ |
| 8293 | if (queue_count < vsi->rss_size) { |
| 8294 | i40e_clear_rss_config_user(vsi); |
| 8295 | dev_dbg(&pf->pdev->dev, |
| 8296 | "discard user configured hash keys and lut\n"); |
| 8297 | } |
| 8298 | |
| 8299 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8300 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8301 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8302 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8303 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8304 | } |
Helin Zhang | e36b0b1 | 2015-10-26 19:44:36 -0400 | [diff] [blame] | 8305 | dev_info(&pf->pdev->dev, "RSS count/HW max RSS count: %d/%d\n", |
| 8306 | pf->alloc_rss_size, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8307 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8308 | } |
| 8309 | |
| 8310 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8311 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 8312 | * @pf: board private structure |
| 8313 | **/ |
| 8314 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 8315 | { |
| 8316 | i40e_status status; |
| 8317 | bool min_valid, max_valid; |
| 8318 | u32 max_bw, min_bw; |
| 8319 | |
| 8320 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8321 | &min_valid, &max_valid); |
| 8322 | |
| 8323 | if (!status) { |
| 8324 | if (min_valid) |
| 8325 | pf->npar_min_bw = min_bw; |
| 8326 | if (max_valid) |
| 8327 | pf->npar_max_bw = max_bw; |
| 8328 | } |
| 8329 | |
| 8330 | return status; |
| 8331 | } |
| 8332 | |
| 8333 | /** |
| 8334 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 8335 | * @pf: board private structure |
| 8336 | **/ |
| 8337 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 8338 | { |
| 8339 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8340 | i40e_status status; |
| 8341 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8342 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8343 | 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] | 8344 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8345 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 8346 | |
| 8347 | /* Set the new bandwidths */ |
| 8348 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8349 | |
| 8350 | return status; |
| 8351 | } |
| 8352 | |
| 8353 | /** |
| 8354 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 8355 | * @pf: board private structure |
| 8356 | **/ |
| 8357 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 8358 | { |
| 8359 | /* Commit temporary BW setting to permanent NVM image */ |
| 8360 | enum i40e_admin_queue_err last_aq_status; |
| 8361 | i40e_status ret; |
| 8362 | u16 nvm_word; |
| 8363 | |
| 8364 | if (pf->hw.partition_id != 1) { |
| 8365 | dev_info(&pf->pdev->dev, |
| 8366 | "Commit BW only works on partition 1! This is partition %d", |
| 8367 | pf->hw.partition_id); |
| 8368 | ret = I40E_NOT_SUPPORTED; |
| 8369 | goto bw_commit_out; |
| 8370 | } |
| 8371 | |
| 8372 | /* Acquire NVM for read access */ |
| 8373 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8374 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8375 | if (ret) { |
| 8376 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8377 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8378 | i40e_stat_str(&pf->hw, ret), |
| 8379 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8380 | goto bw_commit_out; |
| 8381 | } |
| 8382 | |
| 8383 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8384 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8385 | I40E_SR_NVM_CONTROL_WORD, |
| 8386 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8387 | false, NULL); |
| 8388 | /* Save off last admin queue command status before releasing |
| 8389 | * the NVM |
| 8390 | */ |
| 8391 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8392 | i40e_release_nvm(&pf->hw); |
| 8393 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8394 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8395 | i40e_stat_str(&pf->hw, ret), |
| 8396 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8397 | goto bw_commit_out; |
| 8398 | } |
| 8399 | |
| 8400 | /* Wait a bit for NVM release to complete */ |
| 8401 | msleep(50); |
| 8402 | |
| 8403 | /* Acquire NVM for write access */ |
| 8404 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8405 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8406 | if (ret) { |
| 8407 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8408 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8409 | i40e_stat_str(&pf->hw, ret), |
| 8410 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8411 | goto bw_commit_out; |
| 8412 | } |
| 8413 | /* Write it back out unchanged to initiate update NVM, |
| 8414 | * which will force a write of the shadow (alt) RAM to |
| 8415 | * the NVM - thus storing the bandwidth values permanently. |
| 8416 | */ |
| 8417 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8418 | I40E_SR_NVM_CONTROL_WORD, |
| 8419 | 0x10, sizeof(nvm_word), |
| 8420 | &nvm_word, true, NULL); |
| 8421 | /* Save off last admin queue command status before releasing |
| 8422 | * the NVM |
| 8423 | */ |
| 8424 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8425 | i40e_release_nvm(&pf->hw); |
| 8426 | if (ret) |
| 8427 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8428 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8429 | i40e_stat_str(&pf->hw, ret), |
| 8430 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8431 | bw_commit_out: |
| 8432 | |
| 8433 | return ret; |
| 8434 | } |
| 8435 | |
| 8436 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8437 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8438 | * @pf: board private structure to initialize |
| 8439 | * |
| 8440 | * i40e_sw_init initializes the Adapter private data structure. |
| 8441 | * Fields are initialized based on PCI device information and |
| 8442 | * OS network device settings (MTU size). |
| 8443 | **/ |
| 8444 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8445 | { |
| 8446 | int err = 0; |
| 8447 | int size; |
| 8448 | |
| 8449 | pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, |
| 8450 | (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); |
| 8451 | if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { |
| 8452 | if (I40E_DEBUG_USER & debug) |
| 8453 | pf->hw.debug_mask = debug; |
| 8454 | pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), |
| 8455 | I40E_DEFAULT_MSG_ENABLE); |
| 8456 | } |
| 8457 | |
| 8458 | /* Set default capability flags */ |
| 8459 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8460 | I40E_FLAG_MSI_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8461 | I40E_FLAG_MSIX_ENABLED; |
| 8462 | |
| 8463 | if (iommu_present(&pci_bus_type)) |
| 8464 | pf->flags |= I40E_FLAG_RX_PS_ENABLED; |
| 8465 | else |
| 8466 | pf->flags |= I40E_FLAG_RX_1BUF_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8467 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8468 | /* Set default ITR */ |
| 8469 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8470 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8471 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8472 | /* Depending on PF configurations, it is possible that the RSS |
| 8473 | * maximum might end up larger than the available queues |
| 8474 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8475 | 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] | 8476 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8477 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8478 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8479 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8480 | if (pf->hw.func_caps.rss) { |
| 8481 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8482 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8483 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8484 | } |
| 8485 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8486 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8487 | 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] | 8488 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8489 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8490 | if (i40e_get_npar_bw_setting(pf)) |
| 8491 | dev_warn(&pf->pdev->dev, |
| 8492 | "Could not get NPAR bw settings\n"); |
| 8493 | else |
| 8494 | dev_info(&pf->pdev->dev, |
| 8495 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 8496 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8497 | } |
| 8498 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8499 | /* FW/NVM is not yet fixed in this regard */ |
| 8500 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8501 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8502 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8503 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8504 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8505 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8506 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8507 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8508 | else |
| 8509 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8510 | pf->fdir_pf_filter_count = |
| 8511 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8512 | pf->hw.fdir_shared_filter_count = |
| 8513 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8514 | } |
| 8515 | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8516 | if (i40e_is_mac_710(&pf->hw) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8517 | (((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] | 8518 | (pf->hw.aq.fw_maj_ver < 4))) { |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8519 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8520 | /* No DCB support for FW < v4.33 */ |
| 8521 | pf->flags |= I40E_FLAG_NO_DCB_SUPPORT; |
| 8522 | } |
| 8523 | |
| 8524 | /* Disable FW LLDP if FW < v4.3 */ |
| 8525 | if (i40e_is_mac_710(&pf->hw) && |
| 8526 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 8527 | (pf->hw.aq.fw_maj_ver < 4))) |
| 8528 | pf->flags |= I40E_FLAG_STOP_FW_LLDP; |
| 8529 | |
| 8530 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
| 8531 | if (i40e_is_mac_710(&pf->hw) && |
| 8532 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 8533 | (pf->hw.aq.fw_maj_ver >= 5))) |
| 8534 | pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8535 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8536 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8537 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8538 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 8539 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8540 | } |
| 8541 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8542 | if (pf->hw.func_caps.iwarp) { |
| 8543 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 8544 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 8545 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 8546 | } |
| 8547 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8548 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 8549 | i40e_init_pf_fcoe(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8550 | |
| 8551 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8552 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 8553 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8554 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 8555 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 8556 | pf->num_req_vfs = min_t(int, |
| 8557 | pf->hw.func_caps.num_vfs, |
| 8558 | I40E_MAX_VF_COUNT); |
| 8559 | } |
| 8560 | #endif /* CONFIG_PCI_IOV */ |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8561 | if (pf->hw.mac.type == I40E_MAC_X722) { |
| 8562 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE | |
| 8563 | I40E_FLAG_128_QP_RSS_CAPABLE | |
| 8564 | I40E_FLAG_HW_ATR_EVICT_CAPABLE | |
| 8565 | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE | |
| 8566 | I40E_FLAG_WB_ON_ITR_CAPABLE | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8567 | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
Jesse Brandeburg | 8e2cc0e | 2016-02-29 11:00:24 -0800 | [diff] [blame] | 8568 | I40E_FLAG_NO_PCI_LINK_CHECK | |
Catherine Sullivan | f8db54cc | 2015-12-22 14:25:14 -0800 | [diff] [blame] | 8569 | I40E_FLAG_100M_SGMII_CAPABLE | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8570 | I40E_FLAG_USE_SET_LLDP_MIB | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8571 | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8572 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 8573 | ((pf->hw.aq.api_maj_ver == 1) && |
| 8574 | (pf->hw.aq.api_min_ver > 4))) { |
| 8575 | /* Supported in FW API version higher than 1.4 */ |
| 8576 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 8577 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
| 8578 | } else { |
| 8579 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8580 | } |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8581 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8582 | pf->eeprom_version = 0xDEAD; |
| 8583 | pf->lan_veb = I40E_NO_VEB; |
| 8584 | pf->lan_vsi = I40E_NO_VSI; |
| 8585 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 8586 | /* By default FW has this off for performance reasons */ |
| 8587 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 8588 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8589 | /* set up queue assignment tracking */ |
| 8590 | size = sizeof(struct i40e_lump_tracking) |
| 8591 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 8592 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 8593 | if (!pf->qp_pile) { |
| 8594 | err = -ENOMEM; |
| 8595 | goto sw_init_done; |
| 8596 | } |
| 8597 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 8598 | pf->qp_pile->search_hint = 0; |
| 8599 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 8600 | pf->tx_timeout_recovery_level = 1; |
| 8601 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8602 | mutex_init(&pf->switch_mutex); |
| 8603 | |
Greg Rose | c668a12 | 2015-02-26 16:10:39 +0000 | [diff] [blame] | 8604 | /* If NPAR is enabled nudge the Tx scheduler */ |
| 8605 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) |
| 8606 | i40e_set_npar_bw_setting(pf); |
| 8607 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8608 | sw_init_done: |
| 8609 | return err; |
| 8610 | } |
| 8611 | |
| 8612 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8613 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 8614 | * @pf: board private structure to initialize |
| 8615 | * @features: the feature set that the stack is suggesting |
| 8616 | * |
| 8617 | * returns a bool to indicate if reset needs to happen |
| 8618 | **/ |
| 8619 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 8620 | { |
| 8621 | bool need_reset = false; |
| 8622 | |
| 8623 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 8624 | * the state changed, we need to reset. |
| 8625 | */ |
| 8626 | if (features & NETIF_F_NTUPLE) { |
| 8627 | /* Enable filters and mark for reset */ |
| 8628 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 8629 | need_reset = true; |
| 8630 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
| 8631 | } else { |
| 8632 | /* turn off filters, mark for reset and clear SW filter list */ |
| 8633 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8634 | need_reset = true; |
| 8635 | i40e_fdir_filter_exit(pf); |
| 8636 | } |
| 8637 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8638 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 8639 | /* reset fd counters */ |
| 8640 | pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0; |
| 8641 | pf->fdir_pf_active_filters = 0; |
| 8642 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 8643 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 8644 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8645 | /* if ATR was auto disabled it can be re-enabled. */ |
| 8646 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 8647 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 8648 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8649 | } |
| 8650 | return need_reset; |
| 8651 | } |
| 8652 | |
| 8653 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8654 | * i40e_set_features - set the netdev feature flags |
| 8655 | * @netdev: ptr to the netdev being adjusted |
| 8656 | * @features: the feature set that the stack is suggesting |
| 8657 | **/ |
| 8658 | static int i40e_set_features(struct net_device *netdev, |
| 8659 | netdev_features_t features) |
| 8660 | { |
| 8661 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8662 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8663 | struct i40e_pf *pf = vsi->back; |
| 8664 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8665 | |
| 8666 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8667 | i40e_vlan_stripping_enable(vsi); |
| 8668 | else |
| 8669 | i40e_vlan_stripping_disable(vsi); |
| 8670 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8671 | need_reset = i40e_set_ntuple(pf, features); |
| 8672 | |
| 8673 | if (need_reset) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8674 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8675 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8676 | return 0; |
| 8677 | } |
| 8678 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8679 | #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8680 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8681 | * 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] | 8682 | * @pf: board private structure |
| 8683 | * @port: The UDP port to look up |
| 8684 | * |
| 8685 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 8686 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8687 | 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] | 8688 | { |
| 8689 | u8 i; |
| 8690 | |
| 8691 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8692 | if (pf->udp_ports[i].index == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8693 | return i; |
| 8694 | } |
| 8695 | |
| 8696 | return i; |
| 8697 | } |
| 8698 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8699 | #endif |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8700 | |
| 8701 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8702 | /** |
| 8703 | * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up |
| 8704 | * @netdev: This physical port's netdev |
| 8705 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 8706 | * @port: New UDP port number that VXLAN started listening to |
| 8707 | **/ |
| 8708 | static void i40e_add_vxlan_port(struct net_device *netdev, |
| 8709 | sa_family_t sa_family, __be16 port) |
| 8710 | { |
| 8711 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8712 | struct i40e_vsi *vsi = np->vsi; |
| 8713 | struct i40e_pf *pf = vsi->back; |
| 8714 | u8 next_idx; |
| 8715 | u8 idx; |
| 8716 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8717 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8718 | |
| 8719 | /* Check if port already exists */ |
| 8720 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8721 | netdev_info(netdev, "vxlan port %d already offloaded\n", |
| 8722 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8723 | return; |
| 8724 | } |
| 8725 | |
| 8726 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8727 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8728 | |
| 8729 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8730 | netdev_info(netdev, "maximum number of vxlan UDP ports reached, not adding port %d\n", |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8731 | ntohs(port)); |
| 8732 | return; |
| 8733 | } |
| 8734 | |
| 8735 | /* New port: add it and mark its index in the bitmap */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8736 | pf->udp_ports[next_idx].index = port; |
| 8737 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 8738 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8739 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8740 | } |
| 8741 | |
| 8742 | /** |
| 8743 | * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away |
| 8744 | * @netdev: This physical port's netdev |
| 8745 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 8746 | * @port: UDP port number that VXLAN stopped listening to |
| 8747 | **/ |
| 8748 | static void i40e_del_vxlan_port(struct net_device *netdev, |
| 8749 | sa_family_t sa_family, __be16 port) |
| 8750 | { |
| 8751 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8752 | struct i40e_vsi *vsi = np->vsi; |
| 8753 | struct i40e_pf *pf = vsi->back; |
| 8754 | u8 idx; |
| 8755 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8756 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8757 | |
| 8758 | /* Check if port already exists */ |
| 8759 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8760 | /* if port exists, set it to 0 (mark for deletion) |
| 8761 | * and make it pending |
| 8762 | */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8763 | pf->udp_ports[idx].index = 0; |
| 8764 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
| 8765 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8766 | } else { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8767 | netdev_warn(netdev, "vxlan port %d was not found, not deleting\n", |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8768 | ntohs(port)); |
| 8769 | } |
| 8770 | } |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8771 | #endif |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8772 | |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8773 | #if IS_ENABLED(CONFIG_GENEVE) |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8774 | /** |
| 8775 | * i40e_add_geneve_port - Get notifications about GENEVE ports that come up |
| 8776 | * @netdev: This physical port's netdev |
| 8777 | * @sa_family: Socket Family that GENEVE is notifying us about |
| 8778 | * @port: New UDP port number that GENEVE started listening to |
| 8779 | **/ |
| 8780 | static void i40e_add_geneve_port(struct net_device *netdev, |
| 8781 | sa_family_t sa_family, __be16 port) |
| 8782 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8783 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8784 | struct i40e_vsi *vsi = np->vsi; |
| 8785 | struct i40e_pf *pf = vsi->back; |
| 8786 | u8 next_idx; |
| 8787 | u8 idx; |
| 8788 | |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8789 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8790 | return; |
| 8791 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8792 | idx = i40e_get_udp_port_idx(pf, port); |
| 8793 | |
| 8794 | /* Check if port already exists */ |
| 8795 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8796 | netdev_info(netdev, "udp port %d already offloaded\n", |
| 8797 | ntohs(port)); |
| 8798 | return; |
| 8799 | } |
| 8800 | |
| 8801 | /* Now check if there is space to add the new port */ |
| 8802 | next_idx = i40e_get_udp_port_idx(pf, 0); |
| 8803 | |
| 8804 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8805 | netdev_info(netdev, "maximum number of UDP ports reached, not adding port %d\n", |
| 8806 | ntohs(port)); |
| 8807 | return; |
| 8808 | } |
| 8809 | |
| 8810 | /* New port: add it and mark its index in the bitmap */ |
| 8811 | pf->udp_ports[next_idx].index = port; |
| 8812 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 8813 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8814 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8815 | |
| 8816 | dev_info(&pf->pdev->dev, "adding geneve port %d\n", ntohs(port)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8817 | } |
| 8818 | |
| 8819 | /** |
| 8820 | * i40e_del_geneve_port - Get notifications about GENEVE ports that go away |
| 8821 | * @netdev: This physical port's netdev |
| 8822 | * @sa_family: Socket Family that GENEVE is notifying us about |
| 8823 | * @port: UDP port number that GENEVE stopped listening to |
| 8824 | **/ |
| 8825 | static void i40e_del_geneve_port(struct net_device *netdev, |
| 8826 | sa_family_t sa_family, __be16 port) |
| 8827 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8828 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8829 | struct i40e_vsi *vsi = np->vsi; |
| 8830 | struct i40e_pf *pf = vsi->back; |
| 8831 | u8 idx; |
| 8832 | |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8833 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8834 | return; |
| 8835 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8836 | idx = i40e_get_udp_port_idx(pf, port); |
| 8837 | |
| 8838 | /* Check if port already exists */ |
| 8839 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 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); |
| 8845 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8846 | |
| 8847 | dev_info(&pf->pdev->dev, "deleting geneve port %d\n", |
| 8848 | ntohs(port)); |
| 8849 | } else { |
| 8850 | netdev_warn(netdev, "geneve port %d was not found, not deleting\n", |
| 8851 | ntohs(port)); |
| 8852 | } |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8853 | } |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8854 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8855 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8856 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 8857 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8858 | { |
| 8859 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8860 | struct i40e_pf *pf = np->vsi->back; |
| 8861 | struct i40e_hw *hw = &pf->hw; |
| 8862 | |
| 8863 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 8864 | return -EOPNOTSUPP; |
| 8865 | |
| 8866 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 8867 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 8868 | |
| 8869 | return 0; |
| 8870 | } |
| 8871 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 8872 | /** |
| 8873 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 8874 | * @ndm: the input from the stack |
| 8875 | * @tb: pointer to array of nladdr (unused) |
| 8876 | * @dev: the net device pointer |
| 8877 | * @addr: the MAC address entry being added |
| 8878 | * @flags: instructions from stack about fdb operation |
| 8879 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8880 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 8881 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8882 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8883 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8884 | { |
| 8885 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8886 | struct i40e_pf *pf = np->vsi->back; |
| 8887 | int err = 0; |
| 8888 | |
| 8889 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 8890 | return -EOPNOTSUPP; |
| 8891 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 8892 | if (vid) { |
| 8893 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 8894 | return -EINVAL; |
| 8895 | } |
| 8896 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8897 | /* Hardware does not support aging addresses so if a |
| 8898 | * ndm_state is given only allow permanent addresses |
| 8899 | */ |
| 8900 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 8901 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 8902 | return -EINVAL; |
| 8903 | } |
| 8904 | |
| 8905 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 8906 | err = dev_uc_add_excl(dev, addr); |
| 8907 | else if (is_multicast_ether_addr(addr)) |
| 8908 | err = dev_mc_add_excl(dev, addr); |
| 8909 | else |
| 8910 | err = -EINVAL; |
| 8911 | |
| 8912 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 8913 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 8914 | err = 0; |
| 8915 | |
| 8916 | return err; |
| 8917 | } |
| 8918 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8919 | /** |
| 8920 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 8921 | * @dev: the netdev being configured |
| 8922 | * @nlh: RTNL message |
| 8923 | * |
| 8924 | * Inserts a new hardware bridge if not already created and |
| 8925 | * enables the bridging mode requested (VEB or VEPA). If the |
| 8926 | * hardware bridge has already been inserted and the request |
| 8927 | * is to change the mode then that requires a PF reset to |
| 8928 | * allow rebuild of the components with required hardware |
| 8929 | * bridge mode enabled. |
| 8930 | **/ |
| 8931 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 8932 | struct nlmsghdr *nlh, |
| 8933 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8934 | { |
| 8935 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8936 | struct i40e_vsi *vsi = np->vsi; |
| 8937 | struct i40e_pf *pf = vsi->back; |
| 8938 | struct i40e_veb *veb = NULL; |
| 8939 | struct nlattr *attr, *br_spec; |
| 8940 | int i, rem; |
| 8941 | |
| 8942 | /* Only for PF VSI for now */ |
| 8943 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8944 | return -EOPNOTSUPP; |
| 8945 | |
| 8946 | /* Find the HW bridge for PF VSI */ |
| 8947 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8948 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8949 | veb = pf->veb[i]; |
| 8950 | } |
| 8951 | |
| 8952 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 8953 | |
| 8954 | nla_for_each_nested(attr, br_spec, rem) { |
| 8955 | __u16 mode; |
| 8956 | |
| 8957 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 8958 | continue; |
| 8959 | |
| 8960 | mode = nla_get_u16(attr); |
| 8961 | if ((mode != BRIDGE_MODE_VEPA) && |
| 8962 | (mode != BRIDGE_MODE_VEB)) |
| 8963 | return -EINVAL; |
| 8964 | |
| 8965 | /* Insert a new HW bridge */ |
| 8966 | if (!veb) { |
| 8967 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 8968 | vsi->tc_config.enabled_tc); |
| 8969 | if (veb) { |
| 8970 | veb->bridge_mode = mode; |
| 8971 | i40e_config_bridge_mode(veb); |
| 8972 | } else { |
| 8973 | /* No Bridge HW offload available */ |
| 8974 | return -ENOENT; |
| 8975 | } |
| 8976 | break; |
| 8977 | } else if (mode != veb->bridge_mode) { |
| 8978 | /* Existing HW bridge but different mode needs reset */ |
| 8979 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 8980 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 8981 | if (mode == BRIDGE_MODE_VEB) |
| 8982 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 8983 | else |
| 8984 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 8985 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8986 | break; |
| 8987 | } |
| 8988 | } |
| 8989 | |
| 8990 | return 0; |
| 8991 | } |
| 8992 | |
| 8993 | /** |
| 8994 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 8995 | * @skb: skb buff |
| 8996 | * @pid: process id |
| 8997 | * @seq: RTNL message seq # |
| 8998 | * @dev: the netdev being configured |
| 8999 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 9000 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9001 | * |
| 9002 | * Return the mode in which the hardware bridge is operating in |
| 9003 | * i.e VEB or VEPA. |
| 9004 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9005 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 9006 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 9007 | u32 __always_unused filter_mask, |
| 9008 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9009 | { |
| 9010 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9011 | struct i40e_vsi *vsi = np->vsi; |
| 9012 | struct i40e_pf *pf = vsi->back; |
| 9013 | struct i40e_veb *veb = NULL; |
| 9014 | int i; |
| 9015 | |
| 9016 | /* Only for PF VSI for now */ |
| 9017 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9018 | return -EOPNOTSUPP; |
| 9019 | |
| 9020 | /* Find the HW bridge for the PF VSI */ |
| 9021 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9022 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9023 | veb = pf->veb[i]; |
| 9024 | } |
| 9025 | |
| 9026 | if (!veb) |
| 9027 | return 0; |
| 9028 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9029 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 9030 | nlflags, 0, 0, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9031 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9032 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9033 | /* Hardware supports L4 tunnel length of 128B (=2^7) which includes |
| 9034 | * inner mac plus all inner ethertypes. |
| 9035 | */ |
| 9036 | #define I40E_MAX_TUNNEL_HDR_LEN 128 |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9037 | /** |
| 9038 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 9039 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 9040 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9041 | * @features: Offload features that the stack believes apply |
| 9042 | **/ |
| 9043 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 9044 | struct net_device *dev, |
| 9045 | netdev_features_t features) |
| 9046 | { |
| 9047 | if (skb->encapsulation && |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9048 | ((skb_inner_network_header(skb) - skb_transport_header(skb)) > |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9049 | I40E_MAX_TUNNEL_HDR_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 9050 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9051 | |
| 9052 | return features; |
| 9053 | } |
| 9054 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 9055 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9056 | .ndo_open = i40e_open, |
| 9057 | .ndo_stop = i40e_close, |
| 9058 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 9059 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 9060 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 9061 | .ndo_validate_addr = eth_validate_addr, |
| 9062 | .ndo_set_mac_address = i40e_set_mac, |
| 9063 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 9064 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9065 | .ndo_tx_timeout = i40e_tx_timeout, |
| 9066 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 9067 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 9068 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9069 | .ndo_poll_controller = i40e_netpoll, |
| 9070 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9071 | .ndo_setup_tc = __i40e_setup_tc, |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9072 | #ifdef I40E_FCOE |
| 9073 | .ndo_fcoe_enable = i40e_fcoe_enable, |
| 9074 | .ndo_fcoe_disable = i40e_fcoe_disable, |
| 9075 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9076 | .ndo_set_features = i40e_set_features, |
| 9077 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 9078 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9079 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9080 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 9081 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 9082 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Anjali Singhai Jain | c3bbbd2 | 2016-04-01 03:56:07 -0700 | [diff] [blame] | 9083 | .ndo_set_vf_trust = i40e_ndo_set_vf_trust, |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9084 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9085 | .ndo_add_vxlan_port = i40e_add_vxlan_port, |
| 9086 | .ndo_del_vxlan_port = i40e_del_vxlan_port, |
| 9087 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9088 | #if IS_ENABLED(CONFIG_GENEVE) |
| 9089 | .ndo_add_geneve_port = i40e_add_geneve_port, |
| 9090 | .ndo_del_geneve_port = i40e_del_geneve_port, |
| 9091 | #endif |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9092 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9093 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9094 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9095 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 9096 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9097 | }; |
| 9098 | |
| 9099 | /** |
| 9100 | * i40e_config_netdev - Setup the netdev flags |
| 9101 | * @vsi: the VSI being configured |
| 9102 | * |
| 9103 | * Returns 0 on success, negative value on failure |
| 9104 | **/ |
| 9105 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 9106 | { |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 9107 | u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9108 | struct i40e_pf *pf = vsi->back; |
| 9109 | struct i40e_hw *hw = &pf->hw; |
| 9110 | struct i40e_netdev_priv *np; |
| 9111 | struct net_device *netdev; |
| 9112 | u8 mac_addr[ETH_ALEN]; |
| 9113 | int etherdev_size; |
| 9114 | |
| 9115 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9116 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9117 | if (!netdev) |
| 9118 | return -ENOMEM; |
| 9119 | |
| 9120 | vsi->netdev = netdev; |
| 9121 | np = netdev_priv(netdev); |
| 9122 | np->vsi = vsi; |
| 9123 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9124 | netdev->hw_enc_features |= NETIF_F_SG | |
| 9125 | NETIF_F_IP_CSUM | |
| 9126 | NETIF_F_IPV6_CSUM | |
| 9127 | NETIF_F_HIGHDMA | |
| 9128 | NETIF_F_SOFT_FEATURES | |
| 9129 | NETIF_F_TSO | |
| 9130 | NETIF_F_TSO_ECN | |
| 9131 | NETIF_F_TSO6 | |
| 9132 | NETIF_F_GSO_GRE | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame^] | 9133 | NETIF_F_GSO_GRE_CSUM | |
Alexander Duyck | 577389a | 2016-04-02 00:06:56 -0700 | [diff] [blame] | 9134 | NETIF_F_GSO_IPIP | |
| 9135 | NETIF_F_GSO_SIT | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9136 | NETIF_F_GSO_UDP_TUNNEL | |
| 9137 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame^] | 9138 | NETIF_F_GSO_PARTIAL | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9139 | NETIF_F_SCTP_CRC | |
| 9140 | NETIF_F_RXHASH | |
| 9141 | NETIF_F_RXCSUM | |
Jesse Brandeburg | 5afdaaa | 2015-12-10 11:38:50 -0800 | [diff] [blame] | 9142 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9143 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9144 | if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)) |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame^] | 9145 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
| 9146 | |
| 9147 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9148 | |
| 9149 | /* record features VLANs can make use of */ |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame^] | 9150 | netdev->vlan_features |= netdev->hw_enc_features | |
| 9151 | NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9152 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9153 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9154 | netdev->hw_features |= NETIF_F_NTUPLE; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9155 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9156 | netdev->hw_features |= netdev->hw_enc_features | |
| 9157 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9158 | NETIF_F_HW_VLAN_CTAG_RX; |
| 9159 | |
| 9160 | netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame^] | 9161 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9162 | |
| 9163 | if (vsi->type == I40E_VSI_MAIN) { |
| 9164 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9165 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9166 | /* The following steps are necessary to prevent reception |
| 9167 | * of tagged packets - some older NVM configurations load a |
| 9168 | * default a MAC-VLAN filter that accepts any tagged packet |
| 9169 | * which must be replaced by a normal filter. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 9170 | */ |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9171 | if (!i40e_rm_default_mac_filter(vsi, mac_addr)) { |
| 9172 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9173 | i40e_add_filter(vsi, mac_addr, |
| 9174 | I40E_VLAN_ANY, false, true); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9175 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9176 | } |
Anjali Singhai Jain | 3845cce | 2016-03-18 12:18:05 -0700 | [diff] [blame] | 9177 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 9178 | ((pf->hw.aq.api_maj_ver == 1) && |
| 9179 | (pf->hw.aq.api_min_ver > 4))) { |
| 9180 | /* Supported in FW API version higher than 1.4 */ |
| 9181 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
| 9182 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9183 | } else { |
| 9184 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 9185 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 9186 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9187 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9188 | |
| 9189 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9190 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9191 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9192 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9193 | |
| 9194 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 9195 | i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9196 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9197 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9198 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9199 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9200 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9201 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9202 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9203 | /* Setup netdev TC information */ |
| 9204 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9205 | |
| 9206 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9207 | netdev->watchdog_timeo = 5 * HZ; |
| 9208 | i40e_set_ethtool_ops(netdev); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9209 | #ifdef I40E_FCOE |
| 9210 | i40e_fcoe_config_netdev(netdev, vsi); |
| 9211 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9212 | |
| 9213 | return 0; |
| 9214 | } |
| 9215 | |
| 9216 | /** |
| 9217 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9218 | * @vsi: the VSI being removed |
| 9219 | * |
| 9220 | * Returns 0 on success, negative value on failure |
| 9221 | **/ |
| 9222 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9223 | { |
| 9224 | /* remove default VSI is not allowed */ |
| 9225 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9226 | return; |
| 9227 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9228 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9229 | } |
| 9230 | |
| 9231 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9232 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9233 | * @vsi: the VSI being queried |
| 9234 | * |
| 9235 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9236 | **/ |
| 9237 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9238 | { |
| 9239 | struct i40e_veb *veb; |
| 9240 | struct i40e_pf *pf = vsi->back; |
| 9241 | |
| 9242 | /* Uplink is not a bridge so default to VEB */ |
| 9243 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9244 | return 1; |
| 9245 | |
| 9246 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9247 | if (!veb) { |
| 9248 | dev_info(&pf->pdev->dev, |
| 9249 | "There is no veb associated with the bridge\n"); |
| 9250 | return -ENOENT; |
| 9251 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9252 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9253 | /* Uplink is a bridge in VEPA mode */ |
| 9254 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9255 | return 0; |
| 9256 | } else { |
| 9257 | /* Uplink is a bridge in VEB mode */ |
| 9258 | return 1; |
| 9259 | } |
| 9260 | |
| 9261 | /* VEPA is now default bridge, so return 0 */ |
| 9262 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9263 | } |
| 9264 | |
| 9265 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9266 | * i40e_add_vsi - Add a VSI to the switch |
| 9267 | * @vsi: the VSI being configured |
| 9268 | * |
| 9269 | * This initializes a VSI context depending on the VSI type to be added and |
| 9270 | * passes it down to the add_vsi aq command. |
| 9271 | **/ |
| 9272 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9273 | { |
| 9274 | int ret = -ENODEV; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9275 | u8 laa_macaddr[ETH_ALEN]; |
| 9276 | bool found_laa_mac_filter = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9277 | struct i40e_pf *pf = vsi->back; |
| 9278 | struct i40e_hw *hw = &pf->hw; |
| 9279 | struct i40e_vsi_context ctxt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9280 | struct i40e_mac_filter *f, *ftmp; |
| 9281 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9282 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9283 | int f_count = 0; |
| 9284 | |
| 9285 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9286 | switch (vsi->type) { |
| 9287 | case I40E_VSI_MAIN: |
| 9288 | /* The PF's main VSI is already setup as part of the |
| 9289 | * device initialization, so we'll not bother with |
| 9290 | * the add_vsi call, but we will retrieve the current |
| 9291 | * VSI context. |
| 9292 | */ |
| 9293 | ctxt.seid = pf->main_vsi_seid; |
| 9294 | ctxt.pf_num = pf->hw.pf_id; |
| 9295 | ctxt.vf_num = 0; |
| 9296 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9297 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9298 | if (ret) { |
| 9299 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9300 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9301 | i40e_stat_str(&pf->hw, ret), |
| 9302 | i40e_aq_str(&pf->hw, |
| 9303 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9304 | return -ENOENT; |
| 9305 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9306 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9307 | vsi->info.valid_sections = 0; |
| 9308 | |
| 9309 | vsi->seid = ctxt.seid; |
| 9310 | vsi->id = ctxt.vsi_number; |
| 9311 | |
| 9312 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9313 | |
| 9314 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9315 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9316 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9317 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9318 | ctxt.seid = pf->main_vsi_seid; |
| 9319 | ctxt.pf_num = pf->hw.pf_id; |
| 9320 | ctxt.vf_num = 0; |
| 9321 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9322 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9323 | if (ret) { |
| 9324 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9325 | "update vsi failed, err %s aq_err %s\n", |
| 9326 | i40e_stat_str(&pf->hw, ret), |
| 9327 | i40e_aq_str(&pf->hw, |
| 9328 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9329 | ret = -ENOENT; |
| 9330 | goto err; |
| 9331 | } |
| 9332 | /* update the local VSI info queue map */ |
| 9333 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9334 | vsi->info.valid_sections = 0; |
| 9335 | } else { |
| 9336 | /* Default/Main VSI is only enabled for TC0 |
| 9337 | * reconfigure it to enable all TCs that are |
| 9338 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9339 | * For MFP case the iSCSI PF would use this |
| 9340 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9341 | */ |
| 9342 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9343 | if (ret) { |
| 9344 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9345 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9346 | enabled_tc, |
| 9347 | i40e_stat_str(&pf->hw, ret), |
| 9348 | i40e_aq_str(&pf->hw, |
| 9349 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9350 | ret = -ENOENT; |
| 9351 | } |
| 9352 | } |
| 9353 | break; |
| 9354 | |
| 9355 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9356 | ctxt.pf_num = hw->pf_id; |
| 9357 | ctxt.vf_num = 0; |
| 9358 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9359 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9360 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9361 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9362 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9363 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9364 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9365 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9366 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9367 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9368 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9369 | break; |
| 9370 | |
| 9371 | case I40E_VSI_VMDQ2: |
| 9372 | ctxt.pf_num = hw->pf_id; |
| 9373 | ctxt.vf_num = 0; |
| 9374 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9375 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9376 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9377 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9378 | /* This VSI is connected to VEB so the switch_id |
| 9379 | * should be set to zero by default. |
| 9380 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9381 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9382 | ctxt.info.valid_sections |= |
| 9383 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9384 | ctxt.info.switch_id = |
| 9385 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9386 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9387 | |
| 9388 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9389 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9390 | break; |
| 9391 | |
| 9392 | case I40E_VSI_SRIOV: |
| 9393 | ctxt.pf_num = hw->pf_id; |
| 9394 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9395 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9396 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9397 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9398 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9399 | /* This VSI is connected to VEB so the switch_id |
| 9400 | * should be set to zero by default. |
| 9401 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9402 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9403 | ctxt.info.valid_sections |= |
| 9404 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9405 | ctxt.info.switch_id = |
| 9406 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9407 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9408 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9409 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9410 | ctxt.info.valid_sections |= |
| 9411 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 9412 | ctxt.info.queueing_opt_flags |= |
| 9413 | I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 9414 | } |
| 9415 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9416 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9417 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9418 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9419 | ctxt.info.valid_sections |= |
| 9420 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9421 | ctxt.info.sec_flags |= |
| 9422 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9423 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9424 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9425 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9426 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9427 | break; |
| 9428 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9429 | #ifdef I40E_FCOE |
| 9430 | case I40E_VSI_FCOE: |
| 9431 | ret = i40e_fcoe_vsi_init(vsi, &ctxt); |
| 9432 | if (ret) { |
| 9433 | dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n"); |
| 9434 | return ret; |
| 9435 | } |
| 9436 | break; |
| 9437 | |
| 9438 | #endif /* I40E_FCOE */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9439 | case I40E_VSI_IWARP: |
| 9440 | /* send down message to iWARP */ |
| 9441 | break; |
| 9442 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9443 | default: |
| 9444 | return -ENODEV; |
| 9445 | } |
| 9446 | |
| 9447 | if (vsi->type != I40E_VSI_MAIN) { |
| 9448 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9449 | if (ret) { |
| 9450 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9451 | "add vsi failed, err %s aq_err %s\n", |
| 9452 | i40e_stat_str(&pf->hw, ret), |
| 9453 | i40e_aq_str(&pf->hw, |
| 9454 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9455 | ret = -ENOENT; |
| 9456 | goto err; |
| 9457 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9458 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9459 | vsi->info.valid_sections = 0; |
| 9460 | vsi->seid = ctxt.seid; |
| 9461 | vsi->id = ctxt.vsi_number; |
| 9462 | } |
| 9463 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9464 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9465 | /* If macvlan filters already exist, force them to get loaded */ |
| 9466 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 9467 | f->changed = true; |
| 9468 | f_count++; |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9469 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9470 | /* Expected to have only one MAC filter entry for LAA in list */ |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9471 | if (f->is_laa && vsi->type == I40E_VSI_MAIN) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9472 | ether_addr_copy(laa_macaddr, f->macaddr); |
| 9473 | found_laa_mac_filter = true; |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9474 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9475 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9476 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9477 | |
| 9478 | if (found_laa_mac_filter) { |
| 9479 | struct i40e_aqc_remove_macvlan_element_data element; |
| 9480 | |
| 9481 | memset(&element, 0, sizeof(element)); |
| 9482 | ether_addr_copy(element.mac_addr, laa_macaddr); |
| 9483 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 9484 | ret = i40e_aq_remove_macvlan(hw, vsi->seid, |
| 9485 | &element, 1, NULL); |
| 9486 | if (ret) { |
| 9487 | /* some older FW has a different default */ |
| 9488 | element.flags |= |
| 9489 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
| 9490 | i40e_aq_remove_macvlan(hw, vsi->seid, |
| 9491 | &element, 1, NULL); |
| 9492 | } |
| 9493 | |
| 9494 | i40e_aq_mac_address_write(hw, |
| 9495 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 9496 | laa_macaddr, NULL); |
| 9497 | } |
| 9498 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9499 | if (f_count) { |
| 9500 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 9501 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 9502 | } |
| 9503 | |
| 9504 | /* Update VSI BW information */ |
| 9505 | ret = i40e_vsi_get_bw_info(vsi); |
| 9506 | if (ret) { |
| 9507 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9508 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 9509 | i40e_stat_str(&pf->hw, ret), |
| 9510 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9511 | /* VSI is already added so not tearing that up */ |
| 9512 | ret = 0; |
| 9513 | } |
| 9514 | |
| 9515 | err: |
| 9516 | return ret; |
| 9517 | } |
| 9518 | |
| 9519 | /** |
| 9520 | * i40e_vsi_release - Delete a VSI and free its resources |
| 9521 | * @vsi: the VSI being removed |
| 9522 | * |
| 9523 | * Returns 0 on success or < 0 on error |
| 9524 | **/ |
| 9525 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 9526 | { |
| 9527 | struct i40e_mac_filter *f, *ftmp; |
| 9528 | struct i40e_veb *veb = NULL; |
| 9529 | struct i40e_pf *pf; |
| 9530 | u16 uplink_seid; |
| 9531 | int i, n; |
| 9532 | |
| 9533 | pf = vsi->back; |
| 9534 | |
| 9535 | /* release of a VEB-owner or last VSI is not allowed */ |
| 9536 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 9537 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 9538 | vsi->seid, vsi->uplink_seid); |
| 9539 | return -ENODEV; |
| 9540 | } |
| 9541 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 9542 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 9543 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 9544 | return -ENODEV; |
| 9545 | } |
| 9546 | |
| 9547 | uplink_seid = vsi->uplink_seid; |
| 9548 | if (vsi->type != I40E_VSI_SRIOV) { |
| 9549 | if (vsi->netdev_registered) { |
| 9550 | vsi->netdev_registered = false; |
| 9551 | if (vsi->netdev) { |
| 9552 | /* results in a call to i40e_close() */ |
| 9553 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9554 | } |
| 9555 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 9556 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9557 | } |
| 9558 | i40e_vsi_disable_irq(vsi); |
| 9559 | } |
| 9560 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9561 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9562 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
| 9563 | i40e_del_filter(vsi, f->macaddr, f->vlan, |
| 9564 | f->is_vf, f->is_netdev); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9565 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9566 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 9567 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9568 | |
| 9569 | i40e_vsi_delete(vsi); |
| 9570 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 9571 | if (vsi->netdev) { |
| 9572 | free_netdev(vsi->netdev); |
| 9573 | vsi->netdev = NULL; |
| 9574 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9575 | i40e_vsi_clear_rings(vsi); |
| 9576 | i40e_vsi_clear(vsi); |
| 9577 | |
| 9578 | /* If this was the last thing on the VEB, except for the |
| 9579 | * controlling VSI, remove the VEB, which puts the controlling |
| 9580 | * VSI onto the next level down in the switch. |
| 9581 | * |
| 9582 | * Well, okay, there's one more exception here: don't remove |
| 9583 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 9584 | * from up the network stack. |
| 9585 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9586 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9587 | if (pf->vsi[i] && |
| 9588 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 9589 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9590 | n++; /* count the VSIs */ |
| 9591 | } |
| 9592 | } |
| 9593 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9594 | if (!pf->veb[i]) |
| 9595 | continue; |
| 9596 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 9597 | n++; /* count the VEBs */ |
| 9598 | if (pf->veb[i]->seid == uplink_seid) |
| 9599 | veb = pf->veb[i]; |
| 9600 | } |
| 9601 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 9602 | i40e_veb_release(veb); |
| 9603 | |
| 9604 | return 0; |
| 9605 | } |
| 9606 | |
| 9607 | /** |
| 9608 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 9609 | * @vsi: ptr to the VSI |
| 9610 | * |
| 9611 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 9612 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 9613 | * newly allocated VSI. |
| 9614 | * |
| 9615 | * Returns 0 on success or negative on failure |
| 9616 | **/ |
| 9617 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 9618 | { |
| 9619 | int ret = -ENOENT; |
| 9620 | struct i40e_pf *pf = vsi->back; |
| 9621 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9622 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9623 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 9624 | vsi->seid); |
| 9625 | return -EEXIST; |
| 9626 | } |
| 9627 | |
| 9628 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 9629 | 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] | 9630 | vsi->seid, vsi->base_vector); |
| 9631 | return -EEXIST; |
| 9632 | } |
| 9633 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9634 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9635 | if (ret) { |
| 9636 | dev_info(&pf->pdev->dev, |
| 9637 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 9638 | vsi->num_q_vectors, vsi->seid, ret); |
| 9639 | vsi->num_q_vectors = 0; |
| 9640 | goto vector_setup_out; |
| 9641 | } |
| 9642 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 9643 | /* In Legacy mode, we do not have to get any other vector since we |
| 9644 | * piggyback on the misc/ICR0 for queue interrupts. |
| 9645 | */ |
| 9646 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9647 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9648 | if (vsi->num_q_vectors) |
| 9649 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 9650 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9651 | if (vsi->base_vector < 0) { |
| 9652 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9653 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 9654 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9655 | i40e_vsi_free_q_vectors(vsi); |
| 9656 | ret = -ENOENT; |
| 9657 | goto vector_setup_out; |
| 9658 | } |
| 9659 | |
| 9660 | vector_setup_out: |
| 9661 | return ret; |
| 9662 | } |
| 9663 | |
| 9664 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9665 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 9666 | * @vsi: pointer to the vsi. |
| 9667 | * |
| 9668 | * This re-allocates a vsi's queue resources. |
| 9669 | * |
| 9670 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 9671 | * on success, otherwise returns NULL on failure. |
| 9672 | **/ |
| 9673 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 9674 | { |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9675 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9676 | u8 enabled_tc; |
| 9677 | int ret; |
| 9678 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9679 | if (!vsi) |
| 9680 | return NULL; |
| 9681 | |
| 9682 | pf = vsi->back; |
| 9683 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9684 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9685 | i40e_vsi_clear_rings(vsi); |
| 9686 | |
| 9687 | i40e_vsi_free_arrays(vsi, false); |
| 9688 | i40e_set_num_rings_in_vsi(vsi); |
| 9689 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 9690 | if (ret) |
| 9691 | goto err_vsi; |
| 9692 | |
| 9693 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 9694 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9695 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9696 | "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] | 9697 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9698 | goto err_vsi; |
| 9699 | } |
| 9700 | vsi->base_queue = ret; |
| 9701 | |
| 9702 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 9703 | * layout configurations. |
| 9704 | */ |
| 9705 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9706 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9707 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9708 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 9709 | |
| 9710 | /* assign it some queues */ |
| 9711 | ret = i40e_alloc_rings(vsi); |
| 9712 | if (ret) |
| 9713 | goto err_rings; |
| 9714 | |
| 9715 | /* map all of the rings to the q_vectors */ |
| 9716 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9717 | return vsi; |
| 9718 | |
| 9719 | err_rings: |
| 9720 | i40e_vsi_free_q_vectors(vsi); |
| 9721 | if (vsi->netdev_registered) { |
| 9722 | vsi->netdev_registered = false; |
| 9723 | unregister_netdev(vsi->netdev); |
| 9724 | free_netdev(vsi->netdev); |
| 9725 | vsi->netdev = NULL; |
| 9726 | } |
| 9727 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9728 | err_vsi: |
| 9729 | i40e_vsi_clear(vsi); |
| 9730 | return NULL; |
| 9731 | } |
| 9732 | |
| 9733 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9734 | * i40e_macaddr_init - explicitly write the mac address filters. |
| 9735 | * |
| 9736 | * @vsi: pointer to the vsi. |
| 9737 | * @macaddr: the MAC address |
| 9738 | * |
| 9739 | * This is needed when the macaddr has been obtained by other |
| 9740 | * means than the default, e.g., from Open Firmware or IDPROM. |
| 9741 | * Returns 0 on success, negative on failure |
| 9742 | **/ |
| 9743 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) |
| 9744 | { |
| 9745 | int ret; |
| 9746 | struct i40e_aqc_add_macvlan_element_data element; |
| 9747 | |
| 9748 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 9749 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 9750 | macaddr, NULL); |
| 9751 | if (ret) { |
| 9752 | dev_info(&vsi->back->pdev->dev, |
| 9753 | "Addr change for VSI failed: %d\n", ret); |
| 9754 | return -EADDRNOTAVAIL; |
| 9755 | } |
| 9756 | |
| 9757 | memset(&element, 0, sizeof(element)); |
| 9758 | ether_addr_copy(element.mac_addr, macaddr); |
| 9759 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 9760 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); |
| 9761 | if (ret) { |
| 9762 | dev_info(&vsi->back->pdev->dev, |
| 9763 | "add filter failed err %s aq_err %s\n", |
| 9764 | i40e_stat_str(&vsi->back->hw, ret), |
| 9765 | i40e_aq_str(&vsi->back->hw, |
| 9766 | vsi->back->hw.aq.asq_last_status)); |
| 9767 | } |
| 9768 | return ret; |
| 9769 | } |
| 9770 | |
| 9771 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9772 | * i40e_vsi_setup - Set up a VSI by a given type |
| 9773 | * @pf: board private structure |
| 9774 | * @type: VSI type |
| 9775 | * @uplink_seid: the switch element to link to |
| 9776 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 9777 | * |
| 9778 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 9779 | * to the identified VEB. |
| 9780 | * |
| 9781 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 9782 | * success, otherwise returns NULL on failure. |
| 9783 | **/ |
| 9784 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 9785 | u16 uplink_seid, u32 param1) |
| 9786 | { |
| 9787 | struct i40e_vsi *vsi = NULL; |
| 9788 | struct i40e_veb *veb = NULL; |
| 9789 | int ret, i; |
| 9790 | int v_idx; |
| 9791 | |
| 9792 | /* The requested uplink_seid must be either |
| 9793 | * - the PF's port seid |
| 9794 | * no VEB is needed because this is the PF |
| 9795 | * or this is a Flow Director special case VSI |
| 9796 | * - seid of an existing VEB |
| 9797 | * - seid of a VSI that owns an existing VEB |
| 9798 | * - seid of a VSI that doesn't own a VEB |
| 9799 | * a new VEB is created and the VSI becomes the owner |
| 9800 | * - seid of the PF VSI, which is what creates the first VEB |
| 9801 | * this is a special case of the previous |
| 9802 | * |
| 9803 | * Find which uplink_seid we were given and create a new VEB if needed |
| 9804 | */ |
| 9805 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9806 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 9807 | veb = pf->veb[i]; |
| 9808 | break; |
| 9809 | } |
| 9810 | } |
| 9811 | |
| 9812 | if (!veb && uplink_seid != pf->mac_seid) { |
| 9813 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9814 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9815 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 9816 | vsi = pf->vsi[i]; |
| 9817 | break; |
| 9818 | } |
| 9819 | } |
| 9820 | if (!vsi) { |
| 9821 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 9822 | uplink_seid); |
| 9823 | return NULL; |
| 9824 | } |
| 9825 | |
| 9826 | if (vsi->uplink_seid == pf->mac_seid) |
| 9827 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 9828 | vsi->tc_config.enabled_tc); |
| 9829 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 9830 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9831 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9832 | if (veb) { |
| 9833 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 9834 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 9835 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9836 | return NULL; |
| 9837 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 9838 | /* We come up by default in VEPA mode if SRIOV is not |
| 9839 | * already enabled, in which case we can't force VEPA |
| 9840 | * mode. |
| 9841 | */ |
| 9842 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 9843 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 9844 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9845 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9846 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9847 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9848 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9849 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9850 | veb = pf->veb[i]; |
| 9851 | } |
| 9852 | if (!veb) { |
| 9853 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 9854 | return NULL; |
| 9855 | } |
| 9856 | |
| 9857 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 9858 | uplink_seid = veb->seid; |
| 9859 | } |
| 9860 | |
| 9861 | /* get vsi sw struct */ |
| 9862 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 9863 | if (v_idx < 0) |
| 9864 | goto err_alloc; |
| 9865 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9866 | if (!vsi) |
| 9867 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9868 | vsi->type = type; |
| 9869 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 9870 | |
| 9871 | if (type == I40E_VSI_MAIN) |
| 9872 | pf->lan_vsi = v_idx; |
| 9873 | else if (type == I40E_VSI_SRIOV) |
| 9874 | vsi->vf_id = param1; |
| 9875 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9876 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 9877 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9878 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9879 | dev_info(&pf->pdev->dev, |
| 9880 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 9881 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9882 | goto err_vsi; |
| 9883 | } |
| 9884 | vsi->base_queue = ret; |
| 9885 | |
| 9886 | /* get a VSI from the hardware */ |
| 9887 | vsi->uplink_seid = uplink_seid; |
| 9888 | ret = i40e_add_vsi(vsi); |
| 9889 | if (ret) |
| 9890 | goto err_vsi; |
| 9891 | |
| 9892 | switch (vsi->type) { |
| 9893 | /* setup the netdev if needed */ |
| 9894 | case I40E_VSI_MAIN: |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9895 | /* Apply relevant filters if a platform-specific mac |
| 9896 | * address was selected. |
| 9897 | */ |
| 9898 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 9899 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 9900 | if (ret) { |
| 9901 | dev_warn(&pf->pdev->dev, |
| 9902 | "could not set up macaddr; err %d\n", |
| 9903 | ret); |
| 9904 | } |
| 9905 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9906 | case I40E_VSI_VMDQ2: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9907 | case I40E_VSI_FCOE: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9908 | ret = i40e_config_netdev(vsi); |
| 9909 | if (ret) |
| 9910 | goto err_netdev; |
| 9911 | ret = register_netdev(vsi->netdev); |
| 9912 | if (ret) |
| 9913 | goto err_netdev; |
| 9914 | vsi->netdev_registered = true; |
| 9915 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9916 | #ifdef CONFIG_I40E_DCB |
| 9917 | /* Setup DCB netlink interface */ |
| 9918 | i40e_dcbnl_setup(vsi); |
| 9919 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9920 | /* fall through */ |
| 9921 | |
| 9922 | case I40E_VSI_FDIR: |
| 9923 | /* set up vectors and rings if needed */ |
| 9924 | ret = i40e_vsi_setup_vectors(vsi); |
| 9925 | if (ret) |
| 9926 | goto err_msix; |
| 9927 | |
| 9928 | ret = i40e_alloc_rings(vsi); |
| 9929 | if (ret) |
| 9930 | goto err_rings; |
| 9931 | |
| 9932 | /* map all of the rings to the q_vectors */ |
| 9933 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9934 | |
| 9935 | i40e_vsi_reset_stats(vsi); |
| 9936 | break; |
| 9937 | |
| 9938 | default: |
| 9939 | /* no netdev or rings for the other VSI types */ |
| 9940 | break; |
| 9941 | } |
| 9942 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9943 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
| 9944 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 9945 | ret = i40e_vsi_config_rss(vsi); |
| 9946 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9947 | return vsi; |
| 9948 | |
| 9949 | err_rings: |
| 9950 | i40e_vsi_free_q_vectors(vsi); |
| 9951 | err_msix: |
| 9952 | if (vsi->netdev_registered) { |
| 9953 | vsi->netdev_registered = false; |
| 9954 | unregister_netdev(vsi->netdev); |
| 9955 | free_netdev(vsi->netdev); |
| 9956 | vsi->netdev = NULL; |
| 9957 | } |
| 9958 | err_netdev: |
| 9959 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9960 | err_vsi: |
| 9961 | i40e_vsi_clear(vsi); |
| 9962 | err_alloc: |
| 9963 | return NULL; |
| 9964 | } |
| 9965 | |
| 9966 | /** |
| 9967 | * i40e_veb_get_bw_info - Query VEB BW information |
| 9968 | * @veb: the veb to query |
| 9969 | * |
| 9970 | * Query the Tx scheduler BW configuration data for given VEB |
| 9971 | **/ |
| 9972 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 9973 | { |
| 9974 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 9975 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 9976 | struct i40e_pf *pf = veb->pf; |
| 9977 | struct i40e_hw *hw = &pf->hw; |
| 9978 | u32 tc_bw_max; |
| 9979 | int ret = 0; |
| 9980 | int i; |
| 9981 | |
| 9982 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 9983 | &bw_data, NULL); |
| 9984 | if (ret) { |
| 9985 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9986 | "query veb bw config failed, err %s aq_err %s\n", |
| 9987 | i40e_stat_str(&pf->hw, ret), |
| 9988 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9989 | goto out; |
| 9990 | } |
| 9991 | |
| 9992 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 9993 | &ets_data, NULL); |
| 9994 | if (ret) { |
| 9995 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9996 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 9997 | i40e_stat_str(&pf->hw, ret), |
| 9998 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9999 | goto out; |
| 10000 | } |
| 10001 | |
| 10002 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 10003 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 10004 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 10005 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10006 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 10007 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 10008 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 10009 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 10010 | veb->bw_tc_limit_credits[i] = |
| 10011 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 10012 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 10013 | } |
| 10014 | |
| 10015 | out: |
| 10016 | return ret; |
| 10017 | } |
| 10018 | |
| 10019 | /** |
| 10020 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 10021 | * @pf: board private structure |
| 10022 | * |
| 10023 | * On error: returns error code (negative) |
| 10024 | * On success: returns vsi index in PF (positive) |
| 10025 | **/ |
| 10026 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 10027 | { |
| 10028 | int ret = -ENOENT; |
| 10029 | struct i40e_veb *veb; |
| 10030 | int i; |
| 10031 | |
| 10032 | /* Need to protect the allocation of switch elements at the PF level */ |
| 10033 | mutex_lock(&pf->switch_mutex); |
| 10034 | |
| 10035 | /* VEB list may be fragmented if VEB creation/destruction has |
| 10036 | * been happening. We can afford to do a quick scan to look |
| 10037 | * for any free slots in the list. |
| 10038 | * |
| 10039 | * find next empty veb slot, looping back around if necessary |
| 10040 | */ |
| 10041 | i = 0; |
| 10042 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 10043 | i++; |
| 10044 | if (i >= I40E_MAX_VEB) { |
| 10045 | ret = -ENOMEM; |
| 10046 | goto err_alloc_veb; /* out of VEB slots! */ |
| 10047 | } |
| 10048 | |
| 10049 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 10050 | if (!veb) { |
| 10051 | ret = -ENOMEM; |
| 10052 | goto err_alloc_veb; |
| 10053 | } |
| 10054 | veb->pf = pf; |
| 10055 | veb->idx = i; |
| 10056 | veb->enabled_tc = 1; |
| 10057 | |
| 10058 | pf->veb[i] = veb; |
| 10059 | ret = i; |
| 10060 | err_alloc_veb: |
| 10061 | mutex_unlock(&pf->switch_mutex); |
| 10062 | return ret; |
| 10063 | } |
| 10064 | |
| 10065 | /** |
| 10066 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 10067 | * @branch: where to start deleting |
| 10068 | * |
| 10069 | * This uses recursion to find the tips of the branch to be |
| 10070 | * removed, deleting until we get back to and can delete this VEB. |
| 10071 | **/ |
| 10072 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 10073 | { |
| 10074 | struct i40e_pf *pf = branch->pf; |
| 10075 | u16 branch_seid = branch->seid; |
| 10076 | u16 veb_idx = branch->idx; |
| 10077 | int i; |
| 10078 | |
| 10079 | /* release any VEBs on this VEB - RECURSION */ |
| 10080 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10081 | if (!pf->veb[i]) |
| 10082 | continue; |
| 10083 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 10084 | i40e_switch_branch_release(pf->veb[i]); |
| 10085 | } |
| 10086 | |
| 10087 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 10088 | * |
| 10089 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 10090 | * the VEB itself, so don't use (*branch) after this loop. |
| 10091 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10092 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10093 | if (!pf->vsi[i]) |
| 10094 | continue; |
| 10095 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 10096 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 10097 | i40e_vsi_release(pf->vsi[i]); |
| 10098 | } |
| 10099 | } |
| 10100 | |
| 10101 | /* There's one corner case where the VEB might not have been |
| 10102 | * removed, so double check it here and remove it if needed. |
| 10103 | * This case happens if the veb was created from the debugfs |
| 10104 | * commands and no VSIs were added to it. |
| 10105 | */ |
| 10106 | if (pf->veb[veb_idx]) |
| 10107 | i40e_veb_release(pf->veb[veb_idx]); |
| 10108 | } |
| 10109 | |
| 10110 | /** |
| 10111 | * i40e_veb_clear - remove veb struct |
| 10112 | * @veb: the veb to remove |
| 10113 | **/ |
| 10114 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 10115 | { |
| 10116 | if (!veb) |
| 10117 | return; |
| 10118 | |
| 10119 | if (veb->pf) { |
| 10120 | struct i40e_pf *pf = veb->pf; |
| 10121 | |
| 10122 | mutex_lock(&pf->switch_mutex); |
| 10123 | if (pf->veb[veb->idx] == veb) |
| 10124 | pf->veb[veb->idx] = NULL; |
| 10125 | mutex_unlock(&pf->switch_mutex); |
| 10126 | } |
| 10127 | |
| 10128 | kfree(veb); |
| 10129 | } |
| 10130 | |
| 10131 | /** |
| 10132 | * i40e_veb_release - Delete a VEB and free its resources |
| 10133 | * @veb: the VEB being removed |
| 10134 | **/ |
| 10135 | void i40e_veb_release(struct i40e_veb *veb) |
| 10136 | { |
| 10137 | struct i40e_vsi *vsi = NULL; |
| 10138 | struct i40e_pf *pf; |
| 10139 | int i, n = 0; |
| 10140 | |
| 10141 | pf = veb->pf; |
| 10142 | |
| 10143 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10144 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10145 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 10146 | n++; |
| 10147 | vsi = pf->vsi[i]; |
| 10148 | } |
| 10149 | } |
| 10150 | if (n != 1) { |
| 10151 | dev_info(&pf->pdev->dev, |
| 10152 | "can't remove VEB %d with %d VSIs left\n", |
| 10153 | veb->seid, n); |
| 10154 | return; |
| 10155 | } |
| 10156 | |
| 10157 | /* move the remaining VSI to uplink veb */ |
| 10158 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10159 | if (veb->uplink_seid) { |
| 10160 | vsi->uplink_seid = veb->uplink_seid; |
| 10161 | if (veb->uplink_seid == pf->mac_seid) |
| 10162 | vsi->veb_idx = I40E_NO_VEB; |
| 10163 | else |
| 10164 | vsi->veb_idx = veb->veb_idx; |
| 10165 | } else { |
| 10166 | /* floating VEB */ |
| 10167 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10168 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10169 | } |
| 10170 | |
| 10171 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10172 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10173 | } |
| 10174 | |
| 10175 | /** |
| 10176 | * i40e_add_veb - create the VEB in the switch |
| 10177 | * @veb: the VEB to be instantiated |
| 10178 | * @vsi: the controlling VSI |
| 10179 | **/ |
| 10180 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10181 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10182 | struct i40e_pf *pf = veb->pf; |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 10183 | bool is_default = veb->pf->cur_promisc; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10184 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10185 | int ret; |
| 10186 | |
| 10187 | /* get a VEB from the hardware */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10188 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 10189 | veb->enabled_tc, is_default, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10190 | &veb->seid, enable_stats, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10191 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10192 | dev_info(&pf->pdev->dev, |
| 10193 | "couldn't add VEB, err %s aq_err %s\n", |
| 10194 | i40e_stat_str(&pf->hw, ret), |
| 10195 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10196 | return -EPERM; |
| 10197 | } |
| 10198 | |
| 10199 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10200 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10201 | &veb->stats_idx, NULL, NULL, NULL); |
| 10202 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10203 | dev_info(&pf->pdev->dev, |
| 10204 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10205 | i40e_stat_str(&pf->hw, ret), |
| 10206 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10207 | return -EPERM; |
| 10208 | } |
| 10209 | ret = i40e_veb_get_bw_info(veb); |
| 10210 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10211 | dev_info(&pf->pdev->dev, |
| 10212 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10213 | i40e_stat_str(&pf->hw, ret), |
| 10214 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10215 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10216 | return -ENOENT; |
| 10217 | } |
| 10218 | |
| 10219 | vsi->uplink_seid = veb->seid; |
| 10220 | vsi->veb_idx = veb->idx; |
| 10221 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10222 | |
| 10223 | return 0; |
| 10224 | } |
| 10225 | |
| 10226 | /** |
| 10227 | * i40e_veb_setup - Set up a VEB |
| 10228 | * @pf: board private structure |
| 10229 | * @flags: VEB setup flags |
| 10230 | * @uplink_seid: the switch element to link to |
| 10231 | * @vsi_seid: the initial VSI seid |
| 10232 | * @enabled_tc: Enabled TC bit-map |
| 10233 | * |
| 10234 | * This allocates the sw VEB structure and links it into the switch |
| 10235 | * It is possible and legal for this to be a duplicate of an already |
| 10236 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10237 | * to be zero, in order to create a floating VEB. |
| 10238 | * |
| 10239 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10240 | * success, otherwise returns NULL on failure. |
| 10241 | **/ |
| 10242 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10243 | u16 uplink_seid, u16 vsi_seid, |
| 10244 | u8 enabled_tc) |
| 10245 | { |
| 10246 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10247 | int vsi_idx, veb_idx; |
| 10248 | int ret; |
| 10249 | |
| 10250 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10251 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10252 | (uplink_seid + vsi_seid != 0)) { |
| 10253 | dev_info(&pf->pdev->dev, |
| 10254 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10255 | uplink_seid, vsi_seid); |
| 10256 | return NULL; |
| 10257 | } |
| 10258 | |
| 10259 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10260 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10261 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10262 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10263 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10264 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10265 | vsi_seid); |
| 10266 | return NULL; |
| 10267 | } |
| 10268 | |
| 10269 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10270 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10271 | if (pf->veb[veb_idx] && |
| 10272 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10273 | uplink_veb = pf->veb[veb_idx]; |
| 10274 | break; |
| 10275 | } |
| 10276 | } |
| 10277 | if (!uplink_veb) { |
| 10278 | dev_info(&pf->pdev->dev, |
| 10279 | "uplink seid %d not found\n", uplink_seid); |
| 10280 | return NULL; |
| 10281 | } |
| 10282 | } |
| 10283 | |
| 10284 | /* get veb sw struct */ |
| 10285 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10286 | if (veb_idx < 0) |
| 10287 | goto err_alloc; |
| 10288 | veb = pf->veb[veb_idx]; |
| 10289 | veb->flags = flags; |
| 10290 | veb->uplink_seid = uplink_seid; |
| 10291 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10292 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10293 | |
| 10294 | /* create the VEB in the switch */ |
| 10295 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10296 | if (ret) |
| 10297 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10298 | if (vsi_idx == pf->lan_vsi) |
| 10299 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10300 | |
| 10301 | return veb; |
| 10302 | |
| 10303 | err_veb: |
| 10304 | i40e_veb_clear(veb); |
| 10305 | err_alloc: |
| 10306 | return NULL; |
| 10307 | } |
| 10308 | |
| 10309 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10310 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10311 | * @pf: board private structure |
| 10312 | * @ele: element we are building info from |
| 10313 | * @num_reported: total number of elements |
| 10314 | * @printconfig: should we print the contents |
| 10315 | * |
| 10316 | * helper function to assist in extracting a few useful SEID values. |
| 10317 | **/ |
| 10318 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10319 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10320 | u16 num_reported, bool printconfig) |
| 10321 | { |
| 10322 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10323 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10324 | u8 element_type = ele->element_type; |
| 10325 | u16 seid = le16_to_cpu(ele->seid); |
| 10326 | |
| 10327 | if (printconfig) |
| 10328 | dev_info(&pf->pdev->dev, |
| 10329 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10330 | element_type, seid, uplink_seid, downlink_seid); |
| 10331 | |
| 10332 | switch (element_type) { |
| 10333 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10334 | pf->mac_seid = seid; |
| 10335 | break; |
| 10336 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10337 | /* Main VEB? */ |
| 10338 | if (uplink_seid != pf->mac_seid) |
| 10339 | break; |
| 10340 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10341 | int v; |
| 10342 | |
| 10343 | /* find existing or else empty VEB */ |
| 10344 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10345 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10346 | pf->lan_veb = v; |
| 10347 | break; |
| 10348 | } |
| 10349 | } |
| 10350 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10351 | v = i40e_veb_mem_alloc(pf); |
| 10352 | if (v < 0) |
| 10353 | break; |
| 10354 | pf->lan_veb = v; |
| 10355 | } |
| 10356 | } |
| 10357 | |
| 10358 | pf->veb[pf->lan_veb]->seid = seid; |
| 10359 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10360 | pf->veb[pf->lan_veb]->pf = pf; |
| 10361 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10362 | break; |
| 10363 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10364 | if (num_reported != 1) |
| 10365 | break; |
| 10366 | /* This is immediately after a reset so we can assume this is |
| 10367 | * the PF's VSI |
| 10368 | */ |
| 10369 | pf->mac_seid = uplink_seid; |
| 10370 | pf->pf_seid = downlink_seid; |
| 10371 | pf->main_vsi_seid = seid; |
| 10372 | if (printconfig) |
| 10373 | dev_info(&pf->pdev->dev, |
| 10374 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10375 | pf->pf_seid, pf->main_vsi_seid); |
| 10376 | break; |
| 10377 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10378 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10379 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10380 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10381 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10382 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10383 | /* ignore these for now */ |
| 10384 | break; |
| 10385 | default: |
| 10386 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10387 | element_type, seid); |
| 10388 | break; |
| 10389 | } |
| 10390 | } |
| 10391 | |
| 10392 | /** |
| 10393 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10394 | * @pf: board private structure |
| 10395 | * @printconfig: should we print the contents |
| 10396 | * |
| 10397 | * Get the current switch configuration from the device and |
| 10398 | * extract a few useful SEID values. |
| 10399 | **/ |
| 10400 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10401 | { |
| 10402 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10403 | u16 next_seid = 0; |
| 10404 | int ret = 0; |
| 10405 | u8 *aq_buf; |
| 10406 | int i; |
| 10407 | |
| 10408 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10409 | if (!aq_buf) |
| 10410 | return -ENOMEM; |
| 10411 | |
| 10412 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10413 | do { |
| 10414 | u16 num_reported, num_total; |
| 10415 | |
| 10416 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10417 | I40E_AQ_LARGE_BUF, |
| 10418 | &next_seid, NULL); |
| 10419 | if (ret) { |
| 10420 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10421 | "get switch config failed err %s aq_err %s\n", |
| 10422 | i40e_stat_str(&pf->hw, ret), |
| 10423 | i40e_aq_str(&pf->hw, |
| 10424 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10425 | kfree(aq_buf); |
| 10426 | return -ENOENT; |
| 10427 | } |
| 10428 | |
| 10429 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10430 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10431 | |
| 10432 | if (printconfig) |
| 10433 | dev_info(&pf->pdev->dev, |
| 10434 | "header: %d reported %d total\n", |
| 10435 | num_reported, num_total); |
| 10436 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10437 | for (i = 0; i < num_reported; i++) { |
| 10438 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10439 | &sw_config->element[i]; |
| 10440 | |
| 10441 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10442 | printconfig); |
| 10443 | } |
| 10444 | } while (next_seid != 0); |
| 10445 | |
| 10446 | kfree(aq_buf); |
| 10447 | return ret; |
| 10448 | } |
| 10449 | |
| 10450 | /** |
| 10451 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10452 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10453 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10454 | * |
| 10455 | * Returns 0 on success, negative value on failure |
| 10456 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10457 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10458 | { |
| 10459 | int ret; |
| 10460 | |
| 10461 | /* find out what's out there already */ |
| 10462 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10463 | if (ret) { |
| 10464 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10465 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10466 | i40e_stat_str(&pf->hw, ret), |
| 10467 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10468 | return ret; |
| 10469 | } |
| 10470 | i40e_pf_reset_stats(pf); |
| 10471 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10472 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10473 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10474 | struct i40e_vsi *vsi = NULL; |
| 10475 | u16 uplink_seid; |
| 10476 | |
| 10477 | /* Set up the PF VSI associated with the PF's main VSI |
| 10478 | * that is already in the HW switch |
| 10479 | */ |
| 10480 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10481 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10482 | else |
| 10483 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10484 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10485 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10486 | else if (reinit) |
| 10487 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10488 | if (!vsi) { |
| 10489 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10490 | i40e_fdir_teardown(pf); |
| 10491 | return -EAGAIN; |
| 10492 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10493 | } else { |
| 10494 | /* force a reset of TC and queue layout configurations */ |
| 10495 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10496 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10497 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10498 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10499 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10500 | } |
| 10501 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 10502 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10503 | i40e_fdir_sb_setup(pf); |
| 10504 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10505 | /* Setup static PF queue filter control settings */ |
| 10506 | ret = i40e_setup_pf_filter_control(pf); |
| 10507 | if (ret) { |
| 10508 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 10509 | ret); |
| 10510 | /* Failure here should not stop continuing other steps */ |
| 10511 | } |
| 10512 | |
| 10513 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 10514 | * the hash |
| 10515 | */ |
| 10516 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 10517 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10518 | |
| 10519 | /* fill in link information and enable LSE reporting */ |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 10520 | i40e_update_link_info(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10521 | i40e_link_event(pf); |
| 10522 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10523 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10524 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 10525 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10526 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10527 | i40e_ptp_init(pf); |
| 10528 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10529 | return ret; |
| 10530 | } |
| 10531 | |
| 10532 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10533 | * i40e_determine_queue_usage - Work out queue distribution |
| 10534 | * @pf: board private structure |
| 10535 | **/ |
| 10536 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 10537 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10538 | int queues_left; |
| 10539 | |
| 10540 | pf->num_lan_qps = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10541 | #ifdef I40E_FCOE |
| 10542 | pf->num_fcoe_qps = 0; |
| 10543 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10544 | |
| 10545 | /* Find the max queues to be put into basic use. We'll always be |
| 10546 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 10547 | * big RSS set. |
| 10548 | */ |
| 10549 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 10550 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10551 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10552 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10553 | /* one qp for PF, no queues for anything else */ |
| 10554 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10555 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10556 | |
| 10557 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10558 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10559 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10560 | #ifdef I40E_FCOE |
| 10561 | I40E_FLAG_FCOE_ENABLED | |
| 10562 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10563 | I40E_FLAG_FD_SB_ENABLED | |
| 10564 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10565 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10566 | I40E_FLAG_SRIOV_ENABLED | |
| 10567 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10568 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 10569 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 10570 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10571 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10572 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10573 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10574 | queues_left -= pf->num_lan_qps; |
| 10575 | |
| 10576 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10577 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10578 | #ifdef I40E_FCOE |
| 10579 | I40E_FLAG_FCOE_ENABLED | |
| 10580 | #endif |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10581 | I40E_FLAG_FD_SB_ENABLED | |
| 10582 | I40E_FLAG_FD_ATR_ENABLED | |
| 10583 | I40E_FLAG_DCB_ENABLED | |
| 10584 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10585 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10586 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10587 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10588 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10589 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10590 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 10591 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 10592 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 10593 | num_online_cpus()); |
| 10594 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 10595 | pf->hw.func_caps.num_tx_qp); |
| 10596 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10597 | queues_left -= pf->num_lan_qps; |
| 10598 | } |
| 10599 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10600 | #ifdef I40E_FCOE |
| 10601 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 10602 | if (I40E_DEFAULT_FCOE <= queues_left) { |
| 10603 | pf->num_fcoe_qps = I40E_DEFAULT_FCOE; |
| 10604 | } else if (I40E_MINIMUM_FCOE <= queues_left) { |
| 10605 | pf->num_fcoe_qps = I40E_MINIMUM_FCOE; |
| 10606 | } else { |
| 10607 | pf->num_fcoe_qps = 0; |
| 10608 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 10609 | dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n"); |
| 10610 | } |
| 10611 | |
| 10612 | queues_left -= pf->num_fcoe_qps; |
| 10613 | } |
| 10614 | |
| 10615 | #endif |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10616 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10617 | if (queues_left > 1) { |
| 10618 | queues_left -= 1; /* save 1 queue for FD */ |
| 10619 | } else { |
| 10620 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 10621 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 10622 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10623 | } |
| 10624 | |
| 10625 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10626 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10627 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 10628 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10629 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 10630 | } |
| 10631 | |
| 10632 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 10633 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 10634 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 10635 | (queues_left / pf->num_vmdq_qps)); |
| 10636 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 10637 | } |
| 10638 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10639 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10640 | dev_dbg(&pf->pdev->dev, |
| 10641 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 10642 | pf->hw.func_caps.num_tx_qp, |
| 10643 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10644 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 10645 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 10646 | queues_left); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10647 | #ifdef I40E_FCOE |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10648 | 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] | 10649 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10650 | } |
| 10651 | |
| 10652 | /** |
| 10653 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 10654 | * @pf: PF to be setup |
| 10655 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10656 | * 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] | 10657 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 10658 | * based filter sizes required for them. It also enables Flow director, |
| 10659 | * ethertype and macvlan type filter settings for the pf. |
| 10660 | * |
| 10661 | * Returns 0 on success, negative on failure |
| 10662 | **/ |
| 10663 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 10664 | { |
| 10665 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 10666 | |
| 10667 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 10668 | |
| 10669 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10670 | 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] | 10671 | settings->enable_fdir = true; |
| 10672 | |
| 10673 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 10674 | settings->enable_ethtype = true; |
| 10675 | settings->enable_macvlan = true; |
| 10676 | |
| 10677 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 10678 | return -ENOENT; |
| 10679 | |
| 10680 | return 0; |
| 10681 | } |
| 10682 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10683 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10684 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10685 | static void i40e_print_features(struct i40e_pf *pf) |
| 10686 | { |
| 10687 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10688 | char *buf; |
| 10689 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10690 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10691 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 10692 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10693 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10694 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10695 | 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] | 10696 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10697 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10698 | #endif |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10699 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d RX: %s", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10700 | pf->hw.func_caps.num_vsis, |
| 10701 | pf->vsi[pf->lan_vsi]->num_queue_pairs, |
| 10702 | pf->flags & I40E_FLAG_RX_PS_ENABLED ? "PS" : "1BUF"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10703 | |
| 10704 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10705 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10706 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10707 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10708 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10709 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 10710 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10711 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10712 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10713 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Jesse Brandeburg | ce6fcb3 | 2015-08-28 17:55:59 -0400 | [diff] [blame] | 10714 | #if IS_ENABLED(CONFIG_VXLAN) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10715 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Jesse Brandeburg | ce6fcb3 | 2015-08-28 17:55:59 -0400 | [diff] [blame] | 10716 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10717 | #if IS_ENABLED(CONFIG_GENEVE) |
| 10718 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
| 10719 | #endif |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10720 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10721 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10722 | #ifdef I40E_FCOE |
| 10723 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10724 | i += snprintf(&buf[i], REMAIN(i), " FCOE"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10725 | #endif |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10726 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10727 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10728 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10729 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10730 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10731 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 10732 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10733 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10734 | } |
| 10735 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10736 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10737 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
| 10738 | * |
| 10739 | * @pdev: PCI device information struct |
| 10740 | * @pf: board private structure |
| 10741 | * |
| 10742 | * Look up the MAC address in Open Firmware on systems that support it, |
| 10743 | * and use IDPROM on SPARC if no OF address is found. On return, the |
| 10744 | * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value |
| 10745 | * has been selected. |
| 10746 | **/ |
| 10747 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 10748 | { |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10749 | pf->flags &= ~I40E_FLAG_PF_MAC; |
Sowmini Varadhan | ba94272 | 2016-01-12 19:32:31 -0800 | [diff] [blame] | 10750 | if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10751 | pf->flags |= I40E_FLAG_PF_MAC; |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10752 | } |
| 10753 | |
| 10754 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10755 | * i40e_probe - Device initialization routine |
| 10756 | * @pdev: PCI device information struct |
| 10757 | * @ent: entry in i40e_pci_tbl |
| 10758 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10759 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 10760 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10761 | * and a hardware reset occur. |
| 10762 | * |
| 10763 | * Returns 0 on success, negative on failure |
| 10764 | **/ |
| 10765 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 10766 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 10767 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10768 | struct i40e_pf *pf; |
| 10769 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10770 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10771 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10772 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 10773 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10774 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10775 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10776 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10777 | |
| 10778 | err = pci_enable_device_mem(pdev); |
| 10779 | if (err) |
| 10780 | return err; |
| 10781 | |
| 10782 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10783 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10784 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 10785 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10786 | if (err) { |
| 10787 | dev_err(&pdev->dev, |
| 10788 | "DMA configuration failed: 0x%x\n", err); |
| 10789 | goto err_dma; |
| 10790 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10791 | } |
| 10792 | |
| 10793 | /* set up pci connections */ |
| 10794 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 10795 | IORESOURCE_MEM), i40e_driver_name); |
| 10796 | if (err) { |
| 10797 | dev_info(&pdev->dev, |
| 10798 | "pci_request_selected_regions failed %d\n", err); |
| 10799 | goto err_pci_reg; |
| 10800 | } |
| 10801 | |
| 10802 | pci_enable_pcie_error_reporting(pdev); |
| 10803 | pci_set_master(pdev); |
| 10804 | |
| 10805 | /* Now that we have a PCI connection, we need to do the |
| 10806 | * low level device setup. This is primarily setting up |
| 10807 | * the Admin Queue structures and then querying for the |
| 10808 | * device's current profile information. |
| 10809 | */ |
| 10810 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 10811 | if (!pf) { |
| 10812 | err = -ENOMEM; |
| 10813 | goto err_pf_alloc; |
| 10814 | } |
| 10815 | pf->next_vsi = 0; |
| 10816 | pf->pdev = pdev; |
| 10817 | set_bit(__I40E_DOWN, &pf->state); |
| 10818 | |
| 10819 | hw = &pf->hw; |
| 10820 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10821 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10822 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 10823 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10824 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10825 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10826 | if (!hw->hw_addr) { |
| 10827 | err = -EIO; |
| 10828 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 10829 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10830 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10831 | goto err_ioremap; |
| 10832 | } |
| 10833 | hw->vendor_id = pdev->vendor; |
| 10834 | hw->device_id = pdev->device; |
| 10835 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 10836 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 10837 | hw->subsystem_device_id = pdev->subsystem_device; |
| 10838 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 10839 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10840 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10841 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 10842 | /* set up the locks for the AQ, do this only once in probe |
| 10843 | * and destroy them only once in remove |
| 10844 | */ |
| 10845 | mutex_init(&hw->aq.asq_mutex); |
| 10846 | mutex_init(&hw->aq.arq_mutex); |
| 10847 | |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 10848 | if (debug != -1) { |
| 10849 | pf->msg_enable = pf->hw.debug_mask; |
| 10850 | pf->msg_enable = debug; |
| 10851 | } |
| 10852 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10853 | /* do a special CORER for clearing PXE mode once at init */ |
| 10854 | if (hw->revision_id == 0 && |
| 10855 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 10856 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 10857 | i40e_flush(hw); |
| 10858 | msleep(200); |
| 10859 | pf->corer_count++; |
| 10860 | |
| 10861 | i40e_clear_pxe_mode(hw); |
| 10862 | } |
| 10863 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10864 | /* 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] | 10865 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10866 | err = i40e_pf_reset(hw); |
| 10867 | if (err) { |
| 10868 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 10869 | goto err_pf_reset; |
| 10870 | } |
| 10871 | pf->pfr_count++; |
| 10872 | |
| 10873 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 10874 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 10875 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10876 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10877 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10878 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 10879 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10880 | "%s-%s:misc", |
| 10881 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10882 | |
| 10883 | err = i40e_init_shared_code(hw); |
| 10884 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 10885 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 10886 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10887 | goto err_pf_reset; |
| 10888 | } |
| 10889 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10890 | /* set up a default setting for link flow control */ |
| 10891 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 10892 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10893 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 10894 | if (err) { |
| 10895 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 10896 | dev_info(&pdev->dev, |
| 10897 | "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"); |
| 10898 | else |
| 10899 | dev_info(&pdev->dev, |
| 10900 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 10901 | |
| 10902 | goto err_pf_reset; |
| 10903 | } |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10904 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10905 | /* provide nvm, fw, api versions */ |
| 10906 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 10907 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 10908 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 10909 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10910 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10911 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 10912 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10913 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10914 | "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"); |
| 10915 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 10916 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10917 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10918 | "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] | 10919 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 10920 | i40e_verify_eeprom(pf); |
| 10921 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 10922 | /* Rev 0 hardware was never productized */ |
| 10923 | if (hw->revision_id < 1) |
| 10924 | 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"); |
| 10925 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 10926 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10927 | err = i40e_get_capabilities(pf); |
| 10928 | if (err) |
| 10929 | goto err_adminq_setup; |
| 10930 | |
| 10931 | err = i40e_sw_init(pf); |
| 10932 | if (err) { |
| 10933 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 10934 | goto err_sw_init; |
| 10935 | } |
| 10936 | |
| 10937 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 10938 | hw->func_caps.num_rx_qp, |
| 10939 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 10940 | if (err) { |
| 10941 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 10942 | goto err_init_lan_hmc; |
| 10943 | } |
| 10944 | |
| 10945 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 10946 | if (err) { |
| 10947 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 10948 | err = -ENOENT; |
| 10949 | goto err_configure_lan_hmc; |
| 10950 | } |
| 10951 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10952 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 10953 | * Ignore error return codes because if it was already disabled via |
| 10954 | * hardware settings this will fail |
| 10955 | */ |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 10956 | if (pf->flags & I40E_FLAG_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10957 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 10958 | i40e_aq_stop_lldp(hw, true, NULL); |
| 10959 | } |
| 10960 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10961 | i40e_get_mac_addr(hw, hw->mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10962 | /* allow a platform config to override the HW addr */ |
| 10963 | i40e_get_platform_mac_addr(pdev, pf); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 10964 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10965 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 10966 | err = -EIO; |
| 10967 | goto err_mac_addr; |
| 10968 | } |
| 10969 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 10970 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10971 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 10972 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 10973 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10974 | #ifdef I40E_FCOE |
| 10975 | err = i40e_get_san_mac_addr(hw, hw->mac.san_addr); |
| 10976 | if (err) |
| 10977 | dev_info(&pdev->dev, |
| 10978 | "(non-fatal) SAN MAC retrieval failed: %d\n", err); |
| 10979 | if (!is_valid_ether_addr(hw->mac.san_addr)) { |
| 10980 | dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n", |
| 10981 | hw->mac.san_addr); |
| 10982 | ether_addr_copy(hw->mac.san_addr, hw->mac.addr); |
| 10983 | } |
| 10984 | dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr); |
| 10985 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10986 | |
| 10987 | pci_set_drvdata(pdev, pf); |
| 10988 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10989 | #ifdef CONFIG_I40E_DCB |
| 10990 | err = i40e_init_pf_dcb(pf); |
| 10991 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 10992 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10993 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 10994 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10995 | } |
| 10996 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10997 | |
| 10998 | /* set up periodic task facility */ |
| 10999 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 11000 | pf->service_timer_period = HZ; |
| 11001 | |
| 11002 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 11003 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 11004 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11005 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11006 | /* NVM bit on means WoL disabled for the port */ |
| 11007 | 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] | 11008 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 11009 | pf->wol_en = false; |
| 11010 | else |
| 11011 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11012 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 11013 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11014 | /* set up the main switch operations */ |
| 11015 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 11016 | err = i40e_init_interrupt_scheme(pf); |
| 11017 | if (err) |
| 11018 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11019 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11020 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 11021 | * to us; HW supports far more and we share the remaining pool with |
| 11022 | * the other PFs. We allocate space for more than the guarantee with |
| 11023 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11024 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11025 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 11026 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 11027 | else |
| 11028 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 11029 | |
| 11030 | /* 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] | 11031 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 11032 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11033 | if (!pf->vsi) { |
| 11034 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11035 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11036 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11037 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 11038 | #ifdef CONFIG_PCI_IOV |
| 11039 | /* prep for VF support */ |
| 11040 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 11041 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11042 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 11043 | if (pci_num_vf(pdev)) |
| 11044 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 11045 | } |
| 11046 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11047 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11048 | if (err) { |
| 11049 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 11050 | goto err_vsis; |
| 11051 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11052 | |
| 11053 | /* Make sure flow control is set according to current settings */ |
| 11054 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 11055 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 11056 | dev_dbg(&pf->pdev->dev, |
| 11057 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 11058 | i40e_stat_str(hw, err), |
| 11059 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11060 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 11061 | dev_dbg(&pf->pdev->dev, |
| 11062 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 11063 | i40e_stat_str(hw, err), |
| 11064 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11065 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 11066 | dev_dbg(&pf->pdev->dev, |
| 11067 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 11068 | i40e_stat_str(hw, err), |
| 11069 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11070 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11071 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11072 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11073 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 11074 | i40e_vsi_open(pf->vsi[i]); |
| 11075 | break; |
| 11076 | } |
| 11077 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11078 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11079 | /* The driver only wants link up/down and module qualification |
| 11080 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11081 | */ |
| 11082 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11083 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 11084 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11085 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11086 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11087 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 11088 | i40e_stat_str(&pf->hw, err), |
| 11089 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11090 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11091 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 11092 | * of TSO, so that we avoid the MDD being fired and causing |
| 11093 | * a reset in the case of small MSS+TSO. |
| 11094 | */ |
| 11095 | val = rd32(hw, I40E_REG_MSS); |
| 11096 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 11097 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 11098 | val |= I40E_64BYTE_MSS; |
| 11099 | wr32(hw, I40E_REG_MSS, val); |
| 11100 | } |
| 11101 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 11102 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 11103 | msleep(75); |
| 11104 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 11105 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11106 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 11107 | i40e_stat_str(&pf->hw, err), |
| 11108 | i40e_aq_str(&pf->hw, |
| 11109 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 11110 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11111 | /* The main driver is (mostly) up and happy. We need to set this state |
| 11112 | * before setting up the misc vector or we get a race and the vector |
| 11113 | * ends up disabled forever. |
| 11114 | */ |
| 11115 | clear_bit(__I40E_DOWN, &pf->state); |
| 11116 | |
| 11117 | /* In case of MSIX we are going to setup the misc vector right here |
| 11118 | * to handle admin queue events etc. In case of legacy and MSI |
| 11119 | * the misc functionality and queue processing is combined in |
| 11120 | * the same vector and that gets setup at open. |
| 11121 | */ |
| 11122 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 11123 | err = i40e_setup_misc_vector(pf); |
| 11124 | if (err) { |
| 11125 | dev_info(&pdev->dev, |
| 11126 | "setup of misc vector failed: %d\n", err); |
| 11127 | goto err_vsis; |
| 11128 | } |
| 11129 | } |
| 11130 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11131 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11132 | /* prep for VF support */ |
| 11133 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11134 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11135 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11136 | /* disable link interrupts for VFs */ |
| 11137 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11138 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11139 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11140 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11141 | |
| 11142 | if (pci_num_vf(pdev)) { |
| 11143 | dev_info(&pdev->dev, |
| 11144 | "Active VFs found, allocating resources.\n"); |
| 11145 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11146 | if (err) |
| 11147 | dev_info(&pdev->dev, |
| 11148 | "Error %d allocating resources for existing VFs\n", |
| 11149 | err); |
| 11150 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11151 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11152 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11153 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11154 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11155 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11156 | pf->num_iwarp_msix, |
| 11157 | I40E_IWARP_IRQ_PILE_ID); |
| 11158 | if (pf->iwarp_base_vector < 0) { |
| 11159 | dev_info(&pdev->dev, |
| 11160 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 11161 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 11162 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 11163 | } |
| 11164 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11165 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11166 | i40e_dbg_pf_init(pf); |
| 11167 | |
| 11168 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11169 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11170 | |
| 11171 | /* since everything's happy, start the service_task timer */ |
| 11172 | mod_timer(&pf->service_timer, |
| 11173 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11174 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11175 | /* add this PF to client device list and launch a client service task */ |
| 11176 | err = i40e_lan_add_device(pf); |
| 11177 | if (err) |
| 11178 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 11179 | err); |
| 11180 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11181 | #ifdef I40E_FCOE |
| 11182 | /* create FCoE interface */ |
| 11183 | i40e_fcoe_vsi_setup(pf); |
| 11184 | |
| 11185 | #endif |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11186 | #define PCI_SPEED_SIZE 8 |
| 11187 | #define PCI_WIDTH_SIZE 8 |
| 11188 | /* Devices on the IOSF bus do not have this information |
| 11189 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11190 | * checking them. |
| 11191 | */ |
| 11192 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { |
| 11193 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11194 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11195 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11196 | /* Get the negotiated link width and speed from PCI config |
| 11197 | * space |
| 11198 | */ |
| 11199 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11200 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11201 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11202 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11203 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11204 | switch (hw->bus.speed) { |
| 11205 | case i40e_bus_speed_8000: |
| 11206 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11207 | case i40e_bus_speed_5000: |
| 11208 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11209 | case i40e_bus_speed_2500: |
| 11210 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11211 | default: |
| 11212 | break; |
| 11213 | } |
| 11214 | switch (hw->bus.width) { |
| 11215 | case i40e_bus_width_pcie_x8: |
| 11216 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11217 | case i40e_bus_width_pcie_x4: |
| 11218 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11219 | case i40e_bus_width_pcie_x2: |
| 11220 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11221 | case i40e_bus_width_pcie_x1: |
| 11222 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11223 | default: |
| 11224 | break; |
| 11225 | } |
| 11226 | |
| 11227 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11228 | speed, width); |
| 11229 | |
| 11230 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11231 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11232 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11233 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11234 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11235 | } |
| 11236 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11237 | /* get the requested speeds from the fw */ |
| 11238 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11239 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11240 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11241 | i40e_stat_str(&pf->hw, err), |
| 11242 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11243 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11244 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11245 | /* get the supported phy types from the fw */ |
| 11246 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11247 | if (err) |
| 11248 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11249 | i40e_stat_str(&pf->hw, err), |
| 11250 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 11251 | pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type); |
| 11252 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11253 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11254 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11255 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11256 | * PF/VF VSIs. |
| 11257 | * The FW can still send Flow control frames if enabled. |
| 11258 | */ |
| 11259 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11260 | pf->main_vsi_seid); |
| 11261 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 11262 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
| 11263 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
| 11264 | pf->flags |= I40E_FLAG_HAVE_10GBASET_PHY; |
| 11265 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11266 | /* print a string summarizing features */ |
| 11267 | i40e_print_features(pf); |
| 11268 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11269 | return 0; |
| 11270 | |
| 11271 | /* Unwind what we've done if something failed in the setup */ |
| 11272 | err_vsis: |
| 11273 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11274 | i40e_clear_interrupt_scheme(pf); |
| 11275 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11276 | err_switch_setup: |
| 11277 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11278 | del_timer_sync(&pf->service_timer); |
| 11279 | err_mac_addr: |
| 11280 | err_configure_lan_hmc: |
| 11281 | (void)i40e_shutdown_lan_hmc(hw); |
| 11282 | err_init_lan_hmc: |
| 11283 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11284 | err_sw_init: |
| 11285 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11286 | err_pf_reset: |
| 11287 | iounmap(hw->hw_addr); |
| 11288 | err_ioremap: |
| 11289 | kfree(pf); |
| 11290 | err_pf_alloc: |
| 11291 | pci_disable_pcie_error_reporting(pdev); |
| 11292 | pci_release_selected_regions(pdev, |
| 11293 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 11294 | err_pci_reg: |
| 11295 | err_dma: |
| 11296 | pci_disable_device(pdev); |
| 11297 | return err; |
| 11298 | } |
| 11299 | |
| 11300 | /** |
| 11301 | * i40e_remove - Device removal routine |
| 11302 | * @pdev: PCI device information struct |
| 11303 | * |
| 11304 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11305 | * that is should release a PCI device. This could be caused by a |
| 11306 | * Hot-Plug event, or because the driver is going to be removed from |
| 11307 | * memory. |
| 11308 | **/ |
| 11309 | static void i40e_remove(struct pci_dev *pdev) |
| 11310 | { |
| 11311 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11312 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11313 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11314 | int i; |
| 11315 | |
| 11316 | i40e_dbg_pf_exit(pf); |
| 11317 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11318 | i40e_ptp_stop(pf); |
| 11319 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11320 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 11321 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 11322 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11323 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11324 | /* no more scheduling of any task */ |
Pandi Kumar Maharajan | a4618ec | 2016-02-18 09:19:25 -0800 | [diff] [blame] | 11325 | set_bit(__I40E_SUSPENDED, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11326 | set_bit(__I40E_DOWN, &pf->state); |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 11327 | if (pf->service_timer.data) |
| 11328 | del_timer_sync(&pf->service_timer); |
| 11329 | if (pf->service_task.func) |
| 11330 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11331 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11332 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11333 | i40e_free_vfs(pf); |
| 11334 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11335 | } |
| 11336 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11337 | i40e_fdir_teardown(pf); |
| 11338 | |
| 11339 | /* If there is a switch structure or any orphans, remove them. |
| 11340 | * This will leave only the PF's VSI remaining. |
| 11341 | */ |
| 11342 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11343 | if (!pf->veb[i]) |
| 11344 | continue; |
| 11345 | |
| 11346 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11347 | pf->veb[i]->uplink_seid == 0) |
| 11348 | i40e_switch_branch_release(pf->veb[i]); |
| 11349 | } |
| 11350 | |
| 11351 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11352 | * adminq and hmc. |
| 11353 | */ |
| 11354 | if (pf->vsi[pf->lan_vsi]) |
| 11355 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11356 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11357 | /* remove attached clients */ |
| 11358 | ret_code = i40e_lan_del_device(pf); |
| 11359 | if (ret_code) { |
| 11360 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 11361 | ret_code); |
| 11362 | } |
| 11363 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11364 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11365 | if (hw->hmc.hmc_obj) { |
| 11366 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11367 | if (ret_code) |
| 11368 | dev_warn(&pdev->dev, |
| 11369 | "Failed to destroy the HMC resources: %d\n", |
| 11370 | ret_code); |
| 11371 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11372 | |
| 11373 | /* shutdown the adminq */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11374 | ret_code = i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11375 | if (ret_code) |
| 11376 | dev_warn(&pdev->dev, |
| 11377 | "Failed to destroy the Admin Queue resources: %d\n", |
| 11378 | ret_code); |
| 11379 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11380 | /* destroy the locks only once, here */ |
| 11381 | mutex_destroy(&hw->aq.arq_mutex); |
| 11382 | mutex_destroy(&hw->aq.asq_mutex); |
| 11383 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11384 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11385 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11386 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11387 | if (pf->vsi[i]) { |
| 11388 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11389 | i40e_vsi_clear(pf->vsi[i]); |
| 11390 | pf->vsi[i] = NULL; |
| 11391 | } |
| 11392 | } |
| 11393 | |
| 11394 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11395 | kfree(pf->veb[i]); |
| 11396 | pf->veb[i] = NULL; |
| 11397 | } |
| 11398 | |
| 11399 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11400 | kfree(pf->vsi); |
| 11401 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11402 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11403 | kfree(pf); |
| 11404 | pci_release_selected_regions(pdev, |
| 11405 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 11406 | |
| 11407 | pci_disable_pcie_error_reporting(pdev); |
| 11408 | pci_disable_device(pdev); |
| 11409 | } |
| 11410 | |
| 11411 | /** |
| 11412 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11413 | * @pdev: PCI device information struct |
| 11414 | * |
| 11415 | * Called to warn that something happened and the error handling steps |
| 11416 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11417 | * remediation. |
| 11418 | **/ |
| 11419 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11420 | enum pci_channel_state error) |
| 11421 | { |
| 11422 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11423 | |
| 11424 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11425 | |
| 11426 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11427 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11428 | rtnl_lock(); |
| 11429 | i40e_prep_for_reset(pf); |
| 11430 | rtnl_unlock(); |
| 11431 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11432 | |
| 11433 | /* Request a slot reset */ |
| 11434 | return PCI_ERS_RESULT_NEED_RESET; |
| 11435 | } |
| 11436 | |
| 11437 | /** |
| 11438 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11439 | * @pdev: PCI device information struct |
| 11440 | * |
| 11441 | * Called to find if the driver can work with the device now that |
| 11442 | * the pci slot has been reset. If a basic connection seems good |
| 11443 | * (registers are readable and have sane content) then return a |
| 11444 | * happy little PCI_ERS_RESULT_xxx. |
| 11445 | **/ |
| 11446 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11447 | { |
| 11448 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11449 | pci_ers_result_t result; |
| 11450 | int err; |
| 11451 | u32 reg; |
| 11452 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11453 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11454 | if (pci_enable_device_mem(pdev)) { |
| 11455 | dev_info(&pdev->dev, |
| 11456 | "Cannot re-enable PCI device after reset.\n"); |
| 11457 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11458 | } else { |
| 11459 | pci_set_master(pdev); |
| 11460 | pci_restore_state(pdev); |
| 11461 | pci_save_state(pdev); |
| 11462 | pci_wake_from_d3(pdev, false); |
| 11463 | |
| 11464 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11465 | if (reg == 0) |
| 11466 | result = PCI_ERS_RESULT_RECOVERED; |
| 11467 | else |
| 11468 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11469 | } |
| 11470 | |
| 11471 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11472 | if (err) { |
| 11473 | dev_info(&pdev->dev, |
| 11474 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11475 | err); |
| 11476 | /* non-fatal, continue */ |
| 11477 | } |
| 11478 | |
| 11479 | return result; |
| 11480 | } |
| 11481 | |
| 11482 | /** |
| 11483 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11484 | * @pdev: PCI device information struct |
| 11485 | * |
| 11486 | * Called to allow the driver to bring things back up after PCI error |
| 11487 | * and/or reset recovery has finished. |
| 11488 | **/ |
| 11489 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11490 | { |
| 11491 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11492 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11493 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11494 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 11495 | return; |
| 11496 | |
| 11497 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11498 | i40e_handle_reset_warning(pf); |
Vasily Averin | 4c4935a | 2015-07-08 15:04:26 +0300 | [diff] [blame] | 11499 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11500 | } |
| 11501 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11502 | /** |
| 11503 | * i40e_shutdown - PCI callback for shutting down |
| 11504 | * @pdev: PCI device information struct |
| 11505 | **/ |
| 11506 | static void i40e_shutdown(struct pci_dev *pdev) |
| 11507 | { |
| 11508 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11509 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11510 | |
| 11511 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11512 | set_bit(__I40E_DOWN, &pf->state); |
| 11513 | rtnl_lock(); |
| 11514 | i40e_prep_for_reset(pf); |
| 11515 | rtnl_unlock(); |
| 11516 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11517 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11518 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11519 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11520 | del_timer_sync(&pf->service_timer); |
| 11521 | cancel_work_sync(&pf->service_task); |
| 11522 | i40e_fdir_teardown(pf); |
| 11523 | |
| 11524 | rtnl_lock(); |
| 11525 | i40e_prep_for_reset(pf); |
| 11526 | rtnl_unlock(); |
| 11527 | |
| 11528 | wr32(hw, I40E_PFPM_APM, |
| 11529 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11530 | wr32(hw, I40E_PFPM_WUFC, |
| 11531 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11532 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 11533 | i40e_clear_interrupt_scheme(pf); |
| 11534 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11535 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11536 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11537 | pci_set_power_state(pdev, PCI_D3hot); |
| 11538 | } |
| 11539 | } |
| 11540 | |
| 11541 | #ifdef CONFIG_PM |
| 11542 | /** |
| 11543 | * i40e_suspend - PCI callback for moving to D3 |
| 11544 | * @pdev: PCI device information struct |
| 11545 | **/ |
| 11546 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11547 | { |
| 11548 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11549 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11550 | |
| 11551 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11552 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 11553 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11554 | rtnl_lock(); |
| 11555 | i40e_prep_for_reset(pf); |
| 11556 | rtnl_unlock(); |
| 11557 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11558 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11559 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11560 | |
| 11561 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11562 | pci_set_power_state(pdev, PCI_D3hot); |
| 11563 | |
| 11564 | return 0; |
| 11565 | } |
| 11566 | |
| 11567 | /** |
| 11568 | * i40e_resume - PCI callback for waking up from D3 |
| 11569 | * @pdev: PCI device information struct |
| 11570 | **/ |
| 11571 | static int i40e_resume(struct pci_dev *pdev) |
| 11572 | { |
| 11573 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11574 | u32 err; |
| 11575 | |
| 11576 | pci_set_power_state(pdev, PCI_D0); |
| 11577 | pci_restore_state(pdev); |
| 11578 | /* pci_restore_state() clears dev->state_saves, so |
| 11579 | * call pci_save_state() again to restore it. |
| 11580 | */ |
| 11581 | pci_save_state(pdev); |
| 11582 | |
| 11583 | err = pci_enable_device_mem(pdev); |
| 11584 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11585 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11586 | return err; |
| 11587 | } |
| 11588 | pci_set_master(pdev); |
| 11589 | |
| 11590 | /* no wakeup events while running */ |
| 11591 | pci_wake_from_d3(pdev, false); |
| 11592 | |
| 11593 | /* handling the reset will rebuild the device state */ |
| 11594 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11595 | clear_bit(__I40E_DOWN, &pf->state); |
| 11596 | rtnl_lock(); |
| 11597 | i40e_reset_and_rebuild(pf, false); |
| 11598 | rtnl_unlock(); |
| 11599 | } |
| 11600 | |
| 11601 | return 0; |
| 11602 | } |
| 11603 | |
| 11604 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11605 | static const struct pci_error_handlers i40e_err_handler = { |
| 11606 | .error_detected = i40e_pci_error_detected, |
| 11607 | .slot_reset = i40e_pci_error_slot_reset, |
| 11608 | .resume = i40e_pci_error_resume, |
| 11609 | }; |
| 11610 | |
| 11611 | static struct pci_driver i40e_driver = { |
| 11612 | .name = i40e_driver_name, |
| 11613 | .id_table = i40e_pci_tbl, |
| 11614 | .probe = i40e_probe, |
| 11615 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11616 | #ifdef CONFIG_PM |
| 11617 | .suspend = i40e_suspend, |
| 11618 | .resume = i40e_resume, |
| 11619 | #endif |
| 11620 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11621 | .err_handler = &i40e_err_handler, |
| 11622 | .sriov_configure = i40e_pci_sriov_configure, |
| 11623 | }; |
| 11624 | |
| 11625 | /** |
| 11626 | * i40e_init_module - Driver registration routine |
| 11627 | * |
| 11628 | * i40e_init_module is the first routine called when the driver is |
| 11629 | * loaded. All it does is register with the PCI subsystem. |
| 11630 | **/ |
| 11631 | static int __init i40e_init_module(void) |
| 11632 | { |
| 11633 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 11634 | i40e_driver_string, i40e_driver_version_str); |
| 11635 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 11636 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11637 | /* we will see if single thread per module is enough for now, |
| 11638 | * it can't be any worse than using the system workqueue which |
| 11639 | * was already single threaded |
| 11640 | */ |
| 11641 | i40e_wq = create_singlethread_workqueue(i40e_driver_name); |
| 11642 | if (!i40e_wq) { |
| 11643 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 11644 | return -ENOMEM; |
| 11645 | } |
| 11646 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11647 | i40e_dbg_init(); |
| 11648 | return pci_register_driver(&i40e_driver); |
| 11649 | } |
| 11650 | module_init(i40e_init_module); |
| 11651 | |
| 11652 | /** |
| 11653 | * i40e_exit_module - Driver exit cleanup routine |
| 11654 | * |
| 11655 | * i40e_exit_module is called just before the driver is removed |
| 11656 | * from memory. |
| 11657 | **/ |
| 11658 | static void __exit i40e_exit_module(void) |
| 11659 | { |
| 11660 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11661 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11662 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11663 | } |
| 11664 | module_exit(i40e_exit_module); |