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 |
| 49 | #define DRV_VERSION_BUILD 1 |
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}, |
Shannon Nelson | 48a3b51 | 2015-07-23 16:54:39 -0400 | [diff] [blame] | 94 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
| 95 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 96 | /* required last entry */ |
| 97 | {0, } |
| 98 | }; |
| 99 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 100 | |
| 101 | #define I40E_MAX_VF_COUNT 128 |
| 102 | static int debug = -1; |
| 103 | module_param(debug, int, 0); |
| 104 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 105 | |
| 106 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 107 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 108 | MODULE_LICENSE("GPL"); |
| 109 | MODULE_VERSION(DRV_VERSION); |
| 110 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 111 | static struct workqueue_struct *i40e_wq; |
| 112 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 113 | /** |
| 114 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 115 | * @hw: pointer to the HW structure |
| 116 | * @mem: ptr to mem struct to fill out |
| 117 | * @size: size of memory requested |
| 118 | * @alignment: what to align the allocation to |
| 119 | **/ |
| 120 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 121 | u64 size, u32 alignment) |
| 122 | { |
| 123 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 124 | |
| 125 | mem->size = ALIGN(size, alignment); |
| 126 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 127 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 128 | if (!mem->va) |
| 129 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 130 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 131 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /** |
| 135 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 136 | * @hw: pointer to the HW structure |
| 137 | * @mem: ptr to mem struct to free |
| 138 | **/ |
| 139 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 140 | { |
| 141 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 142 | |
| 143 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 144 | mem->va = NULL; |
| 145 | mem->pa = 0; |
| 146 | mem->size = 0; |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 153 | * @hw: pointer to the HW structure |
| 154 | * @mem: ptr to mem struct to fill out |
| 155 | * @size: size of memory requested |
| 156 | **/ |
| 157 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 158 | u32 size) |
| 159 | { |
| 160 | mem->size = size; |
| 161 | mem->va = kzalloc(size, GFP_KERNEL); |
| 162 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 163 | if (!mem->va) |
| 164 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 165 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 166 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /** |
| 170 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 171 | * @hw: pointer to the HW structure |
| 172 | * @mem: ptr to mem struct to free |
| 173 | **/ |
| 174 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 175 | { |
| 176 | /* it's ok to kfree a NULL pointer */ |
| 177 | kfree(mem->va); |
| 178 | mem->va = NULL; |
| 179 | mem->size = 0; |
| 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * i40e_get_lump - find a lump of free generic resource |
| 186 | * @pf: board private structure |
| 187 | * @pile: the pile of resource to search |
| 188 | * @needed: the number of items needed |
| 189 | * @id: an owner id to stick on the items assigned |
| 190 | * |
| 191 | * Returns the base item index of the lump, or negative for error |
| 192 | * |
| 193 | * The search_hint trick and lack of advanced fit-finding only work |
| 194 | * because we're highly likely to have all the same size lump requests. |
| 195 | * Linear search time and any fragmentation should be minimal. |
| 196 | **/ |
| 197 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 198 | u16 needed, u16 id) |
| 199 | { |
| 200 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 201 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 202 | |
| 203 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 204 | dev_info(&pf->pdev->dev, |
| 205 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 206 | pile, needed, id); |
| 207 | return -EINVAL; |
| 208 | } |
| 209 | |
| 210 | /* start the linear search with an imperfect hint */ |
| 211 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 212 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 213 | /* skip already allocated entries */ |
| 214 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 215 | i++; |
| 216 | continue; |
| 217 | } |
| 218 | |
| 219 | /* do we have enough in this lump? */ |
| 220 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 221 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 222 | break; |
| 223 | } |
| 224 | |
| 225 | if (j == needed) { |
| 226 | /* there was enough, so assign it to the requestor */ |
| 227 | for (j = 0; j < needed; j++) |
| 228 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 229 | ret = i; |
| 230 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 231 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 232 | } |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 233 | |
| 234 | /* not enough, so skip over it and continue looking */ |
| 235 | i += j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | return ret; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * i40e_put_lump - return a lump of generic resource |
| 243 | * @pile: the pile of resource to search |
| 244 | * @index: the base item index |
| 245 | * @id: the owner id of the items assigned |
| 246 | * |
| 247 | * Returns the count of items in the lump |
| 248 | **/ |
| 249 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 250 | { |
| 251 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 252 | int count = 0; |
| 253 | int i; |
| 254 | |
| 255 | if (!pile || index >= pile->num_entries) |
| 256 | return -EINVAL; |
| 257 | |
| 258 | for (i = index; |
| 259 | i < pile->num_entries && pile->list[i] == valid_id; |
| 260 | i++) { |
| 261 | pile->list[i] = 0; |
| 262 | count++; |
| 263 | } |
| 264 | |
| 265 | if (count && index < pile->search_hint) |
| 266 | pile->search_hint = index; |
| 267 | |
| 268 | return count; |
| 269 | } |
| 270 | |
| 271 | /** |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 272 | * i40e_find_vsi_from_id - searches for the vsi with the given id |
| 273 | * @pf - the pf structure to search for the vsi |
| 274 | * @id - id of the vsi it is searching for |
| 275 | **/ |
| 276 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) |
| 277 | { |
| 278 | int i; |
| 279 | |
| 280 | for (i = 0; i < pf->num_alloc_vsi; i++) |
| 281 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) |
| 282 | return pf->vsi[i]; |
| 283 | |
| 284 | return NULL; |
| 285 | } |
| 286 | |
| 287 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 288 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 289 | * @pf: board private structure |
| 290 | * |
| 291 | * If not already scheduled, this puts the task into the work queue |
| 292 | **/ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 293 | void i40e_service_event_schedule(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 294 | { |
| 295 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 296 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && |
| 297 | !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 298 | queue_work(i40e_wq, &pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | /** |
| 302 | * i40e_tx_timeout - Respond to a Tx Hang |
| 303 | * @netdev: network interface device structure |
| 304 | * |
| 305 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 306 | * device is munged, not just the one netdev port, so go for the full |
| 307 | * reset. |
| 308 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 309 | #ifdef I40E_FCOE |
| 310 | void i40e_tx_timeout(struct net_device *netdev) |
| 311 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 312 | static void i40e_tx_timeout(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 313 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 314 | { |
| 315 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 316 | struct i40e_vsi *vsi = np->vsi; |
| 317 | struct i40e_pf *pf = vsi->back; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 318 | struct i40e_ring *tx_ring = NULL; |
| 319 | unsigned int i, hung_queue = 0; |
| 320 | u32 head, val; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 321 | |
| 322 | pf->tx_timeout_count++; |
| 323 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 324 | /* find the stopped queue the same way the stack does */ |
| 325 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 326 | struct netdev_queue *q; |
| 327 | unsigned long trans_start; |
| 328 | |
| 329 | q = netdev_get_tx_queue(netdev, i); |
| 330 | trans_start = q->trans_start ? : netdev->trans_start; |
| 331 | if (netif_xmit_stopped(q) && |
| 332 | time_after(jiffies, |
| 333 | (trans_start + netdev->watchdog_timeo))) { |
| 334 | hung_queue = i; |
| 335 | break; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | if (i == netdev->num_tx_queues) { |
| 340 | netdev_info(netdev, "tx_timeout: no netdev hung queue found\n"); |
| 341 | } else { |
| 342 | /* now that we have an index, find the tx_ring struct */ |
| 343 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 344 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 345 | if (hung_queue == |
| 346 | vsi->tx_rings[i]->queue_index) { |
| 347 | tx_ring = vsi->tx_rings[i]; |
| 348 | break; |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 354 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 355 | pf->tx_timeout_recovery_level = 1; /* reset after some time */ |
| 356 | else if (time_before(jiffies, |
| 357 | (pf->tx_timeout_last_recovery + netdev->watchdog_timeo))) |
| 358 | return; /* don't do any new action before the next timeout */ |
| 359 | |
| 360 | if (tx_ring) { |
| 361 | head = i40e_get_head(tx_ring); |
| 362 | /* Read interrupt register */ |
| 363 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 364 | val = rd32(&pf->hw, |
| 365 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 366 | tx_ring->vsi->base_vector - 1)); |
| 367 | else |
| 368 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 369 | |
| 370 | 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", |
| 371 | vsi->seid, hung_queue, tx_ring->next_to_clean, |
| 372 | head, tx_ring->next_to_use, |
| 373 | readl(tx_ring->tail), val); |
| 374 | } |
| 375 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 376 | pf->tx_timeout_last_recovery = jiffies; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 377 | netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n", |
| 378 | pf->tx_timeout_recovery_level, hung_queue); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 379 | |
| 380 | switch (pf->tx_timeout_recovery_level) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 381 | case 1: |
| 382 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 383 | break; |
| 384 | case 2: |
| 385 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 386 | break; |
| 387 | case 3: |
| 388 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 389 | break; |
| 390 | default: |
| 391 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 392 | break; |
| 393 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 394 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 395 | i40e_service_event_schedule(pf); |
| 396 | pf->tx_timeout_recovery_level++; |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * i40e_release_rx_desc - Store the new tail and head values |
| 401 | * @rx_ring: ring to bump |
| 402 | * @val: new head index |
| 403 | **/ |
| 404 | static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val) |
| 405 | { |
| 406 | rx_ring->next_to_use = val; |
| 407 | |
| 408 | /* Force memory writes to complete before letting h/w |
| 409 | * know there are new descriptors to fetch. (Only |
| 410 | * applicable for weak-ordered memory model archs, |
| 411 | * such as IA-64). |
| 412 | */ |
| 413 | wmb(); |
| 414 | writel(val, rx_ring->tail); |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 419 | * @vsi: the VSI we care about |
| 420 | * |
| 421 | * Returns the address of the device statistics structure. |
| 422 | * The statistics are actually updated from the service task. |
| 423 | **/ |
| 424 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 425 | { |
| 426 | return &vsi->net_stats; |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 431 | * @netdev: network interface device structure |
| 432 | * |
| 433 | * Returns the address of the device statistics structure. |
| 434 | * The statistics are actually updated from the service task. |
| 435 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 436 | #ifdef I40E_FCOE |
| 437 | struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 438 | struct net_device *netdev, |
| 439 | struct rtnl_link_stats64 *stats) |
| 440 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 441 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 442 | struct net_device *netdev, |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 443 | struct rtnl_link_stats64 *stats) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 444 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 445 | { |
| 446 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 447 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 448 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 449 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 450 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 451 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 452 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 453 | return stats; |
| 454 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 455 | if (!vsi->tx_rings) |
| 456 | return stats; |
| 457 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 458 | rcu_read_lock(); |
| 459 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 460 | u64 bytes, packets; |
| 461 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 462 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 463 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 464 | if (!tx_ring) |
| 465 | continue; |
| 466 | |
| 467 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 468 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 469 | packets = tx_ring->stats.packets; |
| 470 | bytes = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 471 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 472 | |
| 473 | stats->tx_packets += packets; |
| 474 | stats->tx_bytes += bytes; |
| 475 | rx_ring = &tx_ring[1]; |
| 476 | |
| 477 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 478 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 479 | packets = rx_ring->stats.packets; |
| 480 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 481 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 482 | |
| 483 | stats->rx_packets += packets; |
| 484 | stats->rx_bytes += bytes; |
| 485 | } |
| 486 | rcu_read_unlock(); |
| 487 | |
Akeem G Abodunrin | a5282f4 | 2014-05-10 04:49:03 +0000 | [diff] [blame] | 488 | /* following stats updated by i40e_watchdog_subtask() */ |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 489 | stats->multicast = vsi_stats->multicast; |
| 490 | stats->tx_errors = vsi_stats->tx_errors; |
| 491 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 492 | stats->rx_errors = vsi_stats->rx_errors; |
Jesse Brandeburg | d8201e2 | 2015-07-23 16:54:35 -0400 | [diff] [blame] | 493 | stats->rx_dropped = vsi_stats->rx_dropped; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 494 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 495 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
| 496 | |
| 497 | return stats; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | /** |
| 501 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 502 | * @vsi: the VSI to have its stats reset |
| 503 | **/ |
| 504 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 505 | { |
| 506 | struct rtnl_link_stats64 *ns; |
| 507 | int i; |
| 508 | |
| 509 | if (!vsi) |
| 510 | return; |
| 511 | |
| 512 | ns = i40e_get_vsi_stats_struct(vsi); |
| 513 | memset(ns, 0, sizeof(*ns)); |
| 514 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 515 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 516 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 517 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 518 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 519 | memset(&vsi->rx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 520 | sizeof(vsi->rx_rings[i]->stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 521 | memset(&vsi->rx_rings[i]->rx_stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 522 | sizeof(vsi->rx_rings[i]->rx_stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 523 | memset(&vsi->tx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 524 | sizeof(vsi->tx_rings[i]->stats)); |
| 525 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 526 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 527 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 528 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 529 | vsi->stat_offsets_loaded = false; |
| 530 | } |
| 531 | |
| 532 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 533 | * 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] | 534 | * @pf: the PF to be reset |
| 535 | **/ |
| 536 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 537 | { |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 538 | int i; |
| 539 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 540 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 541 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 542 | pf->stat_offsets_loaded = false; |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 543 | |
| 544 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 545 | if (pf->veb[i]) { |
| 546 | memset(&pf->veb[i]->stats, 0, |
| 547 | sizeof(pf->veb[i]->stats)); |
| 548 | memset(&pf->veb[i]->stats_offsets, 0, |
| 549 | sizeof(pf->veb[i]->stats_offsets)); |
| 550 | pf->veb[i]->stat_offsets_loaded = false; |
| 551 | } |
| 552 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /** |
| 556 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 557 | * @hw: ptr to the hardware info |
| 558 | * @hireg: the high 32 bit reg to read |
| 559 | * @loreg: the low 32 bit reg to read |
| 560 | * @offset_loaded: has the initial offset been loaded yet |
| 561 | * @offset: ptr to current offset value |
| 562 | * @stat: ptr to the stat |
| 563 | * |
| 564 | * Since the device stats are not reset at PFReset, they likely will not |
| 565 | * be zeroed when the driver starts. We'll save the first values read |
| 566 | * and use them as offsets to be subtracted from the raw values in order |
| 567 | * to report stats that count from zero. In the process, we also manage |
| 568 | * the potential roll-over. |
| 569 | **/ |
| 570 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 571 | bool offset_loaded, u64 *offset, u64 *stat) |
| 572 | { |
| 573 | u64 new_data; |
| 574 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 575 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 576 | new_data = rd32(hw, loreg); |
| 577 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 578 | } else { |
| 579 | new_data = rd64(hw, loreg); |
| 580 | } |
| 581 | if (!offset_loaded) |
| 582 | *offset = new_data; |
| 583 | if (likely(new_data >= *offset)) |
| 584 | *stat = new_data - *offset; |
| 585 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 586 | *stat = (new_data + BIT_ULL(48)) - *offset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 587 | *stat &= 0xFFFFFFFFFFFFULL; |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 592 | * @hw: ptr to the hardware info |
| 593 | * @reg: the hw reg to read |
| 594 | * @offset_loaded: has the initial offset been loaded yet |
| 595 | * @offset: ptr to current offset value |
| 596 | * @stat: ptr to the stat |
| 597 | **/ |
| 598 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 599 | bool offset_loaded, u64 *offset, u64 *stat) |
| 600 | { |
| 601 | u32 new_data; |
| 602 | |
| 603 | new_data = rd32(hw, reg); |
| 604 | if (!offset_loaded) |
| 605 | *offset = new_data; |
| 606 | if (likely(new_data >= *offset)) |
| 607 | *stat = (u32)(new_data - *offset); |
| 608 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 609 | *stat = (u32)((new_data + BIT_ULL(32)) - *offset); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /** |
| 613 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 614 | * @vsi: the VSI to be updated |
| 615 | **/ |
| 616 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 617 | { |
| 618 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 619 | struct i40e_pf *pf = vsi->back; |
| 620 | struct i40e_hw *hw = &pf->hw; |
| 621 | struct i40e_eth_stats *oes; |
| 622 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 623 | |
| 624 | es = &vsi->eth_stats; |
| 625 | oes = &vsi->eth_stats_offsets; |
| 626 | |
| 627 | /* Gather up the stats that the hw collects */ |
| 628 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 629 | vsi->stat_offsets_loaded, |
| 630 | &oes->tx_errors, &es->tx_errors); |
| 631 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 632 | vsi->stat_offsets_loaded, |
| 633 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 634 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 635 | vsi->stat_offsets_loaded, |
| 636 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 637 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 638 | vsi->stat_offsets_loaded, |
| 639 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 640 | |
| 641 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 642 | I40E_GLV_GORCL(stat_idx), |
| 643 | vsi->stat_offsets_loaded, |
| 644 | &oes->rx_bytes, &es->rx_bytes); |
| 645 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 646 | I40E_GLV_UPRCL(stat_idx), |
| 647 | vsi->stat_offsets_loaded, |
| 648 | &oes->rx_unicast, &es->rx_unicast); |
| 649 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 650 | I40E_GLV_MPRCL(stat_idx), |
| 651 | vsi->stat_offsets_loaded, |
| 652 | &oes->rx_multicast, &es->rx_multicast); |
| 653 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 654 | I40E_GLV_BPRCL(stat_idx), |
| 655 | vsi->stat_offsets_loaded, |
| 656 | &oes->rx_broadcast, &es->rx_broadcast); |
| 657 | |
| 658 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 659 | I40E_GLV_GOTCL(stat_idx), |
| 660 | vsi->stat_offsets_loaded, |
| 661 | &oes->tx_bytes, &es->tx_bytes); |
| 662 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 663 | I40E_GLV_UPTCL(stat_idx), |
| 664 | vsi->stat_offsets_loaded, |
| 665 | &oes->tx_unicast, &es->tx_unicast); |
| 666 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 667 | I40E_GLV_MPTCL(stat_idx), |
| 668 | vsi->stat_offsets_loaded, |
| 669 | &oes->tx_multicast, &es->tx_multicast); |
| 670 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 671 | I40E_GLV_BPTCL(stat_idx), |
| 672 | vsi->stat_offsets_loaded, |
| 673 | &oes->tx_broadcast, &es->tx_broadcast); |
| 674 | vsi->stat_offsets_loaded = true; |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * i40e_update_veb_stats - Update Switch component statistics |
| 679 | * @veb: the VEB being updated |
| 680 | **/ |
| 681 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 682 | { |
| 683 | struct i40e_pf *pf = veb->pf; |
| 684 | struct i40e_hw *hw = &pf->hw; |
| 685 | struct i40e_eth_stats *oes; |
| 686 | struct i40e_eth_stats *es; /* device's eth stats */ |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 687 | struct i40e_veb_tc_stats *veb_oes; |
| 688 | struct i40e_veb_tc_stats *veb_es; |
| 689 | int i, idx = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 690 | |
| 691 | idx = veb->stats_idx; |
| 692 | es = &veb->stats; |
| 693 | oes = &veb->stats_offsets; |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 694 | veb_es = &veb->tc_stats; |
| 695 | veb_oes = &veb->tc_stats_offsets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 696 | |
| 697 | /* Gather up the stats that the hw collects */ |
| 698 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 699 | veb->stat_offsets_loaded, |
| 700 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 701 | if (hw->revision_id > 0) |
| 702 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 703 | veb->stat_offsets_loaded, |
| 704 | &oes->rx_unknown_protocol, |
| 705 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 706 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 707 | veb->stat_offsets_loaded, |
| 708 | &oes->rx_bytes, &es->rx_bytes); |
| 709 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 710 | veb->stat_offsets_loaded, |
| 711 | &oes->rx_unicast, &es->rx_unicast); |
| 712 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 713 | veb->stat_offsets_loaded, |
| 714 | &oes->rx_multicast, &es->rx_multicast); |
| 715 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 716 | veb->stat_offsets_loaded, |
| 717 | &oes->rx_broadcast, &es->rx_broadcast); |
| 718 | |
| 719 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 720 | veb->stat_offsets_loaded, |
| 721 | &oes->tx_bytes, &es->tx_bytes); |
| 722 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 723 | veb->stat_offsets_loaded, |
| 724 | &oes->tx_unicast, &es->tx_unicast); |
| 725 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 726 | veb->stat_offsets_loaded, |
| 727 | &oes->tx_multicast, &es->tx_multicast); |
| 728 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 729 | veb->stat_offsets_loaded, |
| 730 | &oes->tx_broadcast, &es->tx_broadcast); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 731 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 732 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), |
| 733 | I40E_GLVEBTC_RPCL(i, idx), |
| 734 | veb->stat_offsets_loaded, |
| 735 | &veb_oes->tc_rx_packets[i], |
| 736 | &veb_es->tc_rx_packets[i]); |
| 737 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), |
| 738 | I40E_GLVEBTC_RBCL(i, idx), |
| 739 | veb->stat_offsets_loaded, |
| 740 | &veb_oes->tc_rx_bytes[i], |
| 741 | &veb_es->tc_rx_bytes[i]); |
| 742 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), |
| 743 | I40E_GLVEBTC_TPCL(i, idx), |
| 744 | veb->stat_offsets_loaded, |
| 745 | &veb_oes->tc_tx_packets[i], |
| 746 | &veb_es->tc_tx_packets[i]); |
| 747 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), |
| 748 | I40E_GLVEBTC_TBCL(i, idx), |
| 749 | veb->stat_offsets_loaded, |
| 750 | &veb_oes->tc_tx_bytes[i], |
| 751 | &veb_es->tc_tx_bytes[i]); |
| 752 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 753 | veb->stat_offsets_loaded = true; |
| 754 | } |
| 755 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 756 | #ifdef I40E_FCOE |
| 757 | /** |
| 758 | * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters. |
| 759 | * @vsi: the VSI that is capable of doing FCoE |
| 760 | **/ |
| 761 | static void i40e_update_fcoe_stats(struct i40e_vsi *vsi) |
| 762 | { |
| 763 | struct i40e_pf *pf = vsi->back; |
| 764 | struct i40e_hw *hw = &pf->hw; |
| 765 | struct i40e_fcoe_stats *ofs; |
| 766 | struct i40e_fcoe_stats *fs; /* device's eth stats */ |
| 767 | int idx; |
| 768 | |
| 769 | if (vsi->type != I40E_VSI_FCOE) |
| 770 | return; |
| 771 | |
Kiran Patil | 4147e2c | 2016-01-15 14:33:14 -0800 | [diff] [blame] | 772 | idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 773 | fs = &vsi->fcoe_stats; |
| 774 | ofs = &vsi->fcoe_stats_offsets; |
| 775 | |
| 776 | i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx), |
| 777 | vsi->fcoe_stat_offsets_loaded, |
| 778 | &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets); |
| 779 | i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx), |
| 780 | vsi->fcoe_stat_offsets_loaded, |
| 781 | &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords); |
| 782 | i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx), |
| 783 | vsi->fcoe_stat_offsets_loaded, |
| 784 | &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped); |
| 785 | i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx), |
| 786 | vsi->fcoe_stat_offsets_loaded, |
| 787 | &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets); |
| 788 | i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx), |
| 789 | vsi->fcoe_stat_offsets_loaded, |
| 790 | &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords); |
| 791 | i40e_stat_update32(hw, I40E_GL_FCOECRC(idx), |
| 792 | vsi->fcoe_stat_offsets_loaded, |
| 793 | &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc); |
| 794 | i40e_stat_update32(hw, I40E_GL_FCOELAST(idx), |
| 795 | vsi->fcoe_stat_offsets_loaded, |
| 796 | &ofs->fcoe_last_error, &fs->fcoe_last_error); |
| 797 | i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx), |
| 798 | vsi->fcoe_stat_offsets_loaded, |
| 799 | &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count); |
| 800 | |
| 801 | vsi->fcoe_stat_offsets_loaded = true; |
| 802 | } |
| 803 | |
| 804 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 805 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 806 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 807 | * @vsi: the VSI to be updated |
| 808 | * |
| 809 | * There are a few instances where we store the same stat in a |
| 810 | * couple of different structs. This is partly because we have |
| 811 | * the netdev stats that need to be filled out, which is slightly |
| 812 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 813 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 814 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 815 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 816 | { |
| 817 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 818 | struct rtnl_link_stats64 *ons; |
| 819 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 820 | struct i40e_eth_stats *oes; |
| 821 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 822 | u32 tx_restart, tx_busy; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 823 | u64 tx_lost_interrupt; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 824 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 825 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 826 | u64 bytes, packets; |
| 827 | unsigned int start; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 828 | u64 tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 829 | u64 tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 830 | u64 rx_p, rx_b; |
| 831 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 832 | u16 q; |
| 833 | |
| 834 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 835 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 836 | return; |
| 837 | |
| 838 | ns = i40e_get_vsi_stats_struct(vsi); |
| 839 | ons = &vsi->net_stats_offsets; |
| 840 | es = &vsi->eth_stats; |
| 841 | oes = &vsi->eth_stats_offsets; |
| 842 | |
| 843 | /* Gather up the netdev and vsi stats that the driver collects |
| 844 | * on the fly during packet processing |
| 845 | */ |
| 846 | rx_b = rx_p = 0; |
| 847 | tx_b = tx_p = 0; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 848 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 849 | tx_lost_interrupt = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 850 | rx_page = 0; |
| 851 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 852 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 853 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 854 | /* locate Tx ring */ |
| 855 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 856 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 857 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 858 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 859 | packets = p->stats.packets; |
| 860 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 861 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 862 | tx_b += bytes; |
| 863 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 864 | tx_restart += p->tx_stats.restart_queue; |
| 865 | tx_busy += p->tx_stats.tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 866 | tx_linearize += p->tx_stats.tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 867 | tx_force_wb += p->tx_stats.tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 868 | tx_lost_interrupt += p->tx_stats.tx_lost_interrupt; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 869 | |
| 870 | /* Rx queue is part of the same block as Tx queue */ |
| 871 | p = &p[1]; |
| 872 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 873 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 874 | packets = p->stats.packets; |
| 875 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 876 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 877 | rx_b += bytes; |
| 878 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 879 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 880 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 881 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 882 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 883 | vsi->tx_restart = tx_restart; |
| 884 | vsi->tx_busy = tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 885 | vsi->tx_linearize = tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 886 | vsi->tx_force_wb = tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 887 | vsi->tx_lost_interrupt = tx_lost_interrupt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 888 | vsi->rx_page_failed = rx_page; |
| 889 | vsi->rx_buf_failed = rx_buf; |
| 890 | |
| 891 | ns->rx_packets = rx_p; |
| 892 | ns->rx_bytes = rx_b; |
| 893 | ns->tx_packets = tx_p; |
| 894 | ns->tx_bytes = tx_b; |
| 895 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 896 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 897 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 898 | ons->tx_errors = oes->tx_errors; |
| 899 | ns->tx_errors = es->tx_errors; |
| 900 | ons->multicast = oes->rx_multicast; |
| 901 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 902 | ons->rx_dropped = oes->rx_discards; |
| 903 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 904 | ons->tx_dropped = oes->tx_discards; |
| 905 | ns->tx_dropped = es->tx_discards; |
| 906 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 907 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 908 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 909 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 910 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 911 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 912 | } |
| 913 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 914 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 915 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 916 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 917 | * @pf: the PF to be updated |
| 918 | **/ |
| 919 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 920 | { |
| 921 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 922 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 923 | struct i40e_hw *hw = &pf->hw; |
| 924 | u32 val; |
| 925 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 926 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 927 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 928 | I40E_GLPRT_GORCL(hw->port), |
| 929 | pf->stat_offsets_loaded, |
| 930 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 931 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 932 | I40E_GLPRT_GOTCL(hw->port), |
| 933 | pf->stat_offsets_loaded, |
| 934 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 935 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 936 | pf->stat_offsets_loaded, |
| 937 | &osd->eth.rx_discards, |
| 938 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 939 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 940 | I40E_GLPRT_UPRCL(hw->port), |
| 941 | pf->stat_offsets_loaded, |
| 942 | &osd->eth.rx_unicast, |
| 943 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 944 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 945 | I40E_GLPRT_MPRCL(hw->port), |
| 946 | pf->stat_offsets_loaded, |
| 947 | &osd->eth.rx_multicast, |
| 948 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 949 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 950 | I40E_GLPRT_BPRCL(hw->port), |
| 951 | pf->stat_offsets_loaded, |
| 952 | &osd->eth.rx_broadcast, |
| 953 | &nsd->eth.rx_broadcast); |
| 954 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 955 | I40E_GLPRT_UPTCL(hw->port), |
| 956 | pf->stat_offsets_loaded, |
| 957 | &osd->eth.tx_unicast, |
| 958 | &nsd->eth.tx_unicast); |
| 959 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 960 | I40E_GLPRT_MPTCL(hw->port), |
| 961 | pf->stat_offsets_loaded, |
| 962 | &osd->eth.tx_multicast, |
| 963 | &nsd->eth.tx_multicast); |
| 964 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 965 | I40E_GLPRT_BPTCL(hw->port), |
| 966 | pf->stat_offsets_loaded, |
| 967 | &osd->eth.tx_broadcast, |
| 968 | &nsd->eth.tx_broadcast); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 969 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 970 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 971 | pf->stat_offsets_loaded, |
| 972 | &osd->tx_dropped_link_down, |
| 973 | &nsd->tx_dropped_link_down); |
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_CRCERRS(hw->port), |
| 976 | pf->stat_offsets_loaded, |
| 977 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 978 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 979 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 980 | pf->stat_offsets_loaded, |
| 981 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 982 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 983 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 984 | pf->stat_offsets_loaded, |
| 985 | &osd->mac_local_faults, |
| 986 | &nsd->mac_local_faults); |
| 987 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 988 | pf->stat_offsets_loaded, |
| 989 | &osd->mac_remote_faults, |
| 990 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 991 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 992 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 993 | pf->stat_offsets_loaded, |
| 994 | &osd->rx_length_errors, |
| 995 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 996 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 997 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 998 | pf->stat_offsets_loaded, |
| 999 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 1000 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 1001 | pf->stat_offsets_loaded, |
| 1002 | &osd->link_xon_tx, &nsd->link_xon_tx); |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 1003 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 1004 | pf->stat_offsets_loaded, |
| 1005 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1006 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 1007 | pf->stat_offsets_loaded, |
| 1008 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1009 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1010 | for (i = 0; i < 8; i++) { |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 1011 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 1012 | pf->stat_offsets_loaded, |
| 1013 | &osd->priority_xoff_rx[i], |
| 1014 | &nsd->priority_xoff_rx[i]); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1015 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1016 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1017 | &osd->priority_xon_rx[i], |
| 1018 | &nsd->priority_xon_rx[i]); |
| 1019 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1020 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1021 | &osd->priority_xon_tx[i], |
| 1022 | &nsd->priority_xon_tx[i]); |
| 1023 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1024 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1025 | &osd->priority_xoff_tx[i], |
| 1026 | &nsd->priority_xoff_tx[i]); |
| 1027 | i40e_stat_update32(hw, |
| 1028 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1029 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1030 | &osd->priority_xon_2_xoff[i], |
| 1031 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1034 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 1035 | I40E_GLPRT_PRC64L(hw->port), |
| 1036 | pf->stat_offsets_loaded, |
| 1037 | &osd->rx_size_64, &nsd->rx_size_64); |
| 1038 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 1039 | I40E_GLPRT_PRC127L(hw->port), |
| 1040 | pf->stat_offsets_loaded, |
| 1041 | &osd->rx_size_127, &nsd->rx_size_127); |
| 1042 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 1043 | I40E_GLPRT_PRC255L(hw->port), |
| 1044 | pf->stat_offsets_loaded, |
| 1045 | &osd->rx_size_255, &nsd->rx_size_255); |
| 1046 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 1047 | I40E_GLPRT_PRC511L(hw->port), |
| 1048 | pf->stat_offsets_loaded, |
| 1049 | &osd->rx_size_511, &nsd->rx_size_511); |
| 1050 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 1051 | I40E_GLPRT_PRC1023L(hw->port), |
| 1052 | pf->stat_offsets_loaded, |
| 1053 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 1054 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 1055 | I40E_GLPRT_PRC1522L(hw->port), |
| 1056 | pf->stat_offsets_loaded, |
| 1057 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 1058 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 1059 | I40E_GLPRT_PRC9522L(hw->port), |
| 1060 | pf->stat_offsets_loaded, |
| 1061 | &osd->rx_size_big, &nsd->rx_size_big); |
| 1062 | |
| 1063 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 1064 | I40E_GLPRT_PTC64L(hw->port), |
| 1065 | pf->stat_offsets_loaded, |
| 1066 | &osd->tx_size_64, &nsd->tx_size_64); |
| 1067 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 1068 | I40E_GLPRT_PTC127L(hw->port), |
| 1069 | pf->stat_offsets_loaded, |
| 1070 | &osd->tx_size_127, &nsd->tx_size_127); |
| 1071 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 1072 | I40E_GLPRT_PTC255L(hw->port), |
| 1073 | pf->stat_offsets_loaded, |
| 1074 | &osd->tx_size_255, &nsd->tx_size_255); |
| 1075 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 1076 | I40E_GLPRT_PTC511L(hw->port), |
| 1077 | pf->stat_offsets_loaded, |
| 1078 | &osd->tx_size_511, &nsd->tx_size_511); |
| 1079 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 1080 | I40E_GLPRT_PTC1023L(hw->port), |
| 1081 | pf->stat_offsets_loaded, |
| 1082 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 1083 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 1084 | I40E_GLPRT_PTC1522L(hw->port), |
| 1085 | pf->stat_offsets_loaded, |
| 1086 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1087 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1088 | I40E_GLPRT_PTC9522L(hw->port), |
| 1089 | pf->stat_offsets_loaded, |
| 1090 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1091 | |
| 1092 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1093 | pf->stat_offsets_loaded, |
| 1094 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1095 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1096 | pf->stat_offsets_loaded, |
| 1097 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1098 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1099 | pf->stat_offsets_loaded, |
| 1100 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1101 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1102 | pf->stat_offsets_loaded, |
| 1103 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1104 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1105 | /* FDIR stats */ |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1106 | i40e_stat_update32(hw, |
| 1107 | 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] | 1108 | pf->stat_offsets_loaded, |
| 1109 | &osd->fd_atr_match, &nsd->fd_atr_match); |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1110 | i40e_stat_update32(hw, |
| 1111 | 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] | 1112 | pf->stat_offsets_loaded, |
| 1113 | &osd->fd_sb_match, &nsd->fd_sb_match); |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 1114 | i40e_stat_update32(hw, |
| 1115 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), |
| 1116 | pf->stat_offsets_loaded, |
| 1117 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1118 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1119 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1120 | nsd->tx_lpi_status = |
| 1121 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1122 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1123 | nsd->rx_lpi_status = |
| 1124 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1125 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1126 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1127 | pf->stat_offsets_loaded, |
| 1128 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1129 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1130 | pf->stat_offsets_loaded, |
| 1131 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1132 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1133 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
| 1134 | !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) |
| 1135 | nsd->fd_sb_status = true; |
| 1136 | else |
| 1137 | nsd->fd_sb_status = false; |
| 1138 | |
| 1139 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
| 1140 | !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 1141 | nsd->fd_atr_status = true; |
| 1142 | else |
| 1143 | nsd->fd_atr_status = false; |
| 1144 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1145 | pf->stat_offsets_loaded = true; |
| 1146 | } |
| 1147 | |
| 1148 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1149 | * i40e_update_stats - Update the various statistics counters. |
| 1150 | * @vsi: the VSI to be updated |
| 1151 | * |
| 1152 | * Update the various stats for this VSI and its related entities. |
| 1153 | **/ |
| 1154 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1155 | { |
| 1156 | struct i40e_pf *pf = vsi->back; |
| 1157 | |
| 1158 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1159 | i40e_update_pf_stats(pf); |
| 1160 | |
| 1161 | i40e_update_vsi_stats(vsi); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1162 | #ifdef I40E_FCOE |
| 1163 | i40e_update_fcoe_stats(vsi); |
| 1164 | #endif |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1168 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1169 | * @vsi: the VSI to be searched |
| 1170 | * @macaddr: the MAC address |
| 1171 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1172 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1173 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1174 | * |
| 1175 | * Returns ptr to the filter object or NULL |
| 1176 | **/ |
| 1177 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
| 1178 | u8 *macaddr, s16 vlan, |
| 1179 | bool is_vf, bool is_netdev) |
| 1180 | { |
| 1181 | struct i40e_mac_filter *f; |
| 1182 | |
| 1183 | if (!vsi || !macaddr) |
| 1184 | return NULL; |
| 1185 | |
| 1186 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1187 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1188 | (vlan == f->vlan) && |
| 1189 | (!is_vf || f->is_vf) && |
| 1190 | (!is_netdev || f->is_netdev)) |
| 1191 | return f; |
| 1192 | } |
| 1193 | return NULL; |
| 1194 | } |
| 1195 | |
| 1196 | /** |
| 1197 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1198 | * @vsi: the VSI to be searched |
| 1199 | * @macaddr: the MAC address we are searching for |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1200 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1201 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1202 | * |
| 1203 | * Returns the first filter with the provided MAC address or NULL if |
| 1204 | * MAC address was not found |
| 1205 | **/ |
| 1206 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr, |
| 1207 | bool is_vf, bool is_netdev) |
| 1208 | { |
| 1209 | struct i40e_mac_filter *f; |
| 1210 | |
| 1211 | if (!vsi || !macaddr) |
| 1212 | return NULL; |
| 1213 | |
| 1214 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1215 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1216 | (!is_vf || f->is_vf) && |
| 1217 | (!is_netdev || f->is_netdev)) |
| 1218 | return f; |
| 1219 | } |
| 1220 | return NULL; |
| 1221 | } |
| 1222 | |
| 1223 | /** |
| 1224 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1225 | * @vsi: the VSI to be searched |
| 1226 | * |
| 1227 | * Returns true if VSI is in vlan mode or false otherwise |
| 1228 | **/ |
| 1229 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1230 | { |
| 1231 | struct i40e_mac_filter *f; |
| 1232 | |
| 1233 | /* Only -1 for all the filters denotes not in vlan mode |
| 1234 | * so we have to go through all the list in order to make sure |
| 1235 | */ |
| 1236 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Greg Rose | d9b68f8 | 2015-07-23 16:54:31 -0400 | [diff] [blame] | 1237 | if (f->vlan >= 0 || vsi->info.pvid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1238 | return true; |
| 1239 | } |
| 1240 | |
| 1241 | return false; |
| 1242 | } |
| 1243 | |
| 1244 | /** |
| 1245 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1246 | * @vsi: the VSI to be searched |
| 1247 | * @macaddr: the mac address to be filtered |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1248 | * @is_vf: true if it is a VF |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1249 | * @is_netdev: true if it is a netdev |
| 1250 | * |
| 1251 | * Goes through all the macvlan filters and adds a |
| 1252 | * macvlan filter for each unique vlan that already exists |
| 1253 | * |
| 1254 | * Returns first filter found on success, else NULL |
| 1255 | **/ |
| 1256 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1257 | bool is_vf, bool is_netdev) |
| 1258 | { |
| 1259 | struct i40e_mac_filter *f; |
| 1260 | |
| 1261 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Mitch Williams | ecbb44e | 2015-07-10 19:35:56 -0400 | [diff] [blame] | 1262 | if (vsi->info.pvid) |
| 1263 | f->vlan = le16_to_cpu(vsi->info.pvid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1264 | if (!i40e_find_filter(vsi, macaddr, f->vlan, |
| 1265 | is_vf, is_netdev)) { |
| 1266 | if (!i40e_add_filter(vsi, macaddr, f->vlan, |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 1267 | is_vf, is_netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1268 | return NULL; |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | return list_first_entry_or_null(&vsi->mac_filter_list, |
| 1273 | struct i40e_mac_filter, list); |
| 1274 | } |
| 1275 | |
| 1276 | /** |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1277 | * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS |
| 1278 | * @vsi: the VSI to be searched |
| 1279 | * @macaddr: the mac address to be removed |
| 1280 | * @is_vf: true if it is a VF |
| 1281 | * @is_netdev: true if it is a netdev |
| 1282 | * |
| 1283 | * Removes a given MAC address from a VSI, regardless of VLAN |
| 1284 | * |
| 1285 | * Returns 0 for success, or error |
| 1286 | **/ |
| 1287 | int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1288 | bool is_vf, bool is_netdev) |
| 1289 | { |
| 1290 | struct i40e_mac_filter *f = NULL; |
| 1291 | int changed = 0; |
| 1292 | |
| 1293 | WARN(!spin_is_locked(&vsi->mac_filter_list_lock), |
| 1294 | "Missing mac_filter_list_lock\n"); |
| 1295 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1296 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1297 | (is_vf == f->is_vf) && |
| 1298 | (is_netdev == f->is_netdev)) { |
| 1299 | f->counter--; |
| 1300 | f->changed = true; |
| 1301 | changed = 1; |
| 1302 | } |
| 1303 | } |
| 1304 | if (changed) { |
| 1305 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1306 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1307 | return 0; |
| 1308 | } |
| 1309 | return -ENOENT; |
| 1310 | } |
| 1311 | |
| 1312 | /** |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1313 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM |
| 1314 | * @vsi: the PF Main VSI - inappropriate for any other VSI |
| 1315 | * @macaddr: the MAC address |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1316 | * |
| 1317 | * Some older firmware configurations set up a default promiscuous VLAN |
| 1318 | * filter that needs to be removed. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1319 | **/ |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1320 | 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] | 1321 | { |
| 1322 | struct i40e_aqc_remove_macvlan_element_data element; |
| 1323 | struct i40e_pf *pf = vsi->back; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1324 | i40e_status ret; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1325 | |
| 1326 | /* Only appropriate for the PF main VSI */ |
| 1327 | if (vsi->type != I40E_VSI_MAIN) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1328 | return -EINVAL; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1329 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1330 | memset(&element, 0, sizeof(element)); |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1331 | ether_addr_copy(element.mac_addr, macaddr); |
| 1332 | element.vlan_tag = 0; |
| 1333 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | |
| 1334 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1335 | ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1336 | if (ret) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1337 | return -ENOENT; |
| 1338 | |
| 1339 | return 0; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1343 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1344 | * @vsi: the VSI to be searched |
| 1345 | * @macaddr: the MAC address |
| 1346 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1347 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1348 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1349 | * |
| 1350 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1351 | * |
| 1352 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1353 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1354 | **/ |
| 1355 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
| 1356 | u8 *macaddr, s16 vlan, |
| 1357 | bool is_vf, bool is_netdev) |
| 1358 | { |
| 1359 | struct i40e_mac_filter *f; |
| 1360 | |
| 1361 | if (!vsi || !macaddr) |
| 1362 | return NULL; |
| 1363 | |
| 1364 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1365 | if (!f) { |
| 1366 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1367 | if (!f) |
| 1368 | goto add_filter_out; |
| 1369 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1370 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1371 | f->vlan = vlan; |
| 1372 | f->changed = true; |
| 1373 | |
| 1374 | INIT_LIST_HEAD(&f->list); |
Kiran Patil | 04d5a21 | 2015-12-09 15:50:23 -0800 | [diff] [blame] | 1375 | list_add_tail(&f->list, &vsi->mac_filter_list); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | /* increment counter and add a new flag if needed */ |
| 1379 | if (is_vf) { |
| 1380 | if (!f->is_vf) { |
| 1381 | f->is_vf = true; |
| 1382 | f->counter++; |
| 1383 | } |
| 1384 | } else if (is_netdev) { |
| 1385 | if (!f->is_netdev) { |
| 1386 | f->is_netdev = true; |
| 1387 | f->counter++; |
| 1388 | } |
| 1389 | } else { |
| 1390 | f->counter++; |
| 1391 | } |
| 1392 | |
| 1393 | /* changed tells sync_filters_subtask to |
| 1394 | * push the filter down to the firmware |
| 1395 | */ |
| 1396 | if (f->changed) { |
| 1397 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1398 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1399 | } |
| 1400 | |
| 1401 | add_filter_out: |
| 1402 | return f; |
| 1403 | } |
| 1404 | |
| 1405 | /** |
| 1406 | * i40e_del_filter - Remove a mac/vlan filter from the VSI |
| 1407 | * @vsi: the VSI to be searched |
| 1408 | * @macaddr: the MAC address |
| 1409 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1410 | * @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] | 1411 | * @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] | 1412 | * |
| 1413 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1414 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1415 | **/ |
| 1416 | void i40e_del_filter(struct i40e_vsi *vsi, |
| 1417 | u8 *macaddr, s16 vlan, |
| 1418 | bool is_vf, bool is_netdev) |
| 1419 | { |
| 1420 | struct i40e_mac_filter *f; |
| 1421 | |
| 1422 | if (!vsi || !macaddr) |
| 1423 | return; |
| 1424 | |
| 1425 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1426 | if (!f || f->counter == 0) |
| 1427 | return; |
| 1428 | |
| 1429 | if (is_vf) { |
| 1430 | if (f->is_vf) { |
| 1431 | f->is_vf = false; |
| 1432 | f->counter--; |
| 1433 | } |
| 1434 | } else if (is_netdev) { |
| 1435 | if (f->is_netdev) { |
| 1436 | f->is_netdev = false; |
| 1437 | f->counter--; |
| 1438 | } |
| 1439 | } else { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1440 | /* 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] | 1441 | int min_f = 0; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1442 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1443 | min_f += (f->is_vf ? 1 : 0); |
| 1444 | min_f += (f->is_netdev ? 1 : 0); |
| 1445 | |
| 1446 | if (f->counter > min_f) |
| 1447 | f->counter--; |
| 1448 | } |
| 1449 | |
| 1450 | /* counter == 0 tells sync_filters_subtask to |
| 1451 | * remove the filter from the firmware's list |
| 1452 | */ |
| 1453 | if (f->counter == 0) { |
| 1454 | f->changed = true; |
| 1455 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1456 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | /** |
| 1461 | * i40e_set_mac - NDO callback to set mac address |
| 1462 | * @netdev: network interface device structure |
| 1463 | * @p: pointer to an address structure |
| 1464 | * |
| 1465 | * Returns 0 on success, negative on failure |
| 1466 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1467 | #ifdef I40E_FCOE |
| 1468 | int i40e_set_mac(struct net_device *netdev, void *p) |
| 1469 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1470 | static int i40e_set_mac(struct net_device *netdev, void *p) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1471 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1472 | { |
| 1473 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1474 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1475 | struct i40e_pf *pf = vsi->back; |
| 1476 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1477 | struct sockaddr *addr = p; |
| 1478 | struct i40e_mac_filter *f; |
| 1479 | |
| 1480 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1481 | return -EADDRNOTAVAIL; |
| 1482 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1483 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1484 | netdev_info(netdev, "already using mac address %pM\n", |
| 1485 | addr->sa_data); |
| 1486 | return 0; |
| 1487 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1488 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1489 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1490 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1491 | return -EADDRNOTAVAIL; |
| 1492 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1493 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1494 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1495 | hw->mac.addr); |
| 1496 | else |
| 1497 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1498 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1499 | if (vsi->type == I40E_VSI_MAIN) { |
| 1500 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1501 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1502 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1503 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1504 | addr->sa_data, NULL); |
| 1505 | if (ret) { |
| 1506 | netdev_info(netdev, |
| 1507 | "Addr change for Main VSI failed: %d\n", |
| 1508 | ret); |
| 1509 | return -EADDRNOTAVAIL; |
| 1510 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1513 | if (ether_addr_equal(netdev->dev_addr, hw->mac.addr)) { |
| 1514 | struct i40e_aqc_remove_macvlan_element_data element; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1515 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1516 | memset(&element, 0, sizeof(element)); |
| 1517 | ether_addr_copy(element.mac_addr, netdev->dev_addr); |
| 1518 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1519 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1520 | } else { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1521 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1522 | i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 1523 | false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1524 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1527 | if (ether_addr_equal(addr->sa_data, hw->mac.addr)) { |
| 1528 | struct i40e_aqc_add_macvlan_element_data element; |
| 1529 | |
| 1530 | memset(&element, 0, sizeof(element)); |
| 1531 | ether_addr_copy(element.mac_addr, hw->mac.addr); |
| 1532 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 1533 | i40e_aq_add_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1534 | } else { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1535 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1536 | f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, |
| 1537 | false, false); |
| 1538 | if (f) |
| 1539 | f->is_laa = true; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1540 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1543 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1544 | |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1545 | /* schedule our worker thread which will take care of |
| 1546 | * applying the new filter changes |
| 1547 | */ |
| 1548 | i40e_service_event_schedule(vsi->back); |
| 1549 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | /** |
| 1553 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1554 | * @vsi: the VSI being setup |
| 1555 | * @ctxt: VSI context structure |
| 1556 | * @enabled_tc: Enabled TCs bitmap |
| 1557 | * @is_add: True if called before Add VSI |
| 1558 | * |
| 1559 | * Setup VSI queue mapping for enabled traffic classes. |
| 1560 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1561 | #ifdef I40E_FCOE |
| 1562 | void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1563 | struct i40e_vsi_context *ctxt, |
| 1564 | u8 enabled_tc, |
| 1565 | bool is_add) |
| 1566 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1567 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1568 | struct i40e_vsi_context *ctxt, |
| 1569 | u8 enabled_tc, |
| 1570 | bool is_add) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1571 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1572 | { |
| 1573 | struct i40e_pf *pf = vsi->back; |
| 1574 | u16 sections = 0; |
| 1575 | u8 netdev_tc = 0; |
| 1576 | u16 numtc = 0; |
| 1577 | u16 qcount; |
| 1578 | u8 offset; |
| 1579 | u16 qmap; |
| 1580 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1581 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1582 | |
| 1583 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1584 | offset = 0; |
| 1585 | |
| 1586 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1587 | /* Find numtc from enabled TC bitmap */ |
| 1588 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1589 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1590 | numtc++; |
| 1591 | } |
| 1592 | if (!numtc) { |
| 1593 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1594 | numtc = 1; |
| 1595 | } |
| 1596 | } else { |
| 1597 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1598 | numtc = 1; |
| 1599 | } |
| 1600 | |
| 1601 | vsi->tc_config.numtc = numtc; |
| 1602 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1603 | /* Number of queues per enabled TC */ |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1604 | /* In MFP case we can have a much lower count of MSIx |
| 1605 | * vectors available and so we need to lower the used |
| 1606 | * q count. |
| 1607 | */ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1608 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 1609 | qcount = min_t(int, vsi->alloc_queue_pairs, pf->num_lan_msix); |
| 1610 | else |
| 1611 | qcount = vsi->alloc_queue_pairs; |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1612 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1613 | 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] | 1614 | |
| 1615 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1616 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1617 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1618 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1619 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1620 | int pow, num_qps; |
| 1621 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1622 | switch (vsi->type) { |
| 1623 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1624 | qcount = min_t(int, pf->alloc_rss_size, |
| 1625 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1626 | break; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1627 | #ifdef I40E_FCOE |
| 1628 | case I40E_VSI_FCOE: |
| 1629 | qcount = num_tc_qps; |
| 1630 | break; |
| 1631 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1632 | case I40E_VSI_FDIR: |
| 1633 | case I40E_VSI_SRIOV: |
| 1634 | case I40E_VSI_VMDQ2: |
| 1635 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1636 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1637 | WARN_ON(i != 0); |
| 1638 | break; |
| 1639 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1640 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1641 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1642 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1643 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1644 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1645 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1646 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1647 | pow++; |
| 1648 | num_qps >>= 1; |
| 1649 | } |
| 1650 | |
| 1651 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1652 | qmap = |
| 1653 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1654 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1655 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1656 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1657 | } else { |
| 1658 | /* TC is not enabled so set the offset to |
| 1659 | * default queue and allocate one queue |
| 1660 | * for the given TC. |
| 1661 | */ |
| 1662 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1663 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1664 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1665 | |
| 1666 | qmap = 0; |
| 1667 | } |
| 1668 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1669 | } |
| 1670 | |
| 1671 | /* Set actual Tx/Rx queue pairs */ |
| 1672 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1673 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1674 | if (vsi->req_queue_pairs > 0) |
| 1675 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1676 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1677 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1678 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1679 | |
| 1680 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1681 | if (is_add) { |
| 1682 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1683 | |
| 1684 | ctxt->info.up_enable_bits = enabled_tc; |
| 1685 | } |
| 1686 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1687 | ctxt->info.mapping_flags |= |
| 1688 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1689 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1690 | ctxt->info.queue_mapping[i] = |
| 1691 | cpu_to_le16(vsi->base_queue + i); |
| 1692 | } else { |
| 1693 | ctxt->info.mapping_flags |= |
| 1694 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1695 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1696 | } |
| 1697 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1698 | } |
| 1699 | |
| 1700 | /** |
| 1701 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1702 | * @netdev: network interface device structure |
| 1703 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1704 | #ifdef I40E_FCOE |
| 1705 | void i40e_set_rx_mode(struct net_device *netdev) |
| 1706 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1707 | static void i40e_set_rx_mode(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1708 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1709 | { |
| 1710 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1711 | struct i40e_mac_filter *f, *ftmp; |
| 1712 | struct i40e_vsi *vsi = np->vsi; |
| 1713 | struct netdev_hw_addr *uca; |
| 1714 | struct netdev_hw_addr *mca; |
| 1715 | struct netdev_hw_addr *ha; |
| 1716 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1717 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1718 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1719 | /* add addr if not already in the filter list */ |
| 1720 | netdev_for_each_uc_addr(uca, netdev) { |
| 1721 | if (!i40e_find_mac(vsi, uca->addr, false, true)) { |
| 1722 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1723 | i40e_put_mac_in_vlan(vsi, uca->addr, |
| 1724 | false, true); |
| 1725 | else |
| 1726 | i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY, |
| 1727 | false, true); |
| 1728 | } |
| 1729 | } |
| 1730 | |
| 1731 | netdev_for_each_mc_addr(mca, netdev) { |
| 1732 | if (!i40e_find_mac(vsi, mca->addr, false, true)) { |
| 1733 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1734 | i40e_put_mac_in_vlan(vsi, mca->addr, |
| 1735 | false, true); |
| 1736 | else |
| 1737 | i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY, |
| 1738 | false, true); |
| 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | /* remove filter if not in netdev list */ |
| 1743 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1744 | |
| 1745 | if (!f->is_netdev) |
| 1746 | continue; |
| 1747 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1748 | netdev_for_each_mc_addr(mca, netdev) |
| 1749 | if (ether_addr_equal(mca->addr, f->macaddr)) |
| 1750 | goto bottom_of_search_loop; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1751 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1752 | netdev_for_each_uc_addr(uca, netdev) |
| 1753 | if (ether_addr_equal(uca->addr, f->macaddr)) |
| 1754 | goto bottom_of_search_loop; |
| 1755 | |
| 1756 | for_each_dev_addr(netdev, ha) |
| 1757 | if (ether_addr_equal(ha->addr, f->macaddr)) |
| 1758 | goto bottom_of_search_loop; |
| 1759 | |
| 1760 | /* f->macaddr wasn't found in uc, mc, or ha list so delete it */ |
| 1761 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true); |
| 1762 | |
| 1763 | bottom_of_search_loop: |
| 1764 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1765 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1766 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1767 | |
| 1768 | /* check for other flag changes */ |
| 1769 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1770 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1771 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1772 | } |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1773 | |
| 1774 | /* schedule our worker thread which will take care of |
| 1775 | * applying the new filter changes |
| 1776 | */ |
| 1777 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | /** |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1781 | * i40e_mac_filter_entry_clone - Clones a MAC filter entry |
| 1782 | * @src: source MAC filter entry to be clones |
| 1783 | * |
| 1784 | * Returns the pointer to newly cloned MAC filter entry or NULL |
| 1785 | * in case of error |
| 1786 | **/ |
| 1787 | static struct i40e_mac_filter *i40e_mac_filter_entry_clone( |
| 1788 | struct i40e_mac_filter *src) |
| 1789 | { |
| 1790 | struct i40e_mac_filter *f; |
| 1791 | |
| 1792 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1793 | if (!f) |
| 1794 | return NULL; |
| 1795 | *f = *src; |
| 1796 | |
| 1797 | INIT_LIST_HEAD(&f->list); |
| 1798 | |
| 1799 | return f; |
| 1800 | } |
| 1801 | |
| 1802 | /** |
| 1803 | * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries |
| 1804 | * @vsi: pointer to vsi struct |
| 1805 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1806 | * those entries needs to be undone. |
| 1807 | * |
| 1808 | * MAC filter entries from list were slated to be removed from device. |
| 1809 | **/ |
| 1810 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1811 | struct list_head *from) |
| 1812 | { |
| 1813 | struct i40e_mac_filter *f, *ftmp; |
| 1814 | |
| 1815 | list_for_each_entry_safe(f, ftmp, from, list) { |
| 1816 | f->changed = true; |
| 1817 | /* Move the element back into MAC filter list*/ |
| 1818 | list_move_tail(&f->list, &vsi->mac_filter_list); |
| 1819 | } |
| 1820 | } |
| 1821 | |
| 1822 | /** |
| 1823 | * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries |
| 1824 | * @vsi: pointer to vsi struct |
| 1825 | * |
| 1826 | * MAC filter entries from list were slated to be added from device. |
| 1827 | **/ |
| 1828 | static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi) |
| 1829 | { |
| 1830 | struct i40e_mac_filter *f, *ftmp; |
| 1831 | |
| 1832 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1833 | if (!f->changed && f->counter) |
| 1834 | f->changed = true; |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | /** |
| 1839 | * i40e_cleanup_add_list - Deletes the element from add list and release |
| 1840 | * memory |
| 1841 | * @add_list: Pointer to list which contains MAC filter entries |
| 1842 | **/ |
| 1843 | static void i40e_cleanup_add_list(struct list_head *add_list) |
| 1844 | { |
| 1845 | struct i40e_mac_filter *f, *ftmp; |
| 1846 | |
| 1847 | list_for_each_entry_safe(f, ftmp, add_list, list) { |
| 1848 | list_del(&f->list); |
| 1849 | kfree(f); |
| 1850 | } |
| 1851 | } |
| 1852 | |
| 1853 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1854 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1855 | * @vsi: ptr to the VSI |
| 1856 | * |
| 1857 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1858 | * |
| 1859 | * Returns 0 or error value |
| 1860 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 1861 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1862 | { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1863 | struct list_head tmp_del_list, tmp_add_list; |
| 1864 | struct i40e_mac_filter *f, *ftmp, *fclone; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1865 | bool promisc_forced_on = false; |
| 1866 | bool add_happened = false; |
| 1867 | int filter_list_len = 0; |
| 1868 | u32 changed_flags = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1869 | i40e_status aq_ret = 0; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1870 | bool err_cond = false; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1871 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1872 | struct i40e_pf *pf; |
| 1873 | int num_add = 0; |
| 1874 | int num_del = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1875 | int aq_err = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1876 | u16 cmd_flags; |
| 1877 | |
| 1878 | /* empty array typed pointers, kcalloc later */ |
| 1879 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1880 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1881 | |
| 1882 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1883 | usleep_range(1000, 2000); |
| 1884 | pf = vsi->back; |
| 1885 | |
| 1886 | if (vsi->netdev) { |
| 1887 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1888 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1889 | } |
| 1890 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1891 | INIT_LIST_HEAD(&tmp_del_list); |
| 1892 | INIT_LIST_HEAD(&tmp_add_list); |
| 1893 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1894 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1895 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1896 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1897 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1898 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1899 | if (!f->changed) |
| 1900 | continue; |
| 1901 | |
| 1902 | if (f->counter != 0) |
| 1903 | continue; |
| 1904 | f->changed = false; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1905 | |
| 1906 | /* Move the element into temporary del_list */ |
| 1907 | list_move_tail(&f->list, &tmp_del_list); |
| 1908 | } |
| 1909 | |
| 1910 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1911 | if (!f->changed) |
| 1912 | continue; |
| 1913 | |
| 1914 | if (f->counter == 0) |
| 1915 | continue; |
| 1916 | f->changed = false; |
| 1917 | |
| 1918 | /* Clone MAC filter entry and add into temporary list */ |
| 1919 | fclone = i40e_mac_filter_entry_clone(f); |
| 1920 | if (!fclone) { |
| 1921 | err_cond = true; |
| 1922 | break; |
| 1923 | } |
| 1924 | list_add_tail(&fclone->list, &tmp_add_list); |
| 1925 | } |
| 1926 | |
| 1927 | /* if failed to clone MAC filter entry - undo */ |
| 1928 | if (err_cond) { |
| 1929 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 1930 | i40e_undo_add_filter_entries(vsi); |
| 1931 | } |
| 1932 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 1933 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1934 | if (err_cond) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1935 | i40e_cleanup_add_list(&tmp_add_list); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1936 | retval = -ENOMEM; |
| 1937 | goto out; |
| 1938 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | /* Now process 'del_list' outside the lock */ |
| 1942 | if (!list_empty(&tmp_del_list)) { |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1943 | int del_list_size; |
| 1944 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1945 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 1946 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1947 | del_list_size = filter_list_len * |
| 1948 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Jesse Brandeburg | 38c3cec | 2016-01-04 10:33:05 -0800 | [diff] [blame] | 1949 | del_list = kzalloc(del_list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1950 | if (!del_list) { |
| 1951 | i40e_cleanup_add_list(&tmp_add_list); |
| 1952 | |
| 1953 | /* Undo VSI's MAC filter entry element updates */ |
| 1954 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1955 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 1956 | i40e_undo_add_filter_entries(vsi); |
| 1957 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1958 | retval = -ENOMEM; |
| 1959 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1963 | cmd_flags = 0; |
| 1964 | |
| 1965 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1966 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1967 | del_list[num_del].vlan_tag = |
| 1968 | cpu_to_le16((u16)(f->vlan == |
| 1969 | I40E_VLAN_ANY ? 0 : f->vlan)); |
| 1970 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1971 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1972 | del_list[num_del].flags = cmd_flags; |
| 1973 | num_del++; |
| 1974 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1975 | /* flush a full buffer */ |
| 1976 | if (num_del == filter_list_len) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1977 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, |
| 1978 | vsi->seid, |
| 1979 | del_list, |
| 1980 | num_del, |
| 1981 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1982 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1983 | num_del = 0; |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1984 | memset(del_list, 0, del_list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1985 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1986 | if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) { |
| 1987 | retval = -EIO; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1988 | dev_err(&pf->pdev->dev, |
| 1989 | "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] | 1990 | i40e_stat_str(&pf->hw, aq_ret), |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1991 | i40e_aq_str(&pf->hw, aq_err)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1992 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1993 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1994 | /* Release memory for MAC filter entries which were |
| 1995 | * synced up with HW. |
| 1996 | */ |
| 1997 | list_del(&f->list); |
| 1998 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1999 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2000 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2001 | if (num_del) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2002 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, |
| 2003 | del_list, num_del, |
| 2004 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2005 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2006 | num_del = 0; |
| 2007 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2008 | if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2009 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2010 | "ignoring delete macvlan error, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2011 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2012 | i40e_aq_str(&pf->hw, aq_err)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | kfree(del_list); |
| 2016 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | if (!list_empty(&tmp_add_list)) { |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2020 | int add_list_size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2021 | |
| 2022 | /* do all the adds now */ |
| 2023 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 2024 | sizeof(struct i40e_aqc_add_macvlan_element_data), |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2025 | add_list_size = filter_list_len * |
| 2026 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Jesse Brandeburg | 38c3cec | 2016-01-04 10:33:05 -0800 | [diff] [blame] | 2027 | add_list = kzalloc(add_list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2028 | if (!add_list) { |
| 2029 | /* Purge element from temporary lists */ |
| 2030 | i40e_cleanup_add_list(&tmp_add_list); |
| 2031 | |
| 2032 | /* Undo add filter entries from VSI MAC filter list */ |
| 2033 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2034 | i40e_undo_add_filter_entries(vsi); |
| 2035 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2036 | retval = -ENOMEM; |
| 2037 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2038 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2039 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2040 | list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2041 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2042 | add_happened = true; |
| 2043 | cmd_flags = 0; |
| 2044 | |
| 2045 | /* add to add array */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2046 | ether_addr_copy(add_list[num_add].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2047 | add_list[num_add].vlan_tag = |
| 2048 | cpu_to_le16( |
| 2049 | (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan)); |
| 2050 | add_list[num_add].queue_number = 0; |
| 2051 | |
| 2052 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2053 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2054 | num_add++; |
| 2055 | |
| 2056 | /* flush a full buffer */ |
| 2057 | if (num_add == filter_list_len) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2058 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 2059 | add_list, num_add, |
| 2060 | 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 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2064 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2065 | break; |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2066 | memset(add_list, 0, add_list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2067 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2068 | /* Entries from tmp_add_list were cloned from MAC |
| 2069 | * filter list, hence clean those cloned entries |
| 2070 | */ |
| 2071 | list_del(&f->list); |
| 2072 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2073 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2074 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2075 | if (num_add) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2076 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 2077 | add_list, num_add, NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2078 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2079 | num_add = 0; |
| 2080 | } |
| 2081 | kfree(add_list); |
| 2082 | add_list = NULL; |
| 2083 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2084 | if (add_happened && aq_ret && aq_err != I40E_AQ_RC_EINVAL) { |
| 2085 | retval = i40e_aq_rc_to_posix(aq_ret, aq_err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2086 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2087 | "add filter failed, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2088 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2089 | i40e_aq_str(&pf->hw, aq_err)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2090 | if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) && |
| 2091 | !test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2092 | &vsi->state)) { |
| 2093 | promisc_forced_on = true; |
| 2094 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2095 | &vsi->state); |
| 2096 | dev_info(&pf->pdev->dev, "promiscuous mode forced on\n"); |
| 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | |
| 2101 | /* check for changes in promiscuous modes */ |
| 2102 | if (changed_flags & IFF_ALLMULTI) { |
| 2103 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2104 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2105 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2106 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2107 | vsi->seid, |
| 2108 | cur_multipromisc, |
| 2109 | NULL); |
| 2110 | if (aq_ret) { |
| 2111 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2112 | pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2113 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2114 | "set multi promisc failed, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2115 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2116 | i40e_aq_str(&pf->hw, |
| 2117 | pf->hw.aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2118 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2119 | } |
| 2120 | if ((changed_flags & IFF_PROMISC) || promisc_forced_on) { |
| 2121 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2122 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2123 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 2124 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2125 | &vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2126 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2127 | (pf->lan_veb != I40E_NO_VEB) && |
| 2128 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2129 | /* set defport ON for Main VSI instead of true promisc |
| 2130 | * this way we will get all unicast/multicast and VLAN |
| 2131 | * promisc behavior but will not get VF or VMDq traffic |
| 2132 | * replicated on the Main VSI. |
| 2133 | */ |
| 2134 | if (pf->cur_promisc != cur_promisc) { |
| 2135 | pf->cur_promisc = cur_promisc; |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2136 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2137 | } |
| 2138 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2139 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2140 | &vsi->back->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2141 | vsi->seid, |
| 2142 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2143 | if (aq_ret) { |
| 2144 | retval = |
| 2145 | i40e_aq_rc_to_posix(aq_ret, |
| 2146 | pf->hw.aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2147 | dev_info(&pf->pdev->dev, |
| 2148 | "set unicast promisc failed, err %d, aq_err %d\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2149 | aq_ret, pf->hw.aq.asq_last_status); |
| 2150 | } |
| 2151 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2152 | &vsi->back->hw, |
| 2153 | vsi->seid, |
| 2154 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2155 | if (aq_ret) { |
| 2156 | retval = |
| 2157 | i40e_aq_rc_to_posix(aq_ret, |
| 2158 | pf->hw.aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2159 | dev_info(&pf->pdev->dev, |
| 2160 | "set multicast promisc failed, err %d, aq_err %d\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2161 | aq_ret, pf->hw.aq.asq_last_status); |
| 2162 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2163 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2164 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2165 | vsi->seid, |
| 2166 | cur_promisc, NULL); |
| 2167 | if (aq_ret) { |
| 2168 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2169 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2170 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2171 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2172 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2173 | i40e_aq_str(&pf->hw, |
| 2174 | pf->hw.aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2175 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2176 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2177 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2178 | /* if something went wrong then set the changed flag so we try again */ |
| 2179 | if (retval) |
| 2180 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2181 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2182 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2183 | return retval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | /** |
| 2187 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2188 | * @pf: board private structure |
| 2189 | **/ |
| 2190 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2191 | { |
| 2192 | int v; |
| 2193 | |
| 2194 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2195 | return; |
| 2196 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2197 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2198 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2199 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2200 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2201 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2202 | |
| 2203 | if (ret) { |
| 2204 | /* come back and try again later */ |
| 2205 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2206 | break; |
| 2207 | } |
| 2208 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2209 | } |
| 2210 | } |
| 2211 | |
| 2212 | /** |
| 2213 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2214 | * @netdev: network interface device structure |
| 2215 | * @new_mtu: new value for maximum frame size |
| 2216 | * |
| 2217 | * Returns 0 on success, negative on failure |
| 2218 | **/ |
| 2219 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2220 | { |
| 2221 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 61a46a4 | 2014-04-23 04:50:05 +0000 | [diff] [blame] | 2222 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2223 | struct i40e_vsi *vsi = np->vsi; |
| 2224 | |
| 2225 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 2226 | if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) |
| 2227 | return -EINVAL; |
| 2228 | |
| 2229 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2230 | netdev->mtu, new_mtu); |
| 2231 | netdev->mtu = new_mtu; |
| 2232 | if (netif_running(netdev)) |
| 2233 | i40e_vsi_reinit_locked(vsi); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 2234 | i40e_notify_client_of_l2_param_changes(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2235 | return 0; |
| 2236 | } |
| 2237 | |
| 2238 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2239 | * i40e_ioctl - Access the hwtstamp interface |
| 2240 | * @netdev: network interface device structure |
| 2241 | * @ifr: interface request data |
| 2242 | * @cmd: ioctl command |
| 2243 | **/ |
| 2244 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2245 | { |
| 2246 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2247 | struct i40e_pf *pf = np->vsi->back; |
| 2248 | |
| 2249 | switch (cmd) { |
| 2250 | case SIOCGHWTSTAMP: |
| 2251 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2252 | case SIOCSHWTSTAMP: |
| 2253 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2254 | default: |
| 2255 | return -EOPNOTSUPP; |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2260 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2261 | * @vsi: the vsi being adjusted |
| 2262 | **/ |
| 2263 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2264 | { |
| 2265 | struct i40e_vsi_context ctxt; |
| 2266 | i40e_status ret; |
| 2267 | |
| 2268 | if ((vsi->info.valid_sections & |
| 2269 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2270 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2271 | return; /* already enabled */ |
| 2272 | |
| 2273 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2274 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2275 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2276 | |
| 2277 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2278 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2279 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2280 | if (ret) { |
| 2281 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2282 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2283 | i40e_stat_str(&vsi->back->hw, ret), |
| 2284 | i40e_aq_str(&vsi->back->hw, |
| 2285 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2286 | } |
| 2287 | } |
| 2288 | |
| 2289 | /** |
| 2290 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2291 | * @vsi: the vsi being adjusted |
| 2292 | **/ |
| 2293 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2294 | { |
| 2295 | struct i40e_vsi_context ctxt; |
| 2296 | i40e_status ret; |
| 2297 | |
| 2298 | if ((vsi->info.valid_sections & |
| 2299 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2300 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2301 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2302 | return; /* already disabled */ |
| 2303 | |
| 2304 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2305 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2306 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2307 | |
| 2308 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2309 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2310 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2311 | if (ret) { |
| 2312 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2313 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2314 | i40e_stat_str(&vsi->back->hw, ret), |
| 2315 | i40e_aq_str(&vsi->back->hw, |
| 2316 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2317 | } |
| 2318 | } |
| 2319 | |
| 2320 | /** |
| 2321 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2322 | * @netdev: network interface to be adjusted |
| 2323 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2324 | **/ |
| 2325 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2326 | { |
| 2327 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2328 | struct i40e_vsi *vsi = np->vsi; |
| 2329 | |
| 2330 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2331 | i40e_vlan_stripping_enable(vsi); |
| 2332 | else |
| 2333 | i40e_vlan_stripping_disable(vsi); |
| 2334 | } |
| 2335 | |
| 2336 | /** |
| 2337 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 2338 | * @vsi: the vsi being configured |
| 2339 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 2340 | **/ |
| 2341 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2342 | { |
| 2343 | struct i40e_mac_filter *f, *add_f; |
| 2344 | bool is_netdev, is_vf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2345 | |
| 2346 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2347 | is_netdev = !!(vsi->netdev); |
| 2348 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2349 | /* Locked once because all functions invoked below iterates list*/ |
| 2350 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2351 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2352 | if (is_netdev) { |
| 2353 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid, |
| 2354 | 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, vsi->netdev->dev_addr); |
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 | |
| 2364 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2365 | add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2366 | if (!add_f) { |
| 2367 | dev_info(&vsi->back->pdev->dev, |
| 2368 | "Could not add vlan filter %d for %pM\n", |
| 2369 | vid, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2370 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2371 | return -ENOMEM; |
| 2372 | } |
| 2373 | } |
| 2374 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2375 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 2376 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 2377 | * with 0, so we now accept untagged and specified tagged traffic |
| 2378 | * (and not any taged and untagged) |
| 2379 | */ |
| 2380 | if (vid > 0) { |
| 2381 | if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 2382 | I40E_VLAN_ANY, |
| 2383 | is_vf, is_netdev)) { |
| 2384 | i40e_del_filter(vsi, vsi->netdev->dev_addr, |
| 2385 | I40E_VLAN_ANY, is_vf, is_netdev); |
| 2386 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0, |
| 2387 | is_vf, is_netdev); |
| 2388 | if (!add_f) { |
| 2389 | dev_info(&vsi->back->pdev->dev, |
| 2390 | "Could not add filter 0 for %pM\n", |
| 2391 | vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2392 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2393 | return -ENOMEM; |
| 2394 | } |
| 2395 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2396 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2397 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2398 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
| 2399 | if (vid > 0 && !vsi->info.pvid) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2400 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2401 | if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2402 | is_vf, is_netdev)) |
| 2403 | continue; |
| 2404 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2405 | is_vf, is_netdev); |
| 2406 | add_f = i40e_add_filter(vsi, f->macaddr, |
| 2407 | 0, is_vf, is_netdev); |
| 2408 | if (!add_f) { |
| 2409 | dev_info(&vsi->back->pdev->dev, |
| 2410 | "Could not add filter 0 for %pM\n", |
| 2411 | f->macaddr); |
| 2412 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2413 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2414 | } |
| 2415 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2416 | } |
| 2417 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2418 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2419 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2420 | /* schedule our worker thread which will take care of |
| 2421 | * applying the new filter changes |
| 2422 | */ |
| 2423 | i40e_service_event_schedule(vsi->back); |
| 2424 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | /** |
| 2428 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 2429 | * @vsi: the vsi being configured |
| 2430 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2431 | * |
| 2432 | * Return: 0 on success or negative otherwise |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2433 | **/ |
| 2434 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2435 | { |
| 2436 | struct net_device *netdev = vsi->netdev; |
| 2437 | struct i40e_mac_filter *f, *add_f; |
| 2438 | bool is_vf, is_netdev; |
| 2439 | int filter_count = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2440 | |
| 2441 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2442 | is_netdev = !!(netdev); |
| 2443 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2444 | /* Locked once because all functions invoked below iterates list */ |
| 2445 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2446 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2447 | if (is_netdev) |
| 2448 | i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev); |
| 2449 | |
| 2450 | list_for_each_entry(f, &vsi->mac_filter_list, list) |
| 2451 | i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2452 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2453 | /* go through all the filters for this VSI and if there is only |
| 2454 | * vid == 0 it means there are no other filters, so vid 0 must |
| 2455 | * be replaced with -1. This signifies that we should from now |
| 2456 | * on accept any traffic (with any tag present, or untagged) |
| 2457 | */ |
| 2458 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2459 | if (is_netdev) { |
| 2460 | if (f->vlan && |
| 2461 | ether_addr_equal(netdev->dev_addr, f->macaddr)) |
| 2462 | filter_count++; |
| 2463 | } |
| 2464 | |
| 2465 | if (f->vlan) |
| 2466 | filter_count++; |
| 2467 | } |
| 2468 | |
| 2469 | if (!filter_count && is_netdev) { |
| 2470 | i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev); |
| 2471 | f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 2472 | is_vf, is_netdev); |
| 2473 | if (!f) { |
| 2474 | dev_info(&vsi->back->pdev->dev, |
| 2475 | "Could not add filter %d for %pM\n", |
| 2476 | I40E_VLAN_ANY, netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2477 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2478 | return -ENOMEM; |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | if (!filter_count) { |
| 2483 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2484 | i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev); |
| 2485 | add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2486 | is_vf, is_netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2487 | if (!add_f) { |
| 2488 | dev_info(&vsi->back->pdev->dev, |
| 2489 | "Could not add filter %d for %pM\n", |
| 2490 | I40E_VLAN_ANY, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2491 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2492 | return -ENOMEM; |
| 2493 | } |
| 2494 | } |
| 2495 | } |
| 2496 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2497 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2498 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2499 | /* schedule our worker thread which will take care of |
| 2500 | * applying the new filter changes |
| 2501 | */ |
| 2502 | i40e_service_event_schedule(vsi->back); |
| 2503 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | /** |
| 2507 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2508 | * @netdev: network interface to be adjusted |
| 2509 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2510 | * |
| 2511 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2512 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2513 | #ifdef I40E_FCOE |
| 2514 | int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2515 | __always_unused __be16 proto, u16 vid) |
| 2516 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2517 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2518 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2519 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2520 | { |
| 2521 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2522 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2523 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2524 | |
| 2525 | if (vid > 4095) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2526 | return -EINVAL; |
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 | netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid); |
| 2529 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2530 | /* If the network stack called us with vid = 0 then |
| 2531 | * it is asking to receive priority tagged packets with |
| 2532 | * vlan id 0. Our HW receives them by default when configured |
| 2533 | * to receive untagged packets so there is no need to add an |
| 2534 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2535 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2536 | if (vid) |
| 2537 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2538 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2539 | if (!ret && (vid < VLAN_N_VID)) |
| 2540 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2541 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2542 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | /** |
| 2546 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2547 | * @netdev: network interface to be adjusted |
| 2548 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2549 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2550 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2551 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2552 | #ifdef I40E_FCOE |
| 2553 | int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2554 | __always_unused __be16 proto, u16 vid) |
| 2555 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2556 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2557 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2558 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2559 | { |
| 2560 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2561 | struct i40e_vsi *vsi = np->vsi; |
| 2562 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2563 | netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid); |
| 2564 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2565 | /* return code is ignored as there is nothing a user |
| 2566 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2567 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2568 | */ |
| 2569 | i40e_vsi_kill_vlan(vsi, vid); |
| 2570 | |
| 2571 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2572 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2573 | return 0; |
| 2574 | } |
| 2575 | |
| 2576 | /** |
| 2577 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2578 | * @vsi: the vsi being brought back up |
| 2579 | **/ |
| 2580 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2581 | { |
| 2582 | u16 vid; |
| 2583 | |
| 2584 | if (!vsi->netdev) |
| 2585 | return; |
| 2586 | |
| 2587 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2588 | |
| 2589 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2590 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2591 | vid); |
| 2592 | } |
| 2593 | |
| 2594 | /** |
| 2595 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2596 | * @vsi: the vsi being adjusted |
| 2597 | * @vid: the vlan id to set as a PVID |
| 2598 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2599 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2600 | { |
| 2601 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2602 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2603 | |
| 2604 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2605 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2606 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2607 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2608 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2609 | |
| 2610 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2611 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2612 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2613 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2614 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2615 | "add pvid failed, err %s aq_err %s\n", |
| 2616 | i40e_stat_str(&vsi->back->hw, ret), |
| 2617 | i40e_aq_str(&vsi->back->hw, |
| 2618 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2619 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2620 | } |
| 2621 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2622 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | /** |
| 2626 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2627 | * @vsi: the vsi being adjusted |
| 2628 | * |
| 2629 | * Just use the vlan_rx_register() service to put it back to normal |
| 2630 | **/ |
| 2631 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2632 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2633 | i40e_vlan_stripping_disable(vsi); |
| 2634 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2635 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | /** |
| 2639 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2640 | * @vsi: ptr to the VSI |
| 2641 | * |
| 2642 | * If this function returns with an error, then it's possible one or |
| 2643 | * more of the rings is populated (while the rest are not). It is the |
| 2644 | * callers duty to clean those orphaned rings. |
| 2645 | * |
| 2646 | * Return 0 on success, negative on failure |
| 2647 | **/ |
| 2648 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2649 | { |
| 2650 | int i, err = 0; |
| 2651 | |
| 2652 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2653 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2654 | |
| 2655 | return err; |
| 2656 | } |
| 2657 | |
| 2658 | /** |
| 2659 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2660 | * @vsi: ptr to the VSI |
| 2661 | * |
| 2662 | * Free VSI's transmit software resources |
| 2663 | **/ |
| 2664 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2665 | { |
| 2666 | int i; |
| 2667 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2668 | if (!vsi->tx_rings) |
| 2669 | return; |
| 2670 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2671 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2672 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2673 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2674 | } |
| 2675 | |
| 2676 | /** |
| 2677 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2678 | * @vsi: ptr to the VSI |
| 2679 | * |
| 2680 | * If this function returns with an error, then it's possible one or |
| 2681 | * more of the rings is populated (while the rest are not). It is the |
| 2682 | * callers duty to clean those orphaned rings. |
| 2683 | * |
| 2684 | * Return 0 on success, negative on failure |
| 2685 | **/ |
| 2686 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2687 | { |
| 2688 | int i, err = 0; |
| 2689 | |
| 2690 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2691 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2692 | #ifdef I40E_FCOE |
| 2693 | i40e_fcoe_setup_ddp_resources(vsi); |
| 2694 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2695 | return err; |
| 2696 | } |
| 2697 | |
| 2698 | /** |
| 2699 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2700 | * @vsi: ptr to the VSI |
| 2701 | * |
| 2702 | * Free all receive software resources |
| 2703 | **/ |
| 2704 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2705 | { |
| 2706 | int i; |
| 2707 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2708 | if (!vsi->rx_rings) |
| 2709 | return; |
| 2710 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2711 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2712 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2713 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2714 | #ifdef I40E_FCOE |
| 2715 | i40e_fcoe_free_ddp_resources(vsi); |
| 2716 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2720 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2721 | * @ring: The Tx ring to configure |
| 2722 | * |
| 2723 | * This enables/disables XPS for a given Tx descriptor ring |
| 2724 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2725 | **/ |
| 2726 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2727 | { |
| 2728 | struct i40e_vsi *vsi = ring->vsi; |
| 2729 | cpumask_var_t mask; |
| 2730 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2731 | if (!ring->q_vector || !ring->netdev) |
| 2732 | return; |
| 2733 | |
| 2734 | /* Single TC mode enable XPS */ |
| 2735 | if (vsi->tc_config.numtc <= 1) { |
| 2736 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2737 | netif_set_xps_queue(ring->netdev, |
| 2738 | &ring->q_vector->affinity_mask, |
| 2739 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2740 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2741 | /* Disable XPS to allow selection based on TC */ |
| 2742 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2743 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2744 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2745 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2746 | |
| 2747 | /* schedule our worker thread which will take care of |
| 2748 | * applying the new filter changes |
| 2749 | */ |
| 2750 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2754 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2755 | * @ring: The Tx ring to configure |
| 2756 | * |
| 2757 | * Configure the Tx descriptor ring in the HMC context. |
| 2758 | **/ |
| 2759 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2760 | { |
| 2761 | struct i40e_vsi *vsi = ring->vsi; |
| 2762 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2763 | struct i40e_hw *hw = &vsi->back->hw; |
| 2764 | struct i40e_hmc_obj_txq tx_ctx; |
| 2765 | i40e_status err = 0; |
| 2766 | u32 qtx_ctl = 0; |
| 2767 | |
| 2768 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2769 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2770 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2771 | ring->atr_count = 0; |
| 2772 | } else { |
| 2773 | ring->atr_sample_rate = 0; |
| 2774 | } |
| 2775 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2776 | /* configure XPS */ |
| 2777 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2778 | |
| 2779 | /* clear the context structure first */ |
| 2780 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2781 | |
| 2782 | tx_ctx.new_context = 1; |
| 2783 | tx_ctx.base = (ring->dma / 128); |
| 2784 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2785 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2786 | I40E_FLAG_FD_ATR_ENABLED)); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2787 | #ifdef I40E_FCOE |
| 2788 | tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2789 | #endif |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2790 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2791 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2792 | if (vsi->type != I40E_VSI_FDIR) |
| 2793 | tx_ctx.head_wb_ena = 1; |
| 2794 | tx_ctx.head_wb_addr = ring->dma + |
| 2795 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2796 | |
| 2797 | /* As part of VSI creation/update, FW allocates certain |
| 2798 | * Tx arbitration queue sets for each TC enabled for |
| 2799 | * the VSI. The FW returns the handles to these queue |
| 2800 | * sets as part of the response buffer to Add VSI, |
| 2801 | * Update VSI, etc. AQ commands. It is expected that |
| 2802 | * these queue set handles be associated with the Tx |
| 2803 | * queues by the driver as part of the TX queue context |
| 2804 | * initialization. This has to be done regardless of |
| 2805 | * DCB as by default everything is mapped to TC0. |
| 2806 | */ |
| 2807 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2808 | tx_ctx.rdylist_act = 0; |
| 2809 | |
| 2810 | /* clear the context in the HMC */ |
| 2811 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2812 | if (err) { |
| 2813 | dev_info(&vsi->back->pdev->dev, |
| 2814 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2815 | ring->queue_index, pf_q, err); |
| 2816 | return -ENOMEM; |
| 2817 | } |
| 2818 | |
| 2819 | /* set the context in the HMC */ |
| 2820 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2821 | if (err) { |
| 2822 | dev_info(&vsi->back->pdev->dev, |
| 2823 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2824 | ring->queue_index, pf_q, err); |
| 2825 | return -ENOMEM; |
| 2826 | } |
| 2827 | |
| 2828 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2829 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2830 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2831 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2832 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2833 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2834 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2835 | } |
| 2836 | |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2837 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2838 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2839 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2840 | i40e_flush(hw); |
| 2841 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2842 | /* cache tail off for easier writes later */ |
| 2843 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2844 | |
| 2845 | return 0; |
| 2846 | } |
| 2847 | |
| 2848 | /** |
| 2849 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2850 | * @ring: The Rx ring to configure |
| 2851 | * |
| 2852 | * Configure the Rx descriptor ring in the HMC context. |
| 2853 | **/ |
| 2854 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2855 | { |
| 2856 | struct i40e_vsi *vsi = ring->vsi; |
| 2857 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2858 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2859 | struct i40e_hw *hw = &vsi->back->hw; |
| 2860 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2861 | i40e_status err = 0; |
| 2862 | |
| 2863 | ring->state = 0; |
| 2864 | |
| 2865 | /* clear the context structure first */ |
| 2866 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2867 | |
| 2868 | ring->rx_buf_len = vsi->rx_buf_len; |
| 2869 | ring->rx_hdr_len = vsi->rx_hdr_len; |
| 2870 | |
| 2871 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
| 2872 | rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT; |
| 2873 | |
| 2874 | rx_ctx.base = (ring->dma / 128); |
| 2875 | rx_ctx.qlen = ring->count; |
| 2876 | |
| 2877 | if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) { |
| 2878 | set_ring_16byte_desc_enabled(ring); |
| 2879 | rx_ctx.dsize = 0; |
| 2880 | } else { |
| 2881 | rx_ctx.dsize = 1; |
| 2882 | } |
| 2883 | |
| 2884 | rx_ctx.dtype = vsi->dtype; |
| 2885 | if (vsi->dtype) { |
| 2886 | set_ring_ps_enabled(ring); |
| 2887 | rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 | |
| 2888 | I40E_RX_SPLIT_IP | |
| 2889 | I40E_RX_SPLIT_TCP_UDP | |
| 2890 | I40E_RX_SPLIT_SCTP; |
| 2891 | } else { |
| 2892 | rx_ctx.hsplit_0 = 0; |
| 2893 | } |
| 2894 | |
| 2895 | rx_ctx.rxmax = min_t(u16, vsi->max_frame, |
| 2896 | (chain_len * ring->rx_buf_len)); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 2897 | if (hw->revision_id == 0) |
| 2898 | rx_ctx.lrxqthresh = 0; |
| 2899 | else |
| 2900 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2901 | rx_ctx.crcstrip = 1; |
| 2902 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 2903 | /* this controls whether VLAN is stripped from inner headers */ |
| 2904 | rx_ctx.showiv = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2905 | #ifdef I40E_FCOE |
| 2906 | rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2907 | #endif |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 2908 | /* set the prefena field to 1 because the manual says to */ |
| 2909 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2910 | |
| 2911 | /* clear the context in the HMC */ |
| 2912 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 2913 | if (err) { |
| 2914 | dev_info(&vsi->back->pdev->dev, |
| 2915 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2916 | ring->queue_index, pf_q, err); |
| 2917 | return -ENOMEM; |
| 2918 | } |
| 2919 | |
| 2920 | /* set the context in the HMC */ |
| 2921 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 2922 | if (err) { |
| 2923 | dev_info(&vsi->back->pdev->dev, |
| 2924 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2925 | ring->queue_index, pf_q, err); |
| 2926 | return -ENOMEM; |
| 2927 | } |
| 2928 | |
| 2929 | /* cache tail for quicker writes, and clear the reg before use */ |
| 2930 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 2931 | writel(0, ring->tail); |
| 2932 | |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 2933 | if (ring_is_ps_enabled(ring)) { |
| 2934 | i40e_alloc_rx_headers(ring); |
| 2935 | i40e_alloc_rx_buffers_ps(ring, I40E_DESC_UNUSED(ring)); |
| 2936 | } else { |
| 2937 | i40e_alloc_rx_buffers_1buf(ring, I40E_DESC_UNUSED(ring)); |
| 2938 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2939 | |
| 2940 | return 0; |
| 2941 | } |
| 2942 | |
| 2943 | /** |
| 2944 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 2945 | * @vsi: VSI structure describing this set of rings and resources |
| 2946 | * |
| 2947 | * Configure the Tx VSI for operation. |
| 2948 | **/ |
| 2949 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 2950 | { |
| 2951 | int err = 0; |
| 2952 | u16 i; |
| 2953 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2954 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 2955 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2956 | |
| 2957 | return err; |
| 2958 | } |
| 2959 | |
| 2960 | /** |
| 2961 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 2962 | * @vsi: the VSI being configured |
| 2963 | * |
| 2964 | * Configure the Rx VSI for operation. |
| 2965 | **/ |
| 2966 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 2967 | { |
| 2968 | int err = 0; |
| 2969 | u16 i; |
| 2970 | |
| 2971 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 2972 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 2973 | + ETH_FCS_LEN + VLAN_HLEN; |
| 2974 | else |
| 2975 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 2976 | |
| 2977 | /* figure out correct receive buffer length */ |
| 2978 | switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED | |
| 2979 | I40E_FLAG_RX_PS_ENABLED)) { |
| 2980 | case I40E_FLAG_RX_1BUF_ENABLED: |
| 2981 | vsi->rx_hdr_len = 0; |
| 2982 | vsi->rx_buf_len = vsi->max_frame; |
| 2983 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 2984 | break; |
| 2985 | case I40E_FLAG_RX_PS_ENABLED: |
| 2986 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2987 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2988 | vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT; |
| 2989 | break; |
| 2990 | default: |
| 2991 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2992 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2993 | vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS; |
| 2994 | break; |
| 2995 | } |
| 2996 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2997 | #ifdef I40E_FCOE |
| 2998 | /* setup rx buffer for FCoE */ |
| 2999 | if ((vsi->type == I40E_VSI_FCOE) && |
| 3000 | (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) { |
| 3001 | vsi->rx_hdr_len = 0; |
| 3002 | vsi->rx_buf_len = I40E_RXBUFFER_3072; |
| 3003 | vsi->max_frame = I40E_RXBUFFER_3072; |
| 3004 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 3005 | } |
| 3006 | |
| 3007 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3008 | /* round up for the chip's needs */ |
| 3009 | vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3010 | BIT_ULL(I40E_RXQ_CTX_HBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3011 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3012 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3013 | |
| 3014 | /* set up individual rings */ |
| 3015 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3016 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3017 | |
| 3018 | return err; |
| 3019 | } |
| 3020 | |
| 3021 | /** |
| 3022 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3023 | * @vsi: ptr to the VSI |
| 3024 | **/ |
| 3025 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3026 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3027 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3028 | u16 qoffset, qcount; |
| 3029 | int i, n; |
| 3030 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3031 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3032 | /* Reset the TC information */ |
| 3033 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3034 | rx_ring = vsi->rx_rings[i]; |
| 3035 | tx_ring = vsi->tx_rings[i]; |
| 3036 | rx_ring->dcb_tc = 0; |
| 3037 | tx_ring->dcb_tc = 0; |
| 3038 | } |
| 3039 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3040 | |
| 3041 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3042 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3043 | continue; |
| 3044 | |
| 3045 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3046 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3047 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3048 | rx_ring = vsi->rx_rings[i]; |
| 3049 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3050 | rx_ring->dcb_tc = n; |
| 3051 | tx_ring->dcb_tc = n; |
| 3052 | } |
| 3053 | } |
| 3054 | } |
| 3055 | |
| 3056 | /** |
| 3057 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3058 | * @vsi: ptr to the VSI |
| 3059 | **/ |
| 3060 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3061 | { |
| 3062 | if (vsi->netdev) |
| 3063 | i40e_set_rx_mode(vsi->netdev); |
| 3064 | } |
| 3065 | |
| 3066 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3067 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3068 | * @vsi: Pointer to the targeted VSI |
| 3069 | * |
| 3070 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3071 | * filters were saved. |
| 3072 | **/ |
| 3073 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3074 | { |
| 3075 | struct i40e_fdir_filter *filter; |
| 3076 | struct i40e_pf *pf = vsi->back; |
| 3077 | struct hlist_node *node; |
| 3078 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3079 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3080 | return; |
| 3081 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3082 | hlist_for_each_entry_safe(filter, node, |
| 3083 | &pf->fdir_filter_list, fdir_node) { |
| 3084 | i40e_add_del_fdir(vsi, filter, true); |
| 3085 | } |
| 3086 | } |
| 3087 | |
| 3088 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3089 | * i40e_vsi_configure - Set up the VSI for action |
| 3090 | * @vsi: the VSI being configured |
| 3091 | **/ |
| 3092 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3093 | { |
| 3094 | int err; |
| 3095 | |
| 3096 | i40e_set_vsi_rx_mode(vsi); |
| 3097 | i40e_restore_vlan(vsi); |
| 3098 | i40e_vsi_config_dcb_rings(vsi); |
| 3099 | err = i40e_vsi_configure_tx(vsi); |
| 3100 | if (!err) |
| 3101 | err = i40e_vsi_configure_rx(vsi); |
| 3102 | |
| 3103 | return err; |
| 3104 | } |
| 3105 | |
| 3106 | /** |
| 3107 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3108 | * @vsi: the VSI being configured |
| 3109 | **/ |
| 3110 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3111 | { |
| 3112 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3113 | struct i40e_hw *hw = &pf->hw; |
| 3114 | u16 vector; |
| 3115 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3116 | u32 qp; |
| 3117 | |
| 3118 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3119 | * and PFINT_LNKLSTn registers, e.g.: |
| 3120 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3121 | */ |
| 3122 | qp = vsi->base_queue; |
| 3123 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3124 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3125 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3126 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3127 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3128 | 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] | 3129 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3130 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3131 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3132 | 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] | 3133 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3134 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3135 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3136 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
| 3137 | INTRL_USEC_TO_REG(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3138 | |
| 3139 | /* Linked list for the queuepairs assigned to this vector */ |
| 3140 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3141 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3142 | u32 val; |
| 3143 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3144 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3145 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3146 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3147 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 3148 | (I40E_QUEUE_TYPE_TX |
| 3149 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 3150 | |
| 3151 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3152 | |
| 3153 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3154 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3155 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3156 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 3157 | (I40E_QUEUE_TYPE_RX |
| 3158 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3159 | |
| 3160 | /* Terminate the linked list */ |
| 3161 | if (q == (q_vector->num_ringpairs - 1)) |
| 3162 | val |= (I40E_QUEUE_END_OF_LIST |
| 3163 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3164 | |
| 3165 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3166 | qp++; |
| 3167 | } |
| 3168 | } |
| 3169 | |
| 3170 | i40e_flush(hw); |
| 3171 | } |
| 3172 | |
| 3173 | /** |
| 3174 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3175 | * @hw: ptr to the hardware info |
| 3176 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3177 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3178 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3179 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3180 | u32 val; |
| 3181 | |
| 3182 | /* clear things first */ |
| 3183 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3184 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3185 | |
| 3186 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3187 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3188 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3189 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3190 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3191 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3192 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3193 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3194 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3195 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3196 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3197 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3198 | if (pf->flags & I40E_FLAG_PTP) |
| 3199 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3200 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3201 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3202 | |
| 3203 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3204 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3205 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3206 | |
| 3207 | /* OTHER_ITR_IDX = 0 */ |
| 3208 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3209 | } |
| 3210 | |
| 3211 | /** |
| 3212 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3213 | * @vsi: the VSI being configured |
| 3214 | **/ |
| 3215 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3216 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3217 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3218 | struct i40e_pf *pf = vsi->back; |
| 3219 | struct i40e_hw *hw = &pf->hw; |
| 3220 | u32 val; |
| 3221 | |
| 3222 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3223 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3224 | 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] | 3225 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3226 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3227 | 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] | 3228 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3229 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3230 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3231 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3232 | |
| 3233 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3234 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3235 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3236 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3237 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3238 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3239 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3240 | |
| 3241 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3242 | |
| 3243 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3244 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3245 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3246 | |
| 3247 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3248 | i40e_flush(hw); |
| 3249 | } |
| 3250 | |
| 3251 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3252 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3253 | * @pf: board private structure |
| 3254 | **/ |
| 3255 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3256 | { |
| 3257 | struct i40e_hw *hw = &pf->hw; |
| 3258 | |
| 3259 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3260 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3261 | i40e_flush(hw); |
| 3262 | } |
| 3263 | |
| 3264 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3265 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3266 | * @pf: board private structure |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3267 | * @clearpba: true when all pending interrupt events should be cleared |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3268 | **/ |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3269 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3270 | { |
| 3271 | struct i40e_hw *hw = &pf->hw; |
| 3272 | u32 val; |
| 3273 | |
| 3274 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3275 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3276 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3277 | |
| 3278 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3279 | i40e_flush(hw); |
| 3280 | } |
| 3281 | |
| 3282 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3283 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3284 | * @irq: interrupt number |
| 3285 | * @data: pointer to a q_vector |
| 3286 | **/ |
| 3287 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3288 | { |
| 3289 | struct i40e_q_vector *q_vector = data; |
| 3290 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3291 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3292 | return IRQ_HANDLED; |
| 3293 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3294 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3295 | |
| 3296 | return IRQ_HANDLED; |
| 3297 | } |
| 3298 | |
| 3299 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3300 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3301 | * @vsi: the VSI being configured |
| 3302 | * @basename: name for the vector |
| 3303 | * |
| 3304 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3305 | **/ |
| 3306 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3307 | { |
| 3308 | int q_vectors = vsi->num_q_vectors; |
| 3309 | struct i40e_pf *pf = vsi->back; |
| 3310 | int base = vsi->base_vector; |
| 3311 | int rx_int_idx = 0; |
| 3312 | int tx_int_idx = 0; |
| 3313 | int vector, err; |
| 3314 | |
| 3315 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3316 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3317 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3318 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3319 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3320 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3321 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3322 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3323 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3324 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3325 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3326 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3327 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3328 | } else { |
| 3329 | /* skip this unused q_vector */ |
| 3330 | continue; |
| 3331 | } |
| 3332 | err = request_irq(pf->msix_entries[base + vector].vector, |
| 3333 | vsi->irq_handler, |
| 3334 | 0, |
| 3335 | q_vector->name, |
| 3336 | q_vector); |
| 3337 | if (err) { |
| 3338 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3339 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3340 | goto free_queue_irqs; |
| 3341 | } |
| 3342 | /* assign the mask for this irq */ |
| 3343 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3344 | &q_vector->affinity_mask); |
| 3345 | } |
| 3346 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3347 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3348 | return 0; |
| 3349 | |
| 3350 | free_queue_irqs: |
| 3351 | while (vector) { |
| 3352 | vector--; |
| 3353 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3354 | NULL); |
| 3355 | free_irq(pf->msix_entries[base + vector].vector, |
| 3356 | &(vsi->q_vectors[vector])); |
| 3357 | } |
| 3358 | return err; |
| 3359 | } |
| 3360 | |
| 3361 | /** |
| 3362 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3363 | * @vsi: the VSI being un-configured |
| 3364 | **/ |
| 3365 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3366 | { |
| 3367 | struct i40e_pf *pf = vsi->back; |
| 3368 | struct i40e_hw *hw = &pf->hw; |
| 3369 | int base = vsi->base_vector; |
| 3370 | int i; |
| 3371 | |
| 3372 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3373 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3374 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3378 | for (i = vsi->base_vector; |
| 3379 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3380 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3381 | |
| 3382 | i40e_flush(hw); |
| 3383 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3384 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3385 | } else { |
| 3386 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3387 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3388 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3389 | i40e_flush(hw); |
| 3390 | synchronize_irq(pf->pdev->irq); |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | /** |
| 3395 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3396 | * @vsi: the VSI being configured |
| 3397 | **/ |
| 3398 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3399 | { |
| 3400 | struct i40e_pf *pf = vsi->back; |
| 3401 | int i; |
| 3402 | |
| 3403 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3404 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3405 | i40e_irq_dynamic_enable(vsi, i); |
| 3406 | } else { |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3407 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3408 | } |
| 3409 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3410 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3411 | return 0; |
| 3412 | } |
| 3413 | |
| 3414 | /** |
| 3415 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3416 | * @pf: board private structure |
| 3417 | **/ |
| 3418 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3419 | { |
| 3420 | /* Disable ICR 0 */ |
| 3421 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3422 | i40e_flush(&pf->hw); |
| 3423 | } |
| 3424 | |
| 3425 | /** |
| 3426 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3427 | * @irq: interrupt number |
| 3428 | * @data: pointer to a q_vector |
| 3429 | * |
| 3430 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3431 | * with both queue and non-queue interrupts. This is also used in |
| 3432 | * MSIX mode to handle the non-queue interrupts. |
| 3433 | **/ |
| 3434 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3435 | { |
| 3436 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3437 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3438 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3439 | u32 icr0, icr0_remaining; |
| 3440 | u32 val, ena_mask; |
| 3441 | |
| 3442 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3443 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3444 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3445 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3446 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3447 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3448 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3449 | /* if interrupt but no bits showing, must be SWINT */ |
| 3450 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3451 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3452 | pf->sw_int_count++; |
| 3453 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3454 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 3455 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
| 3456 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3457 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3458 | dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
| 3459 | } |
| 3460 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3461 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3462 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3463 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3464 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3465 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3466 | /* We do not have a way to disarm Queue causes while leaving |
| 3467 | * interrupt enabled for all other causes, ideally |
| 3468 | * interrupt should be disabled while we are in NAPI but |
| 3469 | * this is not a performance path and napi_schedule() |
| 3470 | * can deal with rescheduling. |
| 3471 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3472 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3473 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3477 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3478 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3479 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3480 | } |
| 3481 | |
| 3482 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3483 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3484 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3485 | } |
| 3486 | |
| 3487 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3488 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3489 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3490 | } |
| 3491 | |
| 3492 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3493 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3494 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3495 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3496 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3497 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3498 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3499 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3500 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3501 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3502 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3503 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3504 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3505 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3506 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3507 | } |
| 3508 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3509 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3510 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3511 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3512 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3513 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3514 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3515 | } |
| 3516 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3517 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3518 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3519 | |
| 3520 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3521 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3522 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3523 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3524 | } |
| 3525 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3526 | /* If a critical error is pending we have no choice but to reset the |
| 3527 | * device. |
| 3528 | * Report and mask out any remaining unexpected interrupts. |
| 3529 | */ |
| 3530 | icr0_remaining = icr0 & ena_mask; |
| 3531 | if (icr0_remaining) { |
| 3532 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3533 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3534 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3535 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3536 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3537 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3538 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3539 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3540 | } |
| 3541 | ena_mask &= ~icr0_remaining; |
| 3542 | } |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3543 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3544 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3545 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3546 | /* re-enable interrupt causes */ |
| 3547 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3548 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3549 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3550 | i40e_irq_dynamic_enable_icr0(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3551 | } |
| 3552 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3553 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3557 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3558 | * @tx_ring: tx ring to clean |
| 3559 | * @budget: how many cleans we're allowed |
| 3560 | * |
| 3561 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3562 | **/ |
| 3563 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3564 | { |
| 3565 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3566 | u16 i = tx_ring->next_to_clean; |
| 3567 | struct i40e_tx_buffer *tx_buf; |
| 3568 | struct i40e_tx_desc *tx_desc; |
| 3569 | |
| 3570 | tx_buf = &tx_ring->tx_bi[i]; |
| 3571 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3572 | i -= tx_ring->count; |
| 3573 | |
| 3574 | do { |
| 3575 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3576 | |
| 3577 | /* if next_to_watch is not set then there is no work pending */ |
| 3578 | if (!eop_desc) |
| 3579 | break; |
| 3580 | |
| 3581 | /* prevent any other reads prior to eop_desc */ |
| 3582 | read_barrier_depends(); |
| 3583 | |
| 3584 | /* if the descriptor isn't done, no work yet to do */ |
| 3585 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3586 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3587 | break; |
| 3588 | |
| 3589 | /* clear next_to_watch to prevent false hangs */ |
| 3590 | tx_buf->next_to_watch = NULL; |
| 3591 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3592 | tx_desc->buffer_addr = 0; |
| 3593 | tx_desc->cmd_type_offset_bsz = 0; |
| 3594 | /* move past filter desc */ |
| 3595 | tx_buf++; |
| 3596 | tx_desc++; |
| 3597 | i++; |
| 3598 | if (unlikely(!i)) { |
| 3599 | i -= tx_ring->count; |
| 3600 | tx_buf = tx_ring->tx_bi; |
| 3601 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3602 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3603 | /* unmap skb header data */ |
| 3604 | dma_unmap_single(tx_ring->dev, |
| 3605 | dma_unmap_addr(tx_buf, dma), |
| 3606 | dma_unmap_len(tx_buf, len), |
| 3607 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3608 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3609 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3610 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3611 | tx_buf->raw_buf = NULL; |
| 3612 | tx_buf->tx_flags = 0; |
| 3613 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3614 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3615 | tx_desc->buffer_addr = 0; |
| 3616 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3617 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3618 | /* 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] | 3619 | tx_buf++; |
| 3620 | tx_desc++; |
| 3621 | i++; |
| 3622 | if (unlikely(!i)) { |
| 3623 | i -= tx_ring->count; |
| 3624 | tx_buf = tx_ring->tx_bi; |
| 3625 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3626 | } |
| 3627 | |
| 3628 | /* update budget accounting */ |
| 3629 | budget--; |
| 3630 | } while (likely(budget)); |
| 3631 | |
| 3632 | i += tx_ring->count; |
| 3633 | tx_ring->next_to_clean = i; |
| 3634 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3635 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3636 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3637 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3638 | return budget > 0; |
| 3639 | } |
| 3640 | |
| 3641 | /** |
| 3642 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3643 | * @irq: interrupt number |
| 3644 | * @data: pointer to a q_vector |
| 3645 | **/ |
| 3646 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3647 | { |
| 3648 | struct i40e_q_vector *q_vector = data; |
| 3649 | struct i40e_vsi *vsi; |
| 3650 | |
| 3651 | if (!q_vector->tx.ring) |
| 3652 | return IRQ_HANDLED; |
| 3653 | |
| 3654 | vsi = q_vector->tx.ring->vsi; |
| 3655 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3656 | |
| 3657 | return IRQ_HANDLED; |
| 3658 | } |
| 3659 | |
| 3660 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3661 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3662 | * @vsi: the VSI being configured |
| 3663 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3664 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3665 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3666 | 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] | 3667 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3668 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3669 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3670 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3671 | |
| 3672 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3673 | tx_ring->next = q_vector->tx.ring; |
| 3674 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3675 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3676 | |
| 3677 | rx_ring->q_vector = q_vector; |
| 3678 | rx_ring->next = q_vector->rx.ring; |
| 3679 | q_vector->rx.ring = rx_ring; |
| 3680 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3681 | } |
| 3682 | |
| 3683 | /** |
| 3684 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3685 | * @vsi: the VSI being configured |
| 3686 | * |
| 3687 | * This function maps descriptor rings to the queue-specific vectors |
| 3688 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3689 | * one vector per queue pair, but on a constrained vector budget, we |
| 3690 | * group the queue pairs as "efficiently" as possible. |
| 3691 | **/ |
| 3692 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3693 | { |
| 3694 | int qp_remaining = vsi->num_queue_pairs; |
| 3695 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3696 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3697 | int v_start = 0; |
| 3698 | int qp_idx = 0; |
| 3699 | |
| 3700 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3701 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3702 | * It is also important to go through all the vectors available to be |
| 3703 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3704 | * are cleared. This is especially important when decreasing the |
| 3705 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3706 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3707 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3708 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3709 | |
| 3710 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3711 | |
| 3712 | q_vector->num_ringpairs = num_ringpairs; |
| 3713 | |
| 3714 | q_vector->rx.count = 0; |
| 3715 | q_vector->tx.count = 0; |
| 3716 | q_vector->rx.ring = NULL; |
| 3717 | q_vector->tx.ring = NULL; |
| 3718 | |
| 3719 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3720 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3721 | qp_idx++; |
| 3722 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3723 | } |
| 3724 | } |
| 3725 | } |
| 3726 | |
| 3727 | /** |
| 3728 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3729 | * @vsi: the VSI being configured |
| 3730 | * @basename: name for the vector |
| 3731 | **/ |
| 3732 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3733 | { |
| 3734 | struct i40e_pf *pf = vsi->back; |
| 3735 | int err; |
| 3736 | |
| 3737 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3738 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3739 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3740 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3741 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3742 | else |
| 3743 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3744 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3745 | |
| 3746 | if (err) |
| 3747 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3748 | |
| 3749 | return err; |
| 3750 | } |
| 3751 | |
| 3752 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3753 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3754 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3755 | * @netdev: network interface device structure |
| 3756 | * |
| 3757 | * This is used by netconsole to send skbs without having to re-enable |
| 3758 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3759 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3760 | #ifdef I40E_FCOE |
| 3761 | void i40e_netpoll(struct net_device *netdev) |
| 3762 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3763 | static void i40e_netpoll(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3764 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3765 | { |
| 3766 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3767 | struct i40e_vsi *vsi = np->vsi; |
| 3768 | struct i40e_pf *pf = vsi->back; |
| 3769 | int i; |
| 3770 | |
| 3771 | /* if interface is down do nothing */ |
| 3772 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3773 | return; |
| 3774 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3775 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3776 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3777 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3778 | } else { |
| 3779 | i40e_intr(pf->pdev->irq, netdev); |
| 3780 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3781 | } |
| 3782 | #endif |
| 3783 | |
| 3784 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3785 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3786 | * @pf: the PF being configured |
| 3787 | * @pf_q: the PF queue |
| 3788 | * @enable: enable or disable state of the queue |
| 3789 | * |
| 3790 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3791 | * enabled or disabled state. |
| 3792 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3793 | * multiple retries; else will return 0 in case of success. |
| 3794 | **/ |
| 3795 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3796 | { |
| 3797 | int i; |
| 3798 | u32 tx_reg; |
| 3799 | |
| 3800 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3801 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3802 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3803 | break; |
| 3804 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3805 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3806 | } |
| 3807 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3808 | return -ETIMEDOUT; |
| 3809 | |
| 3810 | return 0; |
| 3811 | } |
| 3812 | |
| 3813 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3814 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3815 | * @vsi: the VSI being configured |
| 3816 | * @enable: start or stop the rings |
| 3817 | **/ |
| 3818 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3819 | { |
| 3820 | struct i40e_pf *pf = vsi->back; |
| 3821 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3822 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3823 | u32 tx_reg; |
| 3824 | |
| 3825 | pf_q = vsi->base_queue; |
| 3826 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3827 | |
| 3828 | /* warn the TX unit of coming changes */ |
| 3829 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3830 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3831 | usleep_range(10, 20); |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3832 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3833 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3834 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3835 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3836 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3837 | break; |
| 3838 | usleep_range(1000, 2000); |
| 3839 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3840 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3841 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3842 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3843 | |
| 3844 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3845 | if (enable) { |
| 3846 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3847 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3848 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3849 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3850 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3851 | |
| 3852 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 3853 | /* No waiting for the Tx queue to disable */ |
| 3854 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3855 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3856 | |
| 3857 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3858 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 3859 | if (ret) { |
| 3860 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3861 | "VSI seid %d Tx ring %d %sable timeout\n", |
| 3862 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3863 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3864 | } |
| 3865 | } |
| 3866 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3867 | if (hw->revision_id == 0) |
| 3868 | mdelay(50); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3869 | return ret; |
| 3870 | } |
| 3871 | |
| 3872 | /** |
| 3873 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 3874 | * @pf: the PF being configured |
| 3875 | * @pf_q: the PF queue |
| 3876 | * @enable: enable or disable state of the queue |
| 3877 | * |
| 3878 | * This routine will wait for the given Rx queue of the PF to reach the |
| 3879 | * enabled or disabled state. |
| 3880 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3881 | * multiple retries; else will return 0 in case of success. |
| 3882 | **/ |
| 3883 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3884 | { |
| 3885 | int i; |
| 3886 | u32 rx_reg; |
| 3887 | |
| 3888 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3889 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 3890 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3891 | break; |
| 3892 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3893 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3894 | } |
| 3895 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3896 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3897 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3898 | return 0; |
| 3899 | } |
| 3900 | |
| 3901 | /** |
| 3902 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 3903 | * @vsi: the VSI being configured |
| 3904 | * @enable: start or stop the rings |
| 3905 | **/ |
| 3906 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 3907 | { |
| 3908 | struct i40e_pf *pf = vsi->back; |
| 3909 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3910 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3911 | u32 rx_reg; |
| 3912 | |
| 3913 | pf_q = vsi->base_queue; |
| 3914 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3915 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3916 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3917 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3918 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3919 | break; |
| 3920 | usleep_range(1000, 2000); |
| 3921 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3922 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3923 | /* Skip if the queue is already in the requested state */ |
| 3924 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3925 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3926 | |
| 3927 | /* turn on/off the queue */ |
| 3928 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3929 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3930 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3931 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3932 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 3933 | /* No waiting for the Tx queue to disable */ |
| 3934 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3935 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3936 | |
| 3937 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3938 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 3939 | if (ret) { |
| 3940 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3941 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 3942 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3943 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3944 | } |
| 3945 | } |
| 3946 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3947 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | /** |
| 3951 | * i40e_vsi_control_rings - Start or stop a VSI's rings |
| 3952 | * @vsi: the VSI being configured |
| 3953 | * @enable: start or stop the rings |
| 3954 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 3955 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3956 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3957 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3958 | |
| 3959 | /* do rx first for enable and last for disable */ |
| 3960 | if (request) { |
| 3961 | ret = i40e_vsi_control_rx(vsi, request); |
| 3962 | if (ret) |
| 3963 | return ret; |
| 3964 | ret = i40e_vsi_control_tx(vsi, request); |
| 3965 | } else { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3966 | /* Ignore return value, we need to shutdown whatever we can */ |
| 3967 | i40e_vsi_control_tx(vsi, request); |
| 3968 | i40e_vsi_control_rx(vsi, request); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | return ret; |
| 3972 | } |
| 3973 | |
| 3974 | /** |
| 3975 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 3976 | * @vsi: the VSI being configured |
| 3977 | **/ |
| 3978 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 3979 | { |
| 3980 | struct i40e_pf *pf = vsi->back; |
| 3981 | struct i40e_hw *hw = &pf->hw; |
| 3982 | int base = vsi->base_vector; |
| 3983 | u32 val, qp; |
| 3984 | int i; |
| 3985 | |
| 3986 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3987 | if (!vsi->q_vectors) |
| 3988 | return; |
| 3989 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3990 | if (!vsi->irqs_ready) |
| 3991 | return; |
| 3992 | |
| 3993 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3994 | for (i = 0; i < vsi->num_q_vectors; i++) { |
| 3995 | u16 vector = i + base; |
| 3996 | |
| 3997 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 3998 | if (!vsi->q_vectors[i] || |
| 3999 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4000 | continue; |
| 4001 | |
| 4002 | /* clear the affinity_mask in the IRQ descriptor */ |
| 4003 | irq_set_affinity_hint(pf->msix_entries[vector].vector, |
| 4004 | NULL); |
| 4005 | free_irq(pf->msix_entries[vector].vector, |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4006 | vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4007 | |
| 4008 | /* Tear down the interrupt queue link list |
| 4009 | * |
| 4010 | * We know that they come in pairs and always |
| 4011 | * the Rx first, then the Tx. To clear the |
| 4012 | * link list, stick the EOL value into the |
| 4013 | * next_q field of the registers. |
| 4014 | */ |
| 4015 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4016 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4017 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4018 | val |= I40E_QUEUE_END_OF_LIST |
| 4019 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4020 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4021 | |
| 4022 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4023 | u32 next; |
| 4024 | |
| 4025 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4026 | |
| 4027 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4028 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4029 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4030 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4031 | |
| 4032 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4033 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4034 | |
| 4035 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4036 | |
| 4037 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4038 | |
| 4039 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4040 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4041 | |
| 4042 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4043 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4044 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4045 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4046 | |
| 4047 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4048 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4049 | |
| 4050 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4051 | qp = next; |
| 4052 | } |
| 4053 | } |
| 4054 | } else { |
| 4055 | free_irq(pf->pdev->irq, pf); |
| 4056 | |
| 4057 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4058 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4059 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4060 | val |= I40E_QUEUE_END_OF_LIST |
| 4061 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4062 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4063 | |
| 4064 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4065 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4066 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4067 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4068 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4069 | |
| 4070 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4071 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4072 | |
| 4073 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4074 | |
| 4075 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4076 | |
| 4077 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4078 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4079 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4080 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4081 | |
| 4082 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4083 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4084 | |
| 4085 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4086 | } |
| 4087 | } |
| 4088 | |
| 4089 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4090 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4091 | * @vsi: the VSI being configured |
| 4092 | * @v_idx: Index of vector to be freed |
| 4093 | * |
| 4094 | * This function frees the memory allocated to the q_vector. In addition if |
| 4095 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4096 | * to freeing the q_vector. |
| 4097 | **/ |
| 4098 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4099 | { |
| 4100 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4101 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4102 | |
| 4103 | if (!q_vector) |
| 4104 | return; |
| 4105 | |
| 4106 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4107 | i40e_for_each_ring(ring, q_vector->tx) |
| 4108 | ring->q_vector = NULL; |
| 4109 | |
| 4110 | i40e_for_each_ring(ring, q_vector->rx) |
| 4111 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4112 | |
| 4113 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4114 | if (vsi->netdev) |
| 4115 | netif_napi_del(&q_vector->napi); |
| 4116 | |
| 4117 | vsi->q_vectors[v_idx] = NULL; |
| 4118 | |
| 4119 | kfree_rcu(q_vector, rcu); |
| 4120 | } |
| 4121 | |
| 4122 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4123 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4124 | * @vsi: the VSI being un-configured |
| 4125 | * |
| 4126 | * This frees the memory allocated to the q_vectors and |
| 4127 | * deletes references to the NAPI struct. |
| 4128 | **/ |
| 4129 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4130 | { |
| 4131 | int v_idx; |
| 4132 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4133 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4134 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | /** |
| 4138 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4139 | * @pf: board private structure |
| 4140 | **/ |
| 4141 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4142 | { |
| 4143 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4144 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4145 | pci_disable_msix(pf->pdev); |
| 4146 | kfree(pf->msix_entries); |
| 4147 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4148 | kfree(pf->irq_pile); |
| 4149 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4150 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4151 | pci_disable_msi(pf->pdev); |
| 4152 | } |
| 4153 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4154 | } |
| 4155 | |
| 4156 | /** |
| 4157 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4158 | * @pf: board private structure |
| 4159 | * |
| 4160 | * We go through and clear interrupt specific resources and reset the structure |
| 4161 | * to pre-load conditions |
| 4162 | **/ |
| 4163 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4164 | { |
| 4165 | int i; |
| 4166 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4167 | i40e_stop_misc_vector(pf); |
Shannon Nelson | 6927839 | 2016-03-10 14:59:43 -0800 | [diff] [blame] | 4168 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4169 | synchronize_irq(pf->msix_entries[0].vector); |
| 4170 | free_irq(pf->msix_entries[0].vector, pf); |
| 4171 | } |
| 4172 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4173 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4174 | I40E_IWARP_IRQ_PILE_ID); |
| 4175 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4176 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4177 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4178 | if (pf->vsi[i]) |
| 4179 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4180 | i40e_reset_interrupt_capability(pf); |
| 4181 | } |
| 4182 | |
| 4183 | /** |
| 4184 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4185 | * @vsi: the VSI being configured |
| 4186 | **/ |
| 4187 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4188 | { |
| 4189 | int q_idx; |
| 4190 | |
| 4191 | if (!vsi->netdev) |
| 4192 | return; |
| 4193 | |
| 4194 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4195 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4196 | } |
| 4197 | |
| 4198 | /** |
| 4199 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4200 | * @vsi: the VSI being configured |
| 4201 | **/ |
| 4202 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4203 | { |
| 4204 | int q_idx; |
| 4205 | |
| 4206 | if (!vsi->netdev) |
| 4207 | return; |
| 4208 | |
| 4209 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4210 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4211 | } |
| 4212 | |
| 4213 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4214 | * i40e_vsi_close - Shut down a VSI |
| 4215 | * @vsi: the vsi to be quelled |
| 4216 | **/ |
| 4217 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4218 | { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4219 | bool reset = false; |
| 4220 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4221 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4222 | i40e_down(vsi); |
| 4223 | i40e_vsi_free_irq(vsi); |
| 4224 | i40e_vsi_free_tx_resources(vsi); |
| 4225 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4226 | vsi->current_netdev_flags = 0; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4227 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4228 | reset = true; |
| 4229 | i40e_notify_client_of_netdev_close(vsi, reset); |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4233 | * i40e_quiesce_vsi - Pause a given VSI |
| 4234 | * @vsi: the VSI being paused |
| 4235 | **/ |
| 4236 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4237 | { |
| 4238 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4239 | return; |
| 4240 | |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4241 | /* No need to disable FCoE VSI when Tx suspended */ |
| 4242 | if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) && |
| 4243 | vsi->type == I40E_VSI_FCOE) { |
| 4244 | dev_dbg(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4245 | "VSI seid %d skipping FCoE VSI disable\n", vsi->seid); |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4246 | return; |
| 4247 | } |
| 4248 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4249 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4250 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4251 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4252 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4253 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | /** |
| 4257 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4258 | * @vsi: the VSI being resumed |
| 4259 | **/ |
| 4260 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4261 | { |
| 4262 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 4263 | return; |
| 4264 | |
| 4265 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4266 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4267 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4268 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4269 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | /** |
| 4273 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4274 | * @pf: the PF |
| 4275 | **/ |
| 4276 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4277 | { |
| 4278 | int v; |
| 4279 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4280 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4281 | if (pf->vsi[v]) |
| 4282 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4283 | } |
| 4284 | } |
| 4285 | |
| 4286 | /** |
| 4287 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4288 | * @pf: the PF |
| 4289 | **/ |
| 4290 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4291 | { |
| 4292 | int v; |
| 4293 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4294 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4295 | if (pf->vsi[v]) |
| 4296 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4297 | } |
| 4298 | } |
| 4299 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4300 | #ifdef CONFIG_I40E_DCB |
| 4301 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4302 | * 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] | 4303 | * @vsi: the VSI being configured |
| 4304 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4305 | * This function waits for the given VSI's queues to be disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4306 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4307 | static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4308 | { |
| 4309 | struct i40e_pf *pf = vsi->back; |
| 4310 | int i, pf_q, ret; |
| 4311 | |
| 4312 | pf_q = vsi->base_queue; |
| 4313 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4314 | /* Check and wait for the disable status of the queue */ |
| 4315 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4316 | if (ret) { |
| 4317 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4318 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4319 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4320 | return ret; |
| 4321 | } |
| 4322 | } |
| 4323 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4324 | pf_q = vsi->base_queue; |
| 4325 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4326 | /* Check and wait for the disable status of the queue */ |
| 4327 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4328 | if (ret) { |
| 4329 | dev_info(&pf->pdev->dev, |
| 4330 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4331 | vsi->seid, pf_q); |
| 4332 | return ret; |
| 4333 | } |
| 4334 | } |
| 4335 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4336 | return 0; |
| 4337 | } |
| 4338 | |
| 4339 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4340 | * 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] | 4341 | * @pf: the PF |
| 4342 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4343 | * 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] | 4344 | * VSIs that are managed by this PF. |
| 4345 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4346 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4347 | { |
| 4348 | int v, ret = 0; |
| 4349 | |
| 4350 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4351 | /* No need to wait for FCoE VSI queues */ |
| 4352 | if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4353 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4354 | if (ret) |
| 4355 | break; |
| 4356 | } |
| 4357 | } |
| 4358 | |
| 4359 | return ret; |
| 4360 | } |
| 4361 | |
| 4362 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4363 | |
| 4364 | /** |
| 4365 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4366 | * @q_idx: TX queue number |
| 4367 | * @vsi: Pointer to VSI struct |
| 4368 | * |
| 4369 | * This function checks specified queue for given VSI. Detects hung condition. |
| 4370 | * Sets hung bit since it is two step process. Before next run of service task |
| 4371 | * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not, |
| 4372 | * hung condition remain unchanged and during subsequent run, this function |
| 4373 | * issues SW interrupt to recover from hung condition. |
| 4374 | **/ |
| 4375 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4376 | { |
| 4377 | struct i40e_ring *tx_ring = NULL; |
| 4378 | struct i40e_pf *pf; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4379 | u32 head, val, tx_pending_hw; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4380 | int i; |
| 4381 | |
| 4382 | pf = vsi->back; |
| 4383 | |
| 4384 | /* now that we have an index, find the tx_ring struct */ |
| 4385 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4386 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4387 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4388 | tx_ring = vsi->tx_rings[i]; |
| 4389 | break; |
| 4390 | } |
| 4391 | } |
| 4392 | } |
| 4393 | |
| 4394 | if (!tx_ring) |
| 4395 | return; |
| 4396 | |
| 4397 | /* Read interrupt register */ |
| 4398 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4399 | val = rd32(&pf->hw, |
| 4400 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4401 | tx_ring->vsi->base_vector - 1)); |
| 4402 | else |
| 4403 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4404 | |
| 4405 | head = i40e_get_head(tx_ring); |
| 4406 | |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4407 | tx_pending_hw = i40e_get_tx_pending(tx_ring, false); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4408 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4409 | /* HW is done executing descriptors, updated HEAD write back, |
| 4410 | * but SW hasn't processed those descriptors. If interrupt is |
| 4411 | * not generated from this point ON, it could result into |
| 4412 | * dev_watchdog detecting timeout on those netdev_queue, |
| 4413 | * hence proactively trigger SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4414 | */ |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4415 | if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4416 | /* NAPI Poll didn't run and clear since it was set */ |
| 4417 | if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4418 | &tx_ring->q_vector->hung_detected)) { |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4419 | 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", |
| 4420 | vsi->seid, q_idx, tx_pending_hw, |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4421 | tx_ring->next_to_clean, head, |
| 4422 | tx_ring->next_to_use, |
| 4423 | readl(tx_ring->tail)); |
| 4424 | netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n", |
| 4425 | vsi->seid, q_idx, val); |
| 4426 | i40e_force_wb(vsi, tx_ring->q_vector); |
| 4427 | } else { |
| 4428 | /* First Chance - detected possible hung */ |
| 4429 | set_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4430 | &tx_ring->q_vector->hung_detected); |
| 4431 | } |
| 4432 | } |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4433 | |
| 4434 | /* This is the case where we have interrupts missing, |
| 4435 | * so the tx_pending in HW will most likely be 0, but we |
| 4436 | * will have tx_pending in SW since the WB happened but the |
| 4437 | * interrupt got lost. |
| 4438 | */ |
| 4439 | if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) && |
| 4440 | (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
| 4441 | if (napi_reschedule(&tx_ring->q_vector->napi)) |
| 4442 | tx_ring->tx_stats.tx_lost_interrupt++; |
| 4443 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | /** |
| 4447 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4448 | * @pf: pointer to PF struct |
| 4449 | * |
| 4450 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4451 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4452 | * SW interrupt. |
| 4453 | **/ |
| 4454 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4455 | { |
| 4456 | struct net_device *netdev; |
| 4457 | struct i40e_vsi *vsi; |
| 4458 | int i; |
| 4459 | |
| 4460 | /* Only for LAN VSI */ |
| 4461 | vsi = pf->vsi[pf->lan_vsi]; |
| 4462 | |
| 4463 | if (!vsi) |
| 4464 | return; |
| 4465 | |
| 4466 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
| 4467 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 4468 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4469 | return; |
| 4470 | |
| 4471 | /* Make sure type is MAIN VSI */ |
| 4472 | if (vsi->type != I40E_VSI_MAIN) |
| 4473 | return; |
| 4474 | |
| 4475 | netdev = vsi->netdev; |
| 4476 | if (!netdev) |
| 4477 | return; |
| 4478 | |
| 4479 | /* Bail out if netif_carrier is not OK */ |
| 4480 | if (!netif_carrier_ok(netdev)) |
| 4481 | return; |
| 4482 | |
| 4483 | /* Go thru' TX queues for netdev */ |
| 4484 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4485 | struct netdev_queue *q; |
| 4486 | |
| 4487 | q = netdev_get_tx_queue(netdev, i); |
| 4488 | if (q) |
| 4489 | i40e_detect_recover_hung_queue(i, vsi); |
| 4490 | } |
| 4491 | } |
| 4492 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4493 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4494 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4495 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4496 | * |
| 4497 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4498 | * and LAN TC. |
| 4499 | **/ |
| 4500 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4501 | { |
| 4502 | struct i40e_dcb_app_priority_table app; |
| 4503 | struct i40e_hw *hw = &pf->hw; |
| 4504 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4505 | u8 tc, i; |
| 4506 | /* Get the iSCSI APP TLV */ |
| 4507 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4508 | |
| 4509 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4510 | app = dcbcfg->app[i]; |
| 4511 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4512 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4513 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4514 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4515 | break; |
| 4516 | } |
| 4517 | } |
| 4518 | |
| 4519 | return enabled_tc; |
| 4520 | } |
| 4521 | |
| 4522 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4523 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4524 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4525 | * |
| 4526 | * Return the number of TCs from given DCBx configuration |
| 4527 | **/ |
| 4528 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4529 | { |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4530 | u8 num_tc = 0; |
| 4531 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4532 | |
| 4533 | /* Scan the ETS Config Priority Table to find |
| 4534 | * traffic class enabled for a given priority |
| 4535 | * and use the traffic class index to get the |
| 4536 | * number of traffic classes enabled |
| 4537 | */ |
| 4538 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4539 | if (dcbcfg->etscfg.prioritytable[i] > num_tc) |
| 4540 | num_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4541 | } |
| 4542 | |
| 4543 | /* Traffic class index starts from zero so |
| 4544 | * increment to return the actual count |
| 4545 | */ |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4546 | return num_tc + 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4547 | } |
| 4548 | |
| 4549 | /** |
| 4550 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4551 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4552 | * |
| 4553 | * Query the current DCB configuration and return the number of |
| 4554 | * traffic classes enabled from the given DCBX config |
| 4555 | **/ |
| 4556 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4557 | { |
| 4558 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4559 | u8 enabled_tc = 1; |
| 4560 | u8 i; |
| 4561 | |
| 4562 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4563 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4564 | |
| 4565 | return enabled_tc; |
| 4566 | } |
| 4567 | |
| 4568 | /** |
| 4569 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4570 | * @pf: PF being queried |
| 4571 | * |
| 4572 | * Return number of traffic classes enabled for the given PF |
| 4573 | **/ |
| 4574 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4575 | { |
| 4576 | struct i40e_hw *hw = &pf->hw; |
| 4577 | u8 i, enabled_tc; |
| 4578 | u8 num_tc = 0; |
| 4579 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4580 | |
| 4581 | /* If DCB is not enabled then always in single TC */ |
| 4582 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4583 | return 1; |
| 4584 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4585 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4586 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4587 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4588 | |
| 4589 | /* MFP mode return count of enabled TCs for this PF */ |
| 4590 | if (pf->hw.func_caps.iscsi) |
| 4591 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4592 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4593 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4594 | |
| 4595 | /* At least have TC0 */ |
| 4596 | enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 4597 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4598 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4599 | num_tc++; |
| 4600 | } |
| 4601 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4602 | } |
| 4603 | |
| 4604 | /** |
| 4605 | * i40e_pf_get_default_tc - Get bitmap for first enabled TC |
| 4606 | * @pf: PF being queried |
| 4607 | * |
| 4608 | * Return a bitmap for first enabled traffic class for this PF. |
| 4609 | **/ |
| 4610 | static u8 i40e_pf_get_default_tc(struct i40e_pf *pf) |
| 4611 | { |
| 4612 | u8 enabled_tc = pf->hw.func_caps.enabled_tcmap; |
| 4613 | u8 i = 0; |
| 4614 | |
| 4615 | if (!enabled_tc) |
| 4616 | return 0x1; /* TC0 */ |
| 4617 | |
| 4618 | /* Find the first enabled TC */ |
| 4619 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4620 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4621 | break; |
| 4622 | } |
| 4623 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4624 | return BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | /** |
| 4628 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4629 | * @pf: PF being queried |
| 4630 | * |
| 4631 | * Return a bitmap for enabled traffic classes for this PF. |
| 4632 | **/ |
| 4633 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4634 | { |
| 4635 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4636 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4637 | return i40e_pf_get_default_tc(pf); |
| 4638 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4639 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4640 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4641 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4642 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4643 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4644 | if (pf->hw.func_caps.iscsi) |
| 4645 | return i40e_get_iscsi_tc_map(pf); |
| 4646 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4647 | return i40e_pf_get_default_tc(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4648 | } |
| 4649 | |
| 4650 | /** |
| 4651 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4652 | * @vsi: the VSI being queried |
| 4653 | * |
| 4654 | * Returns 0 on success, negative value on failure |
| 4655 | **/ |
| 4656 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4657 | { |
| 4658 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4659 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4660 | struct i40e_pf *pf = vsi->back; |
| 4661 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4662 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4663 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4664 | int i; |
| 4665 | |
| 4666 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4667 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, 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 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 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4677 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4678 | NULL); |
| 4679 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4680 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4681 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4682 | i40e_stat_str(&pf->hw, ret), |
| 4683 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4684 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4685 | } |
| 4686 | |
| 4687 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4688 | dev_info(&pf->pdev->dev, |
| 4689 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4690 | bw_config.tc_valid_bits, |
| 4691 | bw_ets_config.tc_valid_bits); |
| 4692 | /* Still continuing */ |
| 4693 | } |
| 4694 | |
| 4695 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4696 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4697 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4698 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4699 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4700 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4701 | vsi->bw_ets_limit_credits[i] = |
| 4702 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4703 | /* 3 bits out of 4 for each TC */ |
| 4704 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4705 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4706 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4707 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
| 4710 | /** |
| 4711 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4712 | * @vsi: the VSI being configured |
| 4713 | * @enabled_tc: TC bitmap |
| 4714 | * @bw_credits: BW shared credits per TC |
| 4715 | * |
| 4716 | * Returns 0 on success, negative value on failure |
| 4717 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4718 | 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] | 4719 | u8 *bw_share) |
| 4720 | { |
| 4721 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4722 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4723 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4724 | |
| 4725 | bw_data.tc_valid_bits = enabled_tc; |
| 4726 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4727 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4728 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4729 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4730 | NULL); |
| 4731 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4732 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4733 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4734 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4735 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4739 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4740 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4741 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4742 | } |
| 4743 | |
| 4744 | /** |
| 4745 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4746 | * @vsi: the VSI being configured |
| 4747 | * @enabled_tc: TC map to be enabled |
| 4748 | * |
| 4749 | **/ |
| 4750 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4751 | { |
| 4752 | struct net_device *netdev = vsi->netdev; |
| 4753 | struct i40e_pf *pf = vsi->back; |
| 4754 | struct i40e_hw *hw = &pf->hw; |
| 4755 | u8 netdev_tc = 0; |
| 4756 | int i; |
| 4757 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4758 | |
| 4759 | if (!netdev) |
| 4760 | return; |
| 4761 | |
| 4762 | if (!enabled_tc) { |
| 4763 | netdev_reset_tc(netdev); |
| 4764 | return; |
| 4765 | } |
| 4766 | |
| 4767 | /* Set up actual enabled TCs on the VSI */ |
| 4768 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 4769 | return; |
| 4770 | |
| 4771 | /* set per TC queues for the VSI */ |
| 4772 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4773 | /* Only set TC queues for enabled tcs |
| 4774 | * |
| 4775 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 4776 | * enabled_tc bitmap would be 0x00001001; the driver |
| 4777 | * will set the numtc for netdev as 2 that will be |
| 4778 | * referenced by the netdev layer as TC 0 and 1. |
| 4779 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4780 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4781 | netdev_set_tc_queue(netdev, |
| 4782 | vsi->tc_config.tc_info[i].netdev_tc, |
| 4783 | vsi->tc_config.tc_info[i].qcount, |
| 4784 | vsi->tc_config.tc_info[i].qoffset); |
| 4785 | } |
| 4786 | |
| 4787 | /* Assign UP2TC map for the VSI */ |
| 4788 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4789 | /* Get the actual TC# for the UP */ |
| 4790 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4791 | /* Get the mapped netdev TC# for the UP */ |
| 4792 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 4793 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 4794 | } |
| 4795 | } |
| 4796 | |
| 4797 | /** |
| 4798 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 4799 | * @vsi: the VSI being configured |
| 4800 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 4801 | **/ |
| 4802 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 4803 | struct i40e_vsi_context *ctxt) |
| 4804 | { |
| 4805 | /* copy just the sections touched not the entire info |
| 4806 | * since not all sections are valid as returned by |
| 4807 | * update vsi params |
| 4808 | */ |
| 4809 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 4810 | memcpy(&vsi->info.queue_mapping, |
| 4811 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 4812 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 4813 | sizeof(vsi->info.tc_mapping)); |
| 4814 | } |
| 4815 | |
| 4816 | /** |
| 4817 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 4818 | * @vsi: VSI to be configured |
| 4819 | * @enabled_tc: TC bitmap |
| 4820 | * |
| 4821 | * This configures a particular VSI for TCs that are mapped to the |
| 4822 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 4823 | * VSIs to configure TC for a particular VSI. |
| 4824 | * |
| 4825 | * NOTE: |
| 4826 | * It is expected that the VSI queues have been quisced before calling |
| 4827 | * this function. |
| 4828 | **/ |
| 4829 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4830 | { |
| 4831 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 4832 | struct i40e_vsi_context ctxt; |
| 4833 | int ret = 0; |
| 4834 | int i; |
| 4835 | |
| 4836 | /* Check if enabled_tc is same as existing or new TCs */ |
| 4837 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 4838 | return ret; |
| 4839 | |
| 4840 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 4841 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4842 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4843 | bw_share[i] = 1; |
| 4844 | } |
| 4845 | |
| 4846 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 4847 | if (ret) { |
| 4848 | dev_info(&vsi->back->pdev->dev, |
| 4849 | "Failed configuring TC map %d for VSI %d\n", |
| 4850 | enabled_tc, vsi->seid); |
| 4851 | goto out; |
| 4852 | } |
| 4853 | |
| 4854 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 4855 | ctxt.seid = vsi->seid; |
| 4856 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 4857 | ctxt.vf_num = 0; |
| 4858 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 4859 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4860 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 4861 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4862 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 4863 | ctxt.info.valid_sections |= |
| 4864 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 4865 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 4866 | } |
| 4867 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4868 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 4869 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 4870 | if (ret) { |
| 4871 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4872 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 4873 | i40e_stat_str(&vsi->back->hw, ret), |
| 4874 | i40e_aq_str(&vsi->back->hw, |
| 4875 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4876 | goto out; |
| 4877 | } |
| 4878 | /* update the local VSI info with updated queue map */ |
| 4879 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 4880 | vsi->info.valid_sections = 0; |
| 4881 | |
| 4882 | /* Update current VSI BW information */ |
| 4883 | ret = i40e_vsi_get_bw_info(vsi); |
| 4884 | if (ret) { |
| 4885 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4886 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 4887 | i40e_stat_str(&vsi->back->hw, ret), |
| 4888 | i40e_aq_str(&vsi->back->hw, |
| 4889 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4890 | goto out; |
| 4891 | } |
| 4892 | |
| 4893 | /* Update the netdev TC setup */ |
| 4894 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 4895 | out: |
| 4896 | return ret; |
| 4897 | } |
| 4898 | |
| 4899 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4900 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 4901 | * @veb: given VEB |
| 4902 | * @enabled_tc: TC bitmap |
| 4903 | * |
| 4904 | * Configures given TC bitmap for VEB (switching) element |
| 4905 | **/ |
| 4906 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 4907 | { |
| 4908 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 4909 | struct i40e_pf *pf = veb->pf; |
| 4910 | int ret = 0; |
| 4911 | int i; |
| 4912 | |
| 4913 | /* No TCs or already enabled TCs just return */ |
| 4914 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 4915 | return ret; |
| 4916 | |
| 4917 | bw_data.tc_valid_bits = enabled_tc; |
| 4918 | /* bw_data.absolute_credits is not set (relative) */ |
| 4919 | |
| 4920 | /* Enable ETS TCs with equal BW Share for now */ |
| 4921 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4922 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4923 | bw_data.tc_bw_share_credits[i] = 1; |
| 4924 | } |
| 4925 | |
| 4926 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 4927 | &bw_data, NULL); |
| 4928 | if (ret) { |
| 4929 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4930 | "VEB bw config failed, err %s aq_err %s\n", |
| 4931 | i40e_stat_str(&pf->hw, ret), |
| 4932 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4933 | goto out; |
| 4934 | } |
| 4935 | |
| 4936 | /* Update the BW information */ |
| 4937 | ret = i40e_veb_get_bw_info(veb); |
| 4938 | if (ret) { |
| 4939 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4940 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 4941 | i40e_stat_str(&pf->hw, ret), |
| 4942 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4943 | } |
| 4944 | |
| 4945 | out: |
| 4946 | return ret; |
| 4947 | } |
| 4948 | |
| 4949 | #ifdef CONFIG_I40E_DCB |
| 4950 | /** |
| 4951 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 4952 | * @pf: PF struct |
| 4953 | * |
| 4954 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 4955 | * the caller would've quiesce all the VSIs before calling |
| 4956 | * this function |
| 4957 | **/ |
| 4958 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 4959 | { |
| 4960 | u8 tc_map = 0; |
| 4961 | int ret; |
| 4962 | u8 v; |
| 4963 | |
| 4964 | /* Enable the TCs available on PF to all VEBs */ |
| 4965 | tc_map = i40e_pf_get_tc_map(pf); |
| 4966 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 4967 | if (!pf->veb[v]) |
| 4968 | continue; |
| 4969 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 4970 | if (ret) { |
| 4971 | dev_info(&pf->pdev->dev, |
| 4972 | "Failed configuring TC for VEB seid=%d\n", |
| 4973 | pf->veb[v]->seid); |
| 4974 | /* Will try to configure as many components */ |
| 4975 | } |
| 4976 | } |
| 4977 | |
| 4978 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4979 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4980 | if (!pf->vsi[v]) |
| 4981 | continue; |
| 4982 | |
| 4983 | /* - Enable all TCs for the LAN VSI |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4984 | #ifdef I40E_FCOE |
| 4985 | * - For FCoE VSI only enable the TC configured |
| 4986 | * as per the APP TLV |
| 4987 | #endif |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4988 | * - For all others keep them at TC0 for now |
| 4989 | */ |
| 4990 | if (v == pf->lan_vsi) |
| 4991 | tc_map = i40e_pf_get_tc_map(pf); |
| 4992 | else |
| 4993 | tc_map = i40e_pf_get_default_tc(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4994 | #ifdef I40E_FCOE |
| 4995 | if (pf->vsi[v]->type == I40E_VSI_FCOE) |
| 4996 | tc_map = i40e_get_fcoe_tc_map(pf); |
| 4997 | #endif /* #ifdef I40E_FCOE */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4998 | |
| 4999 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 5000 | if (ret) { |
| 5001 | dev_info(&pf->pdev->dev, |
| 5002 | "Failed configuring TC for VSI seid=%d\n", |
| 5003 | pf->vsi[v]->seid); |
| 5004 | /* Will try to configure as many components */ |
| 5005 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 5006 | /* Re-configure VSI vectors based on updated TC map */ |
| 5007 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5008 | if (pf->vsi[v]->netdev) |
| 5009 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 5010 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5011 | i40e_notify_client_of_l2_param_changes(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5012 | } |
| 5013 | } |
| 5014 | |
| 5015 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5016 | * i40e_resume_port_tx - Resume port Tx |
| 5017 | * @pf: PF struct |
| 5018 | * |
| 5019 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 5020 | * resume. |
| 5021 | **/ |
| 5022 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 5023 | { |
| 5024 | struct i40e_hw *hw = &pf->hw; |
| 5025 | int ret; |
| 5026 | |
| 5027 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 5028 | if (ret) { |
| 5029 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5030 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 5031 | i40e_stat_str(&pf->hw, ret), |
| 5032 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5033 | /* Schedule PF reset to recover */ |
| 5034 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5035 | i40e_service_event_schedule(pf); |
| 5036 | } |
| 5037 | |
| 5038 | return ret; |
| 5039 | } |
| 5040 | |
| 5041 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5042 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 5043 | * @pf: PF being configured |
| 5044 | * |
| 5045 | * Query the current DCB configuration and cache it |
| 5046 | * in the hardware structure |
| 5047 | **/ |
| 5048 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 5049 | { |
| 5050 | struct i40e_hw *hw = &pf->hw; |
| 5051 | int err = 0; |
| 5052 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5053 | /* 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] | 5054 | if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5055 | goto out; |
| 5056 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5057 | /* Get the initial DCB configuration */ |
| 5058 | err = i40e_init_dcb(hw); |
| 5059 | if (!err) { |
| 5060 | /* Device/Function is not DCBX capable */ |
| 5061 | if ((!hw->func_caps.dcb) || |
| 5062 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5063 | dev_info(&pf->pdev->dev, |
| 5064 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 5065 | |
| 5066 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 5067 | goto out; |
| 5068 | |
| 5069 | } else { |
| 5070 | /* When status is not DISABLED then DCBX in FW */ |
| 5071 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5072 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5073 | |
| 5074 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
| 5075 | /* Enable DCB tagging only when more than one TC */ |
| 5076 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5077 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5078 | dev_dbg(&pf->pdev->dev, |
| 5079 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5080 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5081 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5082 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5083 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5084 | i40e_stat_str(&pf->hw, err), |
| 5085 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5086 | } |
| 5087 | |
| 5088 | out: |
| 5089 | return err; |
| 5090 | } |
| 5091 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5092 | #define SPEED_SIZE 14 |
| 5093 | #define FC_SIZE 8 |
| 5094 | /** |
| 5095 | * i40e_print_link_message - print link up or down |
| 5096 | * @vsi: the VSI for which link needs a message |
| 5097 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5098 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5099 | { |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5100 | char *speed = "Unknown"; |
| 5101 | char *fc = "Unknown"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5102 | |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5103 | if (vsi->current_isup == isup) |
| 5104 | return; |
| 5105 | vsi->current_isup = isup; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5106 | if (!isup) { |
| 5107 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5108 | return; |
| 5109 | } |
| 5110 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5111 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5112 | * least 10GB |
| 5113 | */ |
| 5114 | if (vsi->back->hw.func_caps.npar_enable && |
| 5115 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5116 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5117 | netdev_warn(vsi->netdev, |
| 5118 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5119 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5120 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5121 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5122 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5123 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5124 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5125 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5126 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5127 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5128 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5129 | break; |
| 5130 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5131 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5132 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5133 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5134 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5135 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5136 | default: |
| 5137 | break; |
| 5138 | } |
| 5139 | |
| 5140 | switch (vsi->back->hw.fc.current_mode) { |
| 5141 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5142 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5143 | break; |
| 5144 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5145 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5146 | break; |
| 5147 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5148 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5149 | break; |
| 5150 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5151 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5152 | break; |
| 5153 | } |
| 5154 | |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5155 | 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] | 5156 | speed, fc); |
| 5157 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5158 | |
| 5159 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5160 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5161 | * @vsi: the VSI being configured |
| 5162 | **/ |
| 5163 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5164 | { |
| 5165 | struct i40e_pf *pf = vsi->back; |
| 5166 | int err; |
| 5167 | |
| 5168 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5169 | i40e_vsi_configure_msix(vsi); |
| 5170 | else |
| 5171 | i40e_configure_msi_and_legacy(vsi); |
| 5172 | |
| 5173 | /* start rings */ |
| 5174 | err = i40e_vsi_control_rings(vsi, true); |
| 5175 | if (err) |
| 5176 | return err; |
| 5177 | |
| 5178 | clear_bit(__I40E_DOWN, &vsi->state); |
| 5179 | i40e_napi_enable_all(vsi); |
| 5180 | i40e_vsi_enable_irq(vsi); |
| 5181 | |
| 5182 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5183 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5184 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5185 | netif_tx_start_all_queues(vsi->netdev); |
| 5186 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5187 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5188 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5189 | /* need to check for qualified module here*/ |
| 5190 | if ((pf->hw.phy.link_info.link_info & |
| 5191 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5192 | (!(pf->hw.phy.link_info.an_info & |
| 5193 | I40E_AQ_QUALIFIED_MODULE))) |
| 5194 | netdev_err(vsi->netdev, |
| 5195 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5196 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5197 | |
| 5198 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5199 | if (vsi->type == I40E_VSI_FDIR) { |
| 5200 | /* reset fd counters */ |
| 5201 | pf->fd_add_err = pf->fd_atr_cnt = 0; |
| 5202 | if (pf->fd_tcp_rule > 0) { |
| 5203 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5204 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5205 | 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] | 5206 | pf->fd_tcp_rule = 0; |
| 5207 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5208 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5209 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5210 | |
| 5211 | /* On the next run of the service_task, notify any clients of the new |
| 5212 | * opened netdev |
| 5213 | */ |
| 5214 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5215 | i40e_service_event_schedule(pf); |
| 5216 | |
| 5217 | return 0; |
| 5218 | } |
| 5219 | |
| 5220 | /** |
| 5221 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5222 | * @vsi: the VSI being configured |
| 5223 | * |
| 5224 | * Rebuild the ring structs after some configuration |
| 5225 | * has changed, e.g. MTU size. |
| 5226 | **/ |
| 5227 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5228 | { |
| 5229 | struct i40e_pf *pf = vsi->back; |
| 5230 | |
| 5231 | WARN_ON(in_interrupt()); |
| 5232 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5233 | usleep_range(1000, 2000); |
| 5234 | i40e_down(vsi); |
| 5235 | |
| 5236 | /* Give a VF some time to respond to the reset. The |
| 5237 | * two second wait is based upon the watchdog cycle in |
| 5238 | * the VF driver. |
| 5239 | */ |
| 5240 | if (vsi->type == I40E_VSI_SRIOV) |
| 5241 | msleep(2000); |
| 5242 | i40e_up(vsi); |
| 5243 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 5244 | } |
| 5245 | |
| 5246 | /** |
| 5247 | * i40e_up - Bring the connection back up after being down |
| 5248 | * @vsi: the VSI being configured |
| 5249 | **/ |
| 5250 | int i40e_up(struct i40e_vsi *vsi) |
| 5251 | { |
| 5252 | int err; |
| 5253 | |
| 5254 | err = i40e_vsi_configure(vsi); |
| 5255 | if (!err) |
| 5256 | err = i40e_up_complete(vsi); |
| 5257 | |
| 5258 | return err; |
| 5259 | } |
| 5260 | |
| 5261 | /** |
| 5262 | * i40e_down - Shutdown the connection processing |
| 5263 | * @vsi: the VSI being stopped |
| 5264 | **/ |
| 5265 | void i40e_down(struct i40e_vsi *vsi) |
| 5266 | { |
| 5267 | int i; |
| 5268 | |
| 5269 | /* It is assumed that the caller of this function |
| 5270 | * sets the vsi->state __I40E_DOWN bit. |
| 5271 | */ |
| 5272 | if (vsi->netdev) { |
| 5273 | netif_carrier_off(vsi->netdev); |
| 5274 | netif_tx_disable(vsi->netdev); |
| 5275 | } |
| 5276 | i40e_vsi_disable_irq(vsi); |
| 5277 | i40e_vsi_control_rings(vsi, false); |
| 5278 | i40e_napi_disable_all(vsi); |
| 5279 | |
| 5280 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5281 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 5282 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5283 | } |
| 5284 | } |
| 5285 | |
| 5286 | /** |
| 5287 | * i40e_setup_tc - configure multiple traffic classes |
| 5288 | * @netdev: net device to configure |
| 5289 | * @tc: number of traffic classes to enable |
| 5290 | **/ |
| 5291 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5292 | { |
| 5293 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5294 | struct i40e_vsi *vsi = np->vsi; |
| 5295 | struct i40e_pf *pf = vsi->back; |
| 5296 | u8 enabled_tc = 0; |
| 5297 | int ret = -EINVAL; |
| 5298 | int i; |
| 5299 | |
| 5300 | /* Check if DCB enabled to continue */ |
| 5301 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5302 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5303 | goto exit; |
| 5304 | } |
| 5305 | |
| 5306 | /* Check if MFP enabled */ |
| 5307 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5308 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5309 | goto exit; |
| 5310 | } |
| 5311 | |
| 5312 | /* Check whether tc count is within enabled limit */ |
| 5313 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5314 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5315 | goto exit; |
| 5316 | } |
| 5317 | |
| 5318 | /* Generate TC map for number of tc requested */ |
| 5319 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5320 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5321 | |
| 5322 | /* Requesting same TC configuration as already enabled */ |
| 5323 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5324 | return 0; |
| 5325 | |
| 5326 | /* Quiesce VSI queues */ |
| 5327 | i40e_quiesce_vsi(vsi); |
| 5328 | |
| 5329 | /* Configure VSI for enabled TCs */ |
| 5330 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5331 | if (ret) { |
| 5332 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5333 | vsi->seid); |
| 5334 | goto exit; |
| 5335 | } |
| 5336 | |
| 5337 | /* Unquiesce VSI */ |
| 5338 | i40e_unquiesce_vsi(vsi); |
| 5339 | |
| 5340 | exit: |
| 5341 | return ret; |
| 5342 | } |
| 5343 | |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5344 | #ifdef I40E_FCOE |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5345 | int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5346 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5347 | #else |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5348 | static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5349 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5350 | #endif |
| 5351 | { |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5352 | if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5353 | return -EINVAL; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5354 | return i40e_setup_tc(netdev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5355 | } |
| 5356 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5357 | /** |
| 5358 | * i40e_open - Called when a network interface is made active |
| 5359 | * @netdev: network interface device structure |
| 5360 | * |
| 5361 | * The open entry point is called when a network interface is made |
| 5362 | * active by the system (IFF_UP). At this point all resources needed |
| 5363 | * for transmit and receive operations are allocated, the interrupt |
| 5364 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5365 | * enabled, and the stack is notified that the interface is ready. |
| 5366 | * |
| 5367 | * Returns 0 on success, negative value on failure |
| 5368 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5369 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5370 | { |
| 5371 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5372 | struct i40e_vsi *vsi = np->vsi; |
| 5373 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5374 | int err; |
| 5375 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5376 | /* disallow open during test or if eeprom is broken */ |
| 5377 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 5378 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5379 | return -EBUSY; |
| 5380 | |
| 5381 | netif_carrier_off(netdev); |
| 5382 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5383 | err = i40e_vsi_open(vsi); |
| 5384 | if (err) |
| 5385 | return err; |
| 5386 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5387 | /* configure global TSO hardware offload settings */ |
| 5388 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5389 | TCP_FLAG_FIN) >> 16); |
| 5390 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5391 | TCP_FLAG_FIN | |
| 5392 | TCP_FLAG_CWR) >> 16); |
| 5393 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5394 | |
Singhai, Anjali | 6633d38 | 2015-12-03 23:49:31 -0800 | [diff] [blame] | 5395 | #ifdef CONFIG_I40E_VXLAN |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5396 | vxlan_get_rx_port(netdev); |
| 5397 | #endif |
Singhai, Anjali | cd86660 | 2015-12-14 12:21:21 -0800 | [diff] [blame] | 5398 | #ifdef CONFIG_I40E_GENEVE |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 5399 | if (pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE) |
| 5400 | geneve_get_rx_port(netdev); |
Singhai, Anjali | cd86660 | 2015-12-14 12:21:21 -0800 | [diff] [blame] | 5401 | #endif |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5402 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5403 | i40e_notify_client_of_netdev_open(vsi); |
| 5404 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5405 | return 0; |
| 5406 | } |
| 5407 | |
| 5408 | /** |
| 5409 | * i40e_vsi_open - |
| 5410 | * @vsi: the VSI to open |
| 5411 | * |
| 5412 | * Finish initialization of the VSI. |
| 5413 | * |
| 5414 | * Returns 0 on success, negative value on failure |
| 5415 | **/ |
| 5416 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5417 | { |
| 5418 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5419 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5420 | int err; |
| 5421 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5422 | /* allocate descriptors */ |
| 5423 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5424 | if (err) |
| 5425 | goto err_setup_tx; |
| 5426 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5427 | if (err) |
| 5428 | goto err_setup_rx; |
| 5429 | |
| 5430 | err = i40e_vsi_configure(vsi); |
| 5431 | if (err) |
| 5432 | goto err_setup_rx; |
| 5433 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5434 | if (vsi->netdev) { |
| 5435 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5436 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5437 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5438 | if (err) |
| 5439 | goto err_setup_rx; |
| 5440 | |
| 5441 | /* Notify the stack of the actual queue counts. */ |
| 5442 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5443 | vsi->num_queue_pairs); |
| 5444 | if (err) |
| 5445 | goto err_set_queues; |
| 5446 | |
| 5447 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5448 | vsi->num_queue_pairs); |
| 5449 | if (err) |
| 5450 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5451 | |
| 5452 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5453 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5454 | dev_driver_string(&pf->pdev->dev), |
| 5455 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5456 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5457 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5458 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5459 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5460 | goto err_setup_rx; |
| 5461 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5462 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5463 | err = i40e_up_complete(vsi); |
| 5464 | if (err) |
| 5465 | goto err_up_complete; |
| 5466 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5467 | return 0; |
| 5468 | |
| 5469 | err_up_complete: |
| 5470 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5471 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5472 | i40e_vsi_free_irq(vsi); |
| 5473 | err_setup_rx: |
| 5474 | i40e_vsi_free_rx_resources(vsi); |
| 5475 | err_setup_tx: |
| 5476 | i40e_vsi_free_tx_resources(vsi); |
| 5477 | if (vsi == pf->vsi[pf->lan_vsi]) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5478 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5479 | |
| 5480 | return err; |
| 5481 | } |
| 5482 | |
| 5483 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5484 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5485 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5486 | * |
| 5487 | * This function destroys the hlist where all the Flow Director |
| 5488 | * filters were saved. |
| 5489 | **/ |
| 5490 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5491 | { |
| 5492 | struct i40e_fdir_filter *filter; |
| 5493 | struct hlist_node *node2; |
| 5494 | |
| 5495 | hlist_for_each_entry_safe(filter, node2, |
| 5496 | &pf->fdir_filter_list, fdir_node) { |
| 5497 | hlist_del(&filter->fdir_node); |
| 5498 | kfree(filter); |
| 5499 | } |
| 5500 | pf->fdir_pf_active_filters = 0; |
| 5501 | } |
| 5502 | |
| 5503 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5504 | * i40e_close - Disables a network interface |
| 5505 | * @netdev: network interface device structure |
| 5506 | * |
| 5507 | * The close entry point is called when an interface is de-activated |
| 5508 | * by the OS. The hardware is still under the driver's control, but |
| 5509 | * this netdev interface is disabled. |
| 5510 | * |
| 5511 | * Returns 0, this is not allowed to fail |
| 5512 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5513 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5514 | { |
| 5515 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5516 | struct i40e_vsi *vsi = np->vsi; |
| 5517 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5518 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5519 | |
| 5520 | return 0; |
| 5521 | } |
| 5522 | |
| 5523 | /** |
| 5524 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5525 | * @pf: board private structure |
| 5526 | * @reset_flags: which reset is requested |
| 5527 | * |
| 5528 | * The essential difference in resets is that the PF Reset |
| 5529 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5530 | * firmware, and doesn't bother the other PFs on the chip. |
| 5531 | **/ |
| 5532 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5533 | { |
| 5534 | u32 val; |
| 5535 | |
| 5536 | WARN_ON(in_interrupt()); |
| 5537 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5538 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5539 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5540 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5541 | |
| 5542 | /* Request a Global Reset |
| 5543 | * |
| 5544 | * This will start the chip's countdown to the actual full |
| 5545 | * chip reset event, and a warning interrupt to be sent |
| 5546 | * to all PFs, including the requestor. Our handler |
| 5547 | * for the warning interrupt will deal with the shutdown |
| 5548 | * and recovery of the switch setup. |
| 5549 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5550 | dev_dbg(&pf->pdev->dev, "GlobalR 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_GLOBR_MASK; |
| 5553 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5554 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5555 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5556 | |
| 5557 | /* Request a Core Reset |
| 5558 | * |
| 5559 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5560 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5561 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5562 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5563 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5564 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5565 | i40e_flush(&pf->hw); |
| 5566 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5567 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5568 | |
| 5569 | /* Request a PF Reset |
| 5570 | * |
| 5571 | * Resets only the PF-specific registers |
| 5572 | * |
| 5573 | * This goes directly to the tear-down and rebuild of |
| 5574 | * the switch, since we need to do all the recovery as |
| 5575 | * for the Core Reset. |
| 5576 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5577 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5578 | i40e_handle_reset_warning(pf); |
| 5579 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5580 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5581 | int v; |
| 5582 | |
| 5583 | /* Find the VSI(s) that requested a re-init */ |
| 5584 | dev_info(&pf->pdev->dev, |
| 5585 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5586 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5587 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5588 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5589 | if (vsi != NULL && |
| 5590 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5591 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5592 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5593 | } |
| 5594 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5595 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5596 | int v; |
| 5597 | |
| 5598 | /* Find the VSI(s) that needs to be brought down */ |
| 5599 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5600 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5601 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5602 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5603 | if (vsi != NULL && |
| 5604 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5605 | set_bit(__I40E_DOWN, &vsi->state); |
| 5606 | i40e_down(vsi); |
| 5607 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5608 | } |
| 5609 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5610 | } else { |
| 5611 | dev_info(&pf->pdev->dev, |
| 5612 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5613 | } |
| 5614 | } |
| 5615 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5616 | #ifdef CONFIG_I40E_DCB |
| 5617 | /** |
| 5618 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5619 | * @pf: board private structure |
| 5620 | * @old_cfg: current DCB config |
| 5621 | * @new_cfg: new DCB config |
| 5622 | **/ |
| 5623 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5624 | struct i40e_dcbx_config *old_cfg, |
| 5625 | struct i40e_dcbx_config *new_cfg) |
| 5626 | { |
| 5627 | bool need_reconfig = false; |
| 5628 | |
| 5629 | /* Check if ETS configuration has changed */ |
| 5630 | if (memcmp(&new_cfg->etscfg, |
| 5631 | &old_cfg->etscfg, |
| 5632 | sizeof(new_cfg->etscfg))) { |
| 5633 | /* If Priority Table has changed reconfig is needed */ |
| 5634 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5635 | &old_cfg->etscfg.prioritytable, |
| 5636 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5637 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5638 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5642 | &old_cfg->etscfg.tcbwtable, |
| 5643 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5644 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5645 | |
| 5646 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5647 | &old_cfg->etscfg.tsatable, |
| 5648 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5649 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5650 | } |
| 5651 | |
| 5652 | /* Check if PFC configuration has changed */ |
| 5653 | if (memcmp(&new_cfg->pfc, |
| 5654 | &old_cfg->pfc, |
| 5655 | sizeof(new_cfg->pfc))) { |
| 5656 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5657 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5658 | } |
| 5659 | |
| 5660 | /* Check if APP Table has changed */ |
| 5661 | if (memcmp(&new_cfg->app, |
| 5662 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5663 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5664 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5665 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5666 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5667 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5668 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5669 | return need_reconfig; |
| 5670 | } |
| 5671 | |
| 5672 | /** |
| 5673 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5674 | * @pf: board private structure |
| 5675 | * @e: event info posted on ARQ |
| 5676 | **/ |
| 5677 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5678 | struct i40e_arq_event_info *e) |
| 5679 | { |
| 5680 | struct i40e_aqc_lldp_get_mib *mib = |
| 5681 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5682 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5683 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5684 | bool need_reconfig = false; |
| 5685 | int ret = 0; |
| 5686 | u8 type; |
| 5687 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5688 | /* Not DCB capable or capability disabled */ |
| 5689 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
| 5690 | return ret; |
| 5691 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5692 | /* Ignore if event is not for Nearest Bridge */ |
| 5693 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5694 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5695 | 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] | 5696 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5697 | return ret; |
| 5698 | |
| 5699 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5700 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5701 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5702 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5703 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5704 | /* Update the remote cached instance and return */ |
| 5705 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5706 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5707 | &hw->remote_dcbx_config); |
| 5708 | goto exit; |
| 5709 | } |
| 5710 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5711 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5712 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5713 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5714 | /* Reset the old DCBx configuration data */ |
| 5715 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5716 | /* Get updated DCBX data from firmware */ |
| 5717 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5718 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5719 | dev_info(&pf->pdev->dev, |
| 5720 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 5721 | i40e_stat_str(&pf->hw, ret), |
| 5722 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5723 | goto exit; |
| 5724 | } |
| 5725 | |
| 5726 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5727 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5728 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5729 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5730 | goto exit; |
| 5731 | } |
| 5732 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5733 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5734 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5735 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5736 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5737 | |
| 5738 | if (!need_reconfig) |
| 5739 | goto exit; |
| 5740 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5741 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5742 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5743 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5744 | else |
| 5745 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5746 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5747 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5748 | /* Reconfiguration needed quiesce all VSIs */ |
| 5749 | i40e_pf_quiesce_all_vsi(pf); |
| 5750 | |
| 5751 | /* Changes in configuration update VEB/VSI */ |
| 5752 | i40e_dcb_reconfigure(pf); |
| 5753 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5754 | ret = i40e_resume_port_tx(pf); |
| 5755 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5756 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5757 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5758 | if (ret) |
| 5759 | goto exit; |
| 5760 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 5761 | /* Wait for the PF's queues to be disabled */ |
| 5762 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5763 | if (ret) { |
| 5764 | /* Schedule PF reset to recover */ |
| 5765 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5766 | i40e_service_event_schedule(pf); |
| 5767 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5768 | i40e_pf_unquiesce_all_vsi(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5769 | } |
| 5770 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5771 | exit: |
| 5772 | return ret; |
| 5773 | } |
| 5774 | #endif /* CONFIG_I40E_DCB */ |
| 5775 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5776 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5777 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 5778 | * @pf: board private structure |
| 5779 | * @reset_flags: which reset is requested |
| 5780 | * |
| 5781 | **/ |
| 5782 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 5783 | { |
| 5784 | rtnl_lock(); |
| 5785 | i40e_do_reset(pf, reset_flags); |
| 5786 | rtnl_unlock(); |
| 5787 | } |
| 5788 | |
| 5789 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5790 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 5791 | * @pf: board private structure |
| 5792 | * @e: event info posted on ARQ |
| 5793 | * |
| 5794 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 5795 | * and VF queues |
| 5796 | **/ |
| 5797 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 5798 | struct i40e_arq_event_info *e) |
| 5799 | { |
| 5800 | struct i40e_aqc_lan_overflow *data = |
| 5801 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 5802 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 5803 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 5804 | struct i40e_hw *hw = &pf->hw; |
| 5805 | struct i40e_vf *vf; |
| 5806 | u16 vf_id; |
| 5807 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5808 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 5809 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5810 | |
| 5811 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 5812 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 5813 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 5814 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 5815 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 5816 | vf_id -= hw->func_caps.vf_base_id; |
| 5817 | vf = &pf->vf[vf_id]; |
| 5818 | i40e_vc_notify_vf_reset(vf); |
| 5819 | /* Allow VF to process pending reset notification */ |
| 5820 | msleep(20); |
| 5821 | i40e_reset_vf(vf, false); |
| 5822 | } |
| 5823 | } |
| 5824 | |
| 5825 | /** |
| 5826 | * i40e_service_event_complete - Finish up the service event |
| 5827 | * @pf: board private structure |
| 5828 | **/ |
| 5829 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 5830 | { |
Shannon Nelson | b875f99 | 2015-10-21 19:47:03 -0400 | [diff] [blame] | 5831 | WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5832 | |
| 5833 | /* flush memory to make sure state is correct before next watchog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5834 | smp_mb__before_atomic(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5835 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 5836 | } |
| 5837 | |
| 5838 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5839 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 5840 | * @pf: board private structure |
| 5841 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5842 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5843 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5844 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5845 | |
| 5846 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5847 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 5848 | return fcnt_prog; |
| 5849 | } |
| 5850 | |
| 5851 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5852 | * 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] | 5853 | * @pf: board private structure |
| 5854 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5855 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5856 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5857 | u32 val, fcnt_prog; |
| 5858 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5859 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5860 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 5861 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 5862 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 5863 | return fcnt_prog; |
| 5864 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5865 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5866 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5867 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 5868 | * @pf: board private structure |
| 5869 | **/ |
| 5870 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 5871 | { |
| 5872 | u32 val, fcnt_prog; |
| 5873 | |
| 5874 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 5875 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 5876 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 5877 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 5878 | return fcnt_prog; |
| 5879 | } |
| 5880 | |
| 5881 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5882 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 5883 | * @pf: board private structure |
| 5884 | **/ |
| 5885 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 5886 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5887 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5888 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5889 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5890 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5891 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 5892 | return; |
| 5893 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5894 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 5895 | * to re-enable |
| 5896 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5897 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5898 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5899 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 5900 | (pf->fd_add_err == 0) || |
| 5901 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5902 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 5903 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 5904 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5905 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5906 | 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] | 5907 | } |
| 5908 | } |
| 5909 | /* Wait for some more space to be available to turn on ATR */ |
| 5910 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 5911 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 5912 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
| 5913 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5914 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5915 | 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] | 5916 | } |
| 5917 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5918 | |
| 5919 | /* if hw had a problem adding a filter, delete it */ |
| 5920 | if (pf->fd_inv > 0) { |
| 5921 | hlist_for_each_entry_safe(filter, node, |
| 5922 | &pf->fdir_filter_list, fdir_node) { |
| 5923 | if (filter->fd_id == pf->fd_inv) { |
| 5924 | hlist_del(&filter->fdir_node); |
| 5925 | kfree(filter); |
| 5926 | pf->fdir_pf_active_filters--; |
| 5927 | } |
| 5928 | } |
| 5929 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5930 | } |
| 5931 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5932 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5933 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5934 | /** |
| 5935 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 5936 | * @pf: board private structure |
| 5937 | **/ |
| 5938 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 5939 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5940 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5941 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5942 | bool disable_atr = false; |
| 5943 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5944 | int reg; |
| 5945 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 5946 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 5947 | return; |
| 5948 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5949 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 5950 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 5951 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5952 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5953 | /* If the flush is happening too quick and we have mostly SB rules we |
| 5954 | * should not re-enable ATR for some time. |
| 5955 | */ |
| 5956 | min_flush_time = pf->fd_flush_timestamp + |
| 5957 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 5958 | 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] | 5959 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5960 | if (!(time_after(jiffies, min_flush_time)) && |
| 5961 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 5962 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5963 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 5964 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5965 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5966 | |
| 5967 | pf->fd_flush_timestamp = jiffies; |
| 5968 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
| 5969 | /* flush all filters */ |
| 5970 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 5971 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 5972 | i40e_flush(&pf->hw); |
| 5973 | pf->fd_flush_cnt++; |
| 5974 | pf->fd_add_err = 0; |
| 5975 | do { |
| 5976 | /* Check FD flush status every 5-6msec */ |
| 5977 | usleep_range(5000, 6000); |
| 5978 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 5979 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 5980 | break; |
| 5981 | } while (flush_wait_retry--); |
| 5982 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 5983 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 5984 | } else { |
| 5985 | /* replay sideband filters */ |
| 5986 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
| 5987 | if (!disable_atr) |
| 5988 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 5989 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
| 5990 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5991 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 5992 | } |
| 5993 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5994 | } |
| 5995 | |
| 5996 | /** |
| 5997 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 5998 | * @pf: board private structure |
| 5999 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6000 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6001 | { |
| 6002 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 6003 | } |
| 6004 | |
| 6005 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 6006 | * being applied really fast; before we see the first |
| 6007 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 6008 | * reacting will make sure we don't cause flush too often. |
| 6009 | */ |
| 6010 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 6011 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6012 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6013 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 6014 | * @pf: board private structure |
| 6015 | **/ |
| 6016 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 6017 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6018 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6019 | /* if interface is down do nothing */ |
| 6020 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 6021 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6022 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 6023 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 6024 | return; |
| 6025 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 6026 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 6027 | i40e_fdir_flush_and_replay(pf); |
| 6028 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 6029 | i40e_fdir_check_and_reenable(pf); |
| 6030 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6031 | } |
| 6032 | |
| 6033 | /** |
| 6034 | * i40e_vsi_link_event - notify VSI of a link event |
| 6035 | * @vsi: vsi to be notified |
| 6036 | * @link_up: link up or down |
| 6037 | **/ |
| 6038 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 6039 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 6040 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6041 | return; |
| 6042 | |
| 6043 | switch (vsi->type) { |
| 6044 | case I40E_VSI_MAIN: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6045 | #ifdef I40E_FCOE |
| 6046 | case I40E_VSI_FCOE: |
| 6047 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6048 | if (!vsi->netdev || !vsi->netdev_registered) |
| 6049 | break; |
| 6050 | |
| 6051 | if (link_up) { |
| 6052 | netif_carrier_on(vsi->netdev); |
| 6053 | netif_tx_wake_all_queues(vsi->netdev); |
| 6054 | } else { |
| 6055 | netif_carrier_off(vsi->netdev); |
| 6056 | netif_tx_stop_all_queues(vsi->netdev); |
| 6057 | } |
| 6058 | break; |
| 6059 | |
| 6060 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6061 | case I40E_VSI_VMDQ2: |
| 6062 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6063 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6064 | case I40E_VSI_MIRROR: |
| 6065 | default: |
| 6066 | /* there is no notification for other VSIs */ |
| 6067 | break; |
| 6068 | } |
| 6069 | } |
| 6070 | |
| 6071 | /** |
| 6072 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6073 | * @veb: veb to be notified |
| 6074 | * @link_up: link up or down |
| 6075 | **/ |
| 6076 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6077 | { |
| 6078 | struct i40e_pf *pf; |
| 6079 | int i; |
| 6080 | |
| 6081 | if (!veb || !veb->pf) |
| 6082 | return; |
| 6083 | pf = veb->pf; |
| 6084 | |
| 6085 | /* depth first... */ |
| 6086 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6087 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6088 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6089 | |
| 6090 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6091 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6092 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6093 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6094 | } |
| 6095 | |
| 6096 | /** |
| 6097 | * i40e_link_event - Update netif_carrier status |
| 6098 | * @pf: board private structure |
| 6099 | **/ |
| 6100 | static void i40e_link_event(struct i40e_pf *pf) |
| 6101 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6102 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6103 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6104 | i40e_status status; |
| 6105 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6106 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6107 | /* save off old link status information */ |
| 6108 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6109 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6110 | /* set this to force the get_link_status call to refresh state */ |
| 6111 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6112 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6113 | 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] | 6114 | |
| 6115 | status = i40e_get_link_status(&pf->hw, &new_link); |
| 6116 | if (status) { |
| 6117 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6118 | status); |
| 6119 | return; |
| 6120 | } |
| 6121 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6122 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6123 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6124 | |
| 6125 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6126 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6127 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 6128 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6129 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6130 | |
| 6131 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 6132 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6133 | |
| 6134 | /* Notify the base of the switch tree connected to |
| 6135 | * the link. Floating VEBs are not notified. |
| 6136 | */ |
| 6137 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6138 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6139 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6140 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6141 | |
| 6142 | if (pf->vf) |
| 6143 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6144 | |
| 6145 | if (pf->flags & I40E_FLAG_PTP) |
| 6146 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6147 | } |
| 6148 | |
| 6149 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6150 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6151 | * @pf: board private structure |
| 6152 | **/ |
| 6153 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6154 | { |
| 6155 | int i; |
| 6156 | |
| 6157 | /* if interface is down do nothing */ |
| 6158 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 6159 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6160 | return; |
| 6161 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6162 | /* make sure we don't do these things too often */ |
| 6163 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6164 | pf->service_timer_period))) |
| 6165 | return; |
| 6166 | pf->service_timer_previous = jiffies; |
| 6167 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6168 | if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) |
| 6169 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6170 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6171 | /* Update the stats for active netdevs so the network stack |
| 6172 | * can look at updated numbers whenever it cares to |
| 6173 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6174 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6175 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6176 | i40e_update_stats(pf->vsi[i]); |
| 6177 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6178 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6179 | /* Update the stats for the active switching components */ |
| 6180 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6181 | if (pf->veb[i]) |
| 6182 | i40e_update_veb_stats(pf->veb[i]); |
| 6183 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6184 | |
| 6185 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6186 | } |
| 6187 | |
| 6188 | /** |
| 6189 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6190 | * @pf: board private structure |
| 6191 | **/ |
| 6192 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6193 | { |
| 6194 | u32 reset_flags = 0; |
| 6195 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6196 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6197 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6198 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6199 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 6200 | } |
| 6201 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6202 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6203 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6204 | } |
| 6205 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6206 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6207 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 6208 | } |
| 6209 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6210 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6211 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 6212 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6213 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6214 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6215 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 6216 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6217 | |
| 6218 | /* If there's a recovery already waiting, it takes |
| 6219 | * precedence before starting a new reset sequence. |
| 6220 | */ |
| 6221 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 6222 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6223 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6224 | } |
| 6225 | |
| 6226 | /* If we're already down or resetting, just bail */ |
| 6227 | if (reset_flags && |
| 6228 | !test_bit(__I40E_DOWN, &pf->state) && |
| 6229 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6230 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6231 | |
| 6232 | unlock: |
| 6233 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6234 | } |
| 6235 | |
| 6236 | /** |
| 6237 | * i40e_handle_link_event - Handle link event |
| 6238 | * @pf: board private structure |
| 6239 | * @e: event info posted on ARQ |
| 6240 | **/ |
| 6241 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6242 | struct i40e_arq_event_info *e) |
| 6243 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6244 | struct i40e_aqc_get_link_status *status = |
| 6245 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6246 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6247 | /* Do a new status request to re-enable LSE reporting |
| 6248 | * and load new status information into the hw struct |
| 6249 | * This completely ignores any state information |
| 6250 | * in the ARQ event info, instead choosing to always |
| 6251 | * issue the AQ update link status command. |
| 6252 | */ |
| 6253 | i40e_link_event(pf); |
| 6254 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6255 | /* check for unqualified module, if link is down */ |
| 6256 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6257 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6258 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6259 | dev_err(&pf->pdev->dev, |
| 6260 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6261 | } |
| 6262 | |
| 6263 | /** |
| 6264 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6265 | * @pf: board private structure |
| 6266 | **/ |
| 6267 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6268 | { |
| 6269 | struct i40e_arq_event_info event; |
| 6270 | struct i40e_hw *hw = &pf->hw; |
| 6271 | u16 pending, i = 0; |
| 6272 | i40e_status ret; |
| 6273 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6274 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6275 | u32 val; |
| 6276 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6277 | /* Do not run clean AQ when PF reset fails */ |
| 6278 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 6279 | return; |
| 6280 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6281 | /* check for error indications */ |
| 6282 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6283 | oldval = val; |
| 6284 | if (val & I40E_PF_ARQLEN_ARQVFE_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 VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6287 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6288 | } |
| 6289 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6290 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6291 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6292 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6293 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6294 | } |
| 6295 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6296 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6297 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6298 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6299 | } |
| 6300 | if (oldval != val) |
| 6301 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6302 | |
| 6303 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6304 | oldval = val; |
| 6305 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6306 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6307 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6308 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6309 | } |
| 6310 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6311 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6312 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6313 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6314 | } |
| 6315 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6316 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6317 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6318 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6319 | } |
| 6320 | if (oldval != val) |
| 6321 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6322 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6323 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6324 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6325 | if (!event.msg_buf) |
| 6326 | return; |
| 6327 | |
| 6328 | do { |
| 6329 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6330 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6331 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6332 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6333 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6334 | break; |
| 6335 | } |
| 6336 | |
| 6337 | opcode = le16_to_cpu(event.desc.opcode); |
| 6338 | switch (opcode) { |
| 6339 | |
| 6340 | case i40e_aqc_opc_get_link_status: |
| 6341 | i40e_handle_link_event(pf, &event); |
| 6342 | break; |
| 6343 | case i40e_aqc_opc_send_msg_to_pf: |
| 6344 | ret = i40e_vc_process_vf_msg(pf, |
| 6345 | le16_to_cpu(event.desc.retval), |
| 6346 | le32_to_cpu(event.desc.cookie_high), |
| 6347 | le32_to_cpu(event.desc.cookie_low), |
| 6348 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6349 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6350 | break; |
| 6351 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6352 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6353 | #ifdef CONFIG_I40E_DCB |
| 6354 | rtnl_lock(); |
| 6355 | ret = i40e_handle_lldp_event(pf, &event); |
| 6356 | rtnl_unlock(); |
| 6357 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6358 | break; |
| 6359 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6360 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6361 | i40e_handle_lan_overflow_event(pf, &event); |
| 6362 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6363 | case i40e_aqc_opc_send_msg_to_peer: |
| 6364 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6365 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6366 | case i40e_aqc_opc_nvm_erase: |
| 6367 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6368 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 6369 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 6370 | "ARQ NVM operation 0x%04x completed\n", |
| 6371 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6372 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6373 | default: |
| 6374 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 6375 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6376 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6377 | break; |
| 6378 | } |
| 6379 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 6380 | |
| 6381 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 6382 | /* re-enable Admin queue interrupt cause */ |
| 6383 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6384 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6385 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6386 | i40e_flush(hw); |
| 6387 | |
| 6388 | kfree(event.msg_buf); |
| 6389 | } |
| 6390 | |
| 6391 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6392 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6393 | * @pf: board private structure |
| 6394 | **/ |
| 6395 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6396 | { |
| 6397 | int err; |
| 6398 | |
| 6399 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6400 | if (err) { |
| 6401 | /* retry in case of garbage read */ |
| 6402 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6403 | if (err) { |
| 6404 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6405 | err); |
| 6406 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6407 | } |
| 6408 | } |
| 6409 | |
| 6410 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 6411 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 6412 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6413 | } |
| 6414 | } |
| 6415 | |
| 6416 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6417 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6418 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6419 | * |
| 6420 | * enable switch loop back or die - no point in a return value |
| 6421 | **/ |
| 6422 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6423 | { |
| 6424 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6425 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6426 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6427 | |
| 6428 | ctxt.seid = pf->main_vsi_seid; |
| 6429 | ctxt.pf_num = pf->hw.pf_id; |
| 6430 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6431 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6432 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6433 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6434 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6435 | i40e_stat_str(&pf->hw, ret), |
| 6436 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6437 | return; |
| 6438 | } |
| 6439 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6440 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6441 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6442 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6443 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6444 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6445 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6446 | "update vsi switch failed, err %s aq_err %s\n", |
| 6447 | i40e_stat_str(&pf->hw, ret), |
| 6448 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6449 | } |
| 6450 | } |
| 6451 | |
| 6452 | /** |
| 6453 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6454 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6455 | * |
| 6456 | * disable switch loop back or die - no point in a return value |
| 6457 | **/ |
| 6458 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6459 | { |
| 6460 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6461 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6462 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6463 | |
| 6464 | ctxt.seid = pf->main_vsi_seid; |
| 6465 | ctxt.pf_num = pf->hw.pf_id; |
| 6466 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6467 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6468 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6469 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6470 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6471 | i40e_stat_str(&pf->hw, ret), |
| 6472 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6473 | return; |
| 6474 | } |
| 6475 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6476 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6477 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6478 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6479 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6480 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6481 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6482 | "update vsi switch failed, err %s aq_err %s\n", |
| 6483 | i40e_stat_str(&pf->hw, ret), |
| 6484 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6485 | } |
| 6486 | } |
| 6487 | |
| 6488 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6489 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6490 | * @veb: pointer to the bridge instance |
| 6491 | * |
| 6492 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6493 | * specified HW bridge instance. It is expected this function is called |
| 6494 | * when a new HW bridge is instantiated. |
| 6495 | **/ |
| 6496 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6497 | { |
| 6498 | struct i40e_pf *pf = veb->pf; |
| 6499 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6500 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6501 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6502 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6503 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6504 | i40e_disable_pf_switch_lb(pf); |
| 6505 | else |
| 6506 | i40e_enable_pf_switch_lb(pf); |
| 6507 | } |
| 6508 | |
| 6509 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6510 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6511 | * @veb: pointer to the VEB instance |
| 6512 | * |
| 6513 | * This is a recursive function that first builds the attached VSIs then |
| 6514 | * recurses in to build the next layer of VEB. We track the connections |
| 6515 | * through our own index numbers because the seid's from the HW could |
| 6516 | * change across the reset. |
| 6517 | **/ |
| 6518 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6519 | { |
| 6520 | struct i40e_vsi *ctl_vsi = NULL; |
| 6521 | struct i40e_pf *pf = veb->pf; |
| 6522 | int v, veb_idx; |
| 6523 | int ret; |
| 6524 | |
| 6525 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6526 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6527 | if (pf->vsi[v] && |
| 6528 | pf->vsi[v]->veb_idx == veb->idx && |
| 6529 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6530 | ctl_vsi = pf->vsi[v]; |
| 6531 | break; |
| 6532 | } |
| 6533 | } |
| 6534 | if (!ctl_vsi) { |
| 6535 | dev_info(&pf->pdev->dev, |
| 6536 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6537 | ret = -ENOENT; |
| 6538 | goto end_reconstitute; |
| 6539 | } |
| 6540 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6541 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6542 | ret = i40e_add_vsi(ctl_vsi); |
| 6543 | if (ret) { |
| 6544 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6545 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6546 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6547 | goto end_reconstitute; |
| 6548 | } |
| 6549 | i40e_vsi_reset_stats(ctl_vsi); |
| 6550 | |
| 6551 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6552 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6553 | if (ret) |
| 6554 | goto end_reconstitute; |
| 6555 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6556 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6557 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6558 | else |
| 6559 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6560 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6561 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6562 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6563 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6564 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6565 | continue; |
| 6566 | |
| 6567 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6568 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6569 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6570 | vsi->uplink_seid = veb->seid; |
| 6571 | ret = i40e_add_vsi(vsi); |
| 6572 | if (ret) { |
| 6573 | dev_info(&pf->pdev->dev, |
| 6574 | "rebuild of vsi_idx %d failed: %d\n", |
| 6575 | v, ret); |
| 6576 | goto end_reconstitute; |
| 6577 | } |
| 6578 | i40e_vsi_reset_stats(vsi); |
| 6579 | } |
| 6580 | } |
| 6581 | |
| 6582 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6583 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6584 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6585 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6586 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6587 | if (ret) |
| 6588 | break; |
| 6589 | } |
| 6590 | } |
| 6591 | |
| 6592 | end_reconstitute: |
| 6593 | return ret; |
| 6594 | } |
| 6595 | |
| 6596 | /** |
| 6597 | * i40e_get_capabilities - get info about the HW |
| 6598 | * @pf: the PF struct |
| 6599 | **/ |
| 6600 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6601 | { |
| 6602 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6603 | u16 data_size; |
| 6604 | int buf_len; |
| 6605 | int err; |
| 6606 | |
| 6607 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6608 | do { |
| 6609 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6610 | if (!cap_buf) |
| 6611 | return -ENOMEM; |
| 6612 | |
| 6613 | /* this loads the data into the hw struct for us */ |
| 6614 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6615 | &data_size, |
| 6616 | i40e_aqc_opc_list_func_capabilities, |
| 6617 | NULL); |
| 6618 | /* data loaded, buffer no longer needed */ |
| 6619 | kfree(cap_buf); |
| 6620 | |
| 6621 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6622 | /* retry with a larger buffer */ |
| 6623 | buf_len = data_size; |
| 6624 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6625 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6626 | "capability discovery failed, err %s aq_err %s\n", |
| 6627 | i40e_stat_str(&pf->hw, err), |
| 6628 | i40e_aq_str(&pf->hw, |
| 6629 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6630 | return -ENODEV; |
| 6631 | } |
| 6632 | } while (err); |
| 6633 | |
| 6634 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6635 | dev_info(&pf->pdev->dev, |
| 6636 | "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", |
| 6637 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6638 | pf->hw.func_caps.num_msix_vectors, |
| 6639 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6640 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6641 | pf->hw.func_caps.fd_filters_best_effort, |
| 6642 | pf->hw.func_caps.num_tx_qp, |
| 6643 | pf->hw.func_caps.num_vsis); |
| 6644 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6645 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6646 | + pf->hw.func_caps.num_vfs) |
| 6647 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6648 | dev_info(&pf->pdev->dev, |
| 6649 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6650 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6651 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6652 | } |
| 6653 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6654 | return 0; |
| 6655 | } |
| 6656 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6657 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6658 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6659 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6660 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6661 | * @pf: board private structure |
| 6662 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6663 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6664 | { |
| 6665 | struct i40e_vsi *vsi; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6666 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6667 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6668 | /* quick workaround for an NVM issue that leaves a critical register |
| 6669 | * uninitialized |
| 6670 | */ |
| 6671 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6672 | static const u32 hkey[] = { |
| 6673 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6674 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6675 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6676 | 0x95b3a76d}; |
| 6677 | |
| 6678 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6679 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6680 | } |
| 6681 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6682 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6683 | return; |
| 6684 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6685 | /* find existing VSI and see if it needs configuring */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6686 | vsi = NULL; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6687 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6688 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6689 | vsi = pf->vsi[i]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6690 | break; |
| 6691 | } |
| 6692 | } |
| 6693 | |
| 6694 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6695 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6696 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6697 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6698 | if (!vsi) { |
| 6699 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6700 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6701 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6702 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6703 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6704 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6705 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6706 | } |
| 6707 | |
| 6708 | /** |
| 6709 | * i40e_fdir_teardown - release the Flow Director resources |
| 6710 | * @pf: board private structure |
| 6711 | **/ |
| 6712 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6713 | { |
| 6714 | int i; |
| 6715 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6716 | i40e_fdir_filter_exit(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6717 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6718 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 6719 | i40e_vsi_release(pf->vsi[i]); |
| 6720 | break; |
| 6721 | } |
| 6722 | } |
| 6723 | } |
| 6724 | |
| 6725 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6726 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6727 | * @pf: board private structure |
| 6728 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6729 | * 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] | 6730 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6731 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6732 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6733 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6734 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6735 | u32 v; |
| 6736 | |
| 6737 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6738 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6739 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 6740 | if (i40e_check_asq_alive(&pf->hw)) |
| 6741 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6742 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6743 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6744 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6745 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6746 | i40e_pf_quiesce_all_vsi(pf); |
| 6747 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6748 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6749 | if (pf->vsi[v]) |
| 6750 | pf->vsi[v]->seid = 0; |
| 6751 | } |
| 6752 | |
| 6753 | i40e_shutdown_adminq(&pf->hw); |
| 6754 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6755 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6756 | if (hw->hmc.hmc_obj) { |
| 6757 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6758 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6759 | dev_warn(&pf->pdev->dev, |
| 6760 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6761 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6762 | } |
| 6763 | |
| 6764 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6765 | * i40e_send_version - update firmware with driver version |
| 6766 | * @pf: PF struct |
| 6767 | */ |
| 6768 | static void i40e_send_version(struct i40e_pf *pf) |
| 6769 | { |
| 6770 | struct i40e_driver_version dv; |
| 6771 | |
| 6772 | dv.major_version = DRV_VERSION_MAJOR; |
| 6773 | dv.minor_version = DRV_VERSION_MINOR; |
| 6774 | dv.build_version = DRV_VERSION_BUILD; |
| 6775 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 6776 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6777 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 6778 | } |
| 6779 | |
| 6780 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 6781 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6782 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6783 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6784 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6785 | 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] | 6786 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6787 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6788 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6789 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6790 | u32 val; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6791 | u32 v; |
| 6792 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6793 | /* Now we wait for GRST to settle out. |
| 6794 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 6795 | * because the reset will make them disappear. |
| 6796 | */ |
| 6797 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6798 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6799 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6800 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 6801 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6802 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6803 | pf->pfr_count++; |
| 6804 | |
| 6805 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6806 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6807 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6808 | |
| 6809 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 6810 | ret = i40e_init_adminq(&pf->hw); |
| 6811 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6812 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 6813 | i40e_stat_str(&pf->hw, ret), |
| 6814 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6815 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6816 | } |
| 6817 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6818 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 6819 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6820 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6821 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 6822 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6823 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6824 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6825 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6826 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6827 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 6828 | hw->func_caps.num_rx_qp, |
| 6829 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 6830 | if (ret) { |
| 6831 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 6832 | goto end_core_reset; |
| 6833 | } |
| 6834 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 6835 | if (ret) { |
| 6836 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 6837 | goto end_core_reset; |
| 6838 | } |
| 6839 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6840 | #ifdef CONFIG_I40E_DCB |
| 6841 | ret = i40e_init_pf_dcb(pf); |
| 6842 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6843 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 6844 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 6845 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6846 | } |
| 6847 | #endif /* CONFIG_I40E_DCB */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6848 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 6849 | i40e_init_pf_fcoe(pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6850 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6851 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6852 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6853 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6854 | if (ret) |
| 6855 | goto end_core_reset; |
| 6856 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6857 | /* The driver only wants link up/down and module qualification |
| 6858 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6859 | */ |
| 6860 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6861 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
| 6862 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6863 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6864 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 6865 | i40e_stat_str(&pf->hw, ret), |
| 6866 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6867 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6868 | /* make sure our flow control settings are restored */ |
| 6869 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 6870 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 6871 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 6872 | i40e_stat_str(&pf->hw, ret), |
| 6873 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6874 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6875 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 6876 | * They are still in our local switch element arrays, so only |
| 6877 | * need to rebuild the switch model in the HW. |
| 6878 | * |
| 6879 | * If there were VEBs but the reconstitution failed, we'll try |
| 6880 | * try to recover minimal use by getting the basic PF VSI working. |
| 6881 | */ |
| 6882 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6883 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6884 | /* find the one VEB connected to the MAC, and find orphans */ |
| 6885 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6886 | if (!pf->veb[v]) |
| 6887 | continue; |
| 6888 | |
| 6889 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 6890 | pf->veb[v]->uplink_seid == 0) { |
| 6891 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 6892 | |
| 6893 | if (!ret) |
| 6894 | continue; |
| 6895 | |
| 6896 | /* If Main VEB failed, we're in deep doodoo, |
| 6897 | * so give up rebuilding the switch and set up |
| 6898 | * for minimal rebuild of PF VSI. |
| 6899 | * If orphan failed, we'll report the error |
| 6900 | * but try to keep going. |
| 6901 | */ |
| 6902 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 6903 | dev_info(&pf->pdev->dev, |
| 6904 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 6905 | ret); |
| 6906 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 6907 | = pf->mac_seid; |
| 6908 | break; |
| 6909 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 6910 | dev_info(&pf->pdev->dev, |
| 6911 | "rebuild of orphan VEB failed: %d\n", |
| 6912 | ret); |
| 6913 | } |
| 6914 | } |
| 6915 | } |
| 6916 | } |
| 6917 | |
| 6918 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 6919 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6920 | /* no VEB, so rebuild only the Main VSI */ |
| 6921 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 6922 | if (ret) { |
| 6923 | dev_info(&pf->pdev->dev, |
| 6924 | "rebuild of Main VSI failed: %d\n", ret); |
| 6925 | goto end_core_reset; |
| 6926 | } |
| 6927 | } |
| 6928 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6929 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 6930 | * of TSO, so that we avoid the MDD being fired and causing |
| 6931 | * a reset in the case of small MSS+TSO. |
| 6932 | */ |
| 6933 | #define I40E_REG_MSS 0x000E64DC |
| 6934 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 6935 | #define I40E_64BYTE_MSS 0x400000 |
| 6936 | val = rd32(hw, I40E_REG_MSS); |
| 6937 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 6938 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 6939 | val |= I40E_64BYTE_MSS; |
| 6940 | wr32(hw, I40E_REG_MSS, val); |
| 6941 | } |
| 6942 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 6943 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 6944 | msleep(75); |
| 6945 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 6946 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6947 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 6948 | i40e_stat_str(&pf->hw, ret), |
| 6949 | i40e_aq_str(&pf->hw, |
| 6950 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6951 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6952 | /* reinit the misc interrupt */ |
| 6953 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 6954 | ret = i40e_setup_misc_vector(pf); |
| 6955 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 6956 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 6957 | * transmitted. By doing so we stop a malicious VF from sending out |
| 6958 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 6959 | * PF/VF VSIs. |
| 6960 | * The FW can still send Flow control frames if enabled. |
| 6961 | */ |
| 6962 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 6963 | pf->main_vsi_seid); |
| 6964 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6965 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 6966 | i40e_pf_unquiesce_all_vsi(pf); |
| 6967 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 6968 | if (pf->num_alloc_vfs) { |
| 6969 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 6970 | i40e_reset_vf(&pf->vf[v], true); |
| 6971 | } |
| 6972 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6973 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6974 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6975 | |
| 6976 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6977 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 6978 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6979 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 6980 | } |
| 6981 | |
| 6982 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6983 | * 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] | 6984 | * @pf: board private structure |
| 6985 | * |
| 6986 | * Close up the VFs and other things in prep for a Core Reset, |
| 6987 | * then get ready to rebuild the world. |
| 6988 | **/ |
| 6989 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 6990 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6991 | i40e_prep_for_reset(pf); |
| 6992 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6993 | } |
| 6994 | |
| 6995 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6996 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6997 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6998 | * |
| 6999 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 7000 | **/ |
| 7001 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 7002 | { |
| 7003 | struct i40e_hw *hw = &pf->hw; |
| 7004 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7005 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7006 | struct i40e_vf *vf; |
| 7007 | u32 reg; |
| 7008 | int i; |
| 7009 | |
| 7010 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 7011 | return; |
| 7012 | |
| 7013 | /* find what triggered the MDD event */ |
| 7014 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 7015 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7016 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 7017 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7018 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7019 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7020 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7021 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7022 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 7023 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 7024 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7025 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7026 | 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] | 7027 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7028 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 7029 | mdd_detected = true; |
| 7030 | } |
| 7031 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 7032 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7033 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 7034 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 7035 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 7036 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 7037 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 7038 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 7039 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7040 | if (netif_msg_rx_err(pf)) |
| 7041 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 7042 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7043 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 7044 | mdd_detected = true; |
| 7045 | } |
| 7046 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 7047 | if (mdd_detected) { |
| 7048 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 7049 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 7050 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7051 | 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] | 7052 | pf_mdd_detected = true; |
| 7053 | } |
| 7054 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 7055 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 7056 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7057 | 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] | 7058 | pf_mdd_detected = true; |
| 7059 | } |
| 7060 | /* Queue belongs to the PF, initiate a reset */ |
| 7061 | if (pf_mdd_detected) { |
| 7062 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 7063 | i40e_service_event_schedule(pf); |
| 7064 | } |
| 7065 | } |
| 7066 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7067 | /* see if one of the VFs needs its hand slapped */ |
| 7068 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7069 | vf = &(pf->vf[i]); |
| 7070 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7071 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7072 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7073 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7074 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7075 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7076 | } |
| 7077 | |
| 7078 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7079 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7080 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7081 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7082 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7083 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7084 | } |
| 7085 | |
| 7086 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7087 | dev_info(&pf->pdev->dev, |
| 7088 | "Too many MDD events on VF %d, disabled\n", i); |
| 7089 | dev_info(&pf->pdev->dev, |
| 7090 | "Use PF Control I/F to re-enable the VF\n"); |
| 7091 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 7092 | } |
| 7093 | } |
| 7094 | |
| 7095 | /* re-enable mdd interrupt cause */ |
| 7096 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 7097 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7098 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7099 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7100 | i40e_flush(hw); |
| 7101 | } |
| 7102 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7103 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7104 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7105 | * @pf: board private structure |
| 7106 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7107 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7108 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7109 | #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7110 | struct i40e_hw *hw = &pf->hw; |
| 7111 | i40e_status ret; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7112 | __be16 port; |
| 7113 | int i; |
| 7114 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7115 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7116 | return; |
| 7117 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7118 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7119 | |
| 7120 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7121 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7122 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
| 7123 | port = pf->udp_ports[i].index; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7124 | if (port) |
| 7125 | ret = i40e_aq_add_udp_tunnel(hw, ntohs(port), |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7126 | pf->udp_ports[i].type, |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7127 | NULL, NULL); |
| 7128 | else |
| 7129 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7130 | |
| 7131 | if (ret) { |
Carolyn Wyborny | 730a8f8 | 2016-02-17 16:12:16 -0800 | [diff] [blame] | 7132 | dev_dbg(&pf->pdev->dev, |
| 7133 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 7134 | pf->udp_ports[i].type ? "vxlan" : "geneve", |
| 7135 | port ? "add" : "delete", |
| 7136 | ntohs(port), i, |
| 7137 | i40e_stat_str(&pf->hw, ret), |
| 7138 | i40e_aq_str(&pf->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7139 | pf->hw.aq.asq_last_status)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7140 | pf->udp_ports[i].index = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7141 | } |
| 7142 | } |
| 7143 | } |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7144 | #endif |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7145 | } |
| 7146 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7147 | /** |
| 7148 | * i40e_service_task - Run the driver's async subtasks |
| 7149 | * @work: pointer to work_struct containing our data |
| 7150 | **/ |
| 7151 | static void i40e_service_task(struct work_struct *work) |
| 7152 | { |
| 7153 | struct i40e_pf *pf = container_of(work, |
| 7154 | struct i40e_pf, |
| 7155 | service_task); |
| 7156 | unsigned long start_time = jiffies; |
| 7157 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7158 | /* don't bother with service tasks if a reset is in progress */ |
| 7159 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7160 | i40e_service_event_complete(pf); |
| 7161 | return; |
| 7162 | } |
| 7163 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7164 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 7165 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7166 | i40e_reset_subtask(pf); |
| 7167 | i40e_handle_mdd_event(pf); |
| 7168 | i40e_vc_process_vflr_event(pf); |
| 7169 | i40e_watchdog_subtask(pf); |
| 7170 | i40e_fdir_reinit_subtask(pf); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7171 | i40e_client_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7172 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7173 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7174 | i40e_clean_adminq_subtask(pf); |
| 7175 | |
| 7176 | i40e_service_event_complete(pf); |
| 7177 | |
| 7178 | /* If the tasks have taken longer than one timer cycle or there |
| 7179 | * is more work to be done, reschedule the service task now |
| 7180 | * rather than wait for the timer to tick again. |
| 7181 | */ |
| 7182 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 7183 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 7184 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 7185 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 7186 | i40e_service_event_schedule(pf); |
| 7187 | } |
| 7188 | |
| 7189 | /** |
| 7190 | * i40e_service_timer - timer callback |
| 7191 | * @data: pointer to PF struct |
| 7192 | **/ |
| 7193 | static void i40e_service_timer(unsigned long data) |
| 7194 | { |
| 7195 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7196 | |
| 7197 | mod_timer(&pf->service_timer, |
| 7198 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7199 | i40e_service_event_schedule(pf); |
| 7200 | } |
| 7201 | |
| 7202 | /** |
| 7203 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7204 | * @vsi: the VSI being configured |
| 7205 | **/ |
| 7206 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7207 | { |
| 7208 | struct i40e_pf *pf = vsi->back; |
| 7209 | |
| 7210 | switch (vsi->type) { |
| 7211 | case I40E_VSI_MAIN: |
| 7212 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7213 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7214 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7215 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7216 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7217 | else |
| 7218 | vsi->num_q_vectors = 1; |
| 7219 | |
| 7220 | break; |
| 7221 | |
| 7222 | case I40E_VSI_FDIR: |
| 7223 | vsi->alloc_queue_pairs = 1; |
| 7224 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7225 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7226 | vsi->num_q_vectors = 1; |
| 7227 | break; |
| 7228 | |
| 7229 | case I40E_VSI_VMDQ2: |
| 7230 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7231 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7232 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7233 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7234 | break; |
| 7235 | |
| 7236 | case I40E_VSI_SRIOV: |
| 7237 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7238 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7239 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7240 | break; |
| 7241 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7242 | #ifdef I40E_FCOE |
| 7243 | case I40E_VSI_FCOE: |
| 7244 | vsi->alloc_queue_pairs = pf->num_fcoe_qps; |
| 7245 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7246 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7247 | vsi->num_q_vectors = pf->num_fcoe_msix; |
| 7248 | break; |
| 7249 | |
| 7250 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7251 | default: |
| 7252 | WARN_ON(1); |
| 7253 | return -ENODATA; |
| 7254 | } |
| 7255 | |
| 7256 | return 0; |
| 7257 | } |
| 7258 | |
| 7259 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7260 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7261 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7262 | * @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] | 7263 | * |
| 7264 | * On error: returns error code (negative) |
| 7265 | * On success: returns 0 |
| 7266 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7267 | 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] | 7268 | { |
| 7269 | int size; |
| 7270 | int ret = 0; |
| 7271 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7272 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7273 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 7274 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7275 | if (!vsi->tx_rings) |
| 7276 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7277 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 7278 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7279 | if (alloc_qvectors) { |
| 7280 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7281 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7282 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7283 | if (!vsi->q_vectors) { |
| 7284 | ret = -ENOMEM; |
| 7285 | goto err_vectors; |
| 7286 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7287 | } |
| 7288 | return ret; |
| 7289 | |
| 7290 | err_vectors: |
| 7291 | kfree(vsi->tx_rings); |
| 7292 | return ret; |
| 7293 | } |
| 7294 | |
| 7295 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7296 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7297 | * @pf: board private structure |
| 7298 | * @type: type of VSI |
| 7299 | * |
| 7300 | * On error: returns error code (negative) |
| 7301 | * On success: returns vsi index in PF (positive) |
| 7302 | **/ |
| 7303 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7304 | { |
| 7305 | int ret = -ENODEV; |
| 7306 | struct i40e_vsi *vsi; |
| 7307 | int vsi_idx; |
| 7308 | int i; |
| 7309 | |
| 7310 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7311 | mutex_lock(&pf->switch_mutex); |
| 7312 | |
| 7313 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7314 | * been happening. We can afford to do a quick scan to look |
| 7315 | * for any free VSIs in the list. |
| 7316 | * |
| 7317 | * find next empty vsi slot, looping back around if necessary |
| 7318 | */ |
| 7319 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7320 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7321 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7322 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7323 | i = 0; |
| 7324 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7325 | i++; |
| 7326 | } |
| 7327 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7328 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7329 | vsi_idx = i; /* Found one! */ |
| 7330 | } else { |
| 7331 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7332 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7333 | } |
| 7334 | pf->next_vsi = ++i; |
| 7335 | |
| 7336 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7337 | if (!vsi) { |
| 7338 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7339 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7340 | } |
| 7341 | vsi->type = type; |
| 7342 | vsi->back = pf; |
| 7343 | set_bit(__I40E_DOWN, &vsi->state); |
| 7344 | vsi->flags = 0; |
| 7345 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7346 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7347 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7348 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7349 | vsi->netdev_registered = false; |
| 7350 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
| 7351 | INIT_LIST_HEAD(&vsi->mac_filter_list); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7352 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7353 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7354 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7355 | if (ret) |
| 7356 | goto err_rings; |
| 7357 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7358 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7359 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7360 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7361 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7362 | /* Setup default MSIX irq handler for VSI */ |
| 7363 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7364 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7365 | /* Initialize VSI lock */ |
| 7366 | spin_lock_init(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7367 | pf->vsi[vsi_idx] = vsi; |
| 7368 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7369 | goto unlock_pf; |
| 7370 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7371 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7372 | pf->next_vsi = i - 1; |
| 7373 | kfree(vsi); |
| 7374 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7375 | mutex_unlock(&pf->switch_mutex); |
| 7376 | return ret; |
| 7377 | } |
| 7378 | |
| 7379 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7380 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7381 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7382 | * @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] | 7383 | * |
| 7384 | * On error: returns error code (negative) |
| 7385 | * On success: returns 0 |
| 7386 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7387 | 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] | 7388 | { |
| 7389 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7390 | if (free_qvectors) { |
| 7391 | kfree(vsi->q_vectors); |
| 7392 | vsi->q_vectors = NULL; |
| 7393 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7394 | kfree(vsi->tx_rings); |
| 7395 | vsi->tx_rings = NULL; |
| 7396 | vsi->rx_rings = NULL; |
| 7397 | } |
| 7398 | |
| 7399 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7400 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7401 | * and lookup table |
| 7402 | * @vsi: Pointer to VSI structure |
| 7403 | */ |
| 7404 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7405 | { |
| 7406 | if (!vsi) |
| 7407 | return; |
| 7408 | |
| 7409 | kfree(vsi->rss_hkey_user); |
| 7410 | vsi->rss_hkey_user = NULL; |
| 7411 | |
| 7412 | kfree(vsi->rss_lut_user); |
| 7413 | vsi->rss_lut_user = NULL; |
| 7414 | } |
| 7415 | |
| 7416 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7417 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7418 | * @vsi: the VSI being un-configured |
| 7419 | **/ |
| 7420 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7421 | { |
| 7422 | struct i40e_pf *pf; |
| 7423 | |
| 7424 | if (!vsi) |
| 7425 | return 0; |
| 7426 | |
| 7427 | if (!vsi->back) |
| 7428 | goto free_vsi; |
| 7429 | pf = vsi->back; |
| 7430 | |
| 7431 | mutex_lock(&pf->switch_mutex); |
| 7432 | if (!pf->vsi[vsi->idx]) { |
| 7433 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7434 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7435 | goto unlock_vsi; |
| 7436 | } |
| 7437 | |
| 7438 | if (pf->vsi[vsi->idx] != vsi) { |
| 7439 | dev_err(&pf->pdev->dev, |
| 7440 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7441 | pf->vsi[vsi->idx]->idx, |
| 7442 | pf->vsi[vsi->idx], |
| 7443 | pf->vsi[vsi->idx]->type, |
| 7444 | vsi->idx, vsi, vsi->type); |
| 7445 | goto unlock_vsi; |
| 7446 | } |
| 7447 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7448 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7449 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7450 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7451 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7452 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7453 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7454 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7455 | pf->vsi[vsi->idx] = NULL; |
| 7456 | if (vsi->idx < pf->next_vsi) |
| 7457 | pf->next_vsi = vsi->idx; |
| 7458 | |
| 7459 | unlock_vsi: |
| 7460 | mutex_unlock(&pf->switch_mutex); |
| 7461 | free_vsi: |
| 7462 | kfree(vsi); |
| 7463 | |
| 7464 | return 0; |
| 7465 | } |
| 7466 | |
| 7467 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7468 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7469 | * @vsi: the VSI being cleaned |
| 7470 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7471 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7472 | { |
| 7473 | int i; |
| 7474 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7475 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7476 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7477 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7478 | vsi->tx_rings[i] = NULL; |
| 7479 | vsi->rx_rings[i] = NULL; |
| 7480 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7481 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7482 | } |
| 7483 | |
| 7484 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7485 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7486 | * @vsi: the VSI being configured |
| 7487 | **/ |
| 7488 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7489 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7490 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7491 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7492 | int i; |
| 7493 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7494 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7495 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7496 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7497 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7498 | if (!tx_ring) |
| 7499 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7500 | |
| 7501 | tx_ring->queue_index = i; |
| 7502 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7503 | tx_ring->ring_active = false; |
| 7504 | tx_ring->vsi = vsi; |
| 7505 | tx_ring->netdev = vsi->netdev; |
| 7506 | tx_ring->dev = &pf->pdev->dev; |
| 7507 | tx_ring->count = vsi->num_desc; |
| 7508 | tx_ring->size = 0; |
| 7509 | tx_ring->dcb_tc = 0; |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 7510 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 7511 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7512 | tx_ring->tx_itr_setting = pf->tx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7513 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7514 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7515 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7516 | rx_ring->queue_index = i; |
| 7517 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7518 | rx_ring->ring_active = false; |
| 7519 | rx_ring->vsi = vsi; |
| 7520 | rx_ring->netdev = vsi->netdev; |
| 7521 | rx_ring->dev = &pf->pdev->dev; |
| 7522 | rx_ring->count = vsi->num_desc; |
| 7523 | rx_ring->size = 0; |
| 7524 | rx_ring->dcb_tc = 0; |
| 7525 | if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) |
| 7526 | set_ring_16byte_desc_enabled(rx_ring); |
| 7527 | else |
| 7528 | clear_ring_16byte_desc_enabled(rx_ring); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7529 | rx_ring->rx_itr_setting = pf->rx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7530 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7531 | } |
| 7532 | |
| 7533 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7534 | |
| 7535 | err_out: |
| 7536 | i40e_vsi_clear_rings(vsi); |
| 7537 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7538 | } |
| 7539 | |
| 7540 | /** |
| 7541 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7542 | * @pf: board private structure |
| 7543 | * @vectors: the number of MSI-X vectors to request |
| 7544 | * |
| 7545 | * Returns the number of vectors reserved, or error |
| 7546 | **/ |
| 7547 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7548 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7549 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7550 | I40E_MIN_MSIX, vectors); |
| 7551 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7552 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7553 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7554 | vectors = 0; |
| 7555 | } |
| 7556 | |
| 7557 | return vectors; |
| 7558 | } |
| 7559 | |
| 7560 | /** |
| 7561 | * i40e_init_msix - Setup the MSIX capability |
| 7562 | * @pf: board private structure |
| 7563 | * |
| 7564 | * Work with the OS to set up the MSIX vectors needed. |
| 7565 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7566 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7567 | **/ |
| 7568 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7569 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7570 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7571 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7572 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7573 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7574 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7575 | |
| 7576 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7577 | return -ENODEV; |
| 7578 | |
| 7579 | /* The number of vectors we'll request will be comprised of: |
| 7580 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7581 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7582 | * - Queues being used for RSS. |
| 7583 | * We don't need as many as max_rss_size vectors. |
| 7584 | * use rss_size instead in the calculation since that |
| 7585 | * is governed by number of cpus in the system. |
| 7586 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7587 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7588 | * - The CPU count within the NUMA node if iWARP is enabled |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7589 | #ifdef I40E_FCOE |
| 7590 | * - The number of FCOE qps. |
| 7591 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7592 | * Once we count this up, try the request. |
| 7593 | * |
| 7594 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7595 | * and try again. If that still fails, we punt. |
| 7596 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7597 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7598 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7599 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7600 | /* reserve one vector for miscellaneous handler */ |
| 7601 | if (vectors_left) { |
| 7602 | v_budget++; |
| 7603 | vectors_left--; |
| 7604 | } |
| 7605 | |
| 7606 | /* reserve vectors for the main PF traffic queues */ |
| 7607 | pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left); |
| 7608 | vectors_left -= pf->num_lan_msix; |
| 7609 | v_budget += pf->num_lan_msix; |
| 7610 | |
| 7611 | /* reserve one vector for sideband flow director */ |
| 7612 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7613 | if (vectors_left) { |
| 7614 | v_budget++; |
| 7615 | vectors_left--; |
| 7616 | } else { |
| 7617 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7618 | } |
| 7619 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7620 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7621 | #ifdef I40E_FCOE |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7622 | /* can we reserve enough for FCoE? */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7623 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7624 | if (!vectors_left) |
| 7625 | pf->num_fcoe_msix = 0; |
| 7626 | else if (vectors_left >= pf->num_fcoe_qps) |
| 7627 | pf->num_fcoe_msix = pf->num_fcoe_qps; |
| 7628 | else |
| 7629 | pf->num_fcoe_msix = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7630 | v_budget += pf->num_fcoe_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7631 | vectors_left -= pf->num_fcoe_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7632 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7633 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7634 | #endif |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7635 | /* can we reserve enough for iWARP? */ |
| 7636 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7637 | if (!vectors_left) |
| 7638 | pf->num_iwarp_msix = 0; |
| 7639 | else if (vectors_left < pf->num_iwarp_msix) |
| 7640 | pf->num_iwarp_msix = 1; |
| 7641 | v_budget += pf->num_iwarp_msix; |
| 7642 | vectors_left -= pf->num_iwarp_msix; |
| 7643 | } |
| 7644 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7645 | /* any vectors left over go for VMDq support */ |
| 7646 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7647 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7648 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7649 | |
| 7650 | /* if we're short on vectors for what's desired, we limit |
| 7651 | * the queues per vmdq. If this is still more than are |
| 7652 | * available, the user will need to change the number of |
| 7653 | * queues/vectors used by the PF later with the ethtool |
| 7654 | * channels command |
| 7655 | */ |
| 7656 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7657 | pf->num_vmdq_qps = 1; |
| 7658 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
| 7659 | |
| 7660 | v_budget += vmdq_vecs; |
| 7661 | vectors_left -= vmdq_vecs; |
| 7662 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7663 | |
| 7664 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7665 | GFP_KERNEL); |
| 7666 | if (!pf->msix_entries) |
| 7667 | return -ENOMEM; |
| 7668 | |
| 7669 | for (i = 0; i < v_budget; i++) |
| 7670 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7671 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7672 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7673 | if (v_actual != v_budget) { |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7674 | /* If we have limited resources, we will start with no vectors |
| 7675 | * for the special features and then allocate vectors to some |
| 7676 | * of these features based on the policy and at the end disable |
| 7677 | * the features that did not get any vectors. |
| 7678 | */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7679 | iwarp_requested = pf->num_iwarp_msix; |
| 7680 | pf->num_iwarp_msix = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7681 | #ifdef I40E_FCOE |
| 7682 | pf->num_fcoe_qps = 0; |
| 7683 | pf->num_fcoe_msix = 0; |
| 7684 | #endif |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7685 | pf->num_vmdq_msix = 0; |
| 7686 | } |
| 7687 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7688 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7689 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7690 | kfree(pf->msix_entries); |
| 7691 | pf->msix_entries = NULL; |
| 7692 | return -ENODEV; |
| 7693 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7694 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7695 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7696 | pf->num_vmdq_vsis = 0; |
| 7697 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7698 | pf->num_lan_qps = 1; |
| 7699 | pf->num_lan_msix = 1; |
| 7700 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7701 | } else if (v_actual != v_budget) { |
| 7702 | int vec; |
| 7703 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7704 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7705 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7706 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7707 | /* Scale vector usage down */ |
| 7708 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7709 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7710 | pf->num_vmdq_qps = 1; |
| 7711 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7712 | |
| 7713 | /* partition out the remaining vectors */ |
| 7714 | switch (vec) { |
| 7715 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7716 | pf->num_lan_msix = 1; |
| 7717 | break; |
| 7718 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7719 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7720 | pf->num_lan_msix = 1; |
| 7721 | pf->num_iwarp_msix = 1; |
| 7722 | } else { |
| 7723 | pf->num_lan_msix = 2; |
| 7724 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7725 | #ifdef I40E_FCOE |
| 7726 | /* give one vector to FCoE */ |
| 7727 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7728 | pf->num_lan_msix = 1; |
| 7729 | pf->num_fcoe_msix = 1; |
| 7730 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7731 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7732 | break; |
| 7733 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7734 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7735 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 7736 | iwarp_requested); |
| 7737 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 7738 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7739 | } else { |
| 7740 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 7741 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7742 | } |
| 7743 | pf->num_lan_msix = min_t(int, |
| 7744 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 7745 | pf->num_lan_msix); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7746 | #ifdef I40E_FCOE |
| 7747 | /* give one vector to FCoE */ |
| 7748 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7749 | pf->num_fcoe_msix = 1; |
| 7750 | vec--; |
| 7751 | } |
| 7752 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7753 | break; |
| 7754 | } |
| 7755 | } |
| 7756 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7757 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7758 | (pf->num_vmdq_msix == 0)) { |
| 7759 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 7760 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 7761 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7762 | |
| 7763 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 7764 | (pf->num_iwarp_msix == 0)) { |
| 7765 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 7766 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 7767 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7768 | #ifdef I40E_FCOE |
| 7769 | |
| 7770 | if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { |
| 7771 | dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n"); |
| 7772 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 7773 | } |
| 7774 | #endif |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7775 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7776 | } |
| 7777 | |
| 7778 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7779 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7780 | * @vsi: the VSI being configured |
| 7781 | * @v_idx: index of the vector in the vsi struct |
| 7782 | * |
| 7783 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 7784 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7785 | 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] | 7786 | { |
| 7787 | struct i40e_q_vector *q_vector; |
| 7788 | |
| 7789 | /* allocate q_vector */ |
| 7790 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 7791 | if (!q_vector) |
| 7792 | return -ENOMEM; |
| 7793 | |
| 7794 | q_vector->vsi = vsi; |
| 7795 | q_vector->v_idx = v_idx; |
| 7796 | cpumask_set_cpu(v_idx, &q_vector->affinity_mask); |
| 7797 | if (vsi->netdev) |
| 7798 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 7799 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7800 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 7801 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 7802 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 7803 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7804 | /* tie q_vector and vsi together */ |
| 7805 | vsi->q_vectors[v_idx] = q_vector; |
| 7806 | |
| 7807 | return 0; |
| 7808 | } |
| 7809 | |
| 7810 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7811 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7812 | * @vsi: the VSI being configured |
| 7813 | * |
| 7814 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 7815 | * return -ENOMEM. |
| 7816 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7817 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7818 | { |
| 7819 | struct i40e_pf *pf = vsi->back; |
| 7820 | int v_idx, num_q_vectors; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7821 | int err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7822 | |
| 7823 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 7824 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7825 | num_q_vectors = vsi->num_q_vectors; |
| 7826 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 7827 | num_q_vectors = 1; |
| 7828 | else |
| 7829 | return -EINVAL; |
| 7830 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7831 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7832 | err = i40e_vsi_alloc_q_vector(vsi, v_idx); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7833 | if (err) |
| 7834 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7835 | } |
| 7836 | |
| 7837 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7838 | |
| 7839 | err_out: |
| 7840 | while (v_idx--) |
| 7841 | i40e_free_q_vector(vsi, v_idx); |
| 7842 | |
| 7843 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7844 | } |
| 7845 | |
| 7846 | /** |
| 7847 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 7848 | * @pf: board private structure to initialize |
| 7849 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7850 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7851 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7852 | int vectors = 0; |
| 7853 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7854 | |
| 7855 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7856 | vectors = i40e_init_msix(pf); |
| 7857 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7858 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7859 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7860 | #ifdef I40E_FCOE |
| 7861 | I40E_FLAG_FCOE_ENABLED | |
| 7862 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7863 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7864 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7865 | I40E_FLAG_SRIOV_ENABLED | |
| 7866 | I40E_FLAG_FD_SB_ENABLED | |
| 7867 | I40E_FLAG_FD_ATR_ENABLED | |
| 7868 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7869 | |
| 7870 | /* rework the queue expectations without MSIX */ |
| 7871 | i40e_determine_queue_usage(pf); |
| 7872 | } |
| 7873 | } |
| 7874 | |
| 7875 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 7876 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7877 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7878 | vectors = pci_enable_msi(pf->pdev); |
| 7879 | if (vectors < 0) { |
| 7880 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 7881 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7882 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 7883 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7884 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7885 | } |
| 7886 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 7887 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7888 | 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] | 7889 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7890 | /* set up vector assignment tracking */ |
| 7891 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 7892 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7893 | if (!pf->irq_pile) { |
| 7894 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 7895 | return -ENOMEM; |
| 7896 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7897 | pf->irq_pile->num_entries = vectors; |
| 7898 | pf->irq_pile->search_hint = 0; |
| 7899 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7900 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7901 | (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] | 7902 | |
| 7903 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7904 | } |
| 7905 | |
| 7906 | /** |
| 7907 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 7908 | * @pf: board private structure |
| 7909 | * |
| 7910 | * This sets up the handler for MSIX 0, which is used to manage the |
| 7911 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 7912 | * when in MSI or Legacy interrupt mode. |
| 7913 | **/ |
| 7914 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 7915 | { |
| 7916 | struct i40e_hw *hw = &pf->hw; |
| 7917 | int err = 0; |
| 7918 | |
| 7919 | /* Only request the irq if this is the first time through, and |
| 7920 | * not when we're rebuilding after a Reset |
| 7921 | */ |
| 7922 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7923 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7924 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7925 | if (err) { |
| 7926 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7927 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7928 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7929 | return -EFAULT; |
| 7930 | } |
| 7931 | } |
| 7932 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 7933 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7934 | |
| 7935 | /* associate no queues to the misc vector */ |
| 7936 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 7937 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 7938 | |
| 7939 | i40e_flush(hw); |
| 7940 | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 7941 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7942 | |
| 7943 | return err; |
| 7944 | } |
| 7945 | |
| 7946 | /** |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7947 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 7948 | * @vsi: vsi structure |
| 7949 | * @seed: RSS hash seed |
| 7950 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7951 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 7952 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7953 | { |
| 7954 | struct i40e_aqc_get_set_rss_key_data rss_key; |
| 7955 | struct i40e_pf *pf = vsi->back; |
| 7956 | struct i40e_hw *hw = &pf->hw; |
| 7957 | bool pf_lut = false; |
| 7958 | u8 *rss_lut; |
| 7959 | int ret, i; |
| 7960 | |
| 7961 | memset(&rss_key, 0, sizeof(rss_key)); |
| 7962 | memcpy(&rss_key, seed, sizeof(rss_key)); |
| 7963 | |
| 7964 | rss_lut = kzalloc(pf->rss_table_size, GFP_KERNEL); |
| 7965 | if (!rss_lut) |
| 7966 | return -ENOMEM; |
| 7967 | |
| 7968 | /* Populate the LUT with max no. of queues in round robin fashion */ |
| 7969 | for (i = 0; i < vsi->rss_table_size; i++) |
| 7970 | rss_lut[i] = i % vsi->rss_size; |
| 7971 | |
| 7972 | ret = i40e_aq_set_rss_key(hw, vsi->id, &rss_key); |
| 7973 | if (ret) { |
| 7974 | dev_info(&pf->pdev->dev, |
| 7975 | "Cannot set RSS key, err %s aq_err %s\n", |
| 7976 | i40e_stat_str(&pf->hw, ret), |
| 7977 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai | 126b63d | 2015-08-24 13:26:53 -0700 | [diff] [blame] | 7978 | goto config_rss_aq_out; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7979 | } |
| 7980 | |
| 7981 | if (vsi->type == I40E_VSI_MAIN) |
| 7982 | pf_lut = true; |
| 7983 | |
| 7984 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, rss_lut, |
| 7985 | vsi->rss_table_size); |
| 7986 | if (ret) |
| 7987 | dev_info(&pf->pdev->dev, |
| 7988 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 7989 | i40e_stat_str(&pf->hw, ret), |
| 7990 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 7991 | |
Anjali Singhai | 126b63d | 2015-08-24 13:26:53 -0700 | [diff] [blame] | 7992 | config_rss_aq_out: |
| 7993 | kfree(rss_lut); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7994 | return ret; |
| 7995 | } |
| 7996 | |
| 7997 | /** |
| 7998 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 7999 | * @vsi: VSI structure |
| 8000 | **/ |
| 8001 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 8002 | { |
| 8003 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 8004 | struct i40e_pf *pf = vsi->back; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8005 | u8 *lut; |
| 8006 | int ret; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8007 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8008 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) |
| 8009 | return 0; |
| 8010 | |
| 8011 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8012 | if (!lut) |
| 8013 | return -ENOMEM; |
| 8014 | |
| 8015 | 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] | 8016 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8017 | 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] | 8018 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 8019 | kfree(lut); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8020 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8021 | return ret; |
| 8022 | } |
| 8023 | |
| 8024 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8025 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 8026 | * @vsi: Pointer to vsi structure |
| 8027 | * @seed: Buffter to store the hash keys |
| 8028 | * @lut: Buffer to store the lookup table entries |
| 8029 | * @lut_size: Size of buffer to store the lookup table entries |
| 8030 | * |
| 8031 | * Return 0 on success, negative on failure |
| 8032 | */ |
| 8033 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 8034 | u8 *lut, u16 lut_size) |
| 8035 | { |
| 8036 | struct i40e_pf *pf = vsi->back; |
| 8037 | struct i40e_hw *hw = &pf->hw; |
| 8038 | int ret = 0; |
| 8039 | |
| 8040 | if (seed) { |
| 8041 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 8042 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 8043 | if (ret) { |
| 8044 | dev_info(&pf->pdev->dev, |
| 8045 | "Cannot get RSS key, err %s aq_err %s\n", |
| 8046 | i40e_stat_str(&pf->hw, ret), |
| 8047 | i40e_aq_str(&pf->hw, |
| 8048 | pf->hw.aq.asq_last_status)); |
| 8049 | return ret; |
| 8050 | } |
| 8051 | } |
| 8052 | |
| 8053 | if (lut) { |
| 8054 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 8055 | |
| 8056 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 8057 | if (ret) { |
| 8058 | dev_info(&pf->pdev->dev, |
| 8059 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 8060 | i40e_stat_str(&pf->hw, ret), |
| 8061 | i40e_aq_str(&pf->hw, |
| 8062 | pf->hw.aq.asq_last_status)); |
| 8063 | return ret; |
| 8064 | } |
| 8065 | } |
| 8066 | |
| 8067 | return ret; |
| 8068 | } |
| 8069 | |
| 8070 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8071 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8072 | * @vsi: Pointer to vsi structure |
| 8073 | * @seed: RSS hash seed |
| 8074 | * @lut: Lookup table |
| 8075 | * @lut_size: Lookup table size |
| 8076 | * |
| 8077 | * Returns 0 on success, negative on failure |
| 8078 | **/ |
| 8079 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8080 | const u8 *lut, u16 lut_size) |
| 8081 | { |
| 8082 | struct i40e_pf *pf = vsi->back; |
| 8083 | struct i40e_hw *hw = &pf->hw; |
| 8084 | u8 i; |
| 8085 | |
| 8086 | /* Fill out hash function seed */ |
| 8087 | if (seed) { |
| 8088 | u32 *seed_dw = (u32 *)seed; |
| 8089 | |
| 8090 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8091 | i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), seed_dw[i]); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8092 | } |
| 8093 | |
| 8094 | if (lut) { |
| 8095 | u32 *lut_dw = (u32 *)lut; |
| 8096 | |
| 8097 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8098 | return -EINVAL; |
| 8099 | |
| 8100 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8101 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8102 | } |
| 8103 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8104 | |
| 8105 | return 0; |
| 8106 | } |
| 8107 | |
| 8108 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8109 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8110 | * @vsi: Pointer to VSI structure |
| 8111 | * @seed: Buffer to store the keys |
| 8112 | * @lut: Buffer to store the lookup table entries |
| 8113 | * @lut_size: Size of buffer to store the lookup table entries |
| 8114 | * |
| 8115 | * Returns 0 on success, negative on failure |
| 8116 | */ |
| 8117 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8118 | u8 *lut, u16 lut_size) |
| 8119 | { |
| 8120 | struct i40e_pf *pf = vsi->back; |
| 8121 | struct i40e_hw *hw = &pf->hw; |
| 8122 | u16 i; |
| 8123 | |
| 8124 | if (seed) { |
| 8125 | u32 *seed_dw = (u32 *)seed; |
| 8126 | |
| 8127 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8128 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8129 | } |
| 8130 | if (lut) { |
| 8131 | u32 *lut_dw = (u32 *)lut; |
| 8132 | |
| 8133 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8134 | return -EINVAL; |
| 8135 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8136 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8137 | } |
| 8138 | |
| 8139 | return 0; |
| 8140 | } |
| 8141 | |
| 8142 | /** |
| 8143 | * i40e_config_rss - Configure RSS keys and lut |
| 8144 | * @vsi: Pointer to VSI structure |
| 8145 | * @seed: RSS hash seed |
| 8146 | * @lut: Lookup table |
| 8147 | * @lut_size: Lookup table size |
| 8148 | * |
| 8149 | * Returns 0 on success, negative on failure |
| 8150 | */ |
| 8151 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8152 | { |
| 8153 | struct i40e_pf *pf = vsi->back; |
| 8154 | |
| 8155 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8156 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8157 | else |
| 8158 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8159 | } |
| 8160 | |
| 8161 | /** |
| 8162 | * i40e_get_rss - Get RSS keys and lut |
| 8163 | * @vsi: Pointer to VSI structure |
| 8164 | * @seed: Buffer to store the keys |
| 8165 | * @lut: Buffer to store the lookup table entries |
| 8166 | * lut_size: Size of buffer to store the lookup table entries |
| 8167 | * |
| 8168 | * Returns 0 on success, negative on failure |
| 8169 | */ |
| 8170 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8171 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8172 | struct i40e_pf *pf = vsi->back; |
| 8173 | |
| 8174 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8175 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8176 | else |
| 8177 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8178 | } |
| 8179 | |
| 8180 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8181 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8182 | * @pf: Pointer to board private structure |
| 8183 | * @lut: Lookup table |
| 8184 | * @rss_table_size: Lookup table size |
| 8185 | * @rss_size: Range of queue number for hashing |
| 8186 | */ |
| 8187 | static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8188 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8189 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8190 | u16 i; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8191 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8192 | for (i = 0; i < rss_table_size; i++) |
| 8193 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8194 | } |
| 8195 | |
| 8196 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8197 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8198 | * @pf: board private structure |
| 8199 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8200 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8201 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8202 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8203 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8204 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8205 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8206 | u32 reg_val; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8207 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8208 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8209 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8210 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8211 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 8212 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8213 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8214 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8215 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8216 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8217 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8218 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8219 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8220 | reg_val = (pf->rss_table_size == 512) ? |
| 8221 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8222 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8223 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8224 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8225 | /* Determine the RSS size of the VSI */ |
| 8226 | if (!vsi->rss_size) |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8227 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8228 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8229 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8230 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8231 | if (!lut) |
| 8232 | return -ENOMEM; |
| 8233 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8234 | /* Use user configured lut if there is one, otherwise use default */ |
| 8235 | if (vsi->rss_lut_user) |
| 8236 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8237 | else |
| 8238 | 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] | 8239 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8240 | /* Use user configured hash key if there is one, otherwise |
| 8241 | * use default. |
| 8242 | */ |
| 8243 | if (vsi->rss_hkey_user) |
| 8244 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8245 | else |
| 8246 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8247 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8248 | kfree(lut); |
| 8249 | |
| 8250 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8251 | } |
| 8252 | |
| 8253 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8254 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8255 | * @pf: board private structure |
| 8256 | * @queue_count: the requested queue count for rss. |
| 8257 | * |
| 8258 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8259 | * count which may be different from the requested queue count. |
| 8260 | **/ |
| 8261 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8262 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8263 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8264 | int new_rss_size; |
| 8265 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8266 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8267 | return 0; |
| 8268 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8269 | 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] | 8270 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8271 | if (queue_count != vsi->num_queue_pairs) { |
| 8272 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8273 | i40e_prep_for_reset(pf); |
| 8274 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8275 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8276 | |
| 8277 | i40e_reset_and_rebuild(pf, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8278 | |
| 8279 | /* Discard the user configured hash keys and lut, if less |
| 8280 | * queues are enabled. |
| 8281 | */ |
| 8282 | if (queue_count < vsi->rss_size) { |
| 8283 | i40e_clear_rss_config_user(vsi); |
| 8284 | dev_dbg(&pf->pdev->dev, |
| 8285 | "discard user configured hash keys and lut\n"); |
| 8286 | } |
| 8287 | |
| 8288 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8289 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8290 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8291 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8292 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8293 | } |
Helin Zhang | e36b0b1 | 2015-10-26 19:44:36 -0400 | [diff] [blame] | 8294 | dev_info(&pf->pdev->dev, "RSS count/HW max RSS count: %d/%d\n", |
| 8295 | pf->alloc_rss_size, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8296 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8297 | } |
| 8298 | |
| 8299 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8300 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 8301 | * @pf: board private structure |
| 8302 | **/ |
| 8303 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 8304 | { |
| 8305 | i40e_status status; |
| 8306 | bool min_valid, max_valid; |
| 8307 | u32 max_bw, min_bw; |
| 8308 | |
| 8309 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8310 | &min_valid, &max_valid); |
| 8311 | |
| 8312 | if (!status) { |
| 8313 | if (min_valid) |
| 8314 | pf->npar_min_bw = min_bw; |
| 8315 | if (max_valid) |
| 8316 | pf->npar_max_bw = max_bw; |
| 8317 | } |
| 8318 | |
| 8319 | return status; |
| 8320 | } |
| 8321 | |
| 8322 | /** |
| 8323 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 8324 | * @pf: board private structure |
| 8325 | **/ |
| 8326 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 8327 | { |
| 8328 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8329 | i40e_status status; |
| 8330 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8331 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8332 | 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] | 8333 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8334 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 8335 | |
| 8336 | /* Set the new bandwidths */ |
| 8337 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8338 | |
| 8339 | return status; |
| 8340 | } |
| 8341 | |
| 8342 | /** |
| 8343 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 8344 | * @pf: board private structure |
| 8345 | **/ |
| 8346 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 8347 | { |
| 8348 | /* Commit temporary BW setting to permanent NVM image */ |
| 8349 | enum i40e_admin_queue_err last_aq_status; |
| 8350 | i40e_status ret; |
| 8351 | u16 nvm_word; |
| 8352 | |
| 8353 | if (pf->hw.partition_id != 1) { |
| 8354 | dev_info(&pf->pdev->dev, |
| 8355 | "Commit BW only works on partition 1! This is partition %d", |
| 8356 | pf->hw.partition_id); |
| 8357 | ret = I40E_NOT_SUPPORTED; |
| 8358 | goto bw_commit_out; |
| 8359 | } |
| 8360 | |
| 8361 | /* Acquire NVM for read access */ |
| 8362 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8363 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8364 | if (ret) { |
| 8365 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8366 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8367 | i40e_stat_str(&pf->hw, ret), |
| 8368 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8369 | goto bw_commit_out; |
| 8370 | } |
| 8371 | |
| 8372 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8373 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8374 | I40E_SR_NVM_CONTROL_WORD, |
| 8375 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8376 | false, NULL); |
| 8377 | /* Save off last admin queue command status before releasing |
| 8378 | * the NVM |
| 8379 | */ |
| 8380 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8381 | i40e_release_nvm(&pf->hw); |
| 8382 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8383 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8384 | i40e_stat_str(&pf->hw, ret), |
| 8385 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8386 | goto bw_commit_out; |
| 8387 | } |
| 8388 | |
| 8389 | /* Wait a bit for NVM release to complete */ |
| 8390 | msleep(50); |
| 8391 | |
| 8392 | /* Acquire NVM for write access */ |
| 8393 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8394 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8395 | if (ret) { |
| 8396 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8397 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8398 | i40e_stat_str(&pf->hw, ret), |
| 8399 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8400 | goto bw_commit_out; |
| 8401 | } |
| 8402 | /* Write it back out unchanged to initiate update NVM, |
| 8403 | * which will force a write of the shadow (alt) RAM to |
| 8404 | * the NVM - thus storing the bandwidth values permanently. |
| 8405 | */ |
| 8406 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8407 | I40E_SR_NVM_CONTROL_WORD, |
| 8408 | 0x10, sizeof(nvm_word), |
| 8409 | &nvm_word, true, NULL); |
| 8410 | /* Save off last admin queue command status before releasing |
| 8411 | * the NVM |
| 8412 | */ |
| 8413 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8414 | i40e_release_nvm(&pf->hw); |
| 8415 | if (ret) |
| 8416 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8417 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8418 | i40e_stat_str(&pf->hw, ret), |
| 8419 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8420 | bw_commit_out: |
| 8421 | |
| 8422 | return ret; |
| 8423 | } |
| 8424 | |
| 8425 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8426 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8427 | * @pf: board private structure to initialize |
| 8428 | * |
| 8429 | * i40e_sw_init initializes the Adapter private data structure. |
| 8430 | * Fields are initialized based on PCI device information and |
| 8431 | * OS network device settings (MTU size). |
| 8432 | **/ |
| 8433 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8434 | { |
| 8435 | int err = 0; |
| 8436 | int size; |
| 8437 | |
| 8438 | pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, |
| 8439 | (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); |
Shannon Nelson | 2759997 | 2013-11-16 10:00:43 +0000 | [diff] [blame] | 8440 | pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8441 | if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { |
| 8442 | if (I40E_DEBUG_USER & debug) |
| 8443 | pf->hw.debug_mask = debug; |
| 8444 | pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), |
| 8445 | I40E_DEFAULT_MSG_ENABLE); |
| 8446 | } |
| 8447 | |
| 8448 | /* Set default capability flags */ |
| 8449 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8450 | I40E_FLAG_MSI_ENABLED | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 8451 | I40E_FLAG_LINK_POLLING_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8452 | I40E_FLAG_MSIX_ENABLED; |
| 8453 | |
| 8454 | if (iommu_present(&pci_bus_type)) |
| 8455 | pf->flags |= I40E_FLAG_RX_PS_ENABLED; |
| 8456 | else |
| 8457 | pf->flags |= I40E_FLAG_RX_1BUF_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8458 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8459 | /* Set default ITR */ |
| 8460 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8461 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8462 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8463 | /* Depending on PF configurations, it is possible that the RSS |
| 8464 | * maximum might end up larger than the available queues |
| 8465 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8466 | 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] | 8467 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8468 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8469 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8470 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8471 | if (pf->hw.func_caps.rss) { |
| 8472 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8473 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8474 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8475 | } |
| 8476 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8477 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8478 | 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] | 8479 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8480 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8481 | if (i40e_get_npar_bw_setting(pf)) |
| 8482 | dev_warn(&pf->pdev->dev, |
| 8483 | "Could not get NPAR bw settings\n"); |
| 8484 | else |
| 8485 | dev_info(&pf->pdev->dev, |
| 8486 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 8487 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8488 | } |
| 8489 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8490 | /* FW/NVM is not yet fixed in this regard */ |
| 8491 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8492 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8493 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8494 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8495 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8496 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8497 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8498 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8499 | else |
| 8500 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8501 | pf->fdir_pf_filter_count = |
| 8502 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8503 | pf->hw.fdir_shared_filter_count = |
| 8504 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8505 | } |
| 8506 | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8507 | if (i40e_is_mac_710(&pf->hw) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8508 | (((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] | 8509 | (pf->hw.aq.fw_maj_ver < 4))) { |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8510 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8511 | /* No DCB support for FW < v4.33 */ |
| 8512 | pf->flags |= I40E_FLAG_NO_DCB_SUPPORT; |
| 8513 | } |
| 8514 | |
| 8515 | /* Disable FW LLDP if FW < v4.3 */ |
| 8516 | if (i40e_is_mac_710(&pf->hw) && |
| 8517 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 8518 | (pf->hw.aq.fw_maj_ver < 4))) |
| 8519 | pf->flags |= I40E_FLAG_STOP_FW_LLDP; |
| 8520 | |
| 8521 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
| 8522 | if (i40e_is_mac_710(&pf->hw) && |
| 8523 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 8524 | (pf->hw.aq.fw_maj_ver >= 5))) |
| 8525 | pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8526 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8527 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8528 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8529 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 8530 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8531 | } |
| 8532 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8533 | if (pf->hw.func_caps.iwarp) { |
| 8534 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 8535 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 8536 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 8537 | } |
| 8538 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8539 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 8540 | i40e_init_pf_fcoe(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8541 | |
| 8542 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8543 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 8544 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8545 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 8546 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 8547 | pf->num_req_vfs = min_t(int, |
| 8548 | pf->hw.func_caps.num_vfs, |
| 8549 | I40E_MAX_VF_COUNT); |
| 8550 | } |
| 8551 | #endif /* CONFIG_PCI_IOV */ |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8552 | if (pf->hw.mac.type == I40E_MAC_X722) { |
| 8553 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE | |
| 8554 | I40E_FLAG_128_QP_RSS_CAPABLE | |
| 8555 | I40E_FLAG_HW_ATR_EVICT_CAPABLE | |
| 8556 | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE | |
| 8557 | I40E_FLAG_WB_ON_ITR_CAPABLE | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8558 | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
Catherine Sullivan | f8db54cc | 2015-12-22 14:25:14 -0800 | [diff] [blame] | 8559 | I40E_FLAG_100M_SGMII_CAPABLE | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8560 | I40E_FLAG_USE_SET_LLDP_MIB | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8561 | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8562 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 8563 | ((pf->hw.aq.api_maj_ver == 1) && |
| 8564 | (pf->hw.aq.api_min_ver > 4))) { |
| 8565 | /* Supported in FW API version higher than 1.4 */ |
| 8566 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 8567 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
| 8568 | } else { |
| 8569 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8570 | } |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8571 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8572 | pf->eeprom_version = 0xDEAD; |
| 8573 | pf->lan_veb = I40E_NO_VEB; |
| 8574 | pf->lan_vsi = I40E_NO_VSI; |
| 8575 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 8576 | /* By default FW has this off for performance reasons */ |
| 8577 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 8578 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8579 | /* set up queue assignment tracking */ |
| 8580 | size = sizeof(struct i40e_lump_tracking) |
| 8581 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 8582 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 8583 | if (!pf->qp_pile) { |
| 8584 | err = -ENOMEM; |
| 8585 | goto sw_init_done; |
| 8586 | } |
| 8587 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 8588 | pf->qp_pile->search_hint = 0; |
| 8589 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 8590 | pf->tx_timeout_recovery_level = 1; |
| 8591 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8592 | mutex_init(&pf->switch_mutex); |
| 8593 | |
Greg Rose | c668a12 | 2015-02-26 16:10:39 +0000 | [diff] [blame] | 8594 | /* If NPAR is enabled nudge the Tx scheduler */ |
| 8595 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) |
| 8596 | i40e_set_npar_bw_setting(pf); |
| 8597 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8598 | sw_init_done: |
| 8599 | return err; |
| 8600 | } |
| 8601 | |
| 8602 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8603 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 8604 | * @pf: board private structure to initialize |
| 8605 | * @features: the feature set that the stack is suggesting |
| 8606 | * |
| 8607 | * returns a bool to indicate if reset needs to happen |
| 8608 | **/ |
| 8609 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 8610 | { |
| 8611 | bool need_reset = false; |
| 8612 | |
| 8613 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 8614 | * the state changed, we need to reset. |
| 8615 | */ |
| 8616 | if (features & NETIF_F_NTUPLE) { |
| 8617 | /* Enable filters and mark for reset */ |
| 8618 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 8619 | need_reset = true; |
| 8620 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
| 8621 | } else { |
| 8622 | /* turn off filters, mark for reset and clear SW filter list */ |
| 8623 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8624 | need_reset = true; |
| 8625 | i40e_fdir_filter_exit(pf); |
| 8626 | } |
| 8627 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8628 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 8629 | /* reset fd counters */ |
| 8630 | pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0; |
| 8631 | pf->fdir_pf_active_filters = 0; |
| 8632 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 8633 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 8634 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8635 | /* if ATR was auto disabled it can be re-enabled. */ |
| 8636 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 8637 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 8638 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8639 | } |
| 8640 | return need_reset; |
| 8641 | } |
| 8642 | |
| 8643 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8644 | * i40e_set_features - set the netdev feature flags |
| 8645 | * @netdev: ptr to the netdev being adjusted |
| 8646 | * @features: the feature set that the stack is suggesting |
| 8647 | **/ |
| 8648 | static int i40e_set_features(struct net_device *netdev, |
| 8649 | netdev_features_t features) |
| 8650 | { |
| 8651 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8652 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8653 | struct i40e_pf *pf = vsi->back; |
| 8654 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8655 | |
| 8656 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8657 | i40e_vlan_stripping_enable(vsi); |
| 8658 | else |
| 8659 | i40e_vlan_stripping_disable(vsi); |
| 8660 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8661 | need_reset = i40e_set_ntuple(pf, features); |
| 8662 | |
| 8663 | if (need_reset) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8664 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8665 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8666 | return 0; |
| 8667 | } |
| 8668 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8669 | #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8670 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8671 | * 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] | 8672 | * @pf: board private structure |
| 8673 | * @port: The UDP port to look up |
| 8674 | * |
| 8675 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 8676 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8677 | 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] | 8678 | { |
| 8679 | u8 i; |
| 8680 | |
| 8681 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8682 | if (pf->udp_ports[i].index == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8683 | return i; |
| 8684 | } |
| 8685 | |
| 8686 | return i; |
| 8687 | } |
| 8688 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8689 | #endif |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8690 | |
| 8691 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8692 | /** |
| 8693 | * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up |
| 8694 | * @netdev: This physical port's netdev |
| 8695 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 8696 | * @port: New UDP port number that VXLAN started listening to |
| 8697 | **/ |
| 8698 | static void i40e_add_vxlan_port(struct net_device *netdev, |
| 8699 | sa_family_t sa_family, __be16 port) |
| 8700 | { |
| 8701 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8702 | struct i40e_vsi *vsi = np->vsi; |
| 8703 | struct i40e_pf *pf = vsi->back; |
| 8704 | u8 next_idx; |
| 8705 | u8 idx; |
| 8706 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8707 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8708 | |
| 8709 | /* Check if port already exists */ |
| 8710 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8711 | netdev_info(netdev, "vxlan port %d already offloaded\n", |
| 8712 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8713 | return; |
| 8714 | } |
| 8715 | |
| 8716 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8717 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8718 | |
| 8719 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8720 | 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] | 8721 | ntohs(port)); |
| 8722 | return; |
| 8723 | } |
| 8724 | |
| 8725 | /* New port: add it and mark its index in the bitmap */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8726 | pf->udp_ports[next_idx].index = port; |
| 8727 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 8728 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8729 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8730 | } |
| 8731 | |
| 8732 | /** |
| 8733 | * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away |
| 8734 | * @netdev: This physical port's netdev |
| 8735 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 8736 | * @port: UDP port number that VXLAN stopped listening to |
| 8737 | **/ |
| 8738 | static void i40e_del_vxlan_port(struct net_device *netdev, |
| 8739 | sa_family_t sa_family, __be16 port) |
| 8740 | { |
| 8741 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8742 | struct i40e_vsi *vsi = np->vsi; |
| 8743 | struct i40e_pf *pf = vsi->back; |
| 8744 | u8 idx; |
| 8745 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8746 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8747 | |
| 8748 | /* Check if port already exists */ |
| 8749 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8750 | /* if port exists, set it to 0 (mark for deletion) |
| 8751 | * and make it pending |
| 8752 | */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8753 | pf->udp_ports[idx].index = 0; |
| 8754 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
| 8755 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8756 | } else { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8757 | netdev_warn(netdev, "vxlan port %d was not found, not deleting\n", |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8758 | ntohs(port)); |
| 8759 | } |
| 8760 | } |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8761 | #endif |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8762 | |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8763 | #if IS_ENABLED(CONFIG_GENEVE) |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8764 | /** |
| 8765 | * i40e_add_geneve_port - Get notifications about GENEVE ports that come up |
| 8766 | * @netdev: This physical port's netdev |
| 8767 | * @sa_family: Socket Family that GENEVE is notifying us about |
| 8768 | * @port: New UDP port number that GENEVE started listening to |
| 8769 | **/ |
| 8770 | static void i40e_add_geneve_port(struct net_device *netdev, |
| 8771 | sa_family_t sa_family, __be16 port) |
| 8772 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8773 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8774 | struct i40e_vsi *vsi = np->vsi; |
| 8775 | struct i40e_pf *pf = vsi->back; |
| 8776 | u8 next_idx; |
| 8777 | u8 idx; |
| 8778 | |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8779 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8780 | return; |
| 8781 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8782 | idx = i40e_get_udp_port_idx(pf, port); |
| 8783 | |
| 8784 | /* Check if port already exists */ |
| 8785 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8786 | netdev_info(netdev, "udp port %d already offloaded\n", |
| 8787 | ntohs(port)); |
| 8788 | return; |
| 8789 | } |
| 8790 | |
| 8791 | /* Now check if there is space to add the new port */ |
| 8792 | next_idx = i40e_get_udp_port_idx(pf, 0); |
| 8793 | |
| 8794 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8795 | netdev_info(netdev, "maximum number of UDP ports reached, not adding port %d\n", |
| 8796 | ntohs(port)); |
| 8797 | return; |
| 8798 | } |
| 8799 | |
| 8800 | /* New port: add it and mark its index in the bitmap */ |
| 8801 | pf->udp_ports[next_idx].index = port; |
| 8802 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 8803 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8804 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8805 | |
| 8806 | dev_info(&pf->pdev->dev, "adding geneve port %d\n", ntohs(port)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8807 | } |
| 8808 | |
| 8809 | /** |
| 8810 | * i40e_del_geneve_port - Get notifications about GENEVE ports that go away |
| 8811 | * @netdev: This physical port's netdev |
| 8812 | * @sa_family: Socket Family that GENEVE is notifying us about |
| 8813 | * @port: UDP port number that GENEVE stopped listening to |
| 8814 | **/ |
| 8815 | static void i40e_del_geneve_port(struct net_device *netdev, |
| 8816 | sa_family_t sa_family, __be16 port) |
| 8817 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8818 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8819 | struct i40e_vsi *vsi = np->vsi; |
| 8820 | struct i40e_pf *pf = vsi->back; |
| 8821 | u8 idx; |
| 8822 | |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8823 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8824 | return; |
| 8825 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8826 | idx = i40e_get_udp_port_idx(pf, port); |
| 8827 | |
| 8828 | /* Check if port already exists */ |
| 8829 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8830 | /* if port exists, set it to 0 (mark for deletion) |
| 8831 | * and make it pending |
| 8832 | */ |
| 8833 | pf->udp_ports[idx].index = 0; |
| 8834 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
| 8835 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8836 | |
| 8837 | dev_info(&pf->pdev->dev, "deleting geneve port %d\n", |
| 8838 | ntohs(port)); |
| 8839 | } else { |
| 8840 | netdev_warn(netdev, "geneve port %d was not found, not deleting\n", |
| 8841 | ntohs(port)); |
| 8842 | } |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8843 | } |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8844 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8845 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8846 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 8847 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8848 | { |
| 8849 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8850 | struct i40e_pf *pf = np->vsi->back; |
| 8851 | struct i40e_hw *hw = &pf->hw; |
| 8852 | |
| 8853 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 8854 | return -EOPNOTSUPP; |
| 8855 | |
| 8856 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 8857 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 8858 | |
| 8859 | return 0; |
| 8860 | } |
| 8861 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 8862 | /** |
| 8863 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 8864 | * @ndm: the input from the stack |
| 8865 | * @tb: pointer to array of nladdr (unused) |
| 8866 | * @dev: the net device pointer |
| 8867 | * @addr: the MAC address entry being added |
| 8868 | * @flags: instructions from stack about fdb operation |
| 8869 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8870 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 8871 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8872 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8873 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8874 | { |
| 8875 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8876 | struct i40e_pf *pf = np->vsi->back; |
| 8877 | int err = 0; |
| 8878 | |
| 8879 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 8880 | return -EOPNOTSUPP; |
| 8881 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 8882 | if (vid) { |
| 8883 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 8884 | return -EINVAL; |
| 8885 | } |
| 8886 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8887 | /* Hardware does not support aging addresses so if a |
| 8888 | * ndm_state is given only allow permanent addresses |
| 8889 | */ |
| 8890 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 8891 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 8892 | return -EINVAL; |
| 8893 | } |
| 8894 | |
| 8895 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 8896 | err = dev_uc_add_excl(dev, addr); |
| 8897 | else if (is_multicast_ether_addr(addr)) |
| 8898 | err = dev_mc_add_excl(dev, addr); |
| 8899 | else |
| 8900 | err = -EINVAL; |
| 8901 | |
| 8902 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 8903 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 8904 | err = 0; |
| 8905 | |
| 8906 | return err; |
| 8907 | } |
| 8908 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8909 | /** |
| 8910 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 8911 | * @dev: the netdev being configured |
| 8912 | * @nlh: RTNL message |
| 8913 | * |
| 8914 | * Inserts a new hardware bridge if not already created and |
| 8915 | * enables the bridging mode requested (VEB or VEPA). If the |
| 8916 | * hardware bridge has already been inserted and the request |
| 8917 | * is to change the mode then that requires a PF reset to |
| 8918 | * allow rebuild of the components with required hardware |
| 8919 | * bridge mode enabled. |
| 8920 | **/ |
| 8921 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 8922 | struct nlmsghdr *nlh, |
| 8923 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8924 | { |
| 8925 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8926 | struct i40e_vsi *vsi = np->vsi; |
| 8927 | struct i40e_pf *pf = vsi->back; |
| 8928 | struct i40e_veb *veb = NULL; |
| 8929 | struct nlattr *attr, *br_spec; |
| 8930 | int i, rem; |
| 8931 | |
| 8932 | /* Only for PF VSI for now */ |
| 8933 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8934 | return -EOPNOTSUPP; |
| 8935 | |
| 8936 | /* Find the HW bridge for PF VSI */ |
| 8937 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8938 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8939 | veb = pf->veb[i]; |
| 8940 | } |
| 8941 | |
| 8942 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 8943 | |
| 8944 | nla_for_each_nested(attr, br_spec, rem) { |
| 8945 | __u16 mode; |
| 8946 | |
| 8947 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 8948 | continue; |
| 8949 | |
| 8950 | mode = nla_get_u16(attr); |
| 8951 | if ((mode != BRIDGE_MODE_VEPA) && |
| 8952 | (mode != BRIDGE_MODE_VEB)) |
| 8953 | return -EINVAL; |
| 8954 | |
| 8955 | /* Insert a new HW bridge */ |
| 8956 | if (!veb) { |
| 8957 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 8958 | vsi->tc_config.enabled_tc); |
| 8959 | if (veb) { |
| 8960 | veb->bridge_mode = mode; |
| 8961 | i40e_config_bridge_mode(veb); |
| 8962 | } else { |
| 8963 | /* No Bridge HW offload available */ |
| 8964 | return -ENOENT; |
| 8965 | } |
| 8966 | break; |
| 8967 | } else if (mode != veb->bridge_mode) { |
| 8968 | /* Existing HW bridge but different mode needs reset */ |
| 8969 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 8970 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 8971 | if (mode == BRIDGE_MODE_VEB) |
| 8972 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 8973 | else |
| 8974 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 8975 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8976 | break; |
| 8977 | } |
| 8978 | } |
| 8979 | |
| 8980 | return 0; |
| 8981 | } |
| 8982 | |
| 8983 | /** |
| 8984 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 8985 | * @skb: skb buff |
| 8986 | * @pid: process id |
| 8987 | * @seq: RTNL message seq # |
| 8988 | * @dev: the netdev being configured |
| 8989 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 8990 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8991 | * |
| 8992 | * Return the mode in which the hardware bridge is operating in |
| 8993 | * i.e VEB or VEPA. |
| 8994 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8995 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 8996 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 8997 | u32 __always_unused filter_mask, |
| 8998 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8999 | { |
| 9000 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 9001 | struct i40e_vsi *vsi = np->vsi; |
| 9002 | struct i40e_pf *pf = vsi->back; |
| 9003 | struct i40e_veb *veb = NULL; |
| 9004 | int i; |
| 9005 | |
| 9006 | /* Only for PF VSI for now */ |
| 9007 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 9008 | return -EOPNOTSUPP; |
| 9009 | |
| 9010 | /* Find the HW bridge for the PF VSI */ |
| 9011 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9012 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9013 | veb = pf->veb[i]; |
| 9014 | } |
| 9015 | |
| 9016 | if (!veb) |
| 9017 | return 0; |
| 9018 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9019 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 9020 | nlflags, 0, 0, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9021 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9022 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9023 | /* Hardware supports L4 tunnel length of 128B (=2^7) which includes |
| 9024 | * inner mac plus all inner ethertypes. |
| 9025 | */ |
| 9026 | #define I40E_MAX_TUNNEL_HDR_LEN 128 |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9027 | /** |
| 9028 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 9029 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 9030 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9031 | * @features: Offload features that the stack believes apply |
| 9032 | **/ |
| 9033 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 9034 | struct net_device *dev, |
| 9035 | netdev_features_t features) |
| 9036 | { |
| 9037 | if (skb->encapsulation && |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9038 | ((skb_inner_network_header(skb) - skb_transport_header(skb)) > |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9039 | I40E_MAX_TUNNEL_HDR_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 9040 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9041 | |
| 9042 | return features; |
| 9043 | } |
| 9044 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 9045 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9046 | .ndo_open = i40e_open, |
| 9047 | .ndo_stop = i40e_close, |
| 9048 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 9049 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 9050 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 9051 | .ndo_validate_addr = eth_validate_addr, |
| 9052 | .ndo_set_mac_address = i40e_set_mac, |
| 9053 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 9054 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9055 | .ndo_tx_timeout = i40e_tx_timeout, |
| 9056 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 9057 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 9058 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 9059 | .ndo_poll_controller = i40e_netpoll, |
| 9060 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9061 | .ndo_setup_tc = __i40e_setup_tc, |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9062 | #ifdef I40E_FCOE |
| 9063 | .ndo_fcoe_enable = i40e_fcoe_enable, |
| 9064 | .ndo_fcoe_disable = i40e_fcoe_disable, |
| 9065 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9066 | .ndo_set_features = i40e_set_features, |
| 9067 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 9068 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 9069 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9070 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 9071 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 9072 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9073 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 9074 | .ndo_add_vxlan_port = i40e_add_vxlan_port, |
| 9075 | .ndo_del_vxlan_port = i40e_del_vxlan_port, |
| 9076 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 9077 | #if IS_ENABLED(CONFIG_GENEVE) |
| 9078 | .ndo_add_geneve_port = i40e_add_geneve_port, |
| 9079 | .ndo_del_geneve_port = i40e_del_geneve_port, |
| 9080 | #endif |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9081 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 9082 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 9083 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9084 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 9085 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9086 | }; |
| 9087 | |
| 9088 | /** |
| 9089 | * i40e_config_netdev - Setup the netdev flags |
| 9090 | * @vsi: the VSI being configured |
| 9091 | * |
| 9092 | * Returns 0 on success, negative value on failure |
| 9093 | **/ |
| 9094 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 9095 | { |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 9096 | u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9097 | struct i40e_pf *pf = vsi->back; |
| 9098 | struct i40e_hw *hw = &pf->hw; |
| 9099 | struct i40e_netdev_priv *np; |
| 9100 | struct net_device *netdev; |
| 9101 | u8 mac_addr[ETH_ALEN]; |
| 9102 | int etherdev_size; |
| 9103 | |
| 9104 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9105 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9106 | if (!netdev) |
| 9107 | return -ENOMEM; |
| 9108 | |
| 9109 | vsi->netdev = netdev; |
| 9110 | np = netdev_priv(netdev); |
| 9111 | np->vsi = vsi; |
| 9112 | |
Alexander Duyck | bc5d252 | 2016-01-24 21:17:50 -0800 | [diff] [blame] | 9113 | netdev->hw_enc_features |= NETIF_F_IP_CSUM | |
| 9114 | NETIF_F_IPV6_CSUM | |
| 9115 | NETIF_F_TSO | |
| 9116 | NETIF_F_TSO6 | |
| 9117 | NETIF_F_TSO_ECN | |
| 9118 | NETIF_F_GSO_GRE | |
| 9119 | NETIF_F_GSO_UDP_TUNNEL | |
| 9120 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
Jesse Brandeburg | 5afdaaa | 2015-12-10 11:38:50 -0800 | [diff] [blame] | 9121 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9122 | |
| 9123 | netdev->features = NETIF_F_SG | |
| 9124 | NETIF_F_IP_CSUM | |
Tom Herbert | 53692b1 | 2015-12-14 11:19:41 -0800 | [diff] [blame] | 9125 | NETIF_F_SCTP_CRC | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9126 | NETIF_F_HIGHDMA | |
| 9127 | NETIF_F_GSO_UDP_TUNNEL | |
Jesse Brandeburg | fec31ff | 2015-10-01 18:25:42 -0700 | [diff] [blame] | 9128 | NETIF_F_GSO_GRE | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9129 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9130 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9131 | NETIF_F_HW_VLAN_CTAG_FILTER | |
| 9132 | NETIF_F_IPV6_CSUM | |
| 9133 | NETIF_F_TSO | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 9134 | NETIF_F_TSO_ECN | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9135 | NETIF_F_TSO6 | |
| 9136 | NETIF_F_RXCSUM | |
| 9137 | NETIF_F_RXHASH | |
| 9138 | 0; |
| 9139 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9140 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 9141 | netdev->features |= NETIF_F_NTUPLE; |
Alexander Duyck | bc5d252 | 2016-01-24 21:17:50 -0800 | [diff] [blame] | 9142 | if (pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE) |
| 9143 | netdev->features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9144 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9145 | /* copy netdev features into list of user selectable features */ |
| 9146 | netdev->hw_features |= netdev->features; |
| 9147 | |
| 9148 | if (vsi->type == I40E_VSI_MAIN) { |
| 9149 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9150 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9151 | /* The following steps are necessary to prevent reception |
| 9152 | * of tagged packets - some older NVM configurations load a |
| 9153 | * default a MAC-VLAN filter that accepts any tagged packet |
| 9154 | * which must be replaced by a normal filter. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 9155 | */ |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9156 | if (!i40e_rm_default_mac_filter(vsi, mac_addr)) { |
| 9157 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9158 | i40e_add_filter(vsi, mac_addr, |
| 9159 | I40E_VLAN_ANY, false, true); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9160 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9161 | } |
Anjali Singhai Jain | 3845cce | 2016-03-18 12:18:05 -0700 | [diff] [blame] | 9162 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 9163 | ((pf->hw.aq.api_maj_ver == 1) && |
| 9164 | (pf->hw.aq.api_min_ver > 4))) { |
| 9165 | /* Supported in FW API version higher than 1.4 */ |
| 9166 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
| 9167 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9168 | } else { |
| 9169 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 9170 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 9171 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9172 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9173 | |
| 9174 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9175 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9176 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9177 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9178 | |
| 9179 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 9180 | i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9181 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9182 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9183 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9184 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9185 | /* vlan gets same features (except vlan offload) |
| 9186 | * after any tweaks for specific VSI types |
| 9187 | */ |
| 9188 | netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX | |
| 9189 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9190 | NETIF_F_HW_VLAN_CTAG_FILTER); |
| 9191 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9192 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9193 | /* Setup netdev TC information */ |
| 9194 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9195 | |
| 9196 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9197 | netdev->watchdog_timeo = 5 * HZ; |
| 9198 | i40e_set_ethtool_ops(netdev); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9199 | #ifdef I40E_FCOE |
| 9200 | i40e_fcoe_config_netdev(netdev, vsi); |
| 9201 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9202 | |
| 9203 | return 0; |
| 9204 | } |
| 9205 | |
| 9206 | /** |
| 9207 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9208 | * @vsi: the VSI being removed |
| 9209 | * |
| 9210 | * Returns 0 on success, negative value on failure |
| 9211 | **/ |
| 9212 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9213 | { |
| 9214 | /* remove default VSI is not allowed */ |
| 9215 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9216 | return; |
| 9217 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9218 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9219 | } |
| 9220 | |
| 9221 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9222 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9223 | * @vsi: the VSI being queried |
| 9224 | * |
| 9225 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9226 | **/ |
| 9227 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9228 | { |
| 9229 | struct i40e_veb *veb; |
| 9230 | struct i40e_pf *pf = vsi->back; |
| 9231 | |
| 9232 | /* Uplink is not a bridge so default to VEB */ |
| 9233 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9234 | return 1; |
| 9235 | |
| 9236 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9237 | if (!veb) { |
| 9238 | dev_info(&pf->pdev->dev, |
| 9239 | "There is no veb associated with the bridge\n"); |
| 9240 | return -ENOENT; |
| 9241 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9242 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9243 | /* Uplink is a bridge in VEPA mode */ |
| 9244 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9245 | return 0; |
| 9246 | } else { |
| 9247 | /* Uplink is a bridge in VEB mode */ |
| 9248 | return 1; |
| 9249 | } |
| 9250 | |
| 9251 | /* VEPA is now default bridge, so return 0 */ |
| 9252 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9253 | } |
| 9254 | |
| 9255 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9256 | * i40e_add_vsi - Add a VSI to the switch |
| 9257 | * @vsi: the VSI being configured |
| 9258 | * |
| 9259 | * This initializes a VSI context depending on the VSI type to be added and |
| 9260 | * passes it down to the add_vsi aq command. |
| 9261 | **/ |
| 9262 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9263 | { |
| 9264 | int ret = -ENODEV; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9265 | u8 laa_macaddr[ETH_ALEN]; |
| 9266 | bool found_laa_mac_filter = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9267 | struct i40e_pf *pf = vsi->back; |
| 9268 | struct i40e_hw *hw = &pf->hw; |
| 9269 | struct i40e_vsi_context ctxt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9270 | struct i40e_mac_filter *f, *ftmp; |
| 9271 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9272 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9273 | int f_count = 0; |
| 9274 | |
| 9275 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9276 | switch (vsi->type) { |
| 9277 | case I40E_VSI_MAIN: |
| 9278 | /* The PF's main VSI is already setup as part of the |
| 9279 | * device initialization, so we'll not bother with |
| 9280 | * the add_vsi call, but we will retrieve the current |
| 9281 | * VSI context. |
| 9282 | */ |
| 9283 | ctxt.seid = pf->main_vsi_seid; |
| 9284 | ctxt.pf_num = pf->hw.pf_id; |
| 9285 | ctxt.vf_num = 0; |
| 9286 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9287 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9288 | if (ret) { |
| 9289 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9290 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9291 | i40e_stat_str(&pf->hw, ret), |
| 9292 | i40e_aq_str(&pf->hw, |
| 9293 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9294 | return -ENOENT; |
| 9295 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9296 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9297 | vsi->info.valid_sections = 0; |
| 9298 | |
| 9299 | vsi->seid = ctxt.seid; |
| 9300 | vsi->id = ctxt.vsi_number; |
| 9301 | |
| 9302 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9303 | |
| 9304 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9305 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9306 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9307 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9308 | ctxt.seid = pf->main_vsi_seid; |
| 9309 | ctxt.pf_num = pf->hw.pf_id; |
| 9310 | ctxt.vf_num = 0; |
| 9311 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9312 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9313 | if (ret) { |
| 9314 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9315 | "update vsi failed, err %s aq_err %s\n", |
| 9316 | i40e_stat_str(&pf->hw, ret), |
| 9317 | i40e_aq_str(&pf->hw, |
| 9318 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9319 | ret = -ENOENT; |
| 9320 | goto err; |
| 9321 | } |
| 9322 | /* update the local VSI info queue map */ |
| 9323 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9324 | vsi->info.valid_sections = 0; |
| 9325 | } else { |
| 9326 | /* Default/Main VSI is only enabled for TC0 |
| 9327 | * reconfigure it to enable all TCs that are |
| 9328 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9329 | * For MFP case the iSCSI PF would use this |
| 9330 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9331 | */ |
| 9332 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9333 | if (ret) { |
| 9334 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9335 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9336 | enabled_tc, |
| 9337 | i40e_stat_str(&pf->hw, ret), |
| 9338 | i40e_aq_str(&pf->hw, |
| 9339 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9340 | ret = -ENOENT; |
| 9341 | } |
| 9342 | } |
| 9343 | break; |
| 9344 | |
| 9345 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9346 | ctxt.pf_num = hw->pf_id; |
| 9347 | ctxt.vf_num = 0; |
| 9348 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9349 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9350 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9351 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9352 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9353 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9354 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9355 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9356 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9357 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9358 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9359 | break; |
| 9360 | |
| 9361 | case I40E_VSI_VMDQ2: |
| 9362 | ctxt.pf_num = hw->pf_id; |
| 9363 | ctxt.vf_num = 0; |
| 9364 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9365 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9366 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9367 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9368 | /* This VSI is connected to VEB so the switch_id |
| 9369 | * should be set to zero by default. |
| 9370 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9371 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9372 | ctxt.info.valid_sections |= |
| 9373 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9374 | ctxt.info.switch_id = |
| 9375 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9376 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9377 | |
| 9378 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9379 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9380 | break; |
| 9381 | |
| 9382 | case I40E_VSI_SRIOV: |
| 9383 | ctxt.pf_num = hw->pf_id; |
| 9384 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9385 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9386 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9387 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9388 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9389 | /* This VSI is connected to VEB so the switch_id |
| 9390 | * should be set to zero by default. |
| 9391 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9392 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9393 | ctxt.info.valid_sections |= |
| 9394 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9395 | ctxt.info.switch_id = |
| 9396 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9397 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9398 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9399 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9400 | ctxt.info.valid_sections |= |
| 9401 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 9402 | ctxt.info.queueing_opt_flags |= |
| 9403 | I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 9404 | } |
| 9405 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9406 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9407 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9408 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9409 | ctxt.info.valid_sections |= |
| 9410 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9411 | ctxt.info.sec_flags |= |
| 9412 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9413 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9414 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9415 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9416 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9417 | break; |
| 9418 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9419 | #ifdef I40E_FCOE |
| 9420 | case I40E_VSI_FCOE: |
| 9421 | ret = i40e_fcoe_vsi_init(vsi, &ctxt); |
| 9422 | if (ret) { |
| 9423 | dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n"); |
| 9424 | return ret; |
| 9425 | } |
| 9426 | break; |
| 9427 | |
| 9428 | #endif /* I40E_FCOE */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9429 | case I40E_VSI_IWARP: |
| 9430 | /* send down message to iWARP */ |
| 9431 | break; |
| 9432 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9433 | default: |
| 9434 | return -ENODEV; |
| 9435 | } |
| 9436 | |
| 9437 | if (vsi->type != I40E_VSI_MAIN) { |
| 9438 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9439 | if (ret) { |
| 9440 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9441 | "add vsi failed, err %s aq_err %s\n", |
| 9442 | i40e_stat_str(&pf->hw, ret), |
| 9443 | i40e_aq_str(&pf->hw, |
| 9444 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9445 | ret = -ENOENT; |
| 9446 | goto err; |
| 9447 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9448 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9449 | vsi->info.valid_sections = 0; |
| 9450 | vsi->seid = ctxt.seid; |
| 9451 | vsi->id = ctxt.vsi_number; |
| 9452 | } |
| 9453 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9454 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9455 | /* If macvlan filters already exist, force them to get loaded */ |
| 9456 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 9457 | f->changed = true; |
| 9458 | f_count++; |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9459 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9460 | /* Expected to have only one MAC filter entry for LAA in list */ |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9461 | if (f->is_laa && vsi->type == I40E_VSI_MAIN) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9462 | ether_addr_copy(laa_macaddr, f->macaddr); |
| 9463 | found_laa_mac_filter = true; |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9464 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9465 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9466 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9467 | |
| 9468 | if (found_laa_mac_filter) { |
| 9469 | struct i40e_aqc_remove_macvlan_element_data element; |
| 9470 | |
| 9471 | memset(&element, 0, sizeof(element)); |
| 9472 | ether_addr_copy(element.mac_addr, laa_macaddr); |
| 9473 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 9474 | ret = i40e_aq_remove_macvlan(hw, vsi->seid, |
| 9475 | &element, 1, NULL); |
| 9476 | if (ret) { |
| 9477 | /* some older FW has a different default */ |
| 9478 | element.flags |= |
| 9479 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
| 9480 | i40e_aq_remove_macvlan(hw, vsi->seid, |
| 9481 | &element, 1, NULL); |
| 9482 | } |
| 9483 | |
| 9484 | i40e_aq_mac_address_write(hw, |
| 9485 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 9486 | laa_macaddr, NULL); |
| 9487 | } |
| 9488 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9489 | if (f_count) { |
| 9490 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 9491 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 9492 | } |
| 9493 | |
| 9494 | /* Update VSI BW information */ |
| 9495 | ret = i40e_vsi_get_bw_info(vsi); |
| 9496 | if (ret) { |
| 9497 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9498 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 9499 | i40e_stat_str(&pf->hw, ret), |
| 9500 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9501 | /* VSI is already added so not tearing that up */ |
| 9502 | ret = 0; |
| 9503 | } |
| 9504 | |
| 9505 | err: |
| 9506 | return ret; |
| 9507 | } |
| 9508 | |
| 9509 | /** |
| 9510 | * i40e_vsi_release - Delete a VSI and free its resources |
| 9511 | * @vsi: the VSI being removed |
| 9512 | * |
| 9513 | * Returns 0 on success or < 0 on error |
| 9514 | **/ |
| 9515 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 9516 | { |
| 9517 | struct i40e_mac_filter *f, *ftmp; |
| 9518 | struct i40e_veb *veb = NULL; |
| 9519 | struct i40e_pf *pf; |
| 9520 | u16 uplink_seid; |
| 9521 | int i, n; |
| 9522 | |
| 9523 | pf = vsi->back; |
| 9524 | |
| 9525 | /* release of a VEB-owner or last VSI is not allowed */ |
| 9526 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 9527 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 9528 | vsi->seid, vsi->uplink_seid); |
| 9529 | return -ENODEV; |
| 9530 | } |
| 9531 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 9532 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 9533 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 9534 | return -ENODEV; |
| 9535 | } |
| 9536 | |
| 9537 | uplink_seid = vsi->uplink_seid; |
| 9538 | if (vsi->type != I40E_VSI_SRIOV) { |
| 9539 | if (vsi->netdev_registered) { |
| 9540 | vsi->netdev_registered = false; |
| 9541 | if (vsi->netdev) { |
| 9542 | /* results in a call to i40e_close() */ |
| 9543 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9544 | } |
| 9545 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 9546 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9547 | } |
| 9548 | i40e_vsi_disable_irq(vsi); |
| 9549 | } |
| 9550 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9551 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9552 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
| 9553 | i40e_del_filter(vsi, f->macaddr, f->vlan, |
| 9554 | f->is_vf, f->is_netdev); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9555 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9556 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 9557 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9558 | |
| 9559 | i40e_vsi_delete(vsi); |
| 9560 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 9561 | if (vsi->netdev) { |
| 9562 | free_netdev(vsi->netdev); |
| 9563 | vsi->netdev = NULL; |
| 9564 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9565 | i40e_vsi_clear_rings(vsi); |
| 9566 | i40e_vsi_clear(vsi); |
| 9567 | |
| 9568 | /* If this was the last thing on the VEB, except for the |
| 9569 | * controlling VSI, remove the VEB, which puts the controlling |
| 9570 | * VSI onto the next level down in the switch. |
| 9571 | * |
| 9572 | * Well, okay, there's one more exception here: don't remove |
| 9573 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 9574 | * from up the network stack. |
| 9575 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9576 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9577 | if (pf->vsi[i] && |
| 9578 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 9579 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9580 | n++; /* count the VSIs */ |
| 9581 | } |
| 9582 | } |
| 9583 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9584 | if (!pf->veb[i]) |
| 9585 | continue; |
| 9586 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 9587 | n++; /* count the VEBs */ |
| 9588 | if (pf->veb[i]->seid == uplink_seid) |
| 9589 | veb = pf->veb[i]; |
| 9590 | } |
| 9591 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 9592 | i40e_veb_release(veb); |
| 9593 | |
| 9594 | return 0; |
| 9595 | } |
| 9596 | |
| 9597 | /** |
| 9598 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 9599 | * @vsi: ptr to the VSI |
| 9600 | * |
| 9601 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 9602 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 9603 | * newly allocated VSI. |
| 9604 | * |
| 9605 | * Returns 0 on success or negative on failure |
| 9606 | **/ |
| 9607 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 9608 | { |
| 9609 | int ret = -ENOENT; |
| 9610 | struct i40e_pf *pf = vsi->back; |
| 9611 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9612 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9613 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 9614 | vsi->seid); |
| 9615 | return -EEXIST; |
| 9616 | } |
| 9617 | |
| 9618 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 9619 | 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] | 9620 | vsi->seid, vsi->base_vector); |
| 9621 | return -EEXIST; |
| 9622 | } |
| 9623 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9624 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9625 | if (ret) { |
| 9626 | dev_info(&pf->pdev->dev, |
| 9627 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 9628 | vsi->num_q_vectors, vsi->seid, ret); |
| 9629 | vsi->num_q_vectors = 0; |
| 9630 | goto vector_setup_out; |
| 9631 | } |
| 9632 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 9633 | /* In Legacy mode, we do not have to get any other vector since we |
| 9634 | * piggyback on the misc/ICR0 for queue interrupts. |
| 9635 | */ |
| 9636 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9637 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9638 | if (vsi->num_q_vectors) |
| 9639 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 9640 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9641 | if (vsi->base_vector < 0) { |
| 9642 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9643 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 9644 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9645 | i40e_vsi_free_q_vectors(vsi); |
| 9646 | ret = -ENOENT; |
| 9647 | goto vector_setup_out; |
| 9648 | } |
| 9649 | |
| 9650 | vector_setup_out: |
| 9651 | return ret; |
| 9652 | } |
| 9653 | |
| 9654 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9655 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 9656 | * @vsi: pointer to the vsi. |
| 9657 | * |
| 9658 | * This re-allocates a vsi's queue resources. |
| 9659 | * |
| 9660 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 9661 | * on success, otherwise returns NULL on failure. |
| 9662 | **/ |
| 9663 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 9664 | { |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9665 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9666 | u8 enabled_tc; |
| 9667 | int ret; |
| 9668 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9669 | if (!vsi) |
| 9670 | return NULL; |
| 9671 | |
| 9672 | pf = vsi->back; |
| 9673 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9674 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9675 | i40e_vsi_clear_rings(vsi); |
| 9676 | |
| 9677 | i40e_vsi_free_arrays(vsi, false); |
| 9678 | i40e_set_num_rings_in_vsi(vsi); |
| 9679 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 9680 | if (ret) |
| 9681 | goto err_vsi; |
| 9682 | |
| 9683 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 9684 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9685 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9686 | "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] | 9687 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9688 | goto err_vsi; |
| 9689 | } |
| 9690 | vsi->base_queue = ret; |
| 9691 | |
| 9692 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 9693 | * layout configurations. |
| 9694 | */ |
| 9695 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9696 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9697 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9698 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 9699 | |
| 9700 | /* assign it some queues */ |
| 9701 | ret = i40e_alloc_rings(vsi); |
| 9702 | if (ret) |
| 9703 | goto err_rings; |
| 9704 | |
| 9705 | /* map all of the rings to the q_vectors */ |
| 9706 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9707 | return vsi; |
| 9708 | |
| 9709 | err_rings: |
| 9710 | i40e_vsi_free_q_vectors(vsi); |
| 9711 | if (vsi->netdev_registered) { |
| 9712 | vsi->netdev_registered = false; |
| 9713 | unregister_netdev(vsi->netdev); |
| 9714 | free_netdev(vsi->netdev); |
| 9715 | vsi->netdev = NULL; |
| 9716 | } |
| 9717 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9718 | err_vsi: |
| 9719 | i40e_vsi_clear(vsi); |
| 9720 | return NULL; |
| 9721 | } |
| 9722 | |
| 9723 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9724 | * i40e_macaddr_init - explicitly write the mac address filters. |
| 9725 | * |
| 9726 | * @vsi: pointer to the vsi. |
| 9727 | * @macaddr: the MAC address |
| 9728 | * |
| 9729 | * This is needed when the macaddr has been obtained by other |
| 9730 | * means than the default, e.g., from Open Firmware or IDPROM. |
| 9731 | * Returns 0 on success, negative on failure |
| 9732 | **/ |
| 9733 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) |
| 9734 | { |
| 9735 | int ret; |
| 9736 | struct i40e_aqc_add_macvlan_element_data element; |
| 9737 | |
| 9738 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 9739 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 9740 | macaddr, NULL); |
| 9741 | if (ret) { |
| 9742 | dev_info(&vsi->back->pdev->dev, |
| 9743 | "Addr change for VSI failed: %d\n", ret); |
| 9744 | return -EADDRNOTAVAIL; |
| 9745 | } |
| 9746 | |
| 9747 | memset(&element, 0, sizeof(element)); |
| 9748 | ether_addr_copy(element.mac_addr, macaddr); |
| 9749 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 9750 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); |
| 9751 | if (ret) { |
| 9752 | dev_info(&vsi->back->pdev->dev, |
| 9753 | "add filter failed err %s aq_err %s\n", |
| 9754 | i40e_stat_str(&vsi->back->hw, ret), |
| 9755 | i40e_aq_str(&vsi->back->hw, |
| 9756 | vsi->back->hw.aq.asq_last_status)); |
| 9757 | } |
| 9758 | return ret; |
| 9759 | } |
| 9760 | |
| 9761 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9762 | * i40e_vsi_setup - Set up a VSI by a given type |
| 9763 | * @pf: board private structure |
| 9764 | * @type: VSI type |
| 9765 | * @uplink_seid: the switch element to link to |
| 9766 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 9767 | * |
| 9768 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 9769 | * to the identified VEB. |
| 9770 | * |
| 9771 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 9772 | * success, otherwise returns NULL on failure. |
| 9773 | **/ |
| 9774 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 9775 | u16 uplink_seid, u32 param1) |
| 9776 | { |
| 9777 | struct i40e_vsi *vsi = NULL; |
| 9778 | struct i40e_veb *veb = NULL; |
| 9779 | int ret, i; |
| 9780 | int v_idx; |
| 9781 | |
| 9782 | /* The requested uplink_seid must be either |
| 9783 | * - the PF's port seid |
| 9784 | * no VEB is needed because this is the PF |
| 9785 | * or this is a Flow Director special case VSI |
| 9786 | * - seid of an existing VEB |
| 9787 | * - seid of a VSI that owns an existing VEB |
| 9788 | * - seid of a VSI that doesn't own a VEB |
| 9789 | * a new VEB is created and the VSI becomes the owner |
| 9790 | * - seid of the PF VSI, which is what creates the first VEB |
| 9791 | * this is a special case of the previous |
| 9792 | * |
| 9793 | * Find which uplink_seid we were given and create a new VEB if needed |
| 9794 | */ |
| 9795 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9796 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 9797 | veb = pf->veb[i]; |
| 9798 | break; |
| 9799 | } |
| 9800 | } |
| 9801 | |
| 9802 | if (!veb && uplink_seid != pf->mac_seid) { |
| 9803 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9804 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9805 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 9806 | vsi = pf->vsi[i]; |
| 9807 | break; |
| 9808 | } |
| 9809 | } |
| 9810 | if (!vsi) { |
| 9811 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 9812 | uplink_seid); |
| 9813 | return NULL; |
| 9814 | } |
| 9815 | |
| 9816 | if (vsi->uplink_seid == pf->mac_seid) |
| 9817 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 9818 | vsi->tc_config.enabled_tc); |
| 9819 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 9820 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9821 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9822 | if (veb) { |
| 9823 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 9824 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 9825 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9826 | return NULL; |
| 9827 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 9828 | /* We come up by default in VEPA mode if SRIOV is not |
| 9829 | * already enabled, in which case we can't force VEPA |
| 9830 | * mode. |
| 9831 | */ |
| 9832 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 9833 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 9834 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9835 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9836 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9837 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9838 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9839 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9840 | veb = pf->veb[i]; |
| 9841 | } |
| 9842 | if (!veb) { |
| 9843 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 9844 | return NULL; |
| 9845 | } |
| 9846 | |
| 9847 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 9848 | uplink_seid = veb->seid; |
| 9849 | } |
| 9850 | |
| 9851 | /* get vsi sw struct */ |
| 9852 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 9853 | if (v_idx < 0) |
| 9854 | goto err_alloc; |
| 9855 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9856 | if (!vsi) |
| 9857 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9858 | vsi->type = type; |
| 9859 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 9860 | |
| 9861 | if (type == I40E_VSI_MAIN) |
| 9862 | pf->lan_vsi = v_idx; |
| 9863 | else if (type == I40E_VSI_SRIOV) |
| 9864 | vsi->vf_id = param1; |
| 9865 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9866 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 9867 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9868 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9869 | dev_info(&pf->pdev->dev, |
| 9870 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 9871 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9872 | goto err_vsi; |
| 9873 | } |
| 9874 | vsi->base_queue = ret; |
| 9875 | |
| 9876 | /* get a VSI from the hardware */ |
| 9877 | vsi->uplink_seid = uplink_seid; |
| 9878 | ret = i40e_add_vsi(vsi); |
| 9879 | if (ret) |
| 9880 | goto err_vsi; |
| 9881 | |
| 9882 | switch (vsi->type) { |
| 9883 | /* setup the netdev if needed */ |
| 9884 | case I40E_VSI_MAIN: |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9885 | /* Apply relevant filters if a platform-specific mac |
| 9886 | * address was selected. |
| 9887 | */ |
| 9888 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 9889 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 9890 | if (ret) { |
| 9891 | dev_warn(&pf->pdev->dev, |
| 9892 | "could not set up macaddr; err %d\n", |
| 9893 | ret); |
| 9894 | } |
| 9895 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9896 | case I40E_VSI_VMDQ2: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9897 | case I40E_VSI_FCOE: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9898 | ret = i40e_config_netdev(vsi); |
| 9899 | if (ret) |
| 9900 | goto err_netdev; |
| 9901 | ret = register_netdev(vsi->netdev); |
| 9902 | if (ret) |
| 9903 | goto err_netdev; |
| 9904 | vsi->netdev_registered = true; |
| 9905 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9906 | #ifdef CONFIG_I40E_DCB |
| 9907 | /* Setup DCB netlink interface */ |
| 9908 | i40e_dcbnl_setup(vsi); |
| 9909 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9910 | /* fall through */ |
| 9911 | |
| 9912 | case I40E_VSI_FDIR: |
| 9913 | /* set up vectors and rings if needed */ |
| 9914 | ret = i40e_vsi_setup_vectors(vsi); |
| 9915 | if (ret) |
| 9916 | goto err_msix; |
| 9917 | |
| 9918 | ret = i40e_alloc_rings(vsi); |
| 9919 | if (ret) |
| 9920 | goto err_rings; |
| 9921 | |
| 9922 | /* map all of the rings to the q_vectors */ |
| 9923 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9924 | |
| 9925 | i40e_vsi_reset_stats(vsi); |
| 9926 | break; |
| 9927 | |
| 9928 | default: |
| 9929 | /* no netdev or rings for the other VSI types */ |
| 9930 | break; |
| 9931 | } |
| 9932 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9933 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
| 9934 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 9935 | ret = i40e_vsi_config_rss(vsi); |
| 9936 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9937 | return vsi; |
| 9938 | |
| 9939 | err_rings: |
| 9940 | i40e_vsi_free_q_vectors(vsi); |
| 9941 | err_msix: |
| 9942 | if (vsi->netdev_registered) { |
| 9943 | vsi->netdev_registered = false; |
| 9944 | unregister_netdev(vsi->netdev); |
| 9945 | free_netdev(vsi->netdev); |
| 9946 | vsi->netdev = NULL; |
| 9947 | } |
| 9948 | err_netdev: |
| 9949 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9950 | err_vsi: |
| 9951 | i40e_vsi_clear(vsi); |
| 9952 | err_alloc: |
| 9953 | return NULL; |
| 9954 | } |
| 9955 | |
| 9956 | /** |
| 9957 | * i40e_veb_get_bw_info - Query VEB BW information |
| 9958 | * @veb: the veb to query |
| 9959 | * |
| 9960 | * Query the Tx scheduler BW configuration data for given VEB |
| 9961 | **/ |
| 9962 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 9963 | { |
| 9964 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 9965 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 9966 | struct i40e_pf *pf = veb->pf; |
| 9967 | struct i40e_hw *hw = &pf->hw; |
| 9968 | u32 tc_bw_max; |
| 9969 | int ret = 0; |
| 9970 | int i; |
| 9971 | |
| 9972 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 9973 | &bw_data, NULL); |
| 9974 | if (ret) { |
| 9975 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9976 | "query veb bw config failed, err %s aq_err %s\n", |
| 9977 | i40e_stat_str(&pf->hw, ret), |
| 9978 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9979 | goto out; |
| 9980 | } |
| 9981 | |
| 9982 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 9983 | &ets_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 ets 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 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 9993 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 9994 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 9995 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9996 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 9997 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 9998 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 9999 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 10000 | veb->bw_tc_limit_credits[i] = |
| 10001 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 10002 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 10003 | } |
| 10004 | |
| 10005 | out: |
| 10006 | return ret; |
| 10007 | } |
| 10008 | |
| 10009 | /** |
| 10010 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 10011 | * @pf: board private structure |
| 10012 | * |
| 10013 | * On error: returns error code (negative) |
| 10014 | * On success: returns vsi index in PF (positive) |
| 10015 | **/ |
| 10016 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 10017 | { |
| 10018 | int ret = -ENOENT; |
| 10019 | struct i40e_veb *veb; |
| 10020 | int i; |
| 10021 | |
| 10022 | /* Need to protect the allocation of switch elements at the PF level */ |
| 10023 | mutex_lock(&pf->switch_mutex); |
| 10024 | |
| 10025 | /* VEB list may be fragmented if VEB creation/destruction has |
| 10026 | * been happening. We can afford to do a quick scan to look |
| 10027 | * for any free slots in the list. |
| 10028 | * |
| 10029 | * find next empty veb slot, looping back around if necessary |
| 10030 | */ |
| 10031 | i = 0; |
| 10032 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 10033 | i++; |
| 10034 | if (i >= I40E_MAX_VEB) { |
| 10035 | ret = -ENOMEM; |
| 10036 | goto err_alloc_veb; /* out of VEB slots! */ |
| 10037 | } |
| 10038 | |
| 10039 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 10040 | if (!veb) { |
| 10041 | ret = -ENOMEM; |
| 10042 | goto err_alloc_veb; |
| 10043 | } |
| 10044 | veb->pf = pf; |
| 10045 | veb->idx = i; |
| 10046 | veb->enabled_tc = 1; |
| 10047 | |
| 10048 | pf->veb[i] = veb; |
| 10049 | ret = i; |
| 10050 | err_alloc_veb: |
| 10051 | mutex_unlock(&pf->switch_mutex); |
| 10052 | return ret; |
| 10053 | } |
| 10054 | |
| 10055 | /** |
| 10056 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 10057 | * @branch: where to start deleting |
| 10058 | * |
| 10059 | * This uses recursion to find the tips of the branch to be |
| 10060 | * removed, deleting until we get back to and can delete this VEB. |
| 10061 | **/ |
| 10062 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 10063 | { |
| 10064 | struct i40e_pf *pf = branch->pf; |
| 10065 | u16 branch_seid = branch->seid; |
| 10066 | u16 veb_idx = branch->idx; |
| 10067 | int i; |
| 10068 | |
| 10069 | /* release any VEBs on this VEB - RECURSION */ |
| 10070 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10071 | if (!pf->veb[i]) |
| 10072 | continue; |
| 10073 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 10074 | i40e_switch_branch_release(pf->veb[i]); |
| 10075 | } |
| 10076 | |
| 10077 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 10078 | * |
| 10079 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 10080 | * the VEB itself, so don't use (*branch) after this loop. |
| 10081 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10082 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10083 | if (!pf->vsi[i]) |
| 10084 | continue; |
| 10085 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 10086 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 10087 | i40e_vsi_release(pf->vsi[i]); |
| 10088 | } |
| 10089 | } |
| 10090 | |
| 10091 | /* There's one corner case where the VEB might not have been |
| 10092 | * removed, so double check it here and remove it if needed. |
| 10093 | * This case happens if the veb was created from the debugfs |
| 10094 | * commands and no VSIs were added to it. |
| 10095 | */ |
| 10096 | if (pf->veb[veb_idx]) |
| 10097 | i40e_veb_release(pf->veb[veb_idx]); |
| 10098 | } |
| 10099 | |
| 10100 | /** |
| 10101 | * i40e_veb_clear - remove veb struct |
| 10102 | * @veb: the veb to remove |
| 10103 | **/ |
| 10104 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 10105 | { |
| 10106 | if (!veb) |
| 10107 | return; |
| 10108 | |
| 10109 | if (veb->pf) { |
| 10110 | struct i40e_pf *pf = veb->pf; |
| 10111 | |
| 10112 | mutex_lock(&pf->switch_mutex); |
| 10113 | if (pf->veb[veb->idx] == veb) |
| 10114 | pf->veb[veb->idx] = NULL; |
| 10115 | mutex_unlock(&pf->switch_mutex); |
| 10116 | } |
| 10117 | |
| 10118 | kfree(veb); |
| 10119 | } |
| 10120 | |
| 10121 | /** |
| 10122 | * i40e_veb_release - Delete a VEB and free its resources |
| 10123 | * @veb: the VEB being removed |
| 10124 | **/ |
| 10125 | void i40e_veb_release(struct i40e_veb *veb) |
| 10126 | { |
| 10127 | struct i40e_vsi *vsi = NULL; |
| 10128 | struct i40e_pf *pf; |
| 10129 | int i, n = 0; |
| 10130 | |
| 10131 | pf = veb->pf; |
| 10132 | |
| 10133 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10134 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10135 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 10136 | n++; |
| 10137 | vsi = pf->vsi[i]; |
| 10138 | } |
| 10139 | } |
| 10140 | if (n != 1) { |
| 10141 | dev_info(&pf->pdev->dev, |
| 10142 | "can't remove VEB %d with %d VSIs left\n", |
| 10143 | veb->seid, n); |
| 10144 | return; |
| 10145 | } |
| 10146 | |
| 10147 | /* move the remaining VSI to uplink veb */ |
| 10148 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10149 | if (veb->uplink_seid) { |
| 10150 | vsi->uplink_seid = veb->uplink_seid; |
| 10151 | if (veb->uplink_seid == pf->mac_seid) |
| 10152 | vsi->veb_idx = I40E_NO_VEB; |
| 10153 | else |
| 10154 | vsi->veb_idx = veb->veb_idx; |
| 10155 | } else { |
| 10156 | /* floating VEB */ |
| 10157 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10158 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10159 | } |
| 10160 | |
| 10161 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10162 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10163 | } |
| 10164 | |
| 10165 | /** |
| 10166 | * i40e_add_veb - create the VEB in the switch |
| 10167 | * @veb: the VEB to be instantiated |
| 10168 | * @vsi: the controlling VSI |
| 10169 | **/ |
| 10170 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10171 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10172 | struct i40e_pf *pf = veb->pf; |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 10173 | bool is_default = veb->pf->cur_promisc; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10174 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10175 | int ret; |
| 10176 | |
| 10177 | /* get a VEB from the hardware */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10178 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 10179 | veb->enabled_tc, is_default, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10180 | &veb->seid, enable_stats, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10181 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10182 | dev_info(&pf->pdev->dev, |
| 10183 | "couldn't add VEB, err %s aq_err %s\n", |
| 10184 | i40e_stat_str(&pf->hw, ret), |
| 10185 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10186 | return -EPERM; |
| 10187 | } |
| 10188 | |
| 10189 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10190 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10191 | &veb->stats_idx, NULL, NULL, NULL); |
| 10192 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10193 | dev_info(&pf->pdev->dev, |
| 10194 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10195 | i40e_stat_str(&pf->hw, ret), |
| 10196 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10197 | return -EPERM; |
| 10198 | } |
| 10199 | ret = i40e_veb_get_bw_info(veb); |
| 10200 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10201 | dev_info(&pf->pdev->dev, |
| 10202 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10203 | i40e_stat_str(&pf->hw, ret), |
| 10204 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10205 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10206 | return -ENOENT; |
| 10207 | } |
| 10208 | |
| 10209 | vsi->uplink_seid = veb->seid; |
| 10210 | vsi->veb_idx = veb->idx; |
| 10211 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10212 | |
| 10213 | return 0; |
| 10214 | } |
| 10215 | |
| 10216 | /** |
| 10217 | * i40e_veb_setup - Set up a VEB |
| 10218 | * @pf: board private structure |
| 10219 | * @flags: VEB setup flags |
| 10220 | * @uplink_seid: the switch element to link to |
| 10221 | * @vsi_seid: the initial VSI seid |
| 10222 | * @enabled_tc: Enabled TC bit-map |
| 10223 | * |
| 10224 | * This allocates the sw VEB structure and links it into the switch |
| 10225 | * It is possible and legal for this to be a duplicate of an already |
| 10226 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10227 | * to be zero, in order to create a floating VEB. |
| 10228 | * |
| 10229 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10230 | * success, otherwise returns NULL on failure. |
| 10231 | **/ |
| 10232 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10233 | u16 uplink_seid, u16 vsi_seid, |
| 10234 | u8 enabled_tc) |
| 10235 | { |
| 10236 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10237 | int vsi_idx, veb_idx; |
| 10238 | int ret; |
| 10239 | |
| 10240 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10241 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10242 | (uplink_seid + vsi_seid != 0)) { |
| 10243 | dev_info(&pf->pdev->dev, |
| 10244 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10245 | uplink_seid, vsi_seid); |
| 10246 | return NULL; |
| 10247 | } |
| 10248 | |
| 10249 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10250 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10251 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10252 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10253 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10254 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10255 | vsi_seid); |
| 10256 | return NULL; |
| 10257 | } |
| 10258 | |
| 10259 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10260 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10261 | if (pf->veb[veb_idx] && |
| 10262 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10263 | uplink_veb = pf->veb[veb_idx]; |
| 10264 | break; |
| 10265 | } |
| 10266 | } |
| 10267 | if (!uplink_veb) { |
| 10268 | dev_info(&pf->pdev->dev, |
| 10269 | "uplink seid %d not found\n", uplink_seid); |
| 10270 | return NULL; |
| 10271 | } |
| 10272 | } |
| 10273 | |
| 10274 | /* get veb sw struct */ |
| 10275 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10276 | if (veb_idx < 0) |
| 10277 | goto err_alloc; |
| 10278 | veb = pf->veb[veb_idx]; |
| 10279 | veb->flags = flags; |
| 10280 | veb->uplink_seid = uplink_seid; |
| 10281 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10282 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10283 | |
| 10284 | /* create the VEB in the switch */ |
| 10285 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10286 | if (ret) |
| 10287 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10288 | if (vsi_idx == pf->lan_vsi) |
| 10289 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10290 | |
| 10291 | return veb; |
| 10292 | |
| 10293 | err_veb: |
| 10294 | i40e_veb_clear(veb); |
| 10295 | err_alloc: |
| 10296 | return NULL; |
| 10297 | } |
| 10298 | |
| 10299 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10300 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10301 | * @pf: board private structure |
| 10302 | * @ele: element we are building info from |
| 10303 | * @num_reported: total number of elements |
| 10304 | * @printconfig: should we print the contents |
| 10305 | * |
| 10306 | * helper function to assist in extracting a few useful SEID values. |
| 10307 | **/ |
| 10308 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10309 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10310 | u16 num_reported, bool printconfig) |
| 10311 | { |
| 10312 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10313 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10314 | u8 element_type = ele->element_type; |
| 10315 | u16 seid = le16_to_cpu(ele->seid); |
| 10316 | |
| 10317 | if (printconfig) |
| 10318 | dev_info(&pf->pdev->dev, |
| 10319 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10320 | element_type, seid, uplink_seid, downlink_seid); |
| 10321 | |
| 10322 | switch (element_type) { |
| 10323 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10324 | pf->mac_seid = seid; |
| 10325 | break; |
| 10326 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10327 | /* Main VEB? */ |
| 10328 | if (uplink_seid != pf->mac_seid) |
| 10329 | break; |
| 10330 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10331 | int v; |
| 10332 | |
| 10333 | /* find existing or else empty VEB */ |
| 10334 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10335 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10336 | pf->lan_veb = v; |
| 10337 | break; |
| 10338 | } |
| 10339 | } |
| 10340 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10341 | v = i40e_veb_mem_alloc(pf); |
| 10342 | if (v < 0) |
| 10343 | break; |
| 10344 | pf->lan_veb = v; |
| 10345 | } |
| 10346 | } |
| 10347 | |
| 10348 | pf->veb[pf->lan_veb]->seid = seid; |
| 10349 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10350 | pf->veb[pf->lan_veb]->pf = pf; |
| 10351 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10352 | break; |
| 10353 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10354 | if (num_reported != 1) |
| 10355 | break; |
| 10356 | /* This is immediately after a reset so we can assume this is |
| 10357 | * the PF's VSI |
| 10358 | */ |
| 10359 | pf->mac_seid = uplink_seid; |
| 10360 | pf->pf_seid = downlink_seid; |
| 10361 | pf->main_vsi_seid = seid; |
| 10362 | if (printconfig) |
| 10363 | dev_info(&pf->pdev->dev, |
| 10364 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10365 | pf->pf_seid, pf->main_vsi_seid); |
| 10366 | break; |
| 10367 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10368 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10369 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10370 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10371 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10372 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10373 | /* ignore these for now */ |
| 10374 | break; |
| 10375 | default: |
| 10376 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10377 | element_type, seid); |
| 10378 | break; |
| 10379 | } |
| 10380 | } |
| 10381 | |
| 10382 | /** |
| 10383 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10384 | * @pf: board private structure |
| 10385 | * @printconfig: should we print the contents |
| 10386 | * |
| 10387 | * Get the current switch configuration from the device and |
| 10388 | * extract a few useful SEID values. |
| 10389 | **/ |
| 10390 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10391 | { |
| 10392 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10393 | u16 next_seid = 0; |
| 10394 | int ret = 0; |
| 10395 | u8 *aq_buf; |
| 10396 | int i; |
| 10397 | |
| 10398 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10399 | if (!aq_buf) |
| 10400 | return -ENOMEM; |
| 10401 | |
| 10402 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10403 | do { |
| 10404 | u16 num_reported, num_total; |
| 10405 | |
| 10406 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10407 | I40E_AQ_LARGE_BUF, |
| 10408 | &next_seid, NULL); |
| 10409 | if (ret) { |
| 10410 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10411 | "get switch config failed err %s aq_err %s\n", |
| 10412 | i40e_stat_str(&pf->hw, ret), |
| 10413 | i40e_aq_str(&pf->hw, |
| 10414 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10415 | kfree(aq_buf); |
| 10416 | return -ENOENT; |
| 10417 | } |
| 10418 | |
| 10419 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10420 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10421 | |
| 10422 | if (printconfig) |
| 10423 | dev_info(&pf->pdev->dev, |
| 10424 | "header: %d reported %d total\n", |
| 10425 | num_reported, num_total); |
| 10426 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10427 | for (i = 0; i < num_reported; i++) { |
| 10428 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10429 | &sw_config->element[i]; |
| 10430 | |
| 10431 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10432 | printconfig); |
| 10433 | } |
| 10434 | } while (next_seid != 0); |
| 10435 | |
| 10436 | kfree(aq_buf); |
| 10437 | return ret; |
| 10438 | } |
| 10439 | |
| 10440 | /** |
| 10441 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10442 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10443 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10444 | * |
| 10445 | * Returns 0 on success, negative value on failure |
| 10446 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10447 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10448 | { |
| 10449 | int ret; |
| 10450 | |
| 10451 | /* find out what's out there already */ |
| 10452 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10453 | if (ret) { |
| 10454 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10455 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10456 | i40e_stat_str(&pf->hw, ret), |
| 10457 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10458 | return ret; |
| 10459 | } |
| 10460 | i40e_pf_reset_stats(pf); |
| 10461 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10462 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10463 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10464 | struct i40e_vsi *vsi = NULL; |
| 10465 | u16 uplink_seid; |
| 10466 | |
| 10467 | /* Set up the PF VSI associated with the PF's main VSI |
| 10468 | * that is already in the HW switch |
| 10469 | */ |
| 10470 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10471 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10472 | else |
| 10473 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10474 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10475 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10476 | else if (reinit) |
| 10477 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10478 | if (!vsi) { |
| 10479 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10480 | i40e_fdir_teardown(pf); |
| 10481 | return -EAGAIN; |
| 10482 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10483 | } else { |
| 10484 | /* force a reset of TC and queue layout configurations */ |
| 10485 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10486 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10487 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10488 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10489 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10490 | } |
| 10491 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 10492 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10493 | i40e_fdir_sb_setup(pf); |
| 10494 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10495 | /* Setup static PF queue filter control settings */ |
| 10496 | ret = i40e_setup_pf_filter_control(pf); |
| 10497 | if (ret) { |
| 10498 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 10499 | ret); |
| 10500 | /* Failure here should not stop continuing other steps */ |
| 10501 | } |
| 10502 | |
| 10503 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 10504 | * the hash |
| 10505 | */ |
| 10506 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 10507 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10508 | |
| 10509 | /* fill in link information and enable LSE reporting */ |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 10510 | i40e_update_link_info(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10511 | i40e_link_event(pf); |
| 10512 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10513 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10514 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 10515 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10516 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10517 | i40e_ptp_init(pf); |
| 10518 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10519 | return ret; |
| 10520 | } |
| 10521 | |
| 10522 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10523 | * i40e_determine_queue_usage - Work out queue distribution |
| 10524 | * @pf: board private structure |
| 10525 | **/ |
| 10526 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 10527 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10528 | int queues_left; |
| 10529 | |
| 10530 | pf->num_lan_qps = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10531 | #ifdef I40E_FCOE |
| 10532 | pf->num_fcoe_qps = 0; |
| 10533 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10534 | |
| 10535 | /* Find the max queues to be put into basic use. We'll always be |
| 10536 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 10537 | * big RSS set. |
| 10538 | */ |
| 10539 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 10540 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10541 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10542 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10543 | /* one qp for PF, no queues for anything else */ |
| 10544 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10545 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10546 | |
| 10547 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10548 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10549 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10550 | #ifdef I40E_FCOE |
| 10551 | I40E_FLAG_FCOE_ENABLED | |
| 10552 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10553 | I40E_FLAG_FD_SB_ENABLED | |
| 10554 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10555 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10556 | I40E_FLAG_SRIOV_ENABLED | |
| 10557 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10558 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 10559 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 10560 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10561 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10562 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10563 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10564 | queues_left -= pf->num_lan_qps; |
| 10565 | |
| 10566 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10567 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10568 | #ifdef I40E_FCOE |
| 10569 | I40E_FLAG_FCOE_ENABLED | |
| 10570 | #endif |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10571 | I40E_FLAG_FD_SB_ENABLED | |
| 10572 | I40E_FLAG_FD_ATR_ENABLED | |
| 10573 | I40E_FLAG_DCB_ENABLED | |
| 10574 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10575 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10576 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10577 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10578 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10579 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10580 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 10581 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 10582 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 10583 | num_online_cpus()); |
| 10584 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 10585 | pf->hw.func_caps.num_tx_qp); |
| 10586 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10587 | queues_left -= pf->num_lan_qps; |
| 10588 | } |
| 10589 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10590 | #ifdef I40E_FCOE |
| 10591 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 10592 | if (I40E_DEFAULT_FCOE <= queues_left) { |
| 10593 | pf->num_fcoe_qps = I40E_DEFAULT_FCOE; |
| 10594 | } else if (I40E_MINIMUM_FCOE <= queues_left) { |
| 10595 | pf->num_fcoe_qps = I40E_MINIMUM_FCOE; |
| 10596 | } else { |
| 10597 | pf->num_fcoe_qps = 0; |
| 10598 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 10599 | dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n"); |
| 10600 | } |
| 10601 | |
| 10602 | queues_left -= pf->num_fcoe_qps; |
| 10603 | } |
| 10604 | |
| 10605 | #endif |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10606 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10607 | if (queues_left > 1) { |
| 10608 | queues_left -= 1; /* save 1 queue for FD */ |
| 10609 | } else { |
| 10610 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 10611 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 10612 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10613 | } |
| 10614 | |
| 10615 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10616 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10617 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 10618 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10619 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 10620 | } |
| 10621 | |
| 10622 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 10623 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 10624 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 10625 | (queues_left / pf->num_vmdq_qps)); |
| 10626 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 10627 | } |
| 10628 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10629 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10630 | dev_dbg(&pf->pdev->dev, |
| 10631 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 10632 | pf->hw.func_caps.num_tx_qp, |
| 10633 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10634 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 10635 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 10636 | queues_left); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10637 | #ifdef I40E_FCOE |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10638 | 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] | 10639 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10640 | } |
| 10641 | |
| 10642 | /** |
| 10643 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 10644 | * @pf: PF to be setup |
| 10645 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10646 | * 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] | 10647 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 10648 | * based filter sizes required for them. It also enables Flow director, |
| 10649 | * ethertype and macvlan type filter settings for the pf. |
| 10650 | * |
| 10651 | * Returns 0 on success, negative on failure |
| 10652 | **/ |
| 10653 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 10654 | { |
| 10655 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 10656 | |
| 10657 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 10658 | |
| 10659 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10660 | 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] | 10661 | settings->enable_fdir = true; |
| 10662 | |
| 10663 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 10664 | settings->enable_ethtype = true; |
| 10665 | settings->enable_macvlan = true; |
| 10666 | |
| 10667 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 10668 | return -ENOENT; |
| 10669 | |
| 10670 | return 0; |
| 10671 | } |
| 10672 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10673 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10674 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10675 | static void i40e_print_features(struct i40e_pf *pf) |
| 10676 | { |
| 10677 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10678 | char *buf; |
| 10679 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10680 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10681 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 10682 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10683 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10684 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10685 | 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] | 10686 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10687 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10688 | #endif |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10689 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d RX: %s", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10690 | pf->hw.func_caps.num_vsis, |
| 10691 | pf->vsi[pf->lan_vsi]->num_queue_pairs, |
| 10692 | pf->flags & I40E_FLAG_RX_PS_ENABLED ? "PS" : "1BUF"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10693 | |
| 10694 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10695 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10696 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10697 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10698 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10699 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 10700 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10701 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10702 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10703 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Jesse Brandeburg | ce6fcb3 | 2015-08-28 17:55:59 -0400 | [diff] [blame] | 10704 | #if IS_ENABLED(CONFIG_VXLAN) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10705 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Jesse Brandeburg | ce6fcb3 | 2015-08-28 17:55:59 -0400 | [diff] [blame] | 10706 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10707 | #if IS_ENABLED(CONFIG_GENEVE) |
| 10708 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
| 10709 | #endif |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10710 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10711 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10712 | #ifdef I40E_FCOE |
| 10713 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10714 | i += snprintf(&buf[i], REMAIN(i), " FCOE"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10715 | #endif |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10716 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10717 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10718 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10719 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10720 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10721 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 10722 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10723 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10724 | } |
| 10725 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10726 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10727 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
| 10728 | * |
| 10729 | * @pdev: PCI device information struct |
| 10730 | * @pf: board private structure |
| 10731 | * |
| 10732 | * Look up the MAC address in Open Firmware on systems that support it, |
| 10733 | * and use IDPROM on SPARC if no OF address is found. On return, the |
| 10734 | * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value |
| 10735 | * has been selected. |
| 10736 | **/ |
| 10737 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 10738 | { |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10739 | pf->flags &= ~I40E_FLAG_PF_MAC; |
Sowmini Varadhan | ba94272 | 2016-01-12 19:32:31 -0800 | [diff] [blame] | 10740 | if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10741 | pf->flags |= I40E_FLAG_PF_MAC; |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10742 | } |
| 10743 | |
| 10744 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10745 | * i40e_probe - Device initialization routine |
| 10746 | * @pdev: PCI device information struct |
| 10747 | * @ent: entry in i40e_pci_tbl |
| 10748 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10749 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 10750 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10751 | * and a hardware reset occur. |
| 10752 | * |
| 10753 | * Returns 0 on success, negative on failure |
| 10754 | **/ |
| 10755 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 10756 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 10757 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10758 | struct i40e_pf *pf; |
| 10759 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10760 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10761 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10762 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 10763 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10764 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10765 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10766 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10767 | |
| 10768 | err = pci_enable_device_mem(pdev); |
| 10769 | if (err) |
| 10770 | return err; |
| 10771 | |
| 10772 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10773 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10774 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 10775 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10776 | if (err) { |
| 10777 | dev_err(&pdev->dev, |
| 10778 | "DMA configuration failed: 0x%x\n", err); |
| 10779 | goto err_dma; |
| 10780 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10781 | } |
| 10782 | |
| 10783 | /* set up pci connections */ |
| 10784 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 10785 | IORESOURCE_MEM), i40e_driver_name); |
| 10786 | if (err) { |
| 10787 | dev_info(&pdev->dev, |
| 10788 | "pci_request_selected_regions failed %d\n", err); |
| 10789 | goto err_pci_reg; |
| 10790 | } |
| 10791 | |
| 10792 | pci_enable_pcie_error_reporting(pdev); |
| 10793 | pci_set_master(pdev); |
| 10794 | |
| 10795 | /* Now that we have a PCI connection, we need to do the |
| 10796 | * low level device setup. This is primarily setting up |
| 10797 | * the Admin Queue structures and then querying for the |
| 10798 | * device's current profile information. |
| 10799 | */ |
| 10800 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 10801 | if (!pf) { |
| 10802 | err = -ENOMEM; |
| 10803 | goto err_pf_alloc; |
| 10804 | } |
| 10805 | pf->next_vsi = 0; |
| 10806 | pf->pdev = pdev; |
| 10807 | set_bit(__I40E_DOWN, &pf->state); |
| 10808 | |
| 10809 | hw = &pf->hw; |
| 10810 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10811 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10812 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 10813 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10814 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10815 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10816 | if (!hw->hw_addr) { |
| 10817 | err = -EIO; |
| 10818 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 10819 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10820 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10821 | goto err_ioremap; |
| 10822 | } |
| 10823 | hw->vendor_id = pdev->vendor; |
| 10824 | hw->device_id = pdev->device; |
| 10825 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 10826 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 10827 | hw->subsystem_device_id = pdev->subsystem_device; |
| 10828 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 10829 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10830 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10831 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 10832 | /* set up the locks for the AQ, do this only once in probe |
| 10833 | * and destroy them only once in remove |
| 10834 | */ |
| 10835 | mutex_init(&hw->aq.asq_mutex); |
| 10836 | mutex_init(&hw->aq.arq_mutex); |
| 10837 | |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 10838 | if (debug != -1) { |
| 10839 | pf->msg_enable = pf->hw.debug_mask; |
| 10840 | pf->msg_enable = debug; |
| 10841 | } |
| 10842 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10843 | /* do a special CORER for clearing PXE mode once at init */ |
| 10844 | if (hw->revision_id == 0 && |
| 10845 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 10846 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 10847 | i40e_flush(hw); |
| 10848 | msleep(200); |
| 10849 | pf->corer_count++; |
| 10850 | |
| 10851 | i40e_clear_pxe_mode(hw); |
| 10852 | } |
| 10853 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10854 | /* 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] | 10855 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10856 | err = i40e_pf_reset(hw); |
| 10857 | if (err) { |
| 10858 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 10859 | goto err_pf_reset; |
| 10860 | } |
| 10861 | pf->pfr_count++; |
| 10862 | |
| 10863 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 10864 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 10865 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10866 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10867 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10868 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 10869 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10870 | "%s-%s:misc", |
| 10871 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10872 | |
| 10873 | err = i40e_init_shared_code(hw); |
| 10874 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 10875 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 10876 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10877 | goto err_pf_reset; |
| 10878 | } |
| 10879 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10880 | /* set up a default setting for link flow control */ |
| 10881 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 10882 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10883 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 10884 | if (err) { |
| 10885 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 10886 | dev_info(&pdev->dev, |
| 10887 | "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"); |
| 10888 | else |
| 10889 | dev_info(&pdev->dev, |
| 10890 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 10891 | |
| 10892 | goto err_pf_reset; |
| 10893 | } |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10894 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10895 | /* provide nvm, fw, api versions */ |
| 10896 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 10897 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 10898 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 10899 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10900 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10901 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 10902 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10903 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10904 | "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"); |
| 10905 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 10906 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10907 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10908 | "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] | 10909 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 10910 | i40e_verify_eeprom(pf); |
| 10911 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 10912 | /* Rev 0 hardware was never productized */ |
| 10913 | if (hw->revision_id < 1) |
| 10914 | 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"); |
| 10915 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 10916 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10917 | err = i40e_get_capabilities(pf); |
| 10918 | if (err) |
| 10919 | goto err_adminq_setup; |
| 10920 | |
| 10921 | err = i40e_sw_init(pf); |
| 10922 | if (err) { |
| 10923 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 10924 | goto err_sw_init; |
| 10925 | } |
| 10926 | |
| 10927 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 10928 | hw->func_caps.num_rx_qp, |
| 10929 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 10930 | if (err) { |
| 10931 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 10932 | goto err_init_lan_hmc; |
| 10933 | } |
| 10934 | |
| 10935 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 10936 | if (err) { |
| 10937 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 10938 | err = -ENOENT; |
| 10939 | goto err_configure_lan_hmc; |
| 10940 | } |
| 10941 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10942 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 10943 | * Ignore error return codes because if it was already disabled via |
| 10944 | * hardware settings this will fail |
| 10945 | */ |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 10946 | if (pf->flags & I40E_FLAG_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10947 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 10948 | i40e_aq_stop_lldp(hw, true, NULL); |
| 10949 | } |
| 10950 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10951 | i40e_get_mac_addr(hw, hw->mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10952 | /* allow a platform config to override the HW addr */ |
| 10953 | i40e_get_platform_mac_addr(pdev, pf); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 10954 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10955 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 10956 | err = -EIO; |
| 10957 | goto err_mac_addr; |
| 10958 | } |
| 10959 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 10960 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10961 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 10962 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 10963 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10964 | #ifdef I40E_FCOE |
| 10965 | err = i40e_get_san_mac_addr(hw, hw->mac.san_addr); |
| 10966 | if (err) |
| 10967 | dev_info(&pdev->dev, |
| 10968 | "(non-fatal) SAN MAC retrieval failed: %d\n", err); |
| 10969 | if (!is_valid_ether_addr(hw->mac.san_addr)) { |
| 10970 | dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n", |
| 10971 | hw->mac.san_addr); |
| 10972 | ether_addr_copy(hw->mac.san_addr, hw->mac.addr); |
| 10973 | } |
| 10974 | dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr); |
| 10975 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10976 | |
| 10977 | pci_set_drvdata(pdev, pf); |
| 10978 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10979 | #ifdef CONFIG_I40E_DCB |
| 10980 | err = i40e_init_pf_dcb(pf); |
| 10981 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 10982 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10983 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 10984 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10985 | } |
| 10986 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10987 | |
| 10988 | /* set up periodic task facility */ |
| 10989 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 10990 | pf->service_timer_period = HZ; |
| 10991 | |
| 10992 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 10993 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 10994 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10995 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10996 | /* NVM bit on means WoL disabled for the port */ |
| 10997 | 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] | 10998 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10999 | pf->wol_en = false; |
| 11000 | else |
| 11001 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11002 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 11003 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11004 | /* set up the main switch operations */ |
| 11005 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 11006 | err = i40e_init_interrupt_scheme(pf); |
| 11007 | if (err) |
| 11008 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11009 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11010 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 11011 | * to us; HW supports far more and we share the remaining pool with |
| 11012 | * the other PFs. We allocate space for more than the guarantee with |
| 11013 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11014 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11015 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 11016 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 11017 | else |
| 11018 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 11019 | |
| 11020 | /* 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] | 11021 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 11022 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11023 | if (!pf->vsi) { |
| 11024 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11025 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 11026 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11027 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 11028 | #ifdef CONFIG_PCI_IOV |
| 11029 | /* prep for VF support */ |
| 11030 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 11031 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11032 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 11033 | if (pci_num_vf(pdev)) |
| 11034 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 11035 | } |
| 11036 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 11037 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11038 | if (err) { |
| 11039 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 11040 | goto err_vsis; |
| 11041 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 11042 | |
| 11043 | /* Make sure flow control is set according to current settings */ |
| 11044 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 11045 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 11046 | dev_dbg(&pf->pdev->dev, |
| 11047 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 11048 | i40e_stat_str(hw, err), |
| 11049 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11050 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 11051 | dev_dbg(&pf->pdev->dev, |
| 11052 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 11053 | i40e_stat_str(hw, err), |
| 11054 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11055 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 11056 | dev_dbg(&pf->pdev->dev, |
| 11057 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 11058 | i40e_stat_str(hw, err), |
| 11059 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 11060 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11061 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11062 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 11063 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 11064 | i40e_vsi_open(pf->vsi[i]); |
| 11065 | break; |
| 11066 | } |
| 11067 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11068 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11069 | /* The driver only wants link up/down and module qualification |
| 11070 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11071 | */ |
| 11072 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 11073 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
| 11074 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11075 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11076 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 11077 | i40e_stat_str(&pf->hw, err), |
| 11078 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 11079 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 11080 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 11081 | * of TSO, so that we avoid the MDD being fired and causing |
| 11082 | * a reset in the case of small MSS+TSO. |
| 11083 | */ |
| 11084 | val = rd32(hw, I40E_REG_MSS); |
| 11085 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 11086 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 11087 | val |= I40E_64BYTE_MSS; |
| 11088 | wr32(hw, I40E_REG_MSS, val); |
| 11089 | } |
| 11090 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 11091 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 11092 | msleep(75); |
| 11093 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 11094 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11095 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 11096 | i40e_stat_str(&pf->hw, err), |
| 11097 | i40e_aq_str(&pf->hw, |
| 11098 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 11099 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11100 | /* The main driver is (mostly) up and happy. We need to set this state |
| 11101 | * before setting up the misc vector or we get a race and the vector |
| 11102 | * ends up disabled forever. |
| 11103 | */ |
| 11104 | clear_bit(__I40E_DOWN, &pf->state); |
| 11105 | |
| 11106 | /* In case of MSIX we are going to setup the misc vector right here |
| 11107 | * to handle admin queue events etc. In case of legacy and MSI |
| 11108 | * the misc functionality and queue processing is combined in |
| 11109 | * the same vector and that gets setup at open. |
| 11110 | */ |
| 11111 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 11112 | err = i40e_setup_misc_vector(pf); |
| 11113 | if (err) { |
| 11114 | dev_info(&pdev->dev, |
| 11115 | "setup of misc vector failed: %d\n", err); |
| 11116 | goto err_vsis; |
| 11117 | } |
| 11118 | } |
| 11119 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11120 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11121 | /* prep for VF support */ |
| 11122 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11123 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11124 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11125 | /* disable link interrupts for VFs */ |
| 11126 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11127 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11128 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11129 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11130 | |
| 11131 | if (pci_num_vf(pdev)) { |
| 11132 | dev_info(&pdev->dev, |
| 11133 | "Active VFs found, allocating resources.\n"); |
| 11134 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11135 | if (err) |
| 11136 | dev_info(&pdev->dev, |
| 11137 | "Error %d allocating resources for existing VFs\n", |
| 11138 | err); |
| 11139 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11140 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11141 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11142 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11143 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11144 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11145 | pf->num_iwarp_msix, |
| 11146 | I40E_IWARP_IRQ_PILE_ID); |
| 11147 | if (pf->iwarp_base_vector < 0) { |
| 11148 | dev_info(&pdev->dev, |
| 11149 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 11150 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 11151 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 11152 | } |
| 11153 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11154 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11155 | i40e_dbg_pf_init(pf); |
| 11156 | |
| 11157 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11158 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11159 | |
| 11160 | /* since everything's happy, start the service_task timer */ |
| 11161 | mod_timer(&pf->service_timer, |
| 11162 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11163 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11164 | /* add this PF to client device list and launch a client service task */ |
| 11165 | err = i40e_lan_add_device(pf); |
| 11166 | if (err) |
| 11167 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 11168 | err); |
| 11169 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11170 | #ifdef I40E_FCOE |
| 11171 | /* create FCoE interface */ |
| 11172 | i40e_fcoe_vsi_setup(pf); |
| 11173 | |
| 11174 | #endif |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11175 | #define PCI_SPEED_SIZE 8 |
| 11176 | #define PCI_WIDTH_SIZE 8 |
| 11177 | /* Devices on the IOSF bus do not have this information |
| 11178 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11179 | * checking them. |
| 11180 | */ |
| 11181 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { |
| 11182 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11183 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11184 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11185 | /* Get the negotiated link width and speed from PCI config |
| 11186 | * space |
| 11187 | */ |
| 11188 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11189 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11190 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11191 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11192 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11193 | switch (hw->bus.speed) { |
| 11194 | case i40e_bus_speed_8000: |
| 11195 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11196 | case i40e_bus_speed_5000: |
| 11197 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11198 | case i40e_bus_speed_2500: |
| 11199 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11200 | default: |
| 11201 | break; |
| 11202 | } |
| 11203 | switch (hw->bus.width) { |
| 11204 | case i40e_bus_width_pcie_x8: |
| 11205 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11206 | case i40e_bus_width_pcie_x4: |
| 11207 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11208 | case i40e_bus_width_pcie_x2: |
| 11209 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11210 | case i40e_bus_width_pcie_x1: |
| 11211 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11212 | default: |
| 11213 | break; |
| 11214 | } |
| 11215 | |
| 11216 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11217 | speed, width); |
| 11218 | |
| 11219 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11220 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11221 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11222 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11223 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11224 | } |
| 11225 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11226 | /* get the requested speeds from the fw */ |
| 11227 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11228 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11229 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11230 | i40e_stat_str(&pf->hw, err), |
| 11231 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11232 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11233 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11234 | /* get the supported phy types from the fw */ |
| 11235 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11236 | if (err) |
| 11237 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11238 | i40e_stat_str(&pf->hw, err), |
| 11239 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 11240 | pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type); |
| 11241 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11242 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11243 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11244 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11245 | * PF/VF VSIs. |
| 11246 | * The FW can still send Flow control frames if enabled. |
| 11247 | */ |
| 11248 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11249 | pf->main_vsi_seid); |
| 11250 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 11251 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
| 11252 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
| 11253 | pf->flags |= I40E_FLAG_HAVE_10GBASET_PHY; |
| 11254 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11255 | /* print a string summarizing features */ |
| 11256 | i40e_print_features(pf); |
| 11257 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11258 | return 0; |
| 11259 | |
| 11260 | /* Unwind what we've done if something failed in the setup */ |
| 11261 | err_vsis: |
| 11262 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11263 | i40e_clear_interrupt_scheme(pf); |
| 11264 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11265 | err_switch_setup: |
| 11266 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11267 | del_timer_sync(&pf->service_timer); |
| 11268 | err_mac_addr: |
| 11269 | err_configure_lan_hmc: |
| 11270 | (void)i40e_shutdown_lan_hmc(hw); |
| 11271 | err_init_lan_hmc: |
| 11272 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11273 | err_sw_init: |
| 11274 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11275 | err_pf_reset: |
| 11276 | iounmap(hw->hw_addr); |
| 11277 | err_ioremap: |
| 11278 | kfree(pf); |
| 11279 | err_pf_alloc: |
| 11280 | pci_disable_pcie_error_reporting(pdev); |
| 11281 | pci_release_selected_regions(pdev, |
| 11282 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 11283 | err_pci_reg: |
| 11284 | err_dma: |
| 11285 | pci_disable_device(pdev); |
| 11286 | return err; |
| 11287 | } |
| 11288 | |
| 11289 | /** |
| 11290 | * i40e_remove - Device removal routine |
| 11291 | * @pdev: PCI device information struct |
| 11292 | * |
| 11293 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11294 | * that is should release a PCI device. This could be caused by a |
| 11295 | * Hot-Plug event, or because the driver is going to be removed from |
| 11296 | * memory. |
| 11297 | **/ |
| 11298 | static void i40e_remove(struct pci_dev *pdev) |
| 11299 | { |
| 11300 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11301 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11302 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11303 | int i; |
| 11304 | |
| 11305 | i40e_dbg_pf_exit(pf); |
| 11306 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11307 | i40e_ptp_stop(pf); |
| 11308 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11309 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 11310 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 11311 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11312 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11313 | /* no more scheduling of any task */ |
Pandi Kumar Maharajan | a4618ec | 2016-02-18 09:19:25 -0800 | [diff] [blame] | 11314 | set_bit(__I40E_SUSPENDED, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11315 | set_bit(__I40E_DOWN, &pf->state); |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 11316 | if (pf->service_timer.data) |
| 11317 | del_timer_sync(&pf->service_timer); |
| 11318 | if (pf->service_task.func) |
| 11319 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11320 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11321 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11322 | i40e_free_vfs(pf); |
| 11323 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11324 | } |
| 11325 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11326 | i40e_fdir_teardown(pf); |
| 11327 | |
| 11328 | /* If there is a switch structure or any orphans, remove them. |
| 11329 | * This will leave only the PF's VSI remaining. |
| 11330 | */ |
| 11331 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11332 | if (!pf->veb[i]) |
| 11333 | continue; |
| 11334 | |
| 11335 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11336 | pf->veb[i]->uplink_seid == 0) |
| 11337 | i40e_switch_branch_release(pf->veb[i]); |
| 11338 | } |
| 11339 | |
| 11340 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11341 | * adminq and hmc. |
| 11342 | */ |
| 11343 | if (pf->vsi[pf->lan_vsi]) |
| 11344 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11345 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11346 | /* remove attached clients */ |
| 11347 | ret_code = i40e_lan_del_device(pf); |
| 11348 | if (ret_code) { |
| 11349 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 11350 | ret_code); |
| 11351 | } |
| 11352 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11353 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11354 | if (hw->hmc.hmc_obj) { |
| 11355 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11356 | if (ret_code) |
| 11357 | dev_warn(&pdev->dev, |
| 11358 | "Failed to destroy the HMC resources: %d\n", |
| 11359 | ret_code); |
| 11360 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11361 | |
| 11362 | /* shutdown the adminq */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11363 | ret_code = i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11364 | if (ret_code) |
| 11365 | dev_warn(&pdev->dev, |
| 11366 | "Failed to destroy the Admin Queue resources: %d\n", |
| 11367 | ret_code); |
| 11368 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11369 | /* destroy the locks only once, here */ |
| 11370 | mutex_destroy(&hw->aq.arq_mutex); |
| 11371 | mutex_destroy(&hw->aq.asq_mutex); |
| 11372 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11373 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11374 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11375 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11376 | if (pf->vsi[i]) { |
| 11377 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11378 | i40e_vsi_clear(pf->vsi[i]); |
| 11379 | pf->vsi[i] = NULL; |
| 11380 | } |
| 11381 | } |
| 11382 | |
| 11383 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11384 | kfree(pf->veb[i]); |
| 11385 | pf->veb[i] = NULL; |
| 11386 | } |
| 11387 | |
| 11388 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11389 | kfree(pf->vsi); |
| 11390 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11391 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11392 | kfree(pf); |
| 11393 | pci_release_selected_regions(pdev, |
| 11394 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 11395 | |
| 11396 | pci_disable_pcie_error_reporting(pdev); |
| 11397 | pci_disable_device(pdev); |
| 11398 | } |
| 11399 | |
| 11400 | /** |
| 11401 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11402 | * @pdev: PCI device information struct |
| 11403 | * |
| 11404 | * Called to warn that something happened and the error handling steps |
| 11405 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11406 | * remediation. |
| 11407 | **/ |
| 11408 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11409 | enum pci_channel_state error) |
| 11410 | { |
| 11411 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11412 | |
| 11413 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11414 | |
| 11415 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11416 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11417 | rtnl_lock(); |
| 11418 | i40e_prep_for_reset(pf); |
| 11419 | rtnl_unlock(); |
| 11420 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11421 | |
| 11422 | /* Request a slot reset */ |
| 11423 | return PCI_ERS_RESULT_NEED_RESET; |
| 11424 | } |
| 11425 | |
| 11426 | /** |
| 11427 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11428 | * @pdev: PCI device information struct |
| 11429 | * |
| 11430 | * Called to find if the driver can work with the device now that |
| 11431 | * the pci slot has been reset. If a basic connection seems good |
| 11432 | * (registers are readable and have sane content) then return a |
| 11433 | * happy little PCI_ERS_RESULT_xxx. |
| 11434 | **/ |
| 11435 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11436 | { |
| 11437 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11438 | pci_ers_result_t result; |
| 11439 | int err; |
| 11440 | u32 reg; |
| 11441 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11442 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11443 | if (pci_enable_device_mem(pdev)) { |
| 11444 | dev_info(&pdev->dev, |
| 11445 | "Cannot re-enable PCI device after reset.\n"); |
| 11446 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11447 | } else { |
| 11448 | pci_set_master(pdev); |
| 11449 | pci_restore_state(pdev); |
| 11450 | pci_save_state(pdev); |
| 11451 | pci_wake_from_d3(pdev, false); |
| 11452 | |
| 11453 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11454 | if (reg == 0) |
| 11455 | result = PCI_ERS_RESULT_RECOVERED; |
| 11456 | else |
| 11457 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11458 | } |
| 11459 | |
| 11460 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11461 | if (err) { |
| 11462 | dev_info(&pdev->dev, |
| 11463 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11464 | err); |
| 11465 | /* non-fatal, continue */ |
| 11466 | } |
| 11467 | |
| 11468 | return result; |
| 11469 | } |
| 11470 | |
| 11471 | /** |
| 11472 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11473 | * @pdev: PCI device information struct |
| 11474 | * |
| 11475 | * Called to allow the driver to bring things back up after PCI error |
| 11476 | * and/or reset recovery has finished. |
| 11477 | **/ |
| 11478 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11479 | { |
| 11480 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11481 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11482 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11483 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 11484 | return; |
| 11485 | |
| 11486 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11487 | i40e_handle_reset_warning(pf); |
Vasily Averin | 4c4935a | 2015-07-08 15:04:26 +0300 | [diff] [blame] | 11488 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11489 | } |
| 11490 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11491 | /** |
| 11492 | * i40e_shutdown - PCI callback for shutting down |
| 11493 | * @pdev: PCI device information struct |
| 11494 | **/ |
| 11495 | static void i40e_shutdown(struct pci_dev *pdev) |
| 11496 | { |
| 11497 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11498 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11499 | |
| 11500 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11501 | set_bit(__I40E_DOWN, &pf->state); |
| 11502 | rtnl_lock(); |
| 11503 | i40e_prep_for_reset(pf); |
| 11504 | rtnl_unlock(); |
| 11505 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11506 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11507 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11508 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11509 | del_timer_sync(&pf->service_timer); |
| 11510 | cancel_work_sync(&pf->service_task); |
| 11511 | i40e_fdir_teardown(pf); |
| 11512 | |
| 11513 | rtnl_lock(); |
| 11514 | i40e_prep_for_reset(pf); |
| 11515 | rtnl_unlock(); |
| 11516 | |
| 11517 | wr32(hw, I40E_PFPM_APM, |
| 11518 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11519 | wr32(hw, I40E_PFPM_WUFC, |
| 11520 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11521 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 11522 | i40e_clear_interrupt_scheme(pf); |
| 11523 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11524 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11525 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11526 | pci_set_power_state(pdev, PCI_D3hot); |
| 11527 | } |
| 11528 | } |
| 11529 | |
| 11530 | #ifdef CONFIG_PM |
| 11531 | /** |
| 11532 | * i40e_suspend - PCI callback for moving to D3 |
| 11533 | * @pdev: PCI device information struct |
| 11534 | **/ |
| 11535 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11536 | { |
| 11537 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11538 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11539 | |
| 11540 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11541 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 11542 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11543 | rtnl_lock(); |
| 11544 | i40e_prep_for_reset(pf); |
| 11545 | rtnl_unlock(); |
| 11546 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11547 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11548 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11549 | |
| 11550 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11551 | pci_set_power_state(pdev, PCI_D3hot); |
| 11552 | |
| 11553 | return 0; |
| 11554 | } |
| 11555 | |
| 11556 | /** |
| 11557 | * i40e_resume - PCI callback for waking up from D3 |
| 11558 | * @pdev: PCI device information struct |
| 11559 | **/ |
| 11560 | static int i40e_resume(struct pci_dev *pdev) |
| 11561 | { |
| 11562 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11563 | u32 err; |
| 11564 | |
| 11565 | pci_set_power_state(pdev, PCI_D0); |
| 11566 | pci_restore_state(pdev); |
| 11567 | /* pci_restore_state() clears dev->state_saves, so |
| 11568 | * call pci_save_state() again to restore it. |
| 11569 | */ |
| 11570 | pci_save_state(pdev); |
| 11571 | |
| 11572 | err = pci_enable_device_mem(pdev); |
| 11573 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11574 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11575 | return err; |
| 11576 | } |
| 11577 | pci_set_master(pdev); |
| 11578 | |
| 11579 | /* no wakeup events while running */ |
| 11580 | pci_wake_from_d3(pdev, false); |
| 11581 | |
| 11582 | /* handling the reset will rebuild the device state */ |
| 11583 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11584 | clear_bit(__I40E_DOWN, &pf->state); |
| 11585 | rtnl_lock(); |
| 11586 | i40e_reset_and_rebuild(pf, false); |
| 11587 | rtnl_unlock(); |
| 11588 | } |
| 11589 | |
| 11590 | return 0; |
| 11591 | } |
| 11592 | |
| 11593 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11594 | static const struct pci_error_handlers i40e_err_handler = { |
| 11595 | .error_detected = i40e_pci_error_detected, |
| 11596 | .slot_reset = i40e_pci_error_slot_reset, |
| 11597 | .resume = i40e_pci_error_resume, |
| 11598 | }; |
| 11599 | |
| 11600 | static struct pci_driver i40e_driver = { |
| 11601 | .name = i40e_driver_name, |
| 11602 | .id_table = i40e_pci_tbl, |
| 11603 | .probe = i40e_probe, |
| 11604 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11605 | #ifdef CONFIG_PM |
| 11606 | .suspend = i40e_suspend, |
| 11607 | .resume = i40e_resume, |
| 11608 | #endif |
| 11609 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11610 | .err_handler = &i40e_err_handler, |
| 11611 | .sriov_configure = i40e_pci_sriov_configure, |
| 11612 | }; |
| 11613 | |
| 11614 | /** |
| 11615 | * i40e_init_module - Driver registration routine |
| 11616 | * |
| 11617 | * i40e_init_module is the first routine called when the driver is |
| 11618 | * loaded. All it does is register with the PCI subsystem. |
| 11619 | **/ |
| 11620 | static int __init i40e_init_module(void) |
| 11621 | { |
| 11622 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 11623 | i40e_driver_string, i40e_driver_version_str); |
| 11624 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 11625 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11626 | /* we will see if single thread per module is enough for now, |
| 11627 | * it can't be any worse than using the system workqueue which |
| 11628 | * was already single threaded |
| 11629 | */ |
| 11630 | i40e_wq = create_singlethread_workqueue(i40e_driver_name); |
| 11631 | if (!i40e_wq) { |
| 11632 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 11633 | return -ENOMEM; |
| 11634 | } |
| 11635 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11636 | i40e_dbg_init(); |
| 11637 | return pci_register_driver(&i40e_driver); |
| 11638 | } |
| 11639 | module_init(i40e_init_module); |
| 11640 | |
| 11641 | /** |
| 11642 | * i40e_exit_module - Driver exit cleanup routine |
| 11643 | * |
| 11644 | * i40e_exit_module is called just before the driver is removed |
| 11645 | * from memory. |
| 11646 | **/ |
| 11647 | static void __exit i40e_exit_module(void) |
| 11648 | { |
| 11649 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11650 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11651 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11652 | } |
| 11653 | module_exit(i40e_exit_module); |