Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2016 Intel Corporation. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 27 | #include <linux/etherdevice.h> |
| 28 | #include <linux/of_net.h> |
| 29 | #include <linux/pci.h> |
| 30 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 31 | /* Local includes */ |
| 32 | #include "i40e.h" |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 33 | #include "i40e_diag.h" |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 34 | #include <net/udp_tunnel.h> |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 35 | |
| 36 | const char i40e_driver_name[] = "i40e"; |
| 37 | static const char i40e_driver_string[] = |
| 38 | "Intel(R) Ethernet Connection XL710 Network Driver"; |
| 39 | |
| 40 | #define DRV_KERN "-k" |
| 41 | |
Catherine Sullivan | e8e724d | 2014-07-10 07:58:26 +0000 | [diff] [blame] | 42 | #define DRV_VERSION_MAJOR 1 |
Catherine Sullivan | 50f26a5 | 2016-03-10 14:59:51 -0800 | [diff] [blame] | 43 | #define DRV_VERSION_MINOR 5 |
Bimmy Pujari | c74dff1 | 2016-05-03 15:13:20 -0700 | [diff] [blame] | 44 | #define DRV_VERSION_BUILD 16 |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 45 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 46 | __stringify(DRV_VERSION_MINOR) "." \ |
| 47 | __stringify(DRV_VERSION_BUILD) DRV_KERN |
| 48 | const char i40e_driver_version_str[] = DRV_VERSION; |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 49 | static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation."; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 50 | |
| 51 | /* a bit of forward declarations */ |
| 52 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); |
| 53 | static void i40e_handle_reset_warning(struct i40e_pf *pf); |
| 54 | static int i40e_add_vsi(struct i40e_vsi *vsi); |
| 55 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 56 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 57 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
| 58 | static void i40e_determine_queue_usage(struct i40e_pf *pf); |
| 59 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 60 | static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 61 | u16 rss_table_size, u16 rss_size); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 62 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 63 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 64 | |
| 65 | /* i40e_pci_tbl - PCI Device ID Table |
| 66 | * |
| 67 | * Last entry must be all 0s |
| 68 | * |
| 69 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 70 | * Class, Class Mask, private data (not used) } |
| 71 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 72 | static const struct pci_device_id i40e_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 73 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 74 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 75 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, |
| 76 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 77 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, |
| 78 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, |
| 79 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 80 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0}, |
Shannon Nelson | bc5166b9 | 2015-08-26 15:14:10 -0400 | [diff] [blame] | 81 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0}, |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 82 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
Anjali Singhai Jain | 35dae51 | 2015-12-22 14:25:03 -0800 | [diff] [blame] | 83 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0}, |
| 84 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame] | 85 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0}, |
| 86 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0}, |
| 87 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0}, |
Catherine Sullivan | d6bf58c | 2016-03-18 12:18:08 -0700 | [diff] [blame] | 88 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0}, |
Catherine Sullivan | a3aa503 | 2016-04-13 03:08:31 -0700 | [diff] [blame] | 89 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_I_X722), 0}, |
Shannon Nelson | 48a3b51 | 2015-07-23 16:54:39 -0400 | [diff] [blame] | 90 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
| 91 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 92 | /* required last entry */ |
| 93 | {0, } |
| 94 | }; |
| 95 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 96 | |
| 97 | #define I40E_MAX_VF_COUNT 128 |
| 98 | static int debug = -1; |
| 99 | module_param(debug, int, 0); |
| 100 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 101 | |
| 102 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 103 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 104 | MODULE_LICENSE("GPL"); |
| 105 | MODULE_VERSION(DRV_VERSION); |
| 106 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 107 | static struct workqueue_struct *i40e_wq; |
| 108 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 109 | /** |
| 110 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 111 | * @hw: pointer to the HW structure |
| 112 | * @mem: ptr to mem struct to fill out |
| 113 | * @size: size of memory requested |
| 114 | * @alignment: what to align the allocation to |
| 115 | **/ |
| 116 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 117 | u64 size, u32 alignment) |
| 118 | { |
| 119 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 120 | |
| 121 | mem->size = ALIGN(size, alignment); |
| 122 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 123 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 124 | if (!mem->va) |
| 125 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 126 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 127 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /** |
| 131 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 132 | * @hw: pointer to the HW structure |
| 133 | * @mem: ptr to mem struct to free |
| 134 | **/ |
| 135 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 136 | { |
| 137 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 138 | |
| 139 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 140 | mem->va = NULL; |
| 141 | mem->pa = 0; |
| 142 | mem->size = 0; |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 149 | * @hw: pointer to the HW structure |
| 150 | * @mem: ptr to mem struct to fill out |
| 151 | * @size: size of memory requested |
| 152 | **/ |
| 153 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 154 | u32 size) |
| 155 | { |
| 156 | mem->size = size; |
| 157 | mem->va = kzalloc(size, GFP_KERNEL); |
| 158 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 159 | if (!mem->va) |
| 160 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 161 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 162 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /** |
| 166 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 167 | * @hw: pointer to the HW structure |
| 168 | * @mem: ptr to mem struct to free |
| 169 | **/ |
| 170 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 171 | { |
| 172 | /* it's ok to kfree a NULL pointer */ |
| 173 | kfree(mem->va); |
| 174 | mem->va = NULL; |
| 175 | mem->size = 0; |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * i40e_get_lump - find a lump of free generic resource |
| 182 | * @pf: board private structure |
| 183 | * @pile: the pile of resource to search |
| 184 | * @needed: the number of items needed |
| 185 | * @id: an owner id to stick on the items assigned |
| 186 | * |
| 187 | * Returns the base item index of the lump, or negative for error |
| 188 | * |
| 189 | * The search_hint trick and lack of advanced fit-finding only work |
| 190 | * because we're highly likely to have all the same size lump requests. |
| 191 | * Linear search time and any fragmentation should be minimal. |
| 192 | **/ |
| 193 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 194 | u16 needed, u16 id) |
| 195 | { |
| 196 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 197 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 198 | |
| 199 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 200 | dev_info(&pf->pdev->dev, |
| 201 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 202 | pile, needed, id); |
| 203 | return -EINVAL; |
| 204 | } |
| 205 | |
| 206 | /* start the linear search with an imperfect hint */ |
| 207 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 208 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 209 | /* skip already allocated entries */ |
| 210 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 211 | i++; |
| 212 | continue; |
| 213 | } |
| 214 | |
| 215 | /* do we have enough in this lump? */ |
| 216 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 217 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 218 | break; |
| 219 | } |
| 220 | |
| 221 | if (j == needed) { |
| 222 | /* there was enough, so assign it to the requestor */ |
| 223 | for (j = 0; j < needed; j++) |
| 224 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 225 | ret = i; |
| 226 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 227 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 228 | } |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 229 | |
| 230 | /* not enough, so skip over it and continue looking */ |
| 231 | i += j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | return ret; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * i40e_put_lump - return a lump of generic resource |
| 239 | * @pile: the pile of resource to search |
| 240 | * @index: the base item index |
| 241 | * @id: the owner id of the items assigned |
| 242 | * |
| 243 | * Returns the count of items in the lump |
| 244 | **/ |
| 245 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 246 | { |
| 247 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 248 | int count = 0; |
| 249 | int i; |
| 250 | |
| 251 | if (!pile || index >= pile->num_entries) |
| 252 | return -EINVAL; |
| 253 | |
| 254 | for (i = index; |
| 255 | i < pile->num_entries && pile->list[i] == valid_id; |
| 256 | i++) { |
| 257 | pile->list[i] = 0; |
| 258 | count++; |
| 259 | } |
| 260 | |
| 261 | if (count && index < pile->search_hint) |
| 262 | pile->search_hint = index; |
| 263 | |
| 264 | return count; |
| 265 | } |
| 266 | |
| 267 | /** |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 268 | * i40e_find_vsi_from_id - searches for the vsi with the given id |
| 269 | * @pf - the pf structure to search for the vsi |
| 270 | * @id - id of the vsi it is searching for |
| 271 | **/ |
| 272 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) |
| 273 | { |
| 274 | int i; |
| 275 | |
| 276 | for (i = 0; i < pf->num_alloc_vsi; i++) |
| 277 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) |
| 278 | return pf->vsi[i]; |
| 279 | |
| 280 | return NULL; |
| 281 | } |
| 282 | |
| 283 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 284 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 285 | * @pf: board private structure |
| 286 | * |
| 287 | * If not already scheduled, this puts the task into the work queue |
| 288 | **/ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 289 | void i40e_service_event_schedule(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 290 | { |
| 291 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 292 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && |
| 293 | !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 294 | queue_work(i40e_wq, &pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | /** |
| 298 | * i40e_tx_timeout - Respond to a Tx Hang |
| 299 | * @netdev: network interface device structure |
| 300 | * |
| 301 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 302 | * device is munged, not just the one netdev port, so go for the full |
| 303 | * reset. |
| 304 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 305 | #ifdef I40E_FCOE |
| 306 | void i40e_tx_timeout(struct net_device *netdev) |
| 307 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 308 | static void i40e_tx_timeout(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 309 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 310 | { |
| 311 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 312 | struct i40e_vsi *vsi = np->vsi; |
| 313 | struct i40e_pf *pf = vsi->back; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 314 | struct i40e_ring *tx_ring = NULL; |
| 315 | unsigned int i, hung_queue = 0; |
| 316 | u32 head, val; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 317 | |
| 318 | pf->tx_timeout_count++; |
| 319 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 320 | /* find the stopped queue the same way the stack does */ |
| 321 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 322 | struct netdev_queue *q; |
| 323 | unsigned long trans_start; |
| 324 | |
| 325 | q = netdev_get_tx_queue(netdev, i); |
Florian Westphal | 9b36627 | 2016-05-03 16:33:14 +0200 | [diff] [blame] | 326 | trans_start = q->trans_start; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 327 | if (netif_xmit_stopped(q) && |
| 328 | time_after(jiffies, |
| 329 | (trans_start + netdev->watchdog_timeo))) { |
| 330 | hung_queue = i; |
| 331 | break; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | if (i == netdev->num_tx_queues) { |
| 336 | netdev_info(netdev, "tx_timeout: no netdev hung queue found\n"); |
| 337 | } else { |
| 338 | /* now that we have an index, find the tx_ring struct */ |
| 339 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 340 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 341 | if (hung_queue == |
| 342 | vsi->tx_rings[i]->queue_index) { |
| 343 | tx_ring = vsi->tx_rings[i]; |
| 344 | break; |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 350 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 351 | pf->tx_timeout_recovery_level = 1; /* reset after some time */ |
| 352 | else if (time_before(jiffies, |
| 353 | (pf->tx_timeout_last_recovery + netdev->watchdog_timeo))) |
| 354 | return; /* don't do any new action before the next timeout */ |
| 355 | |
| 356 | if (tx_ring) { |
| 357 | head = i40e_get_head(tx_ring); |
| 358 | /* Read interrupt register */ |
| 359 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 360 | val = rd32(&pf->hw, |
| 361 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 362 | tx_ring->vsi->base_vector - 1)); |
| 363 | else |
| 364 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 365 | |
| 366 | 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", |
| 367 | vsi->seid, hung_queue, tx_ring->next_to_clean, |
| 368 | head, tx_ring->next_to_use, |
| 369 | readl(tx_ring->tail), val); |
| 370 | } |
| 371 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 372 | pf->tx_timeout_last_recovery = jiffies; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 373 | netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n", |
| 374 | pf->tx_timeout_recovery_level, hung_queue); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 375 | |
| 376 | switch (pf->tx_timeout_recovery_level) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 377 | case 1: |
| 378 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 379 | break; |
| 380 | case 2: |
| 381 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 382 | break; |
| 383 | case 3: |
| 384 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 385 | break; |
| 386 | default: |
| 387 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 388 | break; |
| 389 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 390 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 391 | i40e_service_event_schedule(pf); |
| 392 | pf->tx_timeout_recovery_level++; |
| 393 | } |
| 394 | |
| 395 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 396 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 397 | * @vsi: the VSI we care about |
| 398 | * |
| 399 | * Returns the address of the device statistics structure. |
| 400 | * The statistics are actually updated from the service task. |
| 401 | **/ |
| 402 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 403 | { |
| 404 | return &vsi->net_stats; |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 409 | * @netdev: network interface device structure |
| 410 | * |
| 411 | * Returns the address of the device statistics structure. |
| 412 | * The statistics are actually updated from the service task. |
| 413 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 414 | #ifdef I40E_FCOE |
| 415 | struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 416 | struct net_device *netdev, |
| 417 | struct rtnl_link_stats64 *stats) |
| 418 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 419 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 420 | struct net_device *netdev, |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 421 | struct rtnl_link_stats64 *stats) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 422 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 423 | { |
| 424 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 425 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 426 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 427 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 428 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 429 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 430 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 431 | return stats; |
| 432 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 433 | if (!vsi->tx_rings) |
| 434 | return stats; |
| 435 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 436 | rcu_read_lock(); |
| 437 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 438 | u64 bytes, packets; |
| 439 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 440 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 441 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 442 | if (!tx_ring) |
| 443 | continue; |
| 444 | |
| 445 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 446 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 447 | packets = tx_ring->stats.packets; |
| 448 | bytes = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 449 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 450 | |
| 451 | stats->tx_packets += packets; |
| 452 | stats->tx_bytes += bytes; |
| 453 | rx_ring = &tx_ring[1]; |
| 454 | |
| 455 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 456 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 457 | packets = rx_ring->stats.packets; |
| 458 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 459 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 460 | |
| 461 | stats->rx_packets += packets; |
| 462 | stats->rx_bytes += bytes; |
| 463 | } |
| 464 | rcu_read_unlock(); |
| 465 | |
Akeem G Abodunrin | a5282f4 | 2014-05-10 04:49:03 +0000 | [diff] [blame] | 466 | /* following stats updated by i40e_watchdog_subtask() */ |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 467 | stats->multicast = vsi_stats->multicast; |
| 468 | stats->tx_errors = vsi_stats->tx_errors; |
| 469 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 470 | stats->rx_errors = vsi_stats->rx_errors; |
Jesse Brandeburg | d8201e2 | 2015-07-23 16:54:35 -0400 | [diff] [blame] | 471 | stats->rx_dropped = vsi_stats->rx_dropped; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 472 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 473 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
| 474 | |
| 475 | return stats; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | /** |
| 479 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 480 | * @vsi: the VSI to have its stats reset |
| 481 | **/ |
| 482 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 483 | { |
| 484 | struct rtnl_link_stats64 *ns; |
| 485 | int i; |
| 486 | |
| 487 | if (!vsi) |
| 488 | return; |
| 489 | |
| 490 | ns = i40e_get_vsi_stats_struct(vsi); |
| 491 | memset(ns, 0, sizeof(*ns)); |
| 492 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 493 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 494 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 495 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 496 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 497 | memset(&vsi->rx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 498 | sizeof(vsi->rx_rings[i]->stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 499 | memset(&vsi->rx_rings[i]->rx_stats, 0, |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 500 | sizeof(vsi->rx_rings[i]->rx_stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 501 | memset(&vsi->tx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 502 | sizeof(vsi->tx_rings[i]->stats)); |
| 503 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 504 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 505 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 506 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 507 | vsi->stat_offsets_loaded = false; |
| 508 | } |
| 509 | |
| 510 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 511 | * 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] | 512 | * @pf: the PF to be reset |
| 513 | **/ |
| 514 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 515 | { |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 516 | int i; |
| 517 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 518 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 519 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 520 | pf->stat_offsets_loaded = false; |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 521 | |
| 522 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 523 | if (pf->veb[i]) { |
| 524 | memset(&pf->veb[i]->stats, 0, |
| 525 | sizeof(pf->veb[i]->stats)); |
| 526 | memset(&pf->veb[i]->stats_offsets, 0, |
| 527 | sizeof(pf->veb[i]->stats_offsets)); |
| 528 | pf->veb[i]->stat_offsets_loaded = false; |
| 529 | } |
| 530 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | /** |
| 534 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 535 | * @hw: ptr to the hardware info |
| 536 | * @hireg: the high 32 bit reg to read |
| 537 | * @loreg: the low 32 bit reg to read |
| 538 | * @offset_loaded: has the initial offset been loaded yet |
| 539 | * @offset: ptr to current offset value |
| 540 | * @stat: ptr to the stat |
| 541 | * |
| 542 | * Since the device stats are not reset at PFReset, they likely will not |
| 543 | * be zeroed when the driver starts. We'll save the first values read |
| 544 | * and use them as offsets to be subtracted from the raw values in order |
| 545 | * to report stats that count from zero. In the process, we also manage |
| 546 | * the potential roll-over. |
| 547 | **/ |
| 548 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 549 | bool offset_loaded, u64 *offset, u64 *stat) |
| 550 | { |
| 551 | u64 new_data; |
| 552 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 553 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 554 | new_data = rd32(hw, loreg); |
| 555 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 556 | } else { |
| 557 | new_data = rd64(hw, loreg); |
| 558 | } |
| 559 | if (!offset_loaded) |
| 560 | *offset = new_data; |
| 561 | if (likely(new_data >= *offset)) |
| 562 | *stat = new_data - *offset; |
| 563 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 564 | *stat = (new_data + BIT_ULL(48)) - *offset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 565 | *stat &= 0xFFFFFFFFFFFFULL; |
| 566 | } |
| 567 | |
| 568 | /** |
| 569 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 570 | * @hw: ptr to the hardware info |
| 571 | * @reg: the hw reg to read |
| 572 | * @offset_loaded: has the initial offset been loaded yet |
| 573 | * @offset: ptr to current offset value |
| 574 | * @stat: ptr to the stat |
| 575 | **/ |
| 576 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 577 | bool offset_loaded, u64 *offset, u64 *stat) |
| 578 | { |
| 579 | u32 new_data; |
| 580 | |
| 581 | new_data = rd32(hw, reg); |
| 582 | if (!offset_loaded) |
| 583 | *offset = new_data; |
| 584 | if (likely(new_data >= *offset)) |
| 585 | *stat = (u32)(new_data - *offset); |
| 586 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 587 | *stat = (u32)((new_data + BIT_ULL(32)) - *offset); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | /** |
| 591 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 592 | * @vsi: the VSI to be updated |
| 593 | **/ |
| 594 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 595 | { |
| 596 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 597 | struct i40e_pf *pf = vsi->back; |
| 598 | struct i40e_hw *hw = &pf->hw; |
| 599 | struct i40e_eth_stats *oes; |
| 600 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 601 | |
| 602 | es = &vsi->eth_stats; |
| 603 | oes = &vsi->eth_stats_offsets; |
| 604 | |
| 605 | /* Gather up the stats that the hw collects */ |
| 606 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 607 | vsi->stat_offsets_loaded, |
| 608 | &oes->tx_errors, &es->tx_errors); |
| 609 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 610 | vsi->stat_offsets_loaded, |
| 611 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 612 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 613 | vsi->stat_offsets_loaded, |
| 614 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 615 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 616 | vsi->stat_offsets_loaded, |
| 617 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 618 | |
| 619 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 620 | I40E_GLV_GORCL(stat_idx), |
| 621 | vsi->stat_offsets_loaded, |
| 622 | &oes->rx_bytes, &es->rx_bytes); |
| 623 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 624 | I40E_GLV_UPRCL(stat_idx), |
| 625 | vsi->stat_offsets_loaded, |
| 626 | &oes->rx_unicast, &es->rx_unicast); |
| 627 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 628 | I40E_GLV_MPRCL(stat_idx), |
| 629 | vsi->stat_offsets_loaded, |
| 630 | &oes->rx_multicast, &es->rx_multicast); |
| 631 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 632 | I40E_GLV_BPRCL(stat_idx), |
| 633 | vsi->stat_offsets_loaded, |
| 634 | &oes->rx_broadcast, &es->rx_broadcast); |
| 635 | |
| 636 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 637 | I40E_GLV_GOTCL(stat_idx), |
| 638 | vsi->stat_offsets_loaded, |
| 639 | &oes->tx_bytes, &es->tx_bytes); |
| 640 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 641 | I40E_GLV_UPTCL(stat_idx), |
| 642 | vsi->stat_offsets_loaded, |
| 643 | &oes->tx_unicast, &es->tx_unicast); |
| 644 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 645 | I40E_GLV_MPTCL(stat_idx), |
| 646 | vsi->stat_offsets_loaded, |
| 647 | &oes->tx_multicast, &es->tx_multicast); |
| 648 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 649 | I40E_GLV_BPTCL(stat_idx), |
| 650 | vsi->stat_offsets_loaded, |
| 651 | &oes->tx_broadcast, &es->tx_broadcast); |
| 652 | vsi->stat_offsets_loaded = true; |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * i40e_update_veb_stats - Update Switch component statistics |
| 657 | * @veb: the VEB being updated |
| 658 | **/ |
| 659 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 660 | { |
| 661 | struct i40e_pf *pf = veb->pf; |
| 662 | struct i40e_hw *hw = &pf->hw; |
| 663 | struct i40e_eth_stats *oes; |
| 664 | struct i40e_eth_stats *es; /* device's eth stats */ |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 665 | struct i40e_veb_tc_stats *veb_oes; |
| 666 | struct i40e_veb_tc_stats *veb_es; |
| 667 | int i, idx = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 668 | |
| 669 | idx = veb->stats_idx; |
| 670 | es = &veb->stats; |
| 671 | oes = &veb->stats_offsets; |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 672 | veb_es = &veb->tc_stats; |
| 673 | veb_oes = &veb->tc_stats_offsets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 674 | |
| 675 | /* Gather up the stats that the hw collects */ |
| 676 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 677 | veb->stat_offsets_loaded, |
| 678 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 679 | if (hw->revision_id > 0) |
| 680 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 681 | veb->stat_offsets_loaded, |
| 682 | &oes->rx_unknown_protocol, |
| 683 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 684 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 685 | veb->stat_offsets_loaded, |
| 686 | &oes->rx_bytes, &es->rx_bytes); |
| 687 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 688 | veb->stat_offsets_loaded, |
| 689 | &oes->rx_unicast, &es->rx_unicast); |
| 690 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 691 | veb->stat_offsets_loaded, |
| 692 | &oes->rx_multicast, &es->rx_multicast); |
| 693 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 694 | veb->stat_offsets_loaded, |
| 695 | &oes->rx_broadcast, &es->rx_broadcast); |
| 696 | |
| 697 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 698 | veb->stat_offsets_loaded, |
| 699 | &oes->tx_bytes, &es->tx_bytes); |
| 700 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 701 | veb->stat_offsets_loaded, |
| 702 | &oes->tx_unicast, &es->tx_unicast); |
| 703 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 704 | veb->stat_offsets_loaded, |
| 705 | &oes->tx_multicast, &es->tx_multicast); |
| 706 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 707 | veb->stat_offsets_loaded, |
| 708 | &oes->tx_broadcast, &es->tx_broadcast); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 709 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 710 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), |
| 711 | I40E_GLVEBTC_RPCL(i, idx), |
| 712 | veb->stat_offsets_loaded, |
| 713 | &veb_oes->tc_rx_packets[i], |
| 714 | &veb_es->tc_rx_packets[i]); |
| 715 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), |
| 716 | I40E_GLVEBTC_RBCL(i, idx), |
| 717 | veb->stat_offsets_loaded, |
| 718 | &veb_oes->tc_rx_bytes[i], |
| 719 | &veb_es->tc_rx_bytes[i]); |
| 720 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), |
| 721 | I40E_GLVEBTC_TPCL(i, idx), |
| 722 | veb->stat_offsets_loaded, |
| 723 | &veb_oes->tc_tx_packets[i], |
| 724 | &veb_es->tc_tx_packets[i]); |
| 725 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), |
| 726 | I40E_GLVEBTC_TBCL(i, idx), |
| 727 | veb->stat_offsets_loaded, |
| 728 | &veb_oes->tc_tx_bytes[i], |
| 729 | &veb_es->tc_tx_bytes[i]); |
| 730 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 731 | veb->stat_offsets_loaded = true; |
| 732 | } |
| 733 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 734 | #ifdef I40E_FCOE |
| 735 | /** |
| 736 | * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters. |
| 737 | * @vsi: the VSI that is capable of doing FCoE |
| 738 | **/ |
| 739 | static void i40e_update_fcoe_stats(struct i40e_vsi *vsi) |
| 740 | { |
| 741 | struct i40e_pf *pf = vsi->back; |
| 742 | struct i40e_hw *hw = &pf->hw; |
| 743 | struct i40e_fcoe_stats *ofs; |
| 744 | struct i40e_fcoe_stats *fs; /* device's eth stats */ |
| 745 | int idx; |
| 746 | |
| 747 | if (vsi->type != I40E_VSI_FCOE) |
| 748 | return; |
| 749 | |
Kiran Patil | 4147e2c | 2016-01-15 14:33:14 -0800 | [diff] [blame] | 750 | idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 751 | fs = &vsi->fcoe_stats; |
| 752 | ofs = &vsi->fcoe_stats_offsets; |
| 753 | |
| 754 | i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx), |
| 755 | vsi->fcoe_stat_offsets_loaded, |
| 756 | &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets); |
| 757 | i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx), |
| 758 | vsi->fcoe_stat_offsets_loaded, |
| 759 | &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords); |
| 760 | i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx), |
| 761 | vsi->fcoe_stat_offsets_loaded, |
| 762 | &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped); |
| 763 | i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx), |
| 764 | vsi->fcoe_stat_offsets_loaded, |
| 765 | &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets); |
| 766 | i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx), |
| 767 | vsi->fcoe_stat_offsets_loaded, |
| 768 | &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords); |
| 769 | i40e_stat_update32(hw, I40E_GL_FCOECRC(idx), |
| 770 | vsi->fcoe_stat_offsets_loaded, |
| 771 | &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc); |
| 772 | i40e_stat_update32(hw, I40E_GL_FCOELAST(idx), |
| 773 | vsi->fcoe_stat_offsets_loaded, |
| 774 | &ofs->fcoe_last_error, &fs->fcoe_last_error); |
| 775 | i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx), |
| 776 | vsi->fcoe_stat_offsets_loaded, |
| 777 | &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count); |
| 778 | |
| 779 | vsi->fcoe_stat_offsets_loaded = true; |
| 780 | } |
| 781 | |
| 782 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 783 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 784 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 785 | * @vsi: the VSI to be updated |
| 786 | * |
| 787 | * There are a few instances where we store the same stat in a |
| 788 | * couple of different structs. This is partly because we have |
| 789 | * the netdev stats that need to be filled out, which is slightly |
| 790 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 791 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 792 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 793 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 794 | { |
| 795 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 796 | struct rtnl_link_stats64 *ons; |
| 797 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 798 | struct i40e_eth_stats *oes; |
| 799 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 800 | u32 tx_restart, tx_busy; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 801 | u64 tx_lost_interrupt; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 802 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 803 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 804 | u64 bytes, packets; |
| 805 | unsigned int start; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 806 | u64 tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 807 | u64 tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 808 | u64 rx_p, rx_b; |
| 809 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 810 | u16 q; |
| 811 | |
| 812 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 813 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 814 | return; |
| 815 | |
| 816 | ns = i40e_get_vsi_stats_struct(vsi); |
| 817 | ons = &vsi->net_stats_offsets; |
| 818 | es = &vsi->eth_stats; |
| 819 | oes = &vsi->eth_stats_offsets; |
| 820 | |
| 821 | /* Gather up the netdev and vsi stats that the driver collects |
| 822 | * on the fly during packet processing |
| 823 | */ |
| 824 | rx_b = rx_p = 0; |
| 825 | tx_b = tx_p = 0; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 826 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 827 | tx_lost_interrupt = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 828 | rx_page = 0; |
| 829 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 830 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 831 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 832 | /* locate Tx ring */ |
| 833 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 834 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 835 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 836 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 837 | packets = p->stats.packets; |
| 838 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 839 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 840 | tx_b += bytes; |
| 841 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 842 | tx_restart += p->tx_stats.restart_queue; |
| 843 | tx_busy += p->tx_stats.tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 844 | tx_linearize += p->tx_stats.tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 845 | tx_force_wb += p->tx_stats.tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 846 | tx_lost_interrupt += p->tx_stats.tx_lost_interrupt; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 847 | |
| 848 | /* Rx queue is part of the same block as Tx queue */ |
| 849 | p = &p[1]; |
| 850 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 851 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 852 | packets = p->stats.packets; |
| 853 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 854 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 855 | rx_b += bytes; |
| 856 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 857 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 858 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 859 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 860 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 861 | vsi->tx_restart = tx_restart; |
| 862 | vsi->tx_busy = tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 863 | vsi->tx_linearize = tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 864 | vsi->tx_force_wb = tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 865 | vsi->tx_lost_interrupt = tx_lost_interrupt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 866 | vsi->rx_page_failed = rx_page; |
| 867 | vsi->rx_buf_failed = rx_buf; |
| 868 | |
| 869 | ns->rx_packets = rx_p; |
| 870 | ns->rx_bytes = rx_b; |
| 871 | ns->tx_packets = tx_p; |
| 872 | ns->tx_bytes = tx_b; |
| 873 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 874 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 875 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 876 | ons->tx_errors = oes->tx_errors; |
| 877 | ns->tx_errors = es->tx_errors; |
| 878 | ons->multicast = oes->rx_multicast; |
| 879 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 880 | ons->rx_dropped = oes->rx_discards; |
| 881 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 882 | ons->tx_dropped = oes->tx_discards; |
| 883 | ns->tx_dropped = es->tx_discards; |
| 884 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 885 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 886 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 887 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 888 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 889 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 890 | } |
| 891 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 892 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 893 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 894 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 895 | * @pf: the PF to be updated |
| 896 | **/ |
| 897 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 898 | { |
| 899 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 900 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 901 | struct i40e_hw *hw = &pf->hw; |
| 902 | u32 val; |
| 903 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 904 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 905 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 906 | I40E_GLPRT_GORCL(hw->port), |
| 907 | pf->stat_offsets_loaded, |
| 908 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 909 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 910 | I40E_GLPRT_GOTCL(hw->port), |
| 911 | pf->stat_offsets_loaded, |
| 912 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 913 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 914 | pf->stat_offsets_loaded, |
| 915 | &osd->eth.rx_discards, |
| 916 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 917 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 918 | I40E_GLPRT_UPRCL(hw->port), |
| 919 | pf->stat_offsets_loaded, |
| 920 | &osd->eth.rx_unicast, |
| 921 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 922 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 923 | I40E_GLPRT_MPRCL(hw->port), |
| 924 | pf->stat_offsets_loaded, |
| 925 | &osd->eth.rx_multicast, |
| 926 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 927 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 928 | I40E_GLPRT_BPRCL(hw->port), |
| 929 | pf->stat_offsets_loaded, |
| 930 | &osd->eth.rx_broadcast, |
| 931 | &nsd->eth.rx_broadcast); |
| 932 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 933 | I40E_GLPRT_UPTCL(hw->port), |
| 934 | pf->stat_offsets_loaded, |
| 935 | &osd->eth.tx_unicast, |
| 936 | &nsd->eth.tx_unicast); |
| 937 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 938 | I40E_GLPRT_MPTCL(hw->port), |
| 939 | pf->stat_offsets_loaded, |
| 940 | &osd->eth.tx_multicast, |
| 941 | &nsd->eth.tx_multicast); |
| 942 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 943 | I40E_GLPRT_BPTCL(hw->port), |
| 944 | pf->stat_offsets_loaded, |
| 945 | &osd->eth.tx_broadcast, |
| 946 | &nsd->eth.tx_broadcast); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 947 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 948 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 949 | pf->stat_offsets_loaded, |
| 950 | &osd->tx_dropped_link_down, |
| 951 | &nsd->tx_dropped_link_down); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 952 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 953 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 954 | pf->stat_offsets_loaded, |
| 955 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 956 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 957 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 958 | pf->stat_offsets_loaded, |
| 959 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 960 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 961 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 962 | pf->stat_offsets_loaded, |
| 963 | &osd->mac_local_faults, |
| 964 | &nsd->mac_local_faults); |
| 965 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 966 | pf->stat_offsets_loaded, |
| 967 | &osd->mac_remote_faults, |
| 968 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 969 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 970 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 971 | pf->stat_offsets_loaded, |
| 972 | &osd->rx_length_errors, |
| 973 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 974 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 975 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 976 | pf->stat_offsets_loaded, |
| 977 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 978 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 979 | pf->stat_offsets_loaded, |
| 980 | &osd->link_xon_tx, &nsd->link_xon_tx); |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 981 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 982 | pf->stat_offsets_loaded, |
| 983 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 984 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 985 | pf->stat_offsets_loaded, |
| 986 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 987 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 988 | for (i = 0; i < 8; i++) { |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 989 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 990 | pf->stat_offsets_loaded, |
| 991 | &osd->priority_xoff_rx[i], |
| 992 | &nsd->priority_xoff_rx[i]); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 993 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 994 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 995 | &osd->priority_xon_rx[i], |
| 996 | &nsd->priority_xon_rx[i]); |
| 997 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 998 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 999 | &osd->priority_xon_tx[i], |
| 1000 | &nsd->priority_xon_tx[i]); |
| 1001 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1002 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1003 | &osd->priority_xoff_tx[i], |
| 1004 | &nsd->priority_xoff_tx[i]); |
| 1005 | i40e_stat_update32(hw, |
| 1006 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1007 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1008 | &osd->priority_xon_2_xoff[i], |
| 1009 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1012 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 1013 | I40E_GLPRT_PRC64L(hw->port), |
| 1014 | pf->stat_offsets_loaded, |
| 1015 | &osd->rx_size_64, &nsd->rx_size_64); |
| 1016 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 1017 | I40E_GLPRT_PRC127L(hw->port), |
| 1018 | pf->stat_offsets_loaded, |
| 1019 | &osd->rx_size_127, &nsd->rx_size_127); |
| 1020 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 1021 | I40E_GLPRT_PRC255L(hw->port), |
| 1022 | pf->stat_offsets_loaded, |
| 1023 | &osd->rx_size_255, &nsd->rx_size_255); |
| 1024 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 1025 | I40E_GLPRT_PRC511L(hw->port), |
| 1026 | pf->stat_offsets_loaded, |
| 1027 | &osd->rx_size_511, &nsd->rx_size_511); |
| 1028 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 1029 | I40E_GLPRT_PRC1023L(hw->port), |
| 1030 | pf->stat_offsets_loaded, |
| 1031 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 1032 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 1033 | I40E_GLPRT_PRC1522L(hw->port), |
| 1034 | pf->stat_offsets_loaded, |
| 1035 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 1036 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 1037 | I40E_GLPRT_PRC9522L(hw->port), |
| 1038 | pf->stat_offsets_loaded, |
| 1039 | &osd->rx_size_big, &nsd->rx_size_big); |
| 1040 | |
| 1041 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 1042 | I40E_GLPRT_PTC64L(hw->port), |
| 1043 | pf->stat_offsets_loaded, |
| 1044 | &osd->tx_size_64, &nsd->tx_size_64); |
| 1045 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 1046 | I40E_GLPRT_PTC127L(hw->port), |
| 1047 | pf->stat_offsets_loaded, |
| 1048 | &osd->tx_size_127, &nsd->tx_size_127); |
| 1049 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 1050 | I40E_GLPRT_PTC255L(hw->port), |
| 1051 | pf->stat_offsets_loaded, |
| 1052 | &osd->tx_size_255, &nsd->tx_size_255); |
| 1053 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 1054 | I40E_GLPRT_PTC511L(hw->port), |
| 1055 | pf->stat_offsets_loaded, |
| 1056 | &osd->tx_size_511, &nsd->tx_size_511); |
| 1057 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 1058 | I40E_GLPRT_PTC1023L(hw->port), |
| 1059 | pf->stat_offsets_loaded, |
| 1060 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 1061 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 1062 | I40E_GLPRT_PTC1522L(hw->port), |
| 1063 | pf->stat_offsets_loaded, |
| 1064 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1065 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1066 | I40E_GLPRT_PTC9522L(hw->port), |
| 1067 | pf->stat_offsets_loaded, |
| 1068 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1069 | |
| 1070 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1071 | pf->stat_offsets_loaded, |
| 1072 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1073 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1074 | pf->stat_offsets_loaded, |
| 1075 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1076 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1077 | pf->stat_offsets_loaded, |
| 1078 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1079 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1080 | pf->stat_offsets_loaded, |
| 1081 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1082 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1083 | /* FDIR stats */ |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1084 | i40e_stat_update32(hw, |
| 1085 | I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)), |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1086 | pf->stat_offsets_loaded, |
| 1087 | &osd->fd_atr_match, &nsd->fd_atr_match); |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1088 | i40e_stat_update32(hw, |
| 1089 | I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)), |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1090 | pf->stat_offsets_loaded, |
| 1091 | &osd->fd_sb_match, &nsd->fd_sb_match); |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 1092 | i40e_stat_update32(hw, |
| 1093 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), |
| 1094 | pf->stat_offsets_loaded, |
| 1095 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1096 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1097 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1098 | nsd->tx_lpi_status = |
| 1099 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1100 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1101 | nsd->rx_lpi_status = |
| 1102 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1103 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1104 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1105 | pf->stat_offsets_loaded, |
| 1106 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1107 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1108 | pf->stat_offsets_loaded, |
| 1109 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1110 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1111 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
| 1112 | !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) |
| 1113 | nsd->fd_sb_status = true; |
| 1114 | else |
| 1115 | nsd->fd_sb_status = false; |
| 1116 | |
| 1117 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
| 1118 | !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 1119 | nsd->fd_atr_status = true; |
| 1120 | else |
| 1121 | nsd->fd_atr_status = false; |
| 1122 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1123 | pf->stat_offsets_loaded = true; |
| 1124 | } |
| 1125 | |
| 1126 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1127 | * i40e_update_stats - Update the various statistics counters. |
| 1128 | * @vsi: the VSI to be updated |
| 1129 | * |
| 1130 | * Update the various stats for this VSI and its related entities. |
| 1131 | **/ |
| 1132 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1133 | { |
| 1134 | struct i40e_pf *pf = vsi->back; |
| 1135 | |
| 1136 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1137 | i40e_update_pf_stats(pf); |
| 1138 | |
| 1139 | i40e_update_vsi_stats(vsi); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1140 | #ifdef I40E_FCOE |
| 1141 | i40e_update_fcoe_stats(vsi); |
| 1142 | #endif |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1146 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1147 | * @vsi: the VSI to be searched |
| 1148 | * @macaddr: the MAC address |
| 1149 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1150 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1151 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1152 | * |
| 1153 | * Returns ptr to the filter object or NULL |
| 1154 | **/ |
| 1155 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
| 1156 | u8 *macaddr, s16 vlan, |
| 1157 | bool is_vf, bool is_netdev) |
| 1158 | { |
| 1159 | struct i40e_mac_filter *f; |
| 1160 | |
| 1161 | if (!vsi || !macaddr) |
| 1162 | return NULL; |
| 1163 | |
| 1164 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1165 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1166 | (vlan == f->vlan) && |
| 1167 | (!is_vf || f->is_vf) && |
| 1168 | (!is_netdev || f->is_netdev)) |
| 1169 | return f; |
| 1170 | } |
| 1171 | return NULL; |
| 1172 | } |
| 1173 | |
| 1174 | /** |
| 1175 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1176 | * @vsi: the VSI to be searched |
| 1177 | * @macaddr: the MAC address we are searching for |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1178 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1179 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1180 | * |
| 1181 | * Returns the first filter with the provided MAC address or NULL if |
| 1182 | * MAC address was not found |
| 1183 | **/ |
| 1184 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr, |
| 1185 | bool is_vf, bool is_netdev) |
| 1186 | { |
| 1187 | struct i40e_mac_filter *f; |
| 1188 | |
| 1189 | if (!vsi || !macaddr) |
| 1190 | return NULL; |
| 1191 | |
| 1192 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1193 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1194 | (!is_vf || f->is_vf) && |
| 1195 | (!is_netdev || f->is_netdev)) |
| 1196 | return f; |
| 1197 | } |
| 1198 | return NULL; |
| 1199 | } |
| 1200 | |
| 1201 | /** |
| 1202 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1203 | * @vsi: the VSI to be searched |
| 1204 | * |
| 1205 | * Returns true if VSI is in vlan mode or false otherwise |
| 1206 | **/ |
| 1207 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1208 | { |
| 1209 | struct i40e_mac_filter *f; |
| 1210 | |
| 1211 | /* Only -1 for all the filters denotes not in vlan mode |
| 1212 | * so we have to go through all the list in order to make sure |
| 1213 | */ |
| 1214 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Greg Rose | d9b68f8 | 2015-07-23 16:54:31 -0400 | [diff] [blame] | 1215 | if (f->vlan >= 0 || vsi->info.pvid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1216 | return true; |
| 1217 | } |
| 1218 | |
| 1219 | return false; |
| 1220 | } |
| 1221 | |
| 1222 | /** |
| 1223 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1224 | * @vsi: the VSI to be searched |
| 1225 | * @macaddr: the mac address to be filtered |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1226 | * @is_vf: true if it is a VF |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1227 | * @is_netdev: true if it is a netdev |
| 1228 | * |
| 1229 | * Goes through all the macvlan filters and adds a |
| 1230 | * macvlan filter for each unique vlan that already exists |
| 1231 | * |
| 1232 | * Returns first filter found on success, else NULL |
| 1233 | **/ |
| 1234 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1235 | bool is_vf, bool is_netdev) |
| 1236 | { |
| 1237 | struct i40e_mac_filter *f; |
| 1238 | |
| 1239 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Mitch Williams | ecbb44e | 2015-07-10 19:35:56 -0400 | [diff] [blame] | 1240 | if (vsi->info.pvid) |
| 1241 | f->vlan = le16_to_cpu(vsi->info.pvid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1242 | if (!i40e_find_filter(vsi, macaddr, f->vlan, |
| 1243 | is_vf, is_netdev)) { |
| 1244 | if (!i40e_add_filter(vsi, macaddr, f->vlan, |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 1245 | is_vf, is_netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1246 | return NULL; |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | return list_first_entry_or_null(&vsi->mac_filter_list, |
| 1251 | struct i40e_mac_filter, list); |
| 1252 | } |
| 1253 | |
| 1254 | /** |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1255 | * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS |
| 1256 | * @vsi: the VSI to be searched |
| 1257 | * @macaddr: the mac address to be removed |
| 1258 | * @is_vf: true if it is a VF |
| 1259 | * @is_netdev: true if it is a netdev |
| 1260 | * |
| 1261 | * Removes a given MAC address from a VSI, regardless of VLAN |
| 1262 | * |
| 1263 | * Returns 0 for success, or error |
| 1264 | **/ |
| 1265 | int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1266 | bool is_vf, bool is_netdev) |
| 1267 | { |
| 1268 | struct i40e_mac_filter *f = NULL; |
| 1269 | int changed = 0; |
| 1270 | |
| 1271 | WARN(!spin_is_locked(&vsi->mac_filter_list_lock), |
| 1272 | "Missing mac_filter_list_lock\n"); |
| 1273 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1274 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1275 | (is_vf == f->is_vf) && |
| 1276 | (is_netdev == f->is_netdev)) { |
| 1277 | f->counter--; |
| 1278 | f->changed = true; |
| 1279 | changed = 1; |
| 1280 | } |
| 1281 | } |
| 1282 | if (changed) { |
| 1283 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1284 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1285 | return 0; |
| 1286 | } |
| 1287 | return -ENOENT; |
| 1288 | } |
| 1289 | |
| 1290 | /** |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1291 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM |
| 1292 | * @vsi: the PF Main VSI - inappropriate for any other VSI |
| 1293 | * @macaddr: the MAC address |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1294 | * |
| 1295 | * Some older firmware configurations set up a default promiscuous VLAN |
| 1296 | * filter that needs to be removed. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1297 | **/ |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1298 | 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] | 1299 | { |
| 1300 | struct i40e_aqc_remove_macvlan_element_data element; |
| 1301 | struct i40e_pf *pf = vsi->back; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1302 | i40e_status ret; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1303 | |
| 1304 | /* Only appropriate for the PF main VSI */ |
| 1305 | if (vsi->type != I40E_VSI_MAIN) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1306 | return -EINVAL; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1307 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1308 | memset(&element, 0, sizeof(element)); |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1309 | ether_addr_copy(element.mac_addr, macaddr); |
| 1310 | element.vlan_tag = 0; |
| 1311 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | |
| 1312 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1313 | ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1314 | if (ret) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1315 | return -ENOENT; |
| 1316 | |
| 1317 | return 0; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1321 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1322 | * @vsi: the VSI to be searched |
| 1323 | * @macaddr: the MAC address |
| 1324 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1325 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1326 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1327 | * |
| 1328 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1329 | * |
| 1330 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1331 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1332 | **/ |
| 1333 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
| 1334 | u8 *macaddr, s16 vlan, |
| 1335 | bool is_vf, bool is_netdev) |
| 1336 | { |
| 1337 | struct i40e_mac_filter *f; |
| 1338 | |
| 1339 | if (!vsi || !macaddr) |
| 1340 | return NULL; |
| 1341 | |
| 1342 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1343 | if (!f) { |
| 1344 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1345 | if (!f) |
| 1346 | goto add_filter_out; |
| 1347 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1348 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1349 | f->vlan = vlan; |
| 1350 | f->changed = true; |
| 1351 | |
| 1352 | INIT_LIST_HEAD(&f->list); |
Kiran Patil | 04d5a21 | 2015-12-09 15:50:23 -0800 | [diff] [blame] | 1353 | list_add_tail(&f->list, &vsi->mac_filter_list); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | /* increment counter and add a new flag if needed */ |
| 1357 | if (is_vf) { |
| 1358 | if (!f->is_vf) { |
| 1359 | f->is_vf = true; |
| 1360 | f->counter++; |
| 1361 | } |
| 1362 | } else if (is_netdev) { |
| 1363 | if (!f->is_netdev) { |
| 1364 | f->is_netdev = true; |
| 1365 | f->counter++; |
| 1366 | } |
| 1367 | } else { |
| 1368 | f->counter++; |
| 1369 | } |
| 1370 | |
| 1371 | /* changed tells sync_filters_subtask to |
| 1372 | * push the filter down to the firmware |
| 1373 | */ |
| 1374 | if (f->changed) { |
| 1375 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1376 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1377 | } |
| 1378 | |
| 1379 | add_filter_out: |
| 1380 | return f; |
| 1381 | } |
| 1382 | |
| 1383 | /** |
| 1384 | * i40e_del_filter - Remove a mac/vlan filter from the VSI |
| 1385 | * @vsi: the VSI to be searched |
| 1386 | * @macaddr: the MAC address |
| 1387 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1388 | * @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] | 1389 | * @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] | 1390 | * |
| 1391 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1392 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1393 | **/ |
| 1394 | void i40e_del_filter(struct i40e_vsi *vsi, |
| 1395 | u8 *macaddr, s16 vlan, |
| 1396 | bool is_vf, bool is_netdev) |
| 1397 | { |
| 1398 | struct i40e_mac_filter *f; |
| 1399 | |
| 1400 | if (!vsi || !macaddr) |
| 1401 | return; |
| 1402 | |
| 1403 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1404 | if (!f || f->counter == 0) |
| 1405 | return; |
| 1406 | |
| 1407 | if (is_vf) { |
| 1408 | if (f->is_vf) { |
| 1409 | f->is_vf = false; |
| 1410 | f->counter--; |
| 1411 | } |
| 1412 | } else if (is_netdev) { |
| 1413 | if (f->is_netdev) { |
| 1414 | f->is_netdev = false; |
| 1415 | f->counter--; |
| 1416 | } |
| 1417 | } else { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1418 | /* 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] | 1419 | int min_f = 0; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1420 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1421 | min_f += (f->is_vf ? 1 : 0); |
| 1422 | min_f += (f->is_netdev ? 1 : 0); |
| 1423 | |
| 1424 | if (f->counter > min_f) |
| 1425 | f->counter--; |
| 1426 | } |
| 1427 | |
| 1428 | /* counter == 0 tells sync_filters_subtask to |
| 1429 | * remove the filter from the firmware's list |
| 1430 | */ |
| 1431 | if (f->counter == 0) { |
| 1432 | f->changed = true; |
| 1433 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1434 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1435 | } |
| 1436 | } |
| 1437 | |
| 1438 | /** |
| 1439 | * i40e_set_mac - NDO callback to set mac address |
| 1440 | * @netdev: network interface device structure |
| 1441 | * @p: pointer to an address structure |
| 1442 | * |
| 1443 | * Returns 0 on success, negative on failure |
| 1444 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1445 | #ifdef I40E_FCOE |
| 1446 | int i40e_set_mac(struct net_device *netdev, void *p) |
| 1447 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1448 | static int i40e_set_mac(struct net_device *netdev, void *p) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1449 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1450 | { |
| 1451 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1452 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1453 | struct i40e_pf *pf = vsi->back; |
| 1454 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1455 | struct sockaddr *addr = p; |
| 1456 | struct i40e_mac_filter *f; |
| 1457 | |
| 1458 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1459 | return -EADDRNOTAVAIL; |
| 1460 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1461 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1462 | netdev_info(netdev, "already using mac address %pM\n", |
| 1463 | addr->sa_data); |
| 1464 | return 0; |
| 1465 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1466 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1467 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1468 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1469 | return -EADDRNOTAVAIL; |
| 1470 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1471 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1472 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1473 | hw->mac.addr); |
| 1474 | else |
| 1475 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1476 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1477 | if (vsi->type == I40E_VSI_MAIN) { |
| 1478 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1479 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1480 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1481 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1482 | addr->sa_data, NULL); |
| 1483 | if (ret) { |
| 1484 | netdev_info(netdev, |
| 1485 | "Addr change for Main VSI failed: %d\n", |
| 1486 | ret); |
| 1487 | return -EADDRNOTAVAIL; |
| 1488 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1491 | if (ether_addr_equal(netdev->dev_addr, hw->mac.addr)) { |
| 1492 | struct i40e_aqc_remove_macvlan_element_data element; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1493 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1494 | memset(&element, 0, sizeof(element)); |
| 1495 | ether_addr_copy(element.mac_addr, netdev->dev_addr); |
| 1496 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1497 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1498 | } else { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1499 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1500 | i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 1501 | false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1502 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1505 | if (ether_addr_equal(addr->sa_data, hw->mac.addr)) { |
| 1506 | struct i40e_aqc_add_macvlan_element_data element; |
| 1507 | |
| 1508 | memset(&element, 0, sizeof(element)); |
| 1509 | ether_addr_copy(element.mac_addr, hw->mac.addr); |
| 1510 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 1511 | i40e_aq_add_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1512 | } else { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1513 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1514 | f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, |
| 1515 | false, false); |
| 1516 | if (f) |
| 1517 | f->is_laa = true; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1518 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1521 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1522 | |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1523 | /* schedule our worker thread which will take care of |
| 1524 | * applying the new filter changes |
| 1525 | */ |
| 1526 | i40e_service_event_schedule(vsi->back); |
| 1527 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | /** |
| 1531 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1532 | * @vsi: the VSI being setup |
| 1533 | * @ctxt: VSI context structure |
| 1534 | * @enabled_tc: Enabled TCs bitmap |
| 1535 | * @is_add: True if called before Add VSI |
| 1536 | * |
| 1537 | * Setup VSI queue mapping for enabled traffic classes. |
| 1538 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1539 | #ifdef I40E_FCOE |
| 1540 | void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1541 | struct i40e_vsi_context *ctxt, |
| 1542 | u8 enabled_tc, |
| 1543 | bool is_add) |
| 1544 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1545 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1546 | struct i40e_vsi_context *ctxt, |
| 1547 | u8 enabled_tc, |
| 1548 | bool is_add) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1549 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1550 | { |
| 1551 | struct i40e_pf *pf = vsi->back; |
| 1552 | u16 sections = 0; |
| 1553 | u8 netdev_tc = 0; |
| 1554 | u16 numtc = 0; |
| 1555 | u16 qcount; |
| 1556 | u8 offset; |
| 1557 | u16 qmap; |
| 1558 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1559 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1560 | |
| 1561 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1562 | offset = 0; |
| 1563 | |
| 1564 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1565 | /* Find numtc from enabled TC bitmap */ |
| 1566 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1567 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1568 | numtc++; |
| 1569 | } |
| 1570 | if (!numtc) { |
| 1571 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1572 | numtc = 1; |
| 1573 | } |
| 1574 | } else { |
| 1575 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1576 | numtc = 1; |
| 1577 | } |
| 1578 | |
| 1579 | vsi->tc_config.numtc = numtc; |
| 1580 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1581 | /* Number of queues per enabled TC */ |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1582 | /* In MFP case we can have a much lower count of MSIx |
| 1583 | * vectors available and so we need to lower the used |
| 1584 | * q count. |
| 1585 | */ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1586 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 1587 | qcount = min_t(int, vsi->alloc_queue_pairs, pf->num_lan_msix); |
| 1588 | else |
| 1589 | qcount = vsi->alloc_queue_pairs; |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1590 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1591 | 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] | 1592 | |
| 1593 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1594 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1595 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1596 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1597 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1598 | int pow, num_qps; |
| 1599 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1600 | switch (vsi->type) { |
| 1601 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1602 | qcount = min_t(int, pf->alloc_rss_size, |
| 1603 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1604 | break; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1605 | #ifdef I40E_FCOE |
| 1606 | case I40E_VSI_FCOE: |
| 1607 | qcount = num_tc_qps; |
| 1608 | break; |
| 1609 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1610 | case I40E_VSI_FDIR: |
| 1611 | case I40E_VSI_SRIOV: |
| 1612 | case I40E_VSI_VMDQ2: |
| 1613 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1614 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1615 | WARN_ON(i != 0); |
| 1616 | break; |
| 1617 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1618 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1619 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1620 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1621 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1622 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1623 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1624 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1625 | pow++; |
| 1626 | num_qps >>= 1; |
| 1627 | } |
| 1628 | |
| 1629 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1630 | qmap = |
| 1631 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1632 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1633 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1634 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1635 | } else { |
| 1636 | /* TC is not enabled so set the offset to |
| 1637 | * default queue and allocate one queue |
| 1638 | * for the given TC. |
| 1639 | */ |
| 1640 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1641 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1642 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1643 | |
| 1644 | qmap = 0; |
| 1645 | } |
| 1646 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1647 | } |
| 1648 | |
| 1649 | /* Set actual Tx/Rx queue pairs */ |
| 1650 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1651 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1652 | if (vsi->req_queue_pairs > 0) |
| 1653 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1654 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1655 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1656 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1657 | |
| 1658 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1659 | if (is_add) { |
| 1660 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1661 | |
| 1662 | ctxt->info.up_enable_bits = enabled_tc; |
| 1663 | } |
| 1664 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1665 | ctxt->info.mapping_flags |= |
| 1666 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1667 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1668 | ctxt->info.queue_mapping[i] = |
| 1669 | cpu_to_le16(vsi->base_queue + i); |
| 1670 | } else { |
| 1671 | ctxt->info.mapping_flags |= |
| 1672 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1673 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1674 | } |
| 1675 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1676 | } |
| 1677 | |
| 1678 | /** |
| 1679 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1680 | * @netdev: network interface device structure |
| 1681 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1682 | #ifdef I40E_FCOE |
| 1683 | void i40e_set_rx_mode(struct net_device *netdev) |
| 1684 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1685 | static void i40e_set_rx_mode(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1686 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1687 | { |
| 1688 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1689 | struct i40e_mac_filter *f, *ftmp; |
| 1690 | struct i40e_vsi *vsi = np->vsi; |
| 1691 | struct netdev_hw_addr *uca; |
| 1692 | struct netdev_hw_addr *mca; |
| 1693 | struct netdev_hw_addr *ha; |
| 1694 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1695 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1696 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1697 | /* add addr if not already in the filter list */ |
| 1698 | netdev_for_each_uc_addr(uca, netdev) { |
| 1699 | if (!i40e_find_mac(vsi, uca->addr, false, true)) { |
| 1700 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1701 | i40e_put_mac_in_vlan(vsi, uca->addr, |
| 1702 | false, true); |
| 1703 | else |
| 1704 | i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY, |
| 1705 | false, true); |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | netdev_for_each_mc_addr(mca, netdev) { |
| 1710 | if (!i40e_find_mac(vsi, mca->addr, false, true)) { |
| 1711 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1712 | i40e_put_mac_in_vlan(vsi, mca->addr, |
| 1713 | false, true); |
| 1714 | else |
| 1715 | i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY, |
| 1716 | false, true); |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | /* remove filter if not in netdev list */ |
| 1721 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1722 | |
| 1723 | if (!f->is_netdev) |
| 1724 | continue; |
| 1725 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1726 | netdev_for_each_mc_addr(mca, netdev) |
| 1727 | if (ether_addr_equal(mca->addr, f->macaddr)) |
| 1728 | goto bottom_of_search_loop; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1729 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1730 | netdev_for_each_uc_addr(uca, netdev) |
| 1731 | if (ether_addr_equal(uca->addr, f->macaddr)) |
| 1732 | goto bottom_of_search_loop; |
| 1733 | |
| 1734 | for_each_dev_addr(netdev, ha) |
| 1735 | if (ether_addr_equal(ha->addr, f->macaddr)) |
| 1736 | goto bottom_of_search_loop; |
| 1737 | |
| 1738 | /* f->macaddr wasn't found in uc, mc, or ha list so delete it */ |
| 1739 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true); |
| 1740 | |
| 1741 | bottom_of_search_loop: |
| 1742 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1743 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1744 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1745 | |
| 1746 | /* check for other flag changes */ |
| 1747 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1748 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1749 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1750 | } |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1751 | |
| 1752 | /* schedule our worker thread which will take care of |
| 1753 | * applying the new filter changes |
| 1754 | */ |
| 1755 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | /** |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1759 | * i40e_mac_filter_entry_clone - Clones a MAC filter entry |
| 1760 | * @src: source MAC filter entry to be clones |
| 1761 | * |
| 1762 | * Returns the pointer to newly cloned MAC filter entry or NULL |
| 1763 | * in case of error |
| 1764 | **/ |
| 1765 | static struct i40e_mac_filter *i40e_mac_filter_entry_clone( |
| 1766 | struct i40e_mac_filter *src) |
| 1767 | { |
| 1768 | struct i40e_mac_filter *f; |
| 1769 | |
| 1770 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1771 | if (!f) |
| 1772 | return NULL; |
| 1773 | *f = *src; |
| 1774 | |
| 1775 | INIT_LIST_HEAD(&f->list); |
| 1776 | |
| 1777 | return f; |
| 1778 | } |
| 1779 | |
| 1780 | /** |
| 1781 | * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries |
| 1782 | * @vsi: pointer to vsi struct |
| 1783 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1784 | * those entries needs to be undone. |
| 1785 | * |
| 1786 | * MAC filter entries from list were slated to be removed from device. |
| 1787 | **/ |
| 1788 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1789 | struct list_head *from) |
| 1790 | { |
| 1791 | struct i40e_mac_filter *f, *ftmp; |
| 1792 | |
| 1793 | list_for_each_entry_safe(f, ftmp, from, list) { |
| 1794 | f->changed = true; |
| 1795 | /* Move the element back into MAC filter list*/ |
| 1796 | list_move_tail(&f->list, &vsi->mac_filter_list); |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | /** |
| 1801 | * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries |
| 1802 | * @vsi: pointer to vsi struct |
| 1803 | * |
| 1804 | * MAC filter entries from list were slated to be added from device. |
| 1805 | **/ |
| 1806 | static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi) |
| 1807 | { |
| 1808 | struct i40e_mac_filter *f, *ftmp; |
| 1809 | |
| 1810 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1811 | if (!f->changed && f->counter) |
| 1812 | f->changed = true; |
| 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | /** |
| 1817 | * i40e_cleanup_add_list - Deletes the element from add list and release |
| 1818 | * memory |
| 1819 | * @add_list: Pointer to list which contains MAC filter entries |
| 1820 | **/ |
| 1821 | static void i40e_cleanup_add_list(struct list_head *add_list) |
| 1822 | { |
| 1823 | struct i40e_mac_filter *f, *ftmp; |
| 1824 | |
| 1825 | list_for_each_entry_safe(f, ftmp, add_list, list) { |
| 1826 | list_del(&f->list); |
| 1827 | kfree(f); |
| 1828 | } |
| 1829 | } |
| 1830 | |
| 1831 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1832 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1833 | * @vsi: ptr to the VSI |
| 1834 | * |
| 1835 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1836 | * |
| 1837 | * Returns 0 or error value |
| 1838 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 1839 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1840 | { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1841 | struct list_head tmp_del_list, tmp_add_list; |
| 1842 | struct i40e_mac_filter *f, *ftmp, *fclone; |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1843 | struct i40e_hw *hw = &vsi->back->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1844 | bool promisc_forced_on = false; |
| 1845 | bool add_happened = false; |
| 1846 | int filter_list_len = 0; |
| 1847 | u32 changed_flags = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1848 | i40e_status aq_ret = 0; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1849 | bool err_cond = false; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1850 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1851 | struct i40e_pf *pf; |
| 1852 | int num_add = 0; |
| 1853 | int num_del = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1854 | int aq_err = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1855 | u16 cmd_flags; |
| 1856 | |
| 1857 | /* empty array typed pointers, kcalloc later */ |
| 1858 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1859 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1860 | |
| 1861 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1862 | usleep_range(1000, 2000); |
| 1863 | pf = vsi->back; |
| 1864 | |
| 1865 | if (vsi->netdev) { |
| 1866 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1867 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1868 | } |
| 1869 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1870 | INIT_LIST_HEAD(&tmp_del_list); |
| 1871 | INIT_LIST_HEAD(&tmp_add_list); |
| 1872 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1873 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1874 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1875 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1876 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1877 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1878 | if (!f->changed) |
| 1879 | continue; |
| 1880 | |
| 1881 | if (f->counter != 0) |
| 1882 | continue; |
| 1883 | f->changed = false; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1884 | |
| 1885 | /* Move the element into temporary del_list */ |
| 1886 | list_move_tail(&f->list, &tmp_del_list); |
| 1887 | } |
| 1888 | |
| 1889 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1890 | if (!f->changed) |
| 1891 | continue; |
| 1892 | |
| 1893 | if (f->counter == 0) |
| 1894 | continue; |
| 1895 | f->changed = false; |
| 1896 | |
| 1897 | /* Clone MAC filter entry and add into temporary list */ |
| 1898 | fclone = i40e_mac_filter_entry_clone(f); |
| 1899 | if (!fclone) { |
| 1900 | err_cond = true; |
| 1901 | break; |
| 1902 | } |
| 1903 | list_add_tail(&fclone->list, &tmp_add_list); |
| 1904 | } |
| 1905 | |
| 1906 | /* if failed to clone MAC filter entry - undo */ |
| 1907 | if (err_cond) { |
| 1908 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 1909 | i40e_undo_add_filter_entries(vsi); |
| 1910 | } |
| 1911 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 1912 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1913 | if (err_cond) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1914 | i40e_cleanup_add_list(&tmp_add_list); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1915 | retval = -ENOMEM; |
| 1916 | goto out; |
| 1917 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | /* Now process 'del_list' outside the lock */ |
| 1921 | if (!list_empty(&tmp_del_list)) { |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1922 | int del_list_size; |
| 1923 | |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1924 | filter_list_len = hw->aq.asq_buf_size / |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1925 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1926 | del_list_size = filter_list_len * |
| 1927 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Jesse Brandeburg | 38c3cec | 2016-01-04 10:33:05 -0800 | [diff] [blame] | 1928 | del_list = kzalloc(del_list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1929 | if (!del_list) { |
| 1930 | i40e_cleanup_add_list(&tmp_add_list); |
| 1931 | |
| 1932 | /* Undo VSI's MAC filter entry element updates */ |
| 1933 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1934 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 1935 | i40e_undo_add_filter_entries(vsi); |
| 1936 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1937 | retval = -ENOMEM; |
| 1938 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1942 | cmd_flags = 0; |
| 1943 | |
| 1944 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1945 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1946 | del_list[num_del].vlan_tag = |
| 1947 | cpu_to_le16((u16)(f->vlan == |
| 1948 | I40E_VLAN_ANY ? 0 : f->vlan)); |
| 1949 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1950 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1951 | del_list[num_del].flags = cmd_flags; |
| 1952 | num_del++; |
| 1953 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1954 | /* flush a full buffer */ |
| 1955 | if (num_del == filter_list_len) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1956 | aq_ret = |
| 1957 | i40e_aq_remove_macvlan(hw, vsi->seid, |
| 1958 | del_list, |
| 1959 | num_del, NULL); |
| 1960 | aq_err = hw->aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1961 | num_del = 0; |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1962 | memset(del_list, 0, del_list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1963 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1964 | if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) { |
| 1965 | retval = -EIO; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1966 | dev_err(&pf->pdev->dev, |
| 1967 | "ignoring delete macvlan error, err %s, aq_err %s while flushing a full buffer\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1968 | |
| 1969 | i40e_stat_str(hw, aq_ret), |
| 1970 | i40e_aq_str(hw, aq_err)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1971 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1972 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1973 | /* Release memory for MAC filter entries which were |
| 1974 | * synced up with HW. |
| 1975 | */ |
| 1976 | list_del(&f->list); |
| 1977 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1978 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1979 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1980 | if (num_del) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1981 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, del_list, |
| 1982 | num_del, NULL); |
| 1983 | aq_err = hw->aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1984 | num_del = 0; |
| 1985 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1986 | if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1987 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1988 | "ignoring delete macvlan error, err %s aq_err %s\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1989 | i40e_stat_str(hw, aq_ret), |
| 1990 | i40e_aq_str(hw, aq_err)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | kfree(del_list); |
| 1994 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | if (!list_empty(&tmp_add_list)) { |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1998 | int add_list_size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1999 | |
| 2000 | /* do all the adds now */ |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2001 | filter_list_len = hw->aq.asq_buf_size / |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2002 | sizeof(struct i40e_aqc_add_macvlan_element_data), |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2003 | add_list_size = filter_list_len * |
| 2004 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Jesse Brandeburg | 38c3cec | 2016-01-04 10:33:05 -0800 | [diff] [blame] | 2005 | add_list = kzalloc(add_list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2006 | if (!add_list) { |
| 2007 | /* Purge element from temporary lists */ |
| 2008 | i40e_cleanup_add_list(&tmp_add_list); |
| 2009 | |
| 2010 | /* Undo add filter entries from VSI MAC filter list */ |
| 2011 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2012 | i40e_undo_add_filter_entries(vsi); |
| 2013 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2014 | retval = -ENOMEM; |
| 2015 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2016 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2017 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2018 | list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2019 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2020 | add_happened = true; |
| 2021 | cmd_flags = 0; |
| 2022 | |
| 2023 | /* add to add array */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2024 | ether_addr_copy(add_list[num_add].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2025 | add_list[num_add].vlan_tag = |
| 2026 | cpu_to_le16( |
| 2027 | (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan)); |
| 2028 | add_list[num_add].queue_number = 0; |
| 2029 | |
| 2030 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2031 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2032 | num_add++; |
| 2033 | |
| 2034 | /* flush a full buffer */ |
| 2035 | if (num_add == filter_list_len) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2036 | aq_ret = i40e_aq_add_macvlan(hw, vsi->seid, |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2037 | add_list, num_add, |
| 2038 | NULL); |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2039 | aq_err = hw->aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2040 | num_add = 0; |
| 2041 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2042 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2043 | break; |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2044 | memset(add_list, 0, add_list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2045 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2046 | /* Entries from tmp_add_list were cloned from MAC |
| 2047 | * filter list, hence clean those cloned entries |
| 2048 | */ |
| 2049 | list_del(&f->list); |
| 2050 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2051 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2052 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2053 | if (num_add) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2054 | aq_ret = i40e_aq_add_macvlan(hw, vsi->seid, |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2055 | add_list, num_add, NULL); |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2056 | aq_err = hw->aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2057 | num_add = 0; |
| 2058 | } |
| 2059 | kfree(add_list); |
| 2060 | add_list = NULL; |
| 2061 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2062 | if (add_happened && aq_ret && aq_err != I40E_AQ_RC_EINVAL) { |
| 2063 | retval = i40e_aq_rc_to_posix(aq_ret, aq_err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2064 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2065 | "add filter failed, err %s aq_err %s\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2066 | i40e_stat_str(hw, aq_ret), |
| 2067 | i40e_aq_str(hw, aq_err)); |
| 2068 | if ((hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) && |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2069 | !test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2070 | &vsi->state)) { |
| 2071 | promisc_forced_on = true; |
| 2072 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2073 | &vsi->state); |
| 2074 | dev_info(&pf->pdev->dev, "promiscuous mode forced on\n"); |
| 2075 | } |
| 2076 | } |
| 2077 | } |
| 2078 | |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 2079 | /* if the VF is not trusted do not do promisc */ |
| 2080 | if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) { |
| 2081 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 2082 | goto out; |
| 2083 | } |
| 2084 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2085 | /* check for changes in promiscuous modes */ |
| 2086 | if (changed_flags & IFF_ALLMULTI) { |
| 2087 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2088 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2089 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2090 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2091 | vsi->seid, |
| 2092 | cur_multipromisc, |
| 2093 | NULL); |
| 2094 | if (aq_ret) { |
| 2095 | retval = i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2096 | hw->aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2097 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2098 | "set multi promisc failed, err %s aq_err %s\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2099 | i40e_stat_str(hw, aq_ret), |
| 2100 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2101 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2102 | } |
| 2103 | if ((changed_flags & IFF_PROMISC) || promisc_forced_on) { |
| 2104 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2105 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2106 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 2107 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2108 | &vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2109 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2110 | (pf->lan_veb != I40E_NO_VEB) && |
| 2111 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2112 | /* set defport ON for Main VSI instead of true promisc |
| 2113 | * this way we will get all unicast/multicast and VLAN |
| 2114 | * promisc behavior but will not get VF or VMDq traffic |
| 2115 | * replicated on the Main VSI. |
| 2116 | */ |
| 2117 | if (pf->cur_promisc != cur_promisc) { |
| 2118 | pf->cur_promisc = cur_promisc; |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2119 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2120 | } |
| 2121 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2122 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2123 | hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2124 | vsi->seid, |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 2125 | cur_promisc, NULL, |
| 2126 | true); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2127 | if (aq_ret) { |
| 2128 | retval = |
| 2129 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2130 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2131 | dev_info(&pf->pdev->dev, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2132 | "set unicast promisc failed, err %s, aq_err %s\n", |
| 2133 | i40e_stat_str(hw, aq_ret), |
| 2134 | i40e_aq_str(hw, |
| 2135 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2136 | } |
| 2137 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2138 | hw, |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2139 | vsi->seid, |
| 2140 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2141 | if (aq_ret) { |
| 2142 | retval = |
| 2143 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2144 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2145 | dev_info(&pf->pdev->dev, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2146 | "set multicast promisc failed, err %s, aq_err %s\n", |
| 2147 | i40e_stat_str(hw, aq_ret), |
| 2148 | i40e_aq_str(hw, |
| 2149 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2150 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2151 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2152 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2153 | vsi->seid, |
| 2154 | cur_promisc, NULL); |
| 2155 | if (aq_ret) { |
| 2156 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2157 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2158 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2159 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2160 | i40e_stat_str(hw, aq_ret), |
| 2161 | i40e_aq_str(hw, |
| 2162 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2163 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2164 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2165 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2166 | /* if something went wrong then set the changed flag so we try again */ |
| 2167 | if (retval) |
| 2168 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2169 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2170 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2171 | return retval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | /** |
| 2175 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2176 | * @pf: board private structure |
| 2177 | **/ |
| 2178 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2179 | { |
| 2180 | int v; |
| 2181 | |
| 2182 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2183 | return; |
| 2184 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2185 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2186 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2187 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2188 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2189 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2190 | |
| 2191 | if (ret) { |
| 2192 | /* come back and try again later */ |
| 2193 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2194 | break; |
| 2195 | } |
| 2196 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | /** |
| 2201 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2202 | * @netdev: network interface device structure |
| 2203 | * @new_mtu: new value for maximum frame size |
| 2204 | * |
| 2205 | * Returns 0 on success, negative on failure |
| 2206 | **/ |
| 2207 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2208 | { |
| 2209 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 61a46a4 | 2014-04-23 04:50:05 +0000 | [diff] [blame] | 2210 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2211 | struct i40e_vsi *vsi = np->vsi; |
| 2212 | |
| 2213 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 2214 | if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) |
| 2215 | return -EINVAL; |
| 2216 | |
| 2217 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2218 | netdev->mtu, new_mtu); |
| 2219 | netdev->mtu = new_mtu; |
| 2220 | if (netif_running(netdev)) |
| 2221 | i40e_vsi_reinit_locked(vsi); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 2222 | i40e_notify_client_of_l2_param_changes(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2223 | return 0; |
| 2224 | } |
| 2225 | |
| 2226 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2227 | * i40e_ioctl - Access the hwtstamp interface |
| 2228 | * @netdev: network interface device structure |
| 2229 | * @ifr: interface request data |
| 2230 | * @cmd: ioctl command |
| 2231 | **/ |
| 2232 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2233 | { |
| 2234 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2235 | struct i40e_pf *pf = np->vsi->back; |
| 2236 | |
| 2237 | switch (cmd) { |
| 2238 | case SIOCGHWTSTAMP: |
| 2239 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2240 | case SIOCSHWTSTAMP: |
| 2241 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2242 | default: |
| 2243 | return -EOPNOTSUPP; |
| 2244 | } |
| 2245 | } |
| 2246 | |
| 2247 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2248 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2249 | * @vsi: the vsi being adjusted |
| 2250 | **/ |
| 2251 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2252 | { |
| 2253 | struct i40e_vsi_context ctxt; |
| 2254 | i40e_status ret; |
| 2255 | |
| 2256 | if ((vsi->info.valid_sections & |
| 2257 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2258 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2259 | return; /* already enabled */ |
| 2260 | |
| 2261 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2262 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2263 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2264 | |
| 2265 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2266 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2267 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2268 | if (ret) { |
| 2269 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2270 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2271 | i40e_stat_str(&vsi->back->hw, ret), |
| 2272 | i40e_aq_str(&vsi->back->hw, |
| 2273 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | /** |
| 2278 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2279 | * @vsi: the vsi being adjusted |
| 2280 | **/ |
| 2281 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2282 | { |
| 2283 | struct i40e_vsi_context ctxt; |
| 2284 | i40e_status ret; |
| 2285 | |
| 2286 | if ((vsi->info.valid_sections & |
| 2287 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2288 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2289 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2290 | return; /* already disabled */ |
| 2291 | |
| 2292 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2293 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2294 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2295 | |
| 2296 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2297 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2298 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2299 | if (ret) { |
| 2300 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2301 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2302 | i40e_stat_str(&vsi->back->hw, ret), |
| 2303 | i40e_aq_str(&vsi->back->hw, |
| 2304 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2305 | } |
| 2306 | } |
| 2307 | |
| 2308 | /** |
| 2309 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2310 | * @netdev: network interface to be adjusted |
| 2311 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2312 | **/ |
| 2313 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2314 | { |
| 2315 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2316 | struct i40e_vsi *vsi = np->vsi; |
| 2317 | |
| 2318 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2319 | i40e_vlan_stripping_enable(vsi); |
| 2320 | else |
| 2321 | i40e_vlan_stripping_disable(vsi); |
| 2322 | } |
| 2323 | |
| 2324 | /** |
| 2325 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 2326 | * @vsi: the vsi being configured |
| 2327 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 2328 | **/ |
| 2329 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2330 | { |
| 2331 | struct i40e_mac_filter *f, *add_f; |
| 2332 | bool is_netdev, is_vf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2333 | |
| 2334 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2335 | is_netdev = !!(vsi->netdev); |
| 2336 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2337 | /* Locked once because all functions invoked below iterates list*/ |
| 2338 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2339 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2340 | if (is_netdev) { |
| 2341 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid, |
| 2342 | is_vf, is_netdev); |
| 2343 | if (!add_f) { |
| 2344 | dev_info(&vsi->back->pdev->dev, |
| 2345 | "Could not add vlan filter %d for %pM\n", |
| 2346 | vid, vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2347 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2348 | return -ENOMEM; |
| 2349 | } |
| 2350 | } |
| 2351 | |
| 2352 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2353 | add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2354 | if (!add_f) { |
| 2355 | dev_info(&vsi->back->pdev->dev, |
| 2356 | "Could not add vlan filter %d for %pM\n", |
| 2357 | vid, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2358 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2359 | return -ENOMEM; |
| 2360 | } |
| 2361 | } |
| 2362 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2363 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 2364 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 2365 | * with 0, so we now accept untagged and specified tagged traffic |
| 2366 | * (and not any taged and untagged) |
| 2367 | */ |
| 2368 | if (vid > 0) { |
| 2369 | if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 2370 | I40E_VLAN_ANY, |
| 2371 | is_vf, is_netdev)) { |
| 2372 | i40e_del_filter(vsi, vsi->netdev->dev_addr, |
| 2373 | I40E_VLAN_ANY, is_vf, is_netdev); |
| 2374 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0, |
| 2375 | is_vf, is_netdev); |
| 2376 | if (!add_f) { |
| 2377 | dev_info(&vsi->back->pdev->dev, |
| 2378 | "Could not add filter 0 for %pM\n", |
| 2379 | vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2380 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2381 | return -ENOMEM; |
| 2382 | } |
| 2383 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2384 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2385 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2386 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
| 2387 | if (vid > 0 && !vsi->info.pvid) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2388 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2389 | if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2390 | is_vf, is_netdev)) |
| 2391 | continue; |
| 2392 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2393 | is_vf, is_netdev); |
| 2394 | add_f = i40e_add_filter(vsi, f->macaddr, |
| 2395 | 0, is_vf, is_netdev); |
| 2396 | if (!add_f) { |
| 2397 | dev_info(&vsi->back->pdev->dev, |
| 2398 | "Could not add filter 0 for %pM\n", |
| 2399 | f->macaddr); |
| 2400 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2401 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2402 | } |
| 2403 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2404 | } |
| 2405 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2406 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2407 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2408 | /* schedule our worker thread which will take care of |
| 2409 | * applying the new filter changes |
| 2410 | */ |
| 2411 | i40e_service_event_schedule(vsi->back); |
| 2412 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | /** |
| 2416 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 2417 | * @vsi: the vsi being configured |
| 2418 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2419 | * |
| 2420 | * Return: 0 on success or negative otherwise |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2421 | **/ |
| 2422 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2423 | { |
| 2424 | struct net_device *netdev = vsi->netdev; |
| 2425 | struct i40e_mac_filter *f, *add_f; |
| 2426 | bool is_vf, is_netdev; |
| 2427 | int filter_count = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2428 | |
| 2429 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2430 | is_netdev = !!(netdev); |
| 2431 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2432 | /* Locked once because all functions invoked below iterates list */ |
| 2433 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2434 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2435 | if (is_netdev) |
| 2436 | i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev); |
| 2437 | |
| 2438 | list_for_each_entry(f, &vsi->mac_filter_list, list) |
| 2439 | i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2440 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2441 | /* go through all the filters for this VSI and if there is only |
| 2442 | * vid == 0 it means there are no other filters, so vid 0 must |
| 2443 | * be replaced with -1. This signifies that we should from now |
| 2444 | * on accept any traffic (with any tag present, or untagged) |
| 2445 | */ |
| 2446 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2447 | if (is_netdev) { |
| 2448 | if (f->vlan && |
| 2449 | ether_addr_equal(netdev->dev_addr, f->macaddr)) |
| 2450 | filter_count++; |
| 2451 | } |
| 2452 | |
| 2453 | if (f->vlan) |
| 2454 | filter_count++; |
| 2455 | } |
| 2456 | |
| 2457 | if (!filter_count && is_netdev) { |
| 2458 | i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev); |
| 2459 | f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 2460 | is_vf, is_netdev); |
| 2461 | if (!f) { |
| 2462 | dev_info(&vsi->back->pdev->dev, |
| 2463 | "Could not add filter %d for %pM\n", |
| 2464 | I40E_VLAN_ANY, netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2465 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2466 | return -ENOMEM; |
| 2467 | } |
| 2468 | } |
| 2469 | |
| 2470 | if (!filter_count) { |
| 2471 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2472 | i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev); |
| 2473 | add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2474 | is_vf, is_netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2475 | if (!add_f) { |
| 2476 | dev_info(&vsi->back->pdev->dev, |
| 2477 | "Could not add filter %d for %pM\n", |
| 2478 | I40E_VLAN_ANY, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2479 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2480 | return -ENOMEM; |
| 2481 | } |
| 2482 | } |
| 2483 | } |
| 2484 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2485 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2486 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2487 | /* schedule our worker thread which will take care of |
| 2488 | * applying the new filter changes |
| 2489 | */ |
| 2490 | i40e_service_event_schedule(vsi->back); |
| 2491 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | /** |
| 2495 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2496 | * @netdev: network interface to be adjusted |
| 2497 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2498 | * |
| 2499 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2500 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2501 | #ifdef I40E_FCOE |
| 2502 | int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2503 | __always_unused __be16 proto, u16 vid) |
| 2504 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2505 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2506 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2507 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2508 | { |
| 2509 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2510 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2511 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2512 | |
| 2513 | if (vid > 4095) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2514 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2515 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2516 | netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid); |
| 2517 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2518 | /* If the network stack called us with vid = 0 then |
| 2519 | * it is asking to receive priority tagged packets with |
| 2520 | * vlan id 0. Our HW receives them by default when configured |
| 2521 | * to receive untagged packets so there is no need to add an |
| 2522 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2523 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2524 | if (vid) |
| 2525 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2526 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2527 | if (!ret && (vid < VLAN_N_VID)) |
| 2528 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2529 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2530 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | /** |
| 2534 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2535 | * @netdev: network interface to be adjusted |
| 2536 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2537 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2538 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2539 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2540 | #ifdef I40E_FCOE |
| 2541 | int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2542 | __always_unused __be16 proto, u16 vid) |
| 2543 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2544 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2545 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2546 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2547 | { |
| 2548 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2549 | struct i40e_vsi *vsi = np->vsi; |
| 2550 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2551 | netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid); |
| 2552 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2553 | /* return code is ignored as there is nothing a user |
| 2554 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2555 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2556 | */ |
| 2557 | i40e_vsi_kill_vlan(vsi, vid); |
| 2558 | |
| 2559 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2560 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2561 | return 0; |
| 2562 | } |
| 2563 | |
| 2564 | /** |
| 2565 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2566 | * @vsi: the vsi being brought back up |
| 2567 | **/ |
| 2568 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2569 | { |
| 2570 | u16 vid; |
| 2571 | |
| 2572 | if (!vsi->netdev) |
| 2573 | return; |
| 2574 | |
| 2575 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2576 | |
| 2577 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2578 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2579 | vid); |
| 2580 | } |
| 2581 | |
| 2582 | /** |
| 2583 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2584 | * @vsi: the vsi being adjusted |
| 2585 | * @vid: the vlan id to set as a PVID |
| 2586 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2587 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2588 | { |
| 2589 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2590 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2591 | |
| 2592 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2593 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2594 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2595 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2596 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2597 | |
| 2598 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2599 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2600 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2601 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2602 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2603 | "add pvid failed, err %s aq_err %s\n", |
| 2604 | i40e_stat_str(&vsi->back->hw, ret), |
| 2605 | i40e_aq_str(&vsi->back->hw, |
| 2606 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2607 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2608 | } |
| 2609 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2610 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | /** |
| 2614 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2615 | * @vsi: the vsi being adjusted |
| 2616 | * |
| 2617 | * Just use the vlan_rx_register() service to put it back to normal |
| 2618 | **/ |
| 2619 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2620 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2621 | i40e_vlan_stripping_disable(vsi); |
| 2622 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2623 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | /** |
| 2627 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2628 | * @vsi: ptr to the VSI |
| 2629 | * |
| 2630 | * If this function returns with an error, then it's possible one or |
| 2631 | * more of the rings is populated (while the rest are not). It is the |
| 2632 | * callers duty to clean those orphaned rings. |
| 2633 | * |
| 2634 | * Return 0 on success, negative on failure |
| 2635 | **/ |
| 2636 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2637 | { |
| 2638 | int i, err = 0; |
| 2639 | |
| 2640 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2641 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2642 | |
| 2643 | return err; |
| 2644 | } |
| 2645 | |
| 2646 | /** |
| 2647 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2648 | * @vsi: ptr to the VSI |
| 2649 | * |
| 2650 | * Free VSI's transmit software resources |
| 2651 | **/ |
| 2652 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2653 | { |
| 2654 | int i; |
| 2655 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2656 | if (!vsi->tx_rings) |
| 2657 | return; |
| 2658 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2659 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2660 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2661 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | /** |
| 2665 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2666 | * @vsi: ptr to the VSI |
| 2667 | * |
| 2668 | * If this function returns with an error, then it's possible one or |
| 2669 | * more of the rings is populated (while the rest are not). It is the |
| 2670 | * callers duty to clean those orphaned rings. |
| 2671 | * |
| 2672 | * Return 0 on success, negative on failure |
| 2673 | **/ |
| 2674 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2675 | { |
| 2676 | int i, err = 0; |
| 2677 | |
| 2678 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2679 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2680 | #ifdef I40E_FCOE |
| 2681 | i40e_fcoe_setup_ddp_resources(vsi); |
| 2682 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2683 | return err; |
| 2684 | } |
| 2685 | |
| 2686 | /** |
| 2687 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2688 | * @vsi: ptr to the VSI |
| 2689 | * |
| 2690 | * Free all receive software resources |
| 2691 | **/ |
| 2692 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2693 | { |
| 2694 | int i; |
| 2695 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2696 | if (!vsi->rx_rings) |
| 2697 | return; |
| 2698 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2699 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2700 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2701 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2702 | #ifdef I40E_FCOE |
| 2703 | i40e_fcoe_free_ddp_resources(vsi); |
| 2704 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2708 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2709 | * @ring: The Tx ring to configure |
| 2710 | * |
| 2711 | * This enables/disables XPS for a given Tx descriptor ring |
| 2712 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2713 | **/ |
| 2714 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2715 | { |
| 2716 | struct i40e_vsi *vsi = ring->vsi; |
| 2717 | cpumask_var_t mask; |
| 2718 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2719 | if (!ring->q_vector || !ring->netdev) |
| 2720 | return; |
| 2721 | |
| 2722 | /* Single TC mode enable XPS */ |
| 2723 | if (vsi->tc_config.numtc <= 1) { |
| 2724 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2725 | netif_set_xps_queue(ring->netdev, |
| 2726 | &ring->q_vector->affinity_mask, |
| 2727 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2728 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2729 | /* Disable XPS to allow selection based on TC */ |
| 2730 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2731 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2732 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2733 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2734 | |
| 2735 | /* schedule our worker thread which will take care of |
| 2736 | * applying the new filter changes |
| 2737 | */ |
| 2738 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2742 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2743 | * @ring: The Tx ring to configure |
| 2744 | * |
| 2745 | * Configure the Tx descriptor ring in the HMC context. |
| 2746 | **/ |
| 2747 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2748 | { |
| 2749 | struct i40e_vsi *vsi = ring->vsi; |
| 2750 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2751 | struct i40e_hw *hw = &vsi->back->hw; |
| 2752 | struct i40e_hmc_obj_txq tx_ctx; |
| 2753 | i40e_status err = 0; |
| 2754 | u32 qtx_ctl = 0; |
| 2755 | |
| 2756 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2757 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2758 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2759 | ring->atr_count = 0; |
| 2760 | } else { |
| 2761 | ring->atr_sample_rate = 0; |
| 2762 | } |
| 2763 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2764 | /* configure XPS */ |
| 2765 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2766 | |
| 2767 | /* clear the context structure first */ |
| 2768 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2769 | |
| 2770 | tx_ctx.new_context = 1; |
| 2771 | tx_ctx.base = (ring->dma / 128); |
| 2772 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2773 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2774 | I40E_FLAG_FD_ATR_ENABLED)); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2775 | #ifdef I40E_FCOE |
| 2776 | tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2777 | #endif |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2778 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2779 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2780 | if (vsi->type != I40E_VSI_FDIR) |
| 2781 | tx_ctx.head_wb_ena = 1; |
| 2782 | tx_ctx.head_wb_addr = ring->dma + |
| 2783 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2784 | |
| 2785 | /* As part of VSI creation/update, FW allocates certain |
| 2786 | * Tx arbitration queue sets for each TC enabled for |
| 2787 | * the VSI. The FW returns the handles to these queue |
| 2788 | * sets as part of the response buffer to Add VSI, |
| 2789 | * Update VSI, etc. AQ commands. It is expected that |
| 2790 | * these queue set handles be associated with the Tx |
| 2791 | * queues by the driver as part of the TX queue context |
| 2792 | * initialization. This has to be done regardless of |
| 2793 | * DCB as by default everything is mapped to TC0. |
| 2794 | */ |
| 2795 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2796 | tx_ctx.rdylist_act = 0; |
| 2797 | |
| 2798 | /* clear the context in the HMC */ |
| 2799 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2800 | if (err) { |
| 2801 | dev_info(&vsi->back->pdev->dev, |
| 2802 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2803 | ring->queue_index, pf_q, err); |
| 2804 | return -ENOMEM; |
| 2805 | } |
| 2806 | |
| 2807 | /* set the context in the HMC */ |
| 2808 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2809 | if (err) { |
| 2810 | dev_info(&vsi->back->pdev->dev, |
| 2811 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2812 | ring->queue_index, pf_q, err); |
| 2813 | return -ENOMEM; |
| 2814 | } |
| 2815 | |
| 2816 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2817 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2818 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2819 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2820 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2821 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2822 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2823 | } |
| 2824 | |
Shannon Nelson | 13fd977 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2825 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2826 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2827 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2828 | i40e_flush(hw); |
| 2829 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2830 | /* cache tail off for easier writes later */ |
| 2831 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2832 | |
| 2833 | return 0; |
| 2834 | } |
| 2835 | |
| 2836 | /** |
| 2837 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2838 | * @ring: The Rx ring to configure |
| 2839 | * |
| 2840 | * Configure the Rx descriptor ring in the HMC context. |
| 2841 | **/ |
| 2842 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2843 | { |
| 2844 | struct i40e_vsi *vsi = ring->vsi; |
| 2845 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2846 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2847 | struct i40e_hw *hw = &vsi->back->hw; |
| 2848 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2849 | i40e_status err = 0; |
| 2850 | |
| 2851 | ring->state = 0; |
| 2852 | |
| 2853 | /* clear the context structure first */ |
| 2854 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2855 | |
| 2856 | ring->rx_buf_len = vsi->rx_buf_len; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2857 | |
| 2858 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2859 | |
| 2860 | rx_ctx.base = (ring->dma / 128); |
| 2861 | rx_ctx.qlen = ring->count; |
| 2862 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 2863 | /* use 32 byte descriptors */ |
| 2864 | rx_ctx.dsize = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2865 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 2866 | /* descriptor type is always zero |
| 2867 | * rx_ctx.dtype = 0; |
| 2868 | */ |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 2869 | rx_ctx.hsplit_0 = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2870 | |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 2871 | rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 2872 | if (hw->revision_id == 0) |
| 2873 | rx_ctx.lrxqthresh = 0; |
| 2874 | else |
| 2875 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2876 | rx_ctx.crcstrip = 1; |
| 2877 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 2878 | /* this controls whether VLAN is stripped from inner headers */ |
| 2879 | rx_ctx.showiv = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2880 | #ifdef I40E_FCOE |
| 2881 | rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2882 | #endif |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 2883 | /* set the prefena field to 1 because the manual says to */ |
| 2884 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2885 | |
| 2886 | /* clear the context in the HMC */ |
| 2887 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 2888 | if (err) { |
| 2889 | dev_info(&vsi->back->pdev->dev, |
| 2890 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2891 | ring->queue_index, pf_q, err); |
| 2892 | return -ENOMEM; |
| 2893 | } |
| 2894 | |
| 2895 | /* set the context in the HMC */ |
| 2896 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 2897 | if (err) { |
| 2898 | dev_info(&vsi->back->pdev->dev, |
| 2899 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2900 | ring->queue_index, pf_q, err); |
| 2901 | return -ENOMEM; |
| 2902 | } |
| 2903 | |
| 2904 | /* cache tail for quicker writes, and clear the reg before use */ |
| 2905 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 2906 | writel(0, ring->tail); |
| 2907 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 2908 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2909 | |
| 2910 | return 0; |
| 2911 | } |
| 2912 | |
| 2913 | /** |
| 2914 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 2915 | * @vsi: VSI structure describing this set of rings and resources |
| 2916 | * |
| 2917 | * Configure the Tx VSI for operation. |
| 2918 | **/ |
| 2919 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 2920 | { |
| 2921 | int err = 0; |
| 2922 | u16 i; |
| 2923 | |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2924 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 2925 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2926 | |
| 2927 | return err; |
| 2928 | } |
| 2929 | |
| 2930 | /** |
| 2931 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 2932 | * @vsi: the VSI being configured |
| 2933 | * |
| 2934 | * Configure the Rx VSI for operation. |
| 2935 | **/ |
| 2936 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 2937 | { |
| 2938 | int err = 0; |
| 2939 | u16 i; |
| 2940 | |
| 2941 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 2942 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 2943 | + ETH_FCS_LEN + VLAN_HLEN; |
| 2944 | else |
| 2945 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 2946 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 2947 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2948 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2949 | #ifdef I40E_FCOE |
| 2950 | /* setup rx buffer for FCoE */ |
| 2951 | if ((vsi->type == I40E_VSI_FCOE) && |
| 2952 | (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) { |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2953 | vsi->rx_buf_len = I40E_RXBUFFER_3072; |
| 2954 | vsi->max_frame = I40E_RXBUFFER_3072; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2955 | } |
| 2956 | |
| 2957 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2958 | /* round up for the chip's needs */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2959 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2960 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2961 | |
| 2962 | /* set up individual rings */ |
| 2963 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2964 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2965 | |
| 2966 | return err; |
| 2967 | } |
| 2968 | |
| 2969 | /** |
| 2970 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 2971 | * @vsi: ptr to the VSI |
| 2972 | **/ |
| 2973 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 2974 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 2975 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2976 | u16 qoffset, qcount; |
| 2977 | int i, n; |
| 2978 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 2979 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 2980 | /* Reset the TC information */ |
| 2981 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 2982 | rx_ring = vsi->rx_rings[i]; |
| 2983 | tx_ring = vsi->tx_rings[i]; |
| 2984 | rx_ring->dcb_tc = 0; |
| 2985 | tx_ring->dcb_tc = 0; |
| 2986 | } |
| 2987 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2988 | |
| 2989 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2990 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2991 | continue; |
| 2992 | |
| 2993 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 2994 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 2995 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 2996 | rx_ring = vsi->rx_rings[i]; |
| 2997 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2998 | rx_ring->dcb_tc = n; |
| 2999 | tx_ring->dcb_tc = n; |
| 3000 | } |
| 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | /** |
| 3005 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3006 | * @vsi: ptr to the VSI |
| 3007 | **/ |
| 3008 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3009 | { |
| 3010 | if (vsi->netdev) |
| 3011 | i40e_set_rx_mode(vsi->netdev); |
| 3012 | } |
| 3013 | |
| 3014 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3015 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3016 | * @vsi: Pointer to the targeted VSI |
| 3017 | * |
| 3018 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3019 | * filters were saved. |
| 3020 | **/ |
| 3021 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3022 | { |
| 3023 | struct i40e_fdir_filter *filter; |
| 3024 | struct i40e_pf *pf = vsi->back; |
| 3025 | struct hlist_node *node; |
| 3026 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3027 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3028 | return; |
| 3029 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3030 | hlist_for_each_entry_safe(filter, node, |
| 3031 | &pf->fdir_filter_list, fdir_node) { |
| 3032 | i40e_add_del_fdir(vsi, filter, true); |
| 3033 | } |
| 3034 | } |
| 3035 | |
| 3036 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3037 | * i40e_vsi_configure - Set up the VSI for action |
| 3038 | * @vsi: the VSI being configured |
| 3039 | **/ |
| 3040 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3041 | { |
| 3042 | int err; |
| 3043 | |
| 3044 | i40e_set_vsi_rx_mode(vsi); |
| 3045 | i40e_restore_vlan(vsi); |
| 3046 | i40e_vsi_config_dcb_rings(vsi); |
| 3047 | err = i40e_vsi_configure_tx(vsi); |
| 3048 | if (!err) |
| 3049 | err = i40e_vsi_configure_rx(vsi); |
| 3050 | |
| 3051 | return err; |
| 3052 | } |
| 3053 | |
| 3054 | /** |
| 3055 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3056 | * @vsi: the VSI being configured |
| 3057 | **/ |
| 3058 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3059 | { |
| 3060 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3061 | struct i40e_hw *hw = &pf->hw; |
| 3062 | u16 vector; |
| 3063 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3064 | u32 qp; |
| 3065 | |
| 3066 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3067 | * and PFINT_LNKLSTn registers, e.g.: |
| 3068 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3069 | */ |
| 3070 | qp = vsi->base_queue; |
| 3071 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3072 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3073 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3074 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3075 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3076 | 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] | 3077 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3078 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3079 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3080 | 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] | 3081 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3082 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3083 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3084 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
| 3085 | INTRL_USEC_TO_REG(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3086 | |
| 3087 | /* Linked list for the queuepairs assigned to this vector */ |
| 3088 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3089 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3090 | u32 val; |
| 3091 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3092 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3093 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3094 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3095 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 3096 | (I40E_QUEUE_TYPE_TX |
| 3097 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 3098 | |
| 3099 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3100 | |
| 3101 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3102 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3103 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3104 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 3105 | (I40E_QUEUE_TYPE_RX |
| 3106 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3107 | |
| 3108 | /* Terminate the linked list */ |
| 3109 | if (q == (q_vector->num_ringpairs - 1)) |
| 3110 | val |= (I40E_QUEUE_END_OF_LIST |
| 3111 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3112 | |
| 3113 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3114 | qp++; |
| 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | i40e_flush(hw); |
| 3119 | } |
| 3120 | |
| 3121 | /** |
| 3122 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3123 | * @hw: ptr to the hardware info |
| 3124 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3125 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3126 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3127 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3128 | u32 val; |
| 3129 | |
| 3130 | /* clear things first */ |
| 3131 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3132 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3133 | |
| 3134 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3135 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3136 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3137 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3138 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3139 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3140 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3141 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3142 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3143 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3144 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3145 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3146 | if (pf->flags & I40E_FLAG_PTP) |
| 3147 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3148 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3149 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3150 | |
| 3151 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3152 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3153 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3154 | |
| 3155 | /* OTHER_ITR_IDX = 0 */ |
| 3156 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3157 | } |
| 3158 | |
| 3159 | /** |
| 3160 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3161 | * @vsi: the VSI being configured |
| 3162 | **/ |
| 3163 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3164 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3165 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3166 | struct i40e_pf *pf = vsi->back; |
| 3167 | struct i40e_hw *hw = &pf->hw; |
| 3168 | u32 val; |
| 3169 | |
| 3170 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3171 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3172 | 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] | 3173 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3174 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3175 | 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] | 3176 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3177 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3178 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3179 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3180 | |
| 3181 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3182 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3183 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3184 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3185 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3186 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3187 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3188 | |
| 3189 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3190 | |
| 3191 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3192 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3193 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3194 | |
| 3195 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3196 | i40e_flush(hw); |
| 3197 | } |
| 3198 | |
| 3199 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3200 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3201 | * @pf: board private structure |
| 3202 | **/ |
| 3203 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3204 | { |
| 3205 | struct i40e_hw *hw = &pf->hw; |
| 3206 | |
| 3207 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3208 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3209 | i40e_flush(hw); |
| 3210 | } |
| 3211 | |
| 3212 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3213 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3214 | * @pf: board private structure |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3215 | * @clearpba: true when all pending interrupt events should be cleared |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3216 | **/ |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3217 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3218 | { |
| 3219 | struct i40e_hw *hw = &pf->hw; |
| 3220 | u32 val; |
| 3221 | |
| 3222 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3223 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3224 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3225 | |
| 3226 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3227 | i40e_flush(hw); |
| 3228 | } |
| 3229 | |
| 3230 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3231 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3232 | * @irq: interrupt number |
| 3233 | * @data: pointer to a q_vector |
| 3234 | **/ |
| 3235 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3236 | { |
| 3237 | struct i40e_q_vector *q_vector = data; |
| 3238 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3239 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3240 | return IRQ_HANDLED; |
| 3241 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3242 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3243 | |
| 3244 | return IRQ_HANDLED; |
| 3245 | } |
| 3246 | |
| 3247 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3248 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3249 | * @vsi: the VSI being configured |
| 3250 | * @basename: name for the vector |
| 3251 | * |
| 3252 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3253 | **/ |
| 3254 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3255 | { |
| 3256 | int q_vectors = vsi->num_q_vectors; |
| 3257 | struct i40e_pf *pf = vsi->back; |
| 3258 | int base = vsi->base_vector; |
| 3259 | int rx_int_idx = 0; |
| 3260 | int tx_int_idx = 0; |
| 3261 | int vector, err; |
| 3262 | |
| 3263 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3264 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3265 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3266 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3267 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3268 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3269 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3270 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3271 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3272 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3273 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3274 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3275 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3276 | } else { |
| 3277 | /* skip this unused q_vector */ |
| 3278 | continue; |
| 3279 | } |
| 3280 | err = request_irq(pf->msix_entries[base + vector].vector, |
| 3281 | vsi->irq_handler, |
| 3282 | 0, |
| 3283 | q_vector->name, |
| 3284 | q_vector); |
| 3285 | if (err) { |
| 3286 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3287 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3288 | goto free_queue_irqs; |
| 3289 | } |
| 3290 | /* assign the mask for this irq */ |
| 3291 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3292 | &q_vector->affinity_mask); |
| 3293 | } |
| 3294 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3295 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3296 | return 0; |
| 3297 | |
| 3298 | free_queue_irqs: |
| 3299 | while (vector) { |
| 3300 | vector--; |
| 3301 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3302 | NULL); |
| 3303 | free_irq(pf->msix_entries[base + vector].vector, |
| 3304 | &(vsi->q_vectors[vector])); |
| 3305 | } |
| 3306 | return err; |
| 3307 | } |
| 3308 | |
| 3309 | /** |
| 3310 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3311 | * @vsi: the VSI being un-configured |
| 3312 | **/ |
| 3313 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3314 | { |
| 3315 | struct i40e_pf *pf = vsi->back; |
| 3316 | struct i40e_hw *hw = &pf->hw; |
| 3317 | int base = vsi->base_vector; |
| 3318 | int i; |
| 3319 | |
| 3320 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3321 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3322 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3326 | for (i = vsi->base_vector; |
| 3327 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3328 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3329 | |
| 3330 | i40e_flush(hw); |
| 3331 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3332 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3333 | } else { |
| 3334 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3335 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3336 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3337 | i40e_flush(hw); |
| 3338 | synchronize_irq(pf->pdev->irq); |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | /** |
| 3343 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3344 | * @vsi: the VSI being configured |
| 3345 | **/ |
| 3346 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3347 | { |
| 3348 | struct i40e_pf *pf = vsi->back; |
| 3349 | int i; |
| 3350 | |
| 3351 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3352 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3353 | i40e_irq_dynamic_enable(vsi, i); |
| 3354 | } else { |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3355 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3356 | } |
| 3357 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3358 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3359 | return 0; |
| 3360 | } |
| 3361 | |
| 3362 | /** |
| 3363 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3364 | * @pf: board private structure |
| 3365 | **/ |
| 3366 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3367 | { |
| 3368 | /* Disable ICR 0 */ |
| 3369 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3370 | i40e_flush(&pf->hw); |
| 3371 | } |
| 3372 | |
| 3373 | /** |
| 3374 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3375 | * @irq: interrupt number |
| 3376 | * @data: pointer to a q_vector |
| 3377 | * |
| 3378 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3379 | * with both queue and non-queue interrupts. This is also used in |
| 3380 | * MSIX mode to handle the non-queue interrupts. |
| 3381 | **/ |
| 3382 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3383 | { |
| 3384 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3385 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3386 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3387 | u32 icr0, icr0_remaining; |
| 3388 | u32 val, ena_mask; |
| 3389 | |
| 3390 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3391 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3392 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3393 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3394 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3395 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3396 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3397 | /* if interrupt but no bits showing, must be SWINT */ |
| 3398 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3399 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3400 | pf->sw_int_count++; |
| 3401 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3402 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 3403 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
| 3404 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3405 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3406 | dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
| 3407 | } |
| 3408 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3409 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3410 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3411 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3412 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3413 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3414 | /* We do not have a way to disarm Queue causes while leaving |
| 3415 | * interrupt enabled for all other causes, ideally |
| 3416 | * interrupt should be disabled while we are in NAPI but |
| 3417 | * this is not a performance path and napi_schedule() |
| 3418 | * can deal with rescheduling. |
| 3419 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3420 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3421 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3425 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3426 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3427 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3431 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3432 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3433 | } |
| 3434 | |
| 3435 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3436 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3437 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3438 | } |
| 3439 | |
| 3440 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3441 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3442 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3443 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3444 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3445 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3446 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3447 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3448 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3449 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3450 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3451 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3452 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3453 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3454 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3455 | } |
| 3456 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3457 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3458 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3459 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3460 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3461 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3462 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3463 | } |
| 3464 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3465 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3466 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3467 | |
| 3468 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3469 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3470 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3471 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3472 | } |
| 3473 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3474 | /* If a critical error is pending we have no choice but to reset the |
| 3475 | * device. |
| 3476 | * Report and mask out any remaining unexpected interrupts. |
| 3477 | */ |
| 3478 | icr0_remaining = icr0 & ena_mask; |
| 3479 | if (icr0_remaining) { |
| 3480 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3481 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3482 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3483 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3484 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3485 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3486 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3487 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3488 | } |
| 3489 | ena_mask &= ~icr0_remaining; |
| 3490 | } |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3491 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3492 | |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3493 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3494 | /* re-enable interrupt causes */ |
| 3495 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3496 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3497 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3498 | i40e_irq_dynamic_enable_icr0(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3499 | } |
| 3500 | |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3501 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3505 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3506 | * @tx_ring: tx ring to clean |
| 3507 | * @budget: how many cleans we're allowed |
| 3508 | * |
| 3509 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3510 | **/ |
| 3511 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3512 | { |
| 3513 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3514 | u16 i = tx_ring->next_to_clean; |
| 3515 | struct i40e_tx_buffer *tx_buf; |
| 3516 | struct i40e_tx_desc *tx_desc; |
| 3517 | |
| 3518 | tx_buf = &tx_ring->tx_bi[i]; |
| 3519 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3520 | i -= tx_ring->count; |
| 3521 | |
| 3522 | do { |
| 3523 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3524 | |
| 3525 | /* if next_to_watch is not set then there is no work pending */ |
| 3526 | if (!eop_desc) |
| 3527 | break; |
| 3528 | |
| 3529 | /* prevent any other reads prior to eop_desc */ |
| 3530 | read_barrier_depends(); |
| 3531 | |
| 3532 | /* if the descriptor isn't done, no work yet to do */ |
| 3533 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3534 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3535 | break; |
| 3536 | |
| 3537 | /* clear next_to_watch to prevent false hangs */ |
| 3538 | tx_buf->next_to_watch = NULL; |
| 3539 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3540 | tx_desc->buffer_addr = 0; |
| 3541 | tx_desc->cmd_type_offset_bsz = 0; |
| 3542 | /* move past filter desc */ |
| 3543 | tx_buf++; |
| 3544 | tx_desc++; |
| 3545 | i++; |
| 3546 | if (unlikely(!i)) { |
| 3547 | i -= tx_ring->count; |
| 3548 | tx_buf = tx_ring->tx_bi; |
| 3549 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3550 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3551 | /* unmap skb header data */ |
| 3552 | dma_unmap_single(tx_ring->dev, |
| 3553 | dma_unmap_addr(tx_buf, dma), |
| 3554 | dma_unmap_len(tx_buf, len), |
| 3555 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3556 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3557 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3558 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3559 | tx_buf->raw_buf = NULL; |
| 3560 | tx_buf->tx_flags = 0; |
| 3561 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3562 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3563 | tx_desc->buffer_addr = 0; |
| 3564 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3565 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3566 | /* 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] | 3567 | tx_buf++; |
| 3568 | tx_desc++; |
| 3569 | i++; |
| 3570 | if (unlikely(!i)) { |
| 3571 | i -= tx_ring->count; |
| 3572 | tx_buf = tx_ring->tx_bi; |
| 3573 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3574 | } |
| 3575 | |
| 3576 | /* update budget accounting */ |
| 3577 | budget--; |
| 3578 | } while (likely(budget)); |
| 3579 | |
| 3580 | i += tx_ring->count; |
| 3581 | tx_ring->next_to_clean = i; |
| 3582 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3583 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3584 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3585 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3586 | return budget > 0; |
| 3587 | } |
| 3588 | |
| 3589 | /** |
| 3590 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3591 | * @irq: interrupt number |
| 3592 | * @data: pointer to a q_vector |
| 3593 | **/ |
| 3594 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3595 | { |
| 3596 | struct i40e_q_vector *q_vector = data; |
| 3597 | struct i40e_vsi *vsi; |
| 3598 | |
| 3599 | if (!q_vector->tx.ring) |
| 3600 | return IRQ_HANDLED; |
| 3601 | |
| 3602 | vsi = q_vector->tx.ring->vsi; |
| 3603 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3604 | |
| 3605 | return IRQ_HANDLED; |
| 3606 | } |
| 3607 | |
| 3608 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3609 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3610 | * @vsi: the VSI being configured |
| 3611 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3612 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3613 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3614 | 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] | 3615 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3616 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3617 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3618 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3619 | |
| 3620 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3621 | tx_ring->next = q_vector->tx.ring; |
| 3622 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3623 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3624 | |
| 3625 | rx_ring->q_vector = q_vector; |
| 3626 | rx_ring->next = q_vector->rx.ring; |
| 3627 | q_vector->rx.ring = rx_ring; |
| 3628 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | /** |
| 3632 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3633 | * @vsi: the VSI being configured |
| 3634 | * |
| 3635 | * This function maps descriptor rings to the queue-specific vectors |
| 3636 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3637 | * one vector per queue pair, but on a constrained vector budget, we |
| 3638 | * group the queue pairs as "efficiently" as possible. |
| 3639 | **/ |
| 3640 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3641 | { |
| 3642 | int qp_remaining = vsi->num_queue_pairs; |
| 3643 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3644 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3645 | int v_start = 0; |
| 3646 | int qp_idx = 0; |
| 3647 | |
| 3648 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3649 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3650 | * It is also important to go through all the vectors available to be |
| 3651 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3652 | * are cleared. This is especially important when decreasing the |
| 3653 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3654 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3655 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3656 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3657 | |
| 3658 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3659 | |
| 3660 | q_vector->num_ringpairs = num_ringpairs; |
| 3661 | |
| 3662 | q_vector->rx.count = 0; |
| 3663 | q_vector->tx.count = 0; |
| 3664 | q_vector->rx.ring = NULL; |
| 3665 | q_vector->tx.ring = NULL; |
| 3666 | |
| 3667 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3668 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3669 | qp_idx++; |
| 3670 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3671 | } |
| 3672 | } |
| 3673 | } |
| 3674 | |
| 3675 | /** |
| 3676 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3677 | * @vsi: the VSI being configured |
| 3678 | * @basename: name for the vector |
| 3679 | **/ |
| 3680 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3681 | { |
| 3682 | struct i40e_pf *pf = vsi->back; |
| 3683 | int err; |
| 3684 | |
| 3685 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3686 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3687 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3688 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3689 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3690 | else |
| 3691 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3692 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3693 | |
| 3694 | if (err) |
| 3695 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3696 | |
| 3697 | return err; |
| 3698 | } |
| 3699 | |
| 3700 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3701 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3702 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3703 | * @netdev: network interface device structure |
| 3704 | * |
| 3705 | * This is used by netconsole to send skbs without having to re-enable |
| 3706 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3707 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3708 | #ifdef I40E_FCOE |
| 3709 | void i40e_netpoll(struct net_device *netdev) |
| 3710 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3711 | static void i40e_netpoll(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3712 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3713 | { |
| 3714 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3715 | struct i40e_vsi *vsi = np->vsi; |
| 3716 | struct i40e_pf *pf = vsi->back; |
| 3717 | int i; |
| 3718 | |
| 3719 | /* if interface is down do nothing */ |
| 3720 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3721 | return; |
| 3722 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3723 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3724 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3725 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3726 | } else { |
| 3727 | i40e_intr(pf->pdev->irq, netdev); |
| 3728 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3729 | } |
| 3730 | #endif |
| 3731 | |
| 3732 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3733 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3734 | * @pf: the PF being configured |
| 3735 | * @pf_q: the PF queue |
| 3736 | * @enable: enable or disable state of the queue |
| 3737 | * |
| 3738 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3739 | * enabled or disabled state. |
| 3740 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3741 | * multiple retries; else will return 0 in case of success. |
| 3742 | **/ |
| 3743 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3744 | { |
| 3745 | int i; |
| 3746 | u32 tx_reg; |
| 3747 | |
| 3748 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3749 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3750 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3751 | break; |
| 3752 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3753 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3754 | } |
| 3755 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3756 | return -ETIMEDOUT; |
| 3757 | |
| 3758 | return 0; |
| 3759 | } |
| 3760 | |
| 3761 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3762 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3763 | * @vsi: the VSI being configured |
| 3764 | * @enable: start or stop the rings |
| 3765 | **/ |
| 3766 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3767 | { |
| 3768 | struct i40e_pf *pf = vsi->back; |
| 3769 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3770 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3771 | u32 tx_reg; |
| 3772 | |
| 3773 | pf_q = vsi->base_queue; |
| 3774 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499a | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3775 | |
| 3776 | /* warn the TX unit of coming changes */ |
| 3777 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3778 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3779 | usleep_range(10, 20); |
Matt Jared | 351499a | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3780 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3781 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3782 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3783 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3784 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3785 | break; |
| 3786 | usleep_range(1000, 2000); |
| 3787 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3788 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c12200 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3789 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3790 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3791 | |
| 3792 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3793 | if (enable) { |
| 3794 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3795 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3796 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3797 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3798 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3799 | |
| 3800 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 3801 | /* No waiting for the Tx queue to disable */ |
| 3802 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3803 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3804 | |
| 3805 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3806 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 3807 | if (ret) { |
| 3808 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3809 | "VSI seid %d Tx ring %d %sable timeout\n", |
| 3810 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3811 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3812 | } |
| 3813 | } |
| 3814 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3815 | if (hw->revision_id == 0) |
| 3816 | mdelay(50); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3817 | return ret; |
| 3818 | } |
| 3819 | |
| 3820 | /** |
| 3821 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 3822 | * @pf: the PF being configured |
| 3823 | * @pf_q: the PF queue |
| 3824 | * @enable: enable or disable state of the queue |
| 3825 | * |
| 3826 | * This routine will wait for the given Rx queue of the PF to reach the |
| 3827 | * enabled or disabled state. |
| 3828 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3829 | * multiple retries; else will return 0 in case of success. |
| 3830 | **/ |
| 3831 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3832 | { |
| 3833 | int i; |
| 3834 | u32 rx_reg; |
| 3835 | |
| 3836 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3837 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 3838 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3839 | break; |
| 3840 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3841 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3842 | } |
| 3843 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3844 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3845 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3846 | return 0; |
| 3847 | } |
| 3848 | |
| 3849 | /** |
| 3850 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 3851 | * @vsi: the VSI being configured |
| 3852 | * @enable: start or stop the rings |
| 3853 | **/ |
| 3854 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 3855 | { |
| 3856 | struct i40e_pf *pf = vsi->back; |
| 3857 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3858 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3859 | u32 rx_reg; |
| 3860 | |
| 3861 | pf_q = vsi->base_queue; |
| 3862 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3863 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3864 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3865 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3866 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3867 | break; |
| 3868 | usleep_range(1000, 2000); |
| 3869 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3870 | |
Catherine Sullivan | 7c12200 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3871 | /* Skip if the queue is already in the requested state */ |
| 3872 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3873 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3874 | |
| 3875 | /* turn on/off the queue */ |
| 3876 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3877 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3878 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3879 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3880 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 3881 | /* No waiting for the Tx queue to disable */ |
| 3882 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3883 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3884 | |
| 3885 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3886 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 3887 | if (ret) { |
| 3888 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3889 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 3890 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3891 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3892 | } |
| 3893 | } |
| 3894 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3895 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3896 | } |
| 3897 | |
| 3898 | /** |
| 3899 | * i40e_vsi_control_rings - Start or stop a VSI's rings |
| 3900 | * @vsi: the VSI being configured |
| 3901 | * @enable: start or stop the rings |
| 3902 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 3903 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3904 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3905 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3906 | |
| 3907 | /* do rx first for enable and last for disable */ |
| 3908 | if (request) { |
| 3909 | ret = i40e_vsi_control_rx(vsi, request); |
| 3910 | if (ret) |
| 3911 | return ret; |
| 3912 | ret = i40e_vsi_control_tx(vsi, request); |
| 3913 | } else { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3914 | /* Ignore return value, we need to shutdown whatever we can */ |
| 3915 | i40e_vsi_control_tx(vsi, request); |
| 3916 | i40e_vsi_control_rx(vsi, request); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | return ret; |
| 3920 | } |
| 3921 | |
| 3922 | /** |
| 3923 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 3924 | * @vsi: the VSI being configured |
| 3925 | **/ |
| 3926 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 3927 | { |
| 3928 | struct i40e_pf *pf = vsi->back; |
| 3929 | struct i40e_hw *hw = &pf->hw; |
| 3930 | int base = vsi->base_vector; |
| 3931 | u32 val, qp; |
| 3932 | int i; |
| 3933 | |
| 3934 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3935 | if (!vsi->q_vectors) |
| 3936 | return; |
| 3937 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3938 | if (!vsi->irqs_ready) |
| 3939 | return; |
| 3940 | |
| 3941 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3942 | for (i = 0; i < vsi->num_q_vectors; i++) { |
| 3943 | u16 vector = i + base; |
| 3944 | |
| 3945 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 3946 | if (!vsi->q_vectors[i] || |
| 3947 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3948 | continue; |
| 3949 | |
| 3950 | /* clear the affinity_mask in the IRQ descriptor */ |
| 3951 | irq_set_affinity_hint(pf->msix_entries[vector].vector, |
| 3952 | NULL); |
Greg Rose | b33d3b7 | 2016-05-16 10:26:37 -0700 | [diff] [blame^] | 3953 | synchronize_irq(pf->msix_entries[vector].vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3954 | free_irq(pf->msix_entries[vector].vector, |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3955 | vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3956 | |
| 3957 | /* Tear down the interrupt queue link list |
| 3958 | * |
| 3959 | * We know that they come in pairs and always |
| 3960 | * the Rx first, then the Tx. To clear the |
| 3961 | * link list, stick the EOL value into the |
| 3962 | * next_q field of the registers. |
| 3963 | */ |
| 3964 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 3965 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 3966 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3967 | val |= I40E_QUEUE_END_OF_LIST |
| 3968 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3969 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 3970 | |
| 3971 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 3972 | u32 next; |
| 3973 | |
| 3974 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 3975 | |
| 3976 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 3977 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 3978 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3979 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 3980 | |
| 3981 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 3982 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 3983 | |
| 3984 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3985 | |
| 3986 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 3987 | |
| 3988 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 3989 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 3990 | |
| 3991 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 3992 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 3993 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3994 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 3995 | |
| 3996 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 3997 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 3998 | |
| 3999 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4000 | qp = next; |
| 4001 | } |
| 4002 | } |
| 4003 | } else { |
| 4004 | free_irq(pf->pdev->irq, pf); |
| 4005 | |
| 4006 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4007 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4008 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4009 | val |= I40E_QUEUE_END_OF_LIST |
| 4010 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4011 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4012 | |
| 4013 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4014 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4015 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4016 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4017 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4018 | |
| 4019 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4020 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4021 | |
| 4022 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4023 | |
| 4024 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4025 | |
| 4026 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4027 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4028 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4029 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4030 | |
| 4031 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4032 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4033 | |
| 4034 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4035 | } |
| 4036 | } |
| 4037 | |
| 4038 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4039 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4040 | * @vsi: the VSI being configured |
| 4041 | * @v_idx: Index of vector to be freed |
| 4042 | * |
| 4043 | * This function frees the memory allocated to the q_vector. In addition if |
| 4044 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4045 | * to freeing the q_vector. |
| 4046 | **/ |
| 4047 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4048 | { |
| 4049 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4050 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4051 | |
| 4052 | if (!q_vector) |
| 4053 | return; |
| 4054 | |
| 4055 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4056 | i40e_for_each_ring(ring, q_vector->tx) |
| 4057 | ring->q_vector = NULL; |
| 4058 | |
| 4059 | i40e_for_each_ring(ring, q_vector->rx) |
| 4060 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4061 | |
| 4062 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4063 | if (vsi->netdev) |
| 4064 | netif_napi_del(&q_vector->napi); |
| 4065 | |
| 4066 | vsi->q_vectors[v_idx] = NULL; |
| 4067 | |
| 4068 | kfree_rcu(q_vector, rcu); |
| 4069 | } |
| 4070 | |
| 4071 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4072 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4073 | * @vsi: the VSI being un-configured |
| 4074 | * |
| 4075 | * This frees the memory allocated to the q_vectors and |
| 4076 | * deletes references to the NAPI struct. |
| 4077 | **/ |
| 4078 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4079 | { |
| 4080 | int v_idx; |
| 4081 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4082 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4083 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | /** |
| 4087 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4088 | * @pf: board private structure |
| 4089 | **/ |
| 4090 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4091 | { |
| 4092 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4093 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4094 | pci_disable_msix(pf->pdev); |
| 4095 | kfree(pf->msix_entries); |
| 4096 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4097 | kfree(pf->irq_pile); |
| 4098 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4099 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4100 | pci_disable_msi(pf->pdev); |
| 4101 | } |
| 4102 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4103 | } |
| 4104 | |
| 4105 | /** |
| 4106 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4107 | * @pf: board private structure |
| 4108 | * |
| 4109 | * We go through and clear interrupt specific resources and reset the structure |
| 4110 | * to pre-load conditions |
| 4111 | **/ |
| 4112 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4113 | { |
| 4114 | int i; |
| 4115 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4116 | i40e_stop_misc_vector(pf); |
Shannon Nelson | 6927839 | 2016-03-10 14:59:43 -0800 | [diff] [blame] | 4117 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4118 | synchronize_irq(pf->msix_entries[0].vector); |
| 4119 | free_irq(pf->msix_entries[0].vector, pf); |
| 4120 | } |
| 4121 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4122 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4123 | I40E_IWARP_IRQ_PILE_ID); |
| 4124 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4125 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4126 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4127 | if (pf->vsi[i]) |
| 4128 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4129 | i40e_reset_interrupt_capability(pf); |
| 4130 | } |
| 4131 | |
| 4132 | /** |
| 4133 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4134 | * @vsi: the VSI being configured |
| 4135 | **/ |
| 4136 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4137 | { |
| 4138 | int q_idx; |
| 4139 | |
| 4140 | if (!vsi->netdev) |
| 4141 | return; |
| 4142 | |
| 4143 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4144 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4145 | } |
| 4146 | |
| 4147 | /** |
| 4148 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4149 | * @vsi: the VSI being configured |
| 4150 | **/ |
| 4151 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4152 | { |
| 4153 | int q_idx; |
| 4154 | |
| 4155 | if (!vsi->netdev) |
| 4156 | return; |
| 4157 | |
| 4158 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4159 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4160 | } |
| 4161 | |
| 4162 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4163 | * i40e_vsi_close - Shut down a VSI |
| 4164 | * @vsi: the vsi to be quelled |
| 4165 | **/ |
| 4166 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4167 | { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4168 | bool reset = false; |
| 4169 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4170 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4171 | i40e_down(vsi); |
| 4172 | i40e_vsi_free_irq(vsi); |
| 4173 | i40e_vsi_free_tx_resources(vsi); |
| 4174 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4175 | vsi->current_netdev_flags = 0; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4176 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4177 | reset = true; |
| 4178 | i40e_notify_client_of_netdev_close(vsi, reset); |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4182 | * i40e_quiesce_vsi - Pause a given VSI |
| 4183 | * @vsi: the VSI being paused |
| 4184 | **/ |
| 4185 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4186 | { |
| 4187 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4188 | return; |
| 4189 | |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4190 | /* No need to disable FCoE VSI when Tx suspended */ |
| 4191 | if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) && |
| 4192 | vsi->type == I40E_VSI_FCOE) { |
| 4193 | dev_dbg(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4194 | "VSI seid %d skipping FCoE VSI disable\n", vsi->seid); |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4195 | return; |
| 4196 | } |
| 4197 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4198 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4199 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4200 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4201 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4202 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4203 | } |
| 4204 | |
| 4205 | /** |
| 4206 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4207 | * @vsi: the VSI being resumed |
| 4208 | **/ |
| 4209 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4210 | { |
| 4211 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 4212 | return; |
| 4213 | |
| 4214 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4215 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4216 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4217 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4218 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | /** |
| 4222 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4223 | * @pf: the PF |
| 4224 | **/ |
| 4225 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4226 | { |
| 4227 | int v; |
| 4228 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4229 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4230 | if (pf->vsi[v]) |
| 4231 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4232 | } |
| 4233 | } |
| 4234 | |
| 4235 | /** |
| 4236 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4237 | * @pf: the PF |
| 4238 | **/ |
| 4239 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4240 | { |
| 4241 | int v; |
| 4242 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4243 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4244 | if (pf->vsi[v]) |
| 4245 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4246 | } |
| 4247 | } |
| 4248 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4249 | #ifdef CONFIG_I40E_DCB |
| 4250 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4251 | * 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] | 4252 | * @vsi: the VSI being configured |
| 4253 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4254 | * This function waits for the given VSI's queues to be disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4255 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4256 | static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4257 | { |
| 4258 | struct i40e_pf *pf = vsi->back; |
| 4259 | int i, pf_q, ret; |
| 4260 | |
| 4261 | pf_q = vsi->base_queue; |
| 4262 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4263 | /* Check and wait for the disable status of the queue */ |
| 4264 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4265 | if (ret) { |
| 4266 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4267 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4268 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4269 | return ret; |
| 4270 | } |
| 4271 | } |
| 4272 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4273 | pf_q = vsi->base_queue; |
| 4274 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4275 | /* Check and wait for the disable status of the queue */ |
| 4276 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4277 | if (ret) { |
| 4278 | dev_info(&pf->pdev->dev, |
| 4279 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4280 | vsi->seid, pf_q); |
| 4281 | return ret; |
| 4282 | } |
| 4283 | } |
| 4284 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4285 | return 0; |
| 4286 | } |
| 4287 | |
| 4288 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4289 | * 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] | 4290 | * @pf: the PF |
| 4291 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4292 | * 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] | 4293 | * VSIs that are managed by this PF. |
| 4294 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4295 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4296 | { |
| 4297 | int v, ret = 0; |
| 4298 | |
| 4299 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4300 | /* No need to wait for FCoE VSI queues */ |
| 4301 | if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4302 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4303 | if (ret) |
| 4304 | break; |
| 4305 | } |
| 4306 | } |
| 4307 | |
| 4308 | return ret; |
| 4309 | } |
| 4310 | |
| 4311 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4312 | |
| 4313 | /** |
| 4314 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4315 | * @q_idx: TX queue number |
| 4316 | * @vsi: Pointer to VSI struct |
| 4317 | * |
| 4318 | * This function checks specified queue for given VSI. Detects hung condition. |
| 4319 | * Sets hung bit since it is two step process. Before next run of service task |
| 4320 | * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not, |
| 4321 | * hung condition remain unchanged and during subsequent run, this function |
| 4322 | * issues SW interrupt to recover from hung condition. |
| 4323 | **/ |
| 4324 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4325 | { |
| 4326 | struct i40e_ring *tx_ring = NULL; |
| 4327 | struct i40e_pf *pf; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4328 | u32 head, val, tx_pending_hw; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4329 | int i; |
| 4330 | |
| 4331 | pf = vsi->back; |
| 4332 | |
| 4333 | /* now that we have an index, find the tx_ring struct */ |
| 4334 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4335 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4336 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4337 | tx_ring = vsi->tx_rings[i]; |
| 4338 | break; |
| 4339 | } |
| 4340 | } |
| 4341 | } |
| 4342 | |
| 4343 | if (!tx_ring) |
| 4344 | return; |
| 4345 | |
| 4346 | /* Read interrupt register */ |
| 4347 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4348 | val = rd32(&pf->hw, |
| 4349 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4350 | tx_ring->vsi->base_vector - 1)); |
| 4351 | else |
| 4352 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4353 | |
| 4354 | head = i40e_get_head(tx_ring); |
| 4355 | |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4356 | tx_pending_hw = i40e_get_tx_pending(tx_ring, false); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4357 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4358 | /* HW is done executing descriptors, updated HEAD write back, |
| 4359 | * but SW hasn't processed those descriptors. If interrupt is |
| 4360 | * not generated from this point ON, it could result into |
| 4361 | * dev_watchdog detecting timeout on those netdev_queue, |
| 4362 | * hence proactively trigger SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4363 | */ |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4364 | if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4365 | /* NAPI Poll didn't run and clear since it was set */ |
| 4366 | if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4367 | &tx_ring->q_vector->hung_detected)) { |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4368 | 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", |
| 4369 | vsi->seid, q_idx, tx_pending_hw, |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4370 | tx_ring->next_to_clean, head, |
| 4371 | tx_ring->next_to_use, |
| 4372 | readl(tx_ring->tail)); |
| 4373 | netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n", |
| 4374 | vsi->seid, q_idx, val); |
| 4375 | i40e_force_wb(vsi, tx_ring->q_vector); |
| 4376 | } else { |
| 4377 | /* First Chance - detected possible hung */ |
| 4378 | set_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4379 | &tx_ring->q_vector->hung_detected); |
| 4380 | } |
| 4381 | } |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4382 | |
| 4383 | /* This is the case where we have interrupts missing, |
| 4384 | * so the tx_pending in HW will most likely be 0, but we |
| 4385 | * will have tx_pending in SW since the WB happened but the |
| 4386 | * interrupt got lost. |
| 4387 | */ |
| 4388 | if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) && |
| 4389 | (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
| 4390 | if (napi_reschedule(&tx_ring->q_vector->napi)) |
| 4391 | tx_ring->tx_stats.tx_lost_interrupt++; |
| 4392 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | /** |
| 4396 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4397 | * @pf: pointer to PF struct |
| 4398 | * |
| 4399 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4400 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4401 | * SW interrupt. |
| 4402 | **/ |
| 4403 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4404 | { |
| 4405 | struct net_device *netdev; |
| 4406 | struct i40e_vsi *vsi; |
| 4407 | int i; |
| 4408 | |
| 4409 | /* Only for LAN VSI */ |
| 4410 | vsi = pf->vsi[pf->lan_vsi]; |
| 4411 | |
| 4412 | if (!vsi) |
| 4413 | return; |
| 4414 | |
| 4415 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
| 4416 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 4417 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4418 | return; |
| 4419 | |
| 4420 | /* Make sure type is MAIN VSI */ |
| 4421 | if (vsi->type != I40E_VSI_MAIN) |
| 4422 | return; |
| 4423 | |
| 4424 | netdev = vsi->netdev; |
| 4425 | if (!netdev) |
| 4426 | return; |
| 4427 | |
| 4428 | /* Bail out if netif_carrier is not OK */ |
| 4429 | if (!netif_carrier_ok(netdev)) |
| 4430 | return; |
| 4431 | |
| 4432 | /* Go thru' TX queues for netdev */ |
| 4433 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4434 | struct netdev_queue *q; |
| 4435 | |
| 4436 | q = netdev_get_tx_queue(netdev, i); |
| 4437 | if (q) |
| 4438 | i40e_detect_recover_hung_queue(i, vsi); |
| 4439 | } |
| 4440 | } |
| 4441 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4442 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4443 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4444 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4445 | * |
| 4446 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4447 | * and LAN TC. |
| 4448 | **/ |
| 4449 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4450 | { |
| 4451 | struct i40e_dcb_app_priority_table app; |
| 4452 | struct i40e_hw *hw = &pf->hw; |
| 4453 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4454 | u8 tc, i; |
| 4455 | /* Get the iSCSI APP TLV */ |
| 4456 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4457 | |
| 4458 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4459 | app = dcbcfg->app[i]; |
| 4460 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4461 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4462 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4463 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4464 | break; |
| 4465 | } |
| 4466 | } |
| 4467 | |
| 4468 | return enabled_tc; |
| 4469 | } |
| 4470 | |
| 4471 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4472 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4473 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4474 | * |
| 4475 | * Return the number of TCs from given DCBx configuration |
| 4476 | **/ |
| 4477 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4478 | { |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4479 | u8 num_tc = 0; |
| 4480 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4481 | |
| 4482 | /* Scan the ETS Config Priority Table to find |
| 4483 | * traffic class enabled for a given priority |
| 4484 | * and use the traffic class index to get the |
| 4485 | * number of traffic classes enabled |
| 4486 | */ |
| 4487 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4488 | if (dcbcfg->etscfg.prioritytable[i] > num_tc) |
| 4489 | num_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4490 | } |
| 4491 | |
| 4492 | /* Traffic class index starts from zero so |
| 4493 | * increment to return the actual count |
| 4494 | */ |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4495 | return num_tc + 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4496 | } |
| 4497 | |
| 4498 | /** |
| 4499 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4500 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4501 | * |
| 4502 | * Query the current DCB configuration and return the number of |
| 4503 | * traffic classes enabled from the given DCBX config |
| 4504 | **/ |
| 4505 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4506 | { |
| 4507 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4508 | u8 enabled_tc = 1; |
| 4509 | u8 i; |
| 4510 | |
| 4511 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4512 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4513 | |
| 4514 | return enabled_tc; |
| 4515 | } |
| 4516 | |
| 4517 | /** |
| 4518 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4519 | * @pf: PF being queried |
| 4520 | * |
| 4521 | * Return number of traffic classes enabled for the given PF |
| 4522 | **/ |
| 4523 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4524 | { |
| 4525 | struct i40e_hw *hw = &pf->hw; |
| 4526 | u8 i, enabled_tc; |
| 4527 | u8 num_tc = 0; |
| 4528 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4529 | |
| 4530 | /* If DCB is not enabled then always in single TC */ |
| 4531 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4532 | return 1; |
| 4533 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4534 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4535 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4536 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4537 | |
| 4538 | /* MFP mode return count of enabled TCs for this PF */ |
| 4539 | if (pf->hw.func_caps.iscsi) |
| 4540 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4541 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4542 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4543 | |
| 4544 | /* At least have TC0 */ |
| 4545 | enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 4546 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4547 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4548 | num_tc++; |
| 4549 | } |
| 4550 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4551 | } |
| 4552 | |
| 4553 | /** |
| 4554 | * i40e_pf_get_default_tc - Get bitmap for first enabled TC |
| 4555 | * @pf: PF being queried |
| 4556 | * |
| 4557 | * Return a bitmap for first enabled traffic class for this PF. |
| 4558 | **/ |
| 4559 | static u8 i40e_pf_get_default_tc(struct i40e_pf *pf) |
| 4560 | { |
| 4561 | u8 enabled_tc = pf->hw.func_caps.enabled_tcmap; |
| 4562 | u8 i = 0; |
| 4563 | |
| 4564 | if (!enabled_tc) |
| 4565 | return 0x1; /* TC0 */ |
| 4566 | |
| 4567 | /* Find the first enabled TC */ |
| 4568 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4569 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4570 | break; |
| 4571 | } |
| 4572 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4573 | return BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | /** |
| 4577 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4578 | * @pf: PF being queried |
| 4579 | * |
| 4580 | * Return a bitmap for enabled traffic classes for this PF. |
| 4581 | **/ |
| 4582 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4583 | { |
| 4584 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4585 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4586 | return i40e_pf_get_default_tc(pf); |
| 4587 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4588 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4589 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4590 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4591 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4592 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4593 | if (pf->hw.func_caps.iscsi) |
| 4594 | return i40e_get_iscsi_tc_map(pf); |
| 4595 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4596 | return i40e_pf_get_default_tc(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | /** |
| 4600 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4601 | * @vsi: the VSI being queried |
| 4602 | * |
| 4603 | * Returns 0 on success, negative value on failure |
| 4604 | **/ |
| 4605 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4606 | { |
| 4607 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4608 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4609 | struct i40e_pf *pf = vsi->back; |
| 4610 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4611 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4612 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4613 | int i; |
| 4614 | |
| 4615 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4616 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4617 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4618 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4619 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4620 | i40e_stat_str(&pf->hw, ret), |
| 4621 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4622 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4626 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4627 | NULL); |
| 4628 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4629 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4630 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4631 | i40e_stat_str(&pf->hw, ret), |
| 4632 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4633 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4634 | } |
| 4635 | |
| 4636 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4637 | dev_info(&pf->pdev->dev, |
| 4638 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4639 | bw_config.tc_valid_bits, |
| 4640 | bw_ets_config.tc_valid_bits); |
| 4641 | /* Still continuing */ |
| 4642 | } |
| 4643 | |
| 4644 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4645 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4646 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4647 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4648 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4649 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4650 | vsi->bw_ets_limit_credits[i] = |
| 4651 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4652 | /* 3 bits out of 4 for each TC */ |
| 4653 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4654 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4655 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4656 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4657 | } |
| 4658 | |
| 4659 | /** |
| 4660 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4661 | * @vsi: the VSI being configured |
| 4662 | * @enabled_tc: TC bitmap |
| 4663 | * @bw_credits: BW shared credits per TC |
| 4664 | * |
| 4665 | * Returns 0 on success, negative value on failure |
| 4666 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4667 | 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] | 4668 | u8 *bw_share) |
| 4669 | { |
| 4670 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4671 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4672 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4673 | |
| 4674 | bw_data.tc_valid_bits = enabled_tc; |
| 4675 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4676 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4677 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4678 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4679 | NULL); |
| 4680 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4681 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4682 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4683 | vsi->back->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 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4688 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4689 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4690 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4691 | } |
| 4692 | |
| 4693 | /** |
| 4694 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4695 | * @vsi: the VSI being configured |
| 4696 | * @enabled_tc: TC map to be enabled |
| 4697 | * |
| 4698 | **/ |
| 4699 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4700 | { |
| 4701 | struct net_device *netdev = vsi->netdev; |
| 4702 | struct i40e_pf *pf = vsi->back; |
| 4703 | struct i40e_hw *hw = &pf->hw; |
| 4704 | u8 netdev_tc = 0; |
| 4705 | int i; |
| 4706 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4707 | |
| 4708 | if (!netdev) |
| 4709 | return; |
| 4710 | |
| 4711 | if (!enabled_tc) { |
| 4712 | netdev_reset_tc(netdev); |
| 4713 | return; |
| 4714 | } |
| 4715 | |
| 4716 | /* Set up actual enabled TCs on the VSI */ |
| 4717 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 4718 | return; |
| 4719 | |
| 4720 | /* set per TC queues for the VSI */ |
| 4721 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4722 | /* Only set TC queues for enabled tcs |
| 4723 | * |
| 4724 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 4725 | * enabled_tc bitmap would be 0x00001001; the driver |
| 4726 | * will set the numtc for netdev as 2 that will be |
| 4727 | * referenced by the netdev layer as TC 0 and 1. |
| 4728 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4729 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4730 | netdev_set_tc_queue(netdev, |
| 4731 | vsi->tc_config.tc_info[i].netdev_tc, |
| 4732 | vsi->tc_config.tc_info[i].qcount, |
| 4733 | vsi->tc_config.tc_info[i].qoffset); |
| 4734 | } |
| 4735 | |
| 4736 | /* Assign UP2TC map for the VSI */ |
| 4737 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4738 | /* Get the actual TC# for the UP */ |
| 4739 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4740 | /* Get the mapped netdev TC# for the UP */ |
| 4741 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 4742 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 4743 | } |
| 4744 | } |
| 4745 | |
| 4746 | /** |
| 4747 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 4748 | * @vsi: the VSI being configured |
| 4749 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 4750 | **/ |
| 4751 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 4752 | struct i40e_vsi_context *ctxt) |
| 4753 | { |
| 4754 | /* copy just the sections touched not the entire info |
| 4755 | * since not all sections are valid as returned by |
| 4756 | * update vsi params |
| 4757 | */ |
| 4758 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 4759 | memcpy(&vsi->info.queue_mapping, |
| 4760 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 4761 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 4762 | sizeof(vsi->info.tc_mapping)); |
| 4763 | } |
| 4764 | |
| 4765 | /** |
| 4766 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 4767 | * @vsi: VSI to be configured |
| 4768 | * @enabled_tc: TC bitmap |
| 4769 | * |
| 4770 | * This configures a particular VSI for TCs that are mapped to the |
| 4771 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 4772 | * VSIs to configure TC for a particular VSI. |
| 4773 | * |
| 4774 | * NOTE: |
| 4775 | * It is expected that the VSI queues have been quisced before calling |
| 4776 | * this function. |
| 4777 | **/ |
| 4778 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4779 | { |
| 4780 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 4781 | struct i40e_vsi_context ctxt; |
| 4782 | int ret = 0; |
| 4783 | int i; |
| 4784 | |
| 4785 | /* Check if enabled_tc is same as existing or new TCs */ |
| 4786 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 4787 | return ret; |
| 4788 | |
| 4789 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 4790 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4791 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4792 | bw_share[i] = 1; |
| 4793 | } |
| 4794 | |
| 4795 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 4796 | if (ret) { |
| 4797 | dev_info(&vsi->back->pdev->dev, |
| 4798 | "Failed configuring TC map %d for VSI %d\n", |
| 4799 | enabled_tc, vsi->seid); |
| 4800 | goto out; |
| 4801 | } |
| 4802 | |
| 4803 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 4804 | ctxt.seid = vsi->seid; |
| 4805 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 4806 | ctxt.vf_num = 0; |
| 4807 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 4808 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4809 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 4810 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4811 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 4812 | ctxt.info.valid_sections |= |
| 4813 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 4814 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 4815 | } |
| 4816 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4817 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 4818 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 4819 | if (ret) { |
| 4820 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4821 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 4822 | i40e_stat_str(&vsi->back->hw, ret), |
| 4823 | i40e_aq_str(&vsi->back->hw, |
| 4824 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4825 | goto out; |
| 4826 | } |
| 4827 | /* update the local VSI info with updated queue map */ |
| 4828 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 4829 | vsi->info.valid_sections = 0; |
| 4830 | |
| 4831 | /* Update current VSI BW information */ |
| 4832 | ret = i40e_vsi_get_bw_info(vsi); |
| 4833 | if (ret) { |
| 4834 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4835 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 4836 | i40e_stat_str(&vsi->back->hw, ret), |
| 4837 | i40e_aq_str(&vsi->back->hw, |
| 4838 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4839 | goto out; |
| 4840 | } |
| 4841 | |
| 4842 | /* Update the netdev TC setup */ |
| 4843 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 4844 | out: |
| 4845 | return ret; |
| 4846 | } |
| 4847 | |
| 4848 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4849 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 4850 | * @veb: given VEB |
| 4851 | * @enabled_tc: TC bitmap |
| 4852 | * |
| 4853 | * Configures given TC bitmap for VEB (switching) element |
| 4854 | **/ |
| 4855 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 4856 | { |
| 4857 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 4858 | struct i40e_pf *pf = veb->pf; |
| 4859 | int ret = 0; |
| 4860 | int i; |
| 4861 | |
| 4862 | /* No TCs or already enabled TCs just return */ |
| 4863 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 4864 | return ret; |
| 4865 | |
| 4866 | bw_data.tc_valid_bits = enabled_tc; |
| 4867 | /* bw_data.absolute_credits is not set (relative) */ |
| 4868 | |
| 4869 | /* Enable ETS TCs with equal BW Share for now */ |
| 4870 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4871 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4872 | bw_data.tc_bw_share_credits[i] = 1; |
| 4873 | } |
| 4874 | |
| 4875 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 4876 | &bw_data, NULL); |
| 4877 | if (ret) { |
| 4878 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4879 | "VEB bw config failed, err %s aq_err %s\n", |
| 4880 | i40e_stat_str(&pf->hw, ret), |
| 4881 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4882 | goto out; |
| 4883 | } |
| 4884 | |
| 4885 | /* Update the BW information */ |
| 4886 | ret = i40e_veb_get_bw_info(veb); |
| 4887 | if (ret) { |
| 4888 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4889 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 4890 | i40e_stat_str(&pf->hw, ret), |
| 4891 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4892 | } |
| 4893 | |
| 4894 | out: |
| 4895 | return ret; |
| 4896 | } |
| 4897 | |
| 4898 | #ifdef CONFIG_I40E_DCB |
| 4899 | /** |
| 4900 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 4901 | * @pf: PF struct |
| 4902 | * |
| 4903 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 4904 | * the caller would've quiesce all the VSIs before calling |
| 4905 | * this function |
| 4906 | **/ |
| 4907 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 4908 | { |
| 4909 | u8 tc_map = 0; |
| 4910 | int ret; |
| 4911 | u8 v; |
| 4912 | |
| 4913 | /* Enable the TCs available on PF to all VEBs */ |
| 4914 | tc_map = i40e_pf_get_tc_map(pf); |
| 4915 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 4916 | if (!pf->veb[v]) |
| 4917 | continue; |
| 4918 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 4919 | if (ret) { |
| 4920 | dev_info(&pf->pdev->dev, |
| 4921 | "Failed configuring TC for VEB seid=%d\n", |
| 4922 | pf->veb[v]->seid); |
| 4923 | /* Will try to configure as many components */ |
| 4924 | } |
| 4925 | } |
| 4926 | |
| 4927 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4928 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4929 | if (!pf->vsi[v]) |
| 4930 | continue; |
| 4931 | |
| 4932 | /* - Enable all TCs for the LAN VSI |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4933 | #ifdef I40E_FCOE |
| 4934 | * - For FCoE VSI only enable the TC configured |
| 4935 | * as per the APP TLV |
| 4936 | #endif |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4937 | * - For all others keep them at TC0 for now |
| 4938 | */ |
| 4939 | if (v == pf->lan_vsi) |
| 4940 | tc_map = i40e_pf_get_tc_map(pf); |
| 4941 | else |
| 4942 | tc_map = i40e_pf_get_default_tc(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4943 | #ifdef I40E_FCOE |
| 4944 | if (pf->vsi[v]->type == I40E_VSI_FCOE) |
| 4945 | tc_map = i40e_get_fcoe_tc_map(pf); |
| 4946 | #endif /* #ifdef I40E_FCOE */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4947 | |
| 4948 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 4949 | if (ret) { |
| 4950 | dev_info(&pf->pdev->dev, |
| 4951 | "Failed configuring TC for VSI seid=%d\n", |
| 4952 | pf->vsi[v]->seid); |
| 4953 | /* Will try to configure as many components */ |
| 4954 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 4955 | /* Re-configure VSI vectors based on updated TC map */ |
| 4956 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4957 | if (pf->vsi[v]->netdev) |
| 4958 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 4959 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4960 | i40e_notify_client_of_l2_param_changes(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4961 | } |
| 4962 | } |
| 4963 | |
| 4964 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 4965 | * i40e_resume_port_tx - Resume port Tx |
| 4966 | * @pf: PF struct |
| 4967 | * |
| 4968 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 4969 | * resume. |
| 4970 | **/ |
| 4971 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 4972 | { |
| 4973 | struct i40e_hw *hw = &pf->hw; |
| 4974 | int ret; |
| 4975 | |
| 4976 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 4977 | if (ret) { |
| 4978 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4979 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 4980 | i40e_stat_str(&pf->hw, ret), |
| 4981 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 4982 | /* Schedule PF reset to recover */ |
| 4983 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 4984 | i40e_service_event_schedule(pf); |
| 4985 | } |
| 4986 | |
| 4987 | return ret; |
| 4988 | } |
| 4989 | |
| 4990 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4991 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 4992 | * @pf: PF being configured |
| 4993 | * |
| 4994 | * Query the current DCB configuration and cache it |
| 4995 | * in the hardware structure |
| 4996 | **/ |
| 4997 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 4998 | { |
| 4999 | struct i40e_hw *hw = &pf->hw; |
| 5000 | int err = 0; |
| 5001 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5002 | /* 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] | 5003 | if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5004 | goto out; |
| 5005 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5006 | /* Get the initial DCB configuration */ |
| 5007 | err = i40e_init_dcb(hw); |
| 5008 | if (!err) { |
| 5009 | /* Device/Function is not DCBX capable */ |
| 5010 | if ((!hw->func_caps.dcb) || |
| 5011 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5012 | dev_info(&pf->pdev->dev, |
| 5013 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 5014 | |
| 5015 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 5016 | goto out; |
| 5017 | |
| 5018 | } else { |
| 5019 | /* When status is not DISABLED then DCBX in FW */ |
| 5020 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5021 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5022 | |
| 5023 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
| 5024 | /* Enable DCB tagging only when more than one TC */ |
| 5025 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5026 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5027 | dev_dbg(&pf->pdev->dev, |
| 5028 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5029 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5030 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5031 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5032 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5033 | i40e_stat_str(&pf->hw, err), |
| 5034 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5035 | } |
| 5036 | |
| 5037 | out: |
| 5038 | return err; |
| 5039 | } |
| 5040 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5041 | #define SPEED_SIZE 14 |
| 5042 | #define FC_SIZE 8 |
| 5043 | /** |
| 5044 | * i40e_print_link_message - print link up or down |
| 5045 | * @vsi: the VSI for which link needs a message |
| 5046 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5047 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5048 | { |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5049 | char *speed = "Unknown"; |
| 5050 | char *fc = "Unknown"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5051 | |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5052 | if (vsi->current_isup == isup) |
| 5053 | return; |
| 5054 | vsi->current_isup = isup; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5055 | if (!isup) { |
| 5056 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5057 | return; |
| 5058 | } |
| 5059 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5060 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5061 | * least 10GB |
| 5062 | */ |
| 5063 | if (vsi->back->hw.func_caps.npar_enable && |
| 5064 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5065 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5066 | netdev_warn(vsi->netdev, |
| 5067 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5068 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5069 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5070 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5071 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5072 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5073 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5074 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5075 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5076 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5077 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5078 | break; |
| 5079 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5080 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5081 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5082 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5083 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5084 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5085 | default: |
| 5086 | break; |
| 5087 | } |
| 5088 | |
| 5089 | switch (vsi->back->hw.fc.current_mode) { |
| 5090 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5091 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5092 | break; |
| 5093 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5094 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5095 | break; |
| 5096 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5097 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5098 | break; |
| 5099 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5100 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5101 | break; |
| 5102 | } |
| 5103 | |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5104 | 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] | 5105 | speed, fc); |
| 5106 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5107 | |
| 5108 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5109 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5110 | * @vsi: the VSI being configured |
| 5111 | **/ |
| 5112 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5113 | { |
| 5114 | struct i40e_pf *pf = vsi->back; |
| 5115 | int err; |
| 5116 | |
| 5117 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5118 | i40e_vsi_configure_msix(vsi); |
| 5119 | else |
| 5120 | i40e_configure_msi_and_legacy(vsi); |
| 5121 | |
| 5122 | /* start rings */ |
| 5123 | err = i40e_vsi_control_rings(vsi, true); |
| 5124 | if (err) |
| 5125 | return err; |
| 5126 | |
| 5127 | clear_bit(__I40E_DOWN, &vsi->state); |
| 5128 | i40e_napi_enable_all(vsi); |
| 5129 | i40e_vsi_enable_irq(vsi); |
| 5130 | |
| 5131 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5132 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5133 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5134 | netif_tx_start_all_queues(vsi->netdev); |
| 5135 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5136 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5137 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5138 | /* need to check for qualified module here*/ |
| 5139 | if ((pf->hw.phy.link_info.link_info & |
| 5140 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5141 | (!(pf->hw.phy.link_info.an_info & |
| 5142 | I40E_AQ_QUALIFIED_MODULE))) |
| 5143 | netdev_err(vsi->netdev, |
| 5144 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5145 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5146 | |
| 5147 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5148 | if (vsi->type == I40E_VSI_FDIR) { |
| 5149 | /* reset fd counters */ |
| 5150 | pf->fd_add_err = pf->fd_atr_cnt = 0; |
| 5151 | if (pf->fd_tcp_rule > 0) { |
| 5152 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5153 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5154 | 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] | 5155 | pf->fd_tcp_rule = 0; |
| 5156 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5157 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5158 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5159 | |
| 5160 | /* On the next run of the service_task, notify any clients of the new |
| 5161 | * opened netdev |
| 5162 | */ |
| 5163 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5164 | i40e_service_event_schedule(pf); |
| 5165 | |
| 5166 | return 0; |
| 5167 | } |
| 5168 | |
| 5169 | /** |
| 5170 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5171 | * @vsi: the VSI being configured |
| 5172 | * |
| 5173 | * Rebuild the ring structs after some configuration |
| 5174 | * has changed, e.g. MTU size. |
| 5175 | **/ |
| 5176 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5177 | { |
| 5178 | struct i40e_pf *pf = vsi->back; |
| 5179 | |
| 5180 | WARN_ON(in_interrupt()); |
| 5181 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5182 | usleep_range(1000, 2000); |
| 5183 | i40e_down(vsi); |
| 5184 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5185 | i40e_up(vsi); |
| 5186 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 5187 | } |
| 5188 | |
| 5189 | /** |
| 5190 | * i40e_up - Bring the connection back up after being down |
| 5191 | * @vsi: the VSI being configured |
| 5192 | **/ |
| 5193 | int i40e_up(struct i40e_vsi *vsi) |
| 5194 | { |
| 5195 | int err; |
| 5196 | |
| 5197 | err = i40e_vsi_configure(vsi); |
| 5198 | if (!err) |
| 5199 | err = i40e_up_complete(vsi); |
| 5200 | |
| 5201 | return err; |
| 5202 | } |
| 5203 | |
| 5204 | /** |
| 5205 | * i40e_down - Shutdown the connection processing |
| 5206 | * @vsi: the VSI being stopped |
| 5207 | **/ |
| 5208 | void i40e_down(struct i40e_vsi *vsi) |
| 5209 | { |
| 5210 | int i; |
| 5211 | |
| 5212 | /* It is assumed that the caller of this function |
| 5213 | * sets the vsi->state __I40E_DOWN bit. |
| 5214 | */ |
| 5215 | if (vsi->netdev) { |
| 5216 | netif_carrier_off(vsi->netdev); |
| 5217 | netif_tx_disable(vsi->netdev); |
| 5218 | } |
| 5219 | i40e_vsi_disable_irq(vsi); |
| 5220 | i40e_vsi_control_rings(vsi, false); |
| 5221 | i40e_napi_disable_all(vsi); |
| 5222 | |
| 5223 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5224 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 5225 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5226 | } |
Catherine Sullivan | f980d44 | 2016-05-16 10:26:34 -0700 | [diff] [blame] | 5227 | |
| 5228 | i40e_notify_client_of_netdev_close(vsi, false); |
| 5229 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | /** |
| 5233 | * i40e_setup_tc - configure multiple traffic classes |
| 5234 | * @netdev: net device to configure |
| 5235 | * @tc: number of traffic classes to enable |
| 5236 | **/ |
| 5237 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5238 | { |
| 5239 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5240 | struct i40e_vsi *vsi = np->vsi; |
| 5241 | struct i40e_pf *pf = vsi->back; |
| 5242 | u8 enabled_tc = 0; |
| 5243 | int ret = -EINVAL; |
| 5244 | int i; |
| 5245 | |
| 5246 | /* Check if DCB enabled to continue */ |
| 5247 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5248 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5249 | goto exit; |
| 5250 | } |
| 5251 | |
| 5252 | /* Check if MFP enabled */ |
| 5253 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5254 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5255 | goto exit; |
| 5256 | } |
| 5257 | |
| 5258 | /* Check whether tc count is within enabled limit */ |
| 5259 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5260 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5261 | goto exit; |
| 5262 | } |
| 5263 | |
| 5264 | /* Generate TC map for number of tc requested */ |
| 5265 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5266 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5267 | |
| 5268 | /* Requesting same TC configuration as already enabled */ |
| 5269 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5270 | return 0; |
| 5271 | |
| 5272 | /* Quiesce VSI queues */ |
| 5273 | i40e_quiesce_vsi(vsi); |
| 5274 | |
| 5275 | /* Configure VSI for enabled TCs */ |
| 5276 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5277 | if (ret) { |
| 5278 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5279 | vsi->seid); |
| 5280 | goto exit; |
| 5281 | } |
| 5282 | |
| 5283 | /* Unquiesce VSI */ |
| 5284 | i40e_unquiesce_vsi(vsi); |
| 5285 | |
| 5286 | exit: |
| 5287 | return ret; |
| 5288 | } |
| 5289 | |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5290 | #ifdef I40E_FCOE |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5291 | int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5292 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5293 | #else |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5294 | static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5295 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5296 | #endif |
| 5297 | { |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5298 | if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5299 | return -EINVAL; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5300 | return i40e_setup_tc(netdev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5301 | } |
| 5302 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5303 | /** |
| 5304 | * i40e_open - Called when a network interface is made active |
| 5305 | * @netdev: network interface device structure |
| 5306 | * |
| 5307 | * The open entry point is called when a network interface is made |
| 5308 | * active by the system (IFF_UP). At this point all resources needed |
| 5309 | * for transmit and receive operations are allocated, the interrupt |
| 5310 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5311 | * enabled, and the stack is notified that the interface is ready. |
| 5312 | * |
| 5313 | * Returns 0 on success, negative value on failure |
| 5314 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5315 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5316 | { |
| 5317 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5318 | struct i40e_vsi *vsi = np->vsi; |
| 5319 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5320 | int err; |
| 5321 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5322 | /* disallow open during test or if eeprom is broken */ |
| 5323 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 5324 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5325 | return -EBUSY; |
| 5326 | |
| 5327 | netif_carrier_off(netdev); |
| 5328 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5329 | err = i40e_vsi_open(vsi); |
| 5330 | if (err) |
| 5331 | return err; |
| 5332 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5333 | /* configure global TSO hardware offload settings */ |
| 5334 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5335 | TCP_FLAG_FIN) >> 16); |
| 5336 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5337 | TCP_FLAG_FIN | |
| 5338 | TCP_FLAG_CWR) >> 16); |
| 5339 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5340 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 5341 | udp_tunnel_get_rx_info(netdev); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5342 | i40e_notify_client_of_netdev_open(vsi); |
| 5343 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5344 | return 0; |
| 5345 | } |
| 5346 | |
| 5347 | /** |
| 5348 | * i40e_vsi_open - |
| 5349 | * @vsi: the VSI to open |
| 5350 | * |
| 5351 | * Finish initialization of the VSI. |
| 5352 | * |
| 5353 | * Returns 0 on success, negative value on failure |
| 5354 | **/ |
| 5355 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5356 | { |
| 5357 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5358 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5359 | int err; |
| 5360 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5361 | /* allocate descriptors */ |
| 5362 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5363 | if (err) |
| 5364 | goto err_setup_tx; |
| 5365 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5366 | if (err) |
| 5367 | goto err_setup_rx; |
| 5368 | |
| 5369 | err = i40e_vsi_configure(vsi); |
| 5370 | if (err) |
| 5371 | goto err_setup_rx; |
| 5372 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5373 | if (vsi->netdev) { |
| 5374 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5375 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5376 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5377 | if (err) |
| 5378 | goto err_setup_rx; |
| 5379 | |
| 5380 | /* Notify the stack of the actual queue counts. */ |
| 5381 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5382 | vsi->num_queue_pairs); |
| 5383 | if (err) |
| 5384 | goto err_set_queues; |
| 5385 | |
| 5386 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5387 | vsi->num_queue_pairs); |
| 5388 | if (err) |
| 5389 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5390 | |
| 5391 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5392 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5393 | dev_driver_string(&pf->pdev->dev), |
| 5394 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5395 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5396 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5397 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5398 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5399 | goto err_setup_rx; |
| 5400 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5401 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5402 | err = i40e_up_complete(vsi); |
| 5403 | if (err) |
| 5404 | goto err_up_complete; |
| 5405 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5406 | return 0; |
| 5407 | |
| 5408 | err_up_complete: |
| 5409 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5410 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5411 | i40e_vsi_free_irq(vsi); |
| 5412 | err_setup_rx: |
| 5413 | i40e_vsi_free_rx_resources(vsi); |
| 5414 | err_setup_tx: |
| 5415 | i40e_vsi_free_tx_resources(vsi); |
| 5416 | if (vsi == pf->vsi[pf->lan_vsi]) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5417 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5418 | |
| 5419 | return err; |
| 5420 | } |
| 5421 | |
| 5422 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5423 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5424 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5425 | * |
| 5426 | * This function destroys the hlist where all the Flow Director |
| 5427 | * filters were saved. |
| 5428 | **/ |
| 5429 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5430 | { |
| 5431 | struct i40e_fdir_filter *filter; |
| 5432 | struct hlist_node *node2; |
| 5433 | |
| 5434 | hlist_for_each_entry_safe(filter, node2, |
| 5435 | &pf->fdir_filter_list, fdir_node) { |
| 5436 | hlist_del(&filter->fdir_node); |
| 5437 | kfree(filter); |
| 5438 | } |
| 5439 | pf->fdir_pf_active_filters = 0; |
| 5440 | } |
| 5441 | |
| 5442 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5443 | * i40e_close - Disables a network interface |
| 5444 | * @netdev: network interface device structure |
| 5445 | * |
| 5446 | * The close entry point is called when an interface is de-activated |
| 5447 | * by the OS. The hardware is still under the driver's control, but |
| 5448 | * this netdev interface is disabled. |
| 5449 | * |
| 5450 | * Returns 0, this is not allowed to fail |
| 5451 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5452 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5453 | { |
| 5454 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5455 | struct i40e_vsi *vsi = np->vsi; |
| 5456 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5457 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5458 | |
| 5459 | return 0; |
| 5460 | } |
| 5461 | |
| 5462 | /** |
| 5463 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5464 | * @pf: board private structure |
| 5465 | * @reset_flags: which reset is requested |
| 5466 | * |
| 5467 | * The essential difference in resets is that the PF Reset |
| 5468 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5469 | * firmware, and doesn't bother the other PFs on the chip. |
| 5470 | **/ |
| 5471 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5472 | { |
| 5473 | u32 val; |
| 5474 | |
| 5475 | WARN_ON(in_interrupt()); |
| 5476 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5477 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5478 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5479 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5480 | |
| 5481 | /* Request a Global Reset |
| 5482 | * |
| 5483 | * This will start the chip's countdown to the actual full |
| 5484 | * chip reset event, and a warning interrupt to be sent |
| 5485 | * to all PFs, including the requestor. Our handler |
| 5486 | * for the warning interrupt will deal with the shutdown |
| 5487 | * and recovery of the switch setup. |
| 5488 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5489 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5490 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5491 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5492 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5493 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5494 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5495 | |
| 5496 | /* Request a Core Reset |
| 5497 | * |
| 5498 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5499 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5500 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5501 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5502 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5503 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5504 | i40e_flush(&pf->hw); |
| 5505 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5506 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5507 | |
| 5508 | /* Request a PF Reset |
| 5509 | * |
| 5510 | * Resets only the PF-specific registers |
| 5511 | * |
| 5512 | * This goes directly to the tear-down and rebuild of |
| 5513 | * the switch, since we need to do all the recovery as |
| 5514 | * for the Core Reset. |
| 5515 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5516 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5517 | i40e_handle_reset_warning(pf); |
| 5518 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5519 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5520 | int v; |
| 5521 | |
| 5522 | /* Find the VSI(s) that requested a re-init */ |
| 5523 | dev_info(&pf->pdev->dev, |
| 5524 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5525 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5526 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5527 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5528 | if (vsi != NULL && |
| 5529 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5530 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5531 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5532 | } |
| 5533 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5534 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5535 | int v; |
| 5536 | |
| 5537 | /* Find the VSI(s) that needs to be brought down */ |
| 5538 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5539 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5540 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5541 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5542 | if (vsi != NULL && |
| 5543 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5544 | set_bit(__I40E_DOWN, &vsi->state); |
| 5545 | i40e_down(vsi); |
| 5546 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5547 | } |
| 5548 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5549 | } else { |
| 5550 | dev_info(&pf->pdev->dev, |
| 5551 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5552 | } |
| 5553 | } |
| 5554 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5555 | #ifdef CONFIG_I40E_DCB |
| 5556 | /** |
| 5557 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5558 | * @pf: board private structure |
| 5559 | * @old_cfg: current DCB config |
| 5560 | * @new_cfg: new DCB config |
| 5561 | **/ |
| 5562 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5563 | struct i40e_dcbx_config *old_cfg, |
| 5564 | struct i40e_dcbx_config *new_cfg) |
| 5565 | { |
| 5566 | bool need_reconfig = false; |
| 5567 | |
| 5568 | /* Check if ETS configuration has changed */ |
| 5569 | if (memcmp(&new_cfg->etscfg, |
| 5570 | &old_cfg->etscfg, |
| 5571 | sizeof(new_cfg->etscfg))) { |
| 5572 | /* If Priority Table has changed reconfig is needed */ |
| 5573 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5574 | &old_cfg->etscfg.prioritytable, |
| 5575 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5576 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5577 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5578 | } |
| 5579 | |
| 5580 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5581 | &old_cfg->etscfg.tcbwtable, |
| 5582 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5583 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5584 | |
| 5585 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5586 | &old_cfg->etscfg.tsatable, |
| 5587 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5588 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5589 | } |
| 5590 | |
| 5591 | /* Check if PFC configuration has changed */ |
| 5592 | if (memcmp(&new_cfg->pfc, |
| 5593 | &old_cfg->pfc, |
| 5594 | sizeof(new_cfg->pfc))) { |
| 5595 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5596 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5597 | } |
| 5598 | |
| 5599 | /* Check if APP Table has changed */ |
| 5600 | if (memcmp(&new_cfg->app, |
| 5601 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5602 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5603 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5604 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5605 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5606 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5607 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5608 | return need_reconfig; |
| 5609 | } |
| 5610 | |
| 5611 | /** |
| 5612 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5613 | * @pf: board private structure |
| 5614 | * @e: event info posted on ARQ |
| 5615 | **/ |
| 5616 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5617 | struct i40e_arq_event_info *e) |
| 5618 | { |
| 5619 | struct i40e_aqc_lldp_get_mib *mib = |
| 5620 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5621 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5622 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5623 | bool need_reconfig = false; |
| 5624 | int ret = 0; |
| 5625 | u8 type; |
| 5626 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5627 | /* Not DCB capable or capability disabled */ |
| 5628 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
| 5629 | return ret; |
| 5630 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5631 | /* Ignore if event is not for Nearest Bridge */ |
| 5632 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5633 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5634 | 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] | 5635 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5636 | return ret; |
| 5637 | |
| 5638 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5639 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5640 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5641 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5642 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5643 | /* Update the remote cached instance and return */ |
| 5644 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5645 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5646 | &hw->remote_dcbx_config); |
| 5647 | goto exit; |
| 5648 | } |
| 5649 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5650 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5651 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5652 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5653 | /* Reset the old DCBx configuration data */ |
| 5654 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5655 | /* Get updated DCBX data from firmware */ |
| 5656 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5657 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5658 | dev_info(&pf->pdev->dev, |
| 5659 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 5660 | i40e_stat_str(&pf->hw, ret), |
| 5661 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5662 | goto exit; |
| 5663 | } |
| 5664 | |
| 5665 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5666 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5667 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5668 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5669 | goto exit; |
| 5670 | } |
| 5671 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5672 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5673 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5674 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5675 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5676 | |
| 5677 | if (!need_reconfig) |
| 5678 | goto exit; |
| 5679 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5680 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5681 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5682 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5683 | else |
| 5684 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5685 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5686 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5687 | /* Reconfiguration needed quiesce all VSIs */ |
| 5688 | i40e_pf_quiesce_all_vsi(pf); |
| 5689 | |
| 5690 | /* Changes in configuration update VEB/VSI */ |
| 5691 | i40e_dcb_reconfigure(pf); |
| 5692 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5693 | ret = i40e_resume_port_tx(pf); |
| 5694 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5695 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5696 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5697 | if (ret) |
| 5698 | goto exit; |
| 5699 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 5700 | /* Wait for the PF's queues to be disabled */ |
| 5701 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5702 | if (ret) { |
| 5703 | /* Schedule PF reset to recover */ |
| 5704 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5705 | i40e_service_event_schedule(pf); |
| 5706 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5707 | i40e_pf_unquiesce_all_vsi(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5708 | } |
| 5709 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5710 | exit: |
| 5711 | return ret; |
| 5712 | } |
| 5713 | #endif /* CONFIG_I40E_DCB */ |
| 5714 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5715 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5716 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 5717 | * @pf: board private structure |
| 5718 | * @reset_flags: which reset is requested |
| 5719 | * |
| 5720 | **/ |
| 5721 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 5722 | { |
| 5723 | rtnl_lock(); |
| 5724 | i40e_do_reset(pf, reset_flags); |
| 5725 | rtnl_unlock(); |
| 5726 | } |
| 5727 | |
| 5728 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5729 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 5730 | * @pf: board private structure |
| 5731 | * @e: event info posted on ARQ |
| 5732 | * |
| 5733 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 5734 | * and VF queues |
| 5735 | **/ |
| 5736 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 5737 | struct i40e_arq_event_info *e) |
| 5738 | { |
| 5739 | struct i40e_aqc_lan_overflow *data = |
| 5740 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 5741 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 5742 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 5743 | struct i40e_hw *hw = &pf->hw; |
| 5744 | struct i40e_vf *vf; |
| 5745 | u16 vf_id; |
| 5746 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5747 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 5748 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5749 | |
| 5750 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 5751 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 5752 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 5753 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 5754 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 5755 | vf_id -= hw->func_caps.vf_base_id; |
| 5756 | vf = &pf->vf[vf_id]; |
| 5757 | i40e_vc_notify_vf_reset(vf); |
| 5758 | /* Allow VF to process pending reset notification */ |
| 5759 | msleep(20); |
| 5760 | i40e_reset_vf(vf, false); |
| 5761 | } |
| 5762 | } |
| 5763 | |
| 5764 | /** |
| 5765 | * i40e_service_event_complete - Finish up the service event |
| 5766 | * @pf: board private structure |
| 5767 | **/ |
| 5768 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 5769 | { |
Shannon Nelson | b875f99 | 2015-10-21 19:47:03 -0400 | [diff] [blame] | 5770 | WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5771 | |
| 5772 | /* flush memory to make sure state is correct before next watchog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5773 | smp_mb__before_atomic(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5774 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 5775 | } |
| 5776 | |
| 5777 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5778 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 5779 | * @pf: board private structure |
| 5780 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5781 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5782 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5783 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5784 | |
| 5785 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5786 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 5787 | return fcnt_prog; |
| 5788 | } |
| 5789 | |
| 5790 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5791 | * 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] | 5792 | * @pf: board private structure |
| 5793 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5794 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5795 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5796 | u32 val, fcnt_prog; |
| 5797 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5798 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5799 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 5800 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 5801 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 5802 | return fcnt_prog; |
| 5803 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5804 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5805 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5806 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 5807 | * @pf: board private structure |
| 5808 | **/ |
| 5809 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 5810 | { |
| 5811 | u32 val, fcnt_prog; |
| 5812 | |
| 5813 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 5814 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 5815 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 5816 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 5817 | return fcnt_prog; |
| 5818 | } |
| 5819 | |
| 5820 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5821 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 5822 | * @pf: board private structure |
| 5823 | **/ |
| 5824 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 5825 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5826 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5827 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5828 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5829 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5830 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 5831 | return; |
| 5832 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5833 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 5834 | * to re-enable |
| 5835 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5836 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5837 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5838 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 5839 | (pf->fd_add_err == 0) || |
| 5840 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5841 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 5842 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 5843 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5844 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5845 | 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] | 5846 | } |
| 5847 | } |
| 5848 | /* Wait for some more space to be available to turn on ATR */ |
| 5849 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 5850 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 5851 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
| 5852 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5853 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5854 | 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] | 5855 | } |
| 5856 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5857 | |
| 5858 | /* if hw had a problem adding a filter, delete it */ |
| 5859 | if (pf->fd_inv > 0) { |
| 5860 | hlist_for_each_entry_safe(filter, node, |
| 5861 | &pf->fdir_filter_list, fdir_node) { |
| 5862 | if (filter->fd_id == pf->fd_inv) { |
| 5863 | hlist_del(&filter->fdir_node); |
| 5864 | kfree(filter); |
| 5865 | pf->fdir_pf_active_filters--; |
| 5866 | } |
| 5867 | } |
| 5868 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5869 | } |
| 5870 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5871 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5872 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5873 | /** |
| 5874 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 5875 | * @pf: board private structure |
| 5876 | **/ |
| 5877 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 5878 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5879 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5880 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5881 | bool disable_atr = false; |
| 5882 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5883 | int reg; |
| 5884 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 5885 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 5886 | return; |
| 5887 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5888 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 5889 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 5890 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5891 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5892 | /* If the flush is happening too quick and we have mostly SB rules we |
| 5893 | * should not re-enable ATR for some time. |
| 5894 | */ |
| 5895 | min_flush_time = pf->fd_flush_timestamp + |
| 5896 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 5897 | 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] | 5898 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5899 | if (!(time_after(jiffies, min_flush_time)) && |
| 5900 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 5901 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5902 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 5903 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5904 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5905 | |
| 5906 | pf->fd_flush_timestamp = jiffies; |
| 5907 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
| 5908 | /* flush all filters */ |
| 5909 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 5910 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 5911 | i40e_flush(&pf->hw); |
| 5912 | pf->fd_flush_cnt++; |
| 5913 | pf->fd_add_err = 0; |
| 5914 | do { |
| 5915 | /* Check FD flush status every 5-6msec */ |
| 5916 | usleep_range(5000, 6000); |
| 5917 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 5918 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 5919 | break; |
| 5920 | } while (flush_wait_retry--); |
| 5921 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 5922 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 5923 | } else { |
| 5924 | /* replay sideband filters */ |
| 5925 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
| 5926 | if (!disable_atr) |
| 5927 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 5928 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
| 5929 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5930 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 5931 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5932 | } |
| 5933 | |
| 5934 | /** |
| 5935 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 5936 | * @pf: board private structure |
| 5937 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5938 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5939 | { |
| 5940 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 5941 | } |
| 5942 | |
| 5943 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 5944 | * being applied really fast; before we see the first |
| 5945 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 5946 | * reacting will make sure we don't cause flush too often. |
| 5947 | */ |
| 5948 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 5949 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5950 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5951 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 5952 | * @pf: board private structure |
| 5953 | **/ |
| 5954 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 5955 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5956 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5957 | /* if interface is down do nothing */ |
| 5958 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 5959 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5960 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 5961 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 5962 | return; |
| 5963 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5964 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5965 | i40e_fdir_flush_and_replay(pf); |
| 5966 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5967 | i40e_fdir_check_and_reenable(pf); |
| 5968 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5969 | } |
| 5970 | |
| 5971 | /** |
| 5972 | * i40e_vsi_link_event - notify VSI of a link event |
| 5973 | * @vsi: vsi to be notified |
| 5974 | * @link_up: link up or down |
| 5975 | **/ |
| 5976 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 5977 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 5978 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5979 | return; |
| 5980 | |
| 5981 | switch (vsi->type) { |
| 5982 | case I40E_VSI_MAIN: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5983 | #ifdef I40E_FCOE |
| 5984 | case I40E_VSI_FCOE: |
| 5985 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5986 | if (!vsi->netdev || !vsi->netdev_registered) |
| 5987 | break; |
| 5988 | |
| 5989 | if (link_up) { |
| 5990 | netif_carrier_on(vsi->netdev); |
| 5991 | netif_tx_wake_all_queues(vsi->netdev); |
| 5992 | } else { |
| 5993 | netif_carrier_off(vsi->netdev); |
| 5994 | netif_tx_stop_all_queues(vsi->netdev); |
| 5995 | } |
| 5996 | break; |
| 5997 | |
| 5998 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5999 | case I40E_VSI_VMDQ2: |
| 6000 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 6001 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6002 | case I40E_VSI_MIRROR: |
| 6003 | default: |
| 6004 | /* there is no notification for other VSIs */ |
| 6005 | break; |
| 6006 | } |
| 6007 | } |
| 6008 | |
| 6009 | /** |
| 6010 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6011 | * @veb: veb to be notified |
| 6012 | * @link_up: link up or down |
| 6013 | **/ |
| 6014 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6015 | { |
| 6016 | struct i40e_pf *pf; |
| 6017 | int i; |
| 6018 | |
| 6019 | if (!veb || !veb->pf) |
| 6020 | return; |
| 6021 | pf = veb->pf; |
| 6022 | |
| 6023 | /* depth first... */ |
| 6024 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6025 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6026 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6027 | |
| 6028 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6029 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6030 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6031 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6032 | } |
| 6033 | |
| 6034 | /** |
| 6035 | * i40e_link_event - Update netif_carrier status |
| 6036 | * @pf: board private structure |
| 6037 | **/ |
| 6038 | static void i40e_link_event(struct i40e_pf *pf) |
| 6039 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6040 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6041 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6042 | i40e_status status; |
| 6043 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6044 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6045 | /* save off old link status information */ |
| 6046 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6047 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6048 | /* set this to force the get_link_status call to refresh state */ |
| 6049 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6050 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6051 | 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] | 6052 | |
| 6053 | status = i40e_get_link_status(&pf->hw, &new_link); |
| 6054 | if (status) { |
| 6055 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6056 | status); |
| 6057 | return; |
| 6058 | } |
| 6059 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6060 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6061 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6062 | |
| 6063 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6064 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6065 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 6066 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6067 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6068 | |
| 6069 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 6070 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6071 | |
| 6072 | /* Notify the base of the switch tree connected to |
| 6073 | * the link. Floating VEBs are not notified. |
| 6074 | */ |
| 6075 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6076 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6077 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6078 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6079 | |
| 6080 | if (pf->vf) |
| 6081 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6082 | |
| 6083 | if (pf->flags & I40E_FLAG_PTP) |
| 6084 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6085 | } |
| 6086 | |
| 6087 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6088 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6089 | * @pf: board private structure |
| 6090 | **/ |
| 6091 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6092 | { |
| 6093 | int i; |
| 6094 | |
| 6095 | /* if interface is down do nothing */ |
| 6096 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 6097 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6098 | return; |
| 6099 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6100 | /* make sure we don't do these things too often */ |
| 6101 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6102 | pf->service_timer_period))) |
| 6103 | return; |
| 6104 | pf->service_timer_previous = jiffies; |
| 6105 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6106 | if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) |
| 6107 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6108 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6109 | /* Update the stats for active netdevs so the network stack |
| 6110 | * can look at updated numbers whenever it cares to |
| 6111 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6112 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6113 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6114 | i40e_update_stats(pf->vsi[i]); |
| 6115 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6116 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6117 | /* Update the stats for the active switching components */ |
| 6118 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6119 | if (pf->veb[i]) |
| 6120 | i40e_update_veb_stats(pf->veb[i]); |
| 6121 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6122 | |
| 6123 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6124 | } |
| 6125 | |
| 6126 | /** |
| 6127 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6128 | * @pf: board private structure |
| 6129 | **/ |
| 6130 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6131 | { |
| 6132 | u32 reset_flags = 0; |
| 6133 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6134 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6135 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6136 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6137 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 6138 | } |
| 6139 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6140 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6141 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6142 | } |
| 6143 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6144 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6145 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 6146 | } |
| 6147 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6148 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6149 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 6150 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6151 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6152 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6153 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 6154 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6155 | |
| 6156 | /* If there's a recovery already waiting, it takes |
| 6157 | * precedence before starting a new reset sequence. |
| 6158 | */ |
| 6159 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 6160 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6161 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6162 | } |
| 6163 | |
| 6164 | /* If we're already down or resetting, just bail */ |
| 6165 | if (reset_flags && |
| 6166 | !test_bit(__I40E_DOWN, &pf->state) && |
| 6167 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6168 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6169 | |
| 6170 | unlock: |
| 6171 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6172 | } |
| 6173 | |
| 6174 | /** |
| 6175 | * i40e_handle_link_event - Handle link event |
| 6176 | * @pf: board private structure |
| 6177 | * @e: event info posted on ARQ |
| 6178 | **/ |
| 6179 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6180 | struct i40e_arq_event_info *e) |
| 6181 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6182 | struct i40e_aqc_get_link_status *status = |
| 6183 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6184 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6185 | /* Do a new status request to re-enable LSE reporting |
| 6186 | * and load new status information into the hw struct |
| 6187 | * This completely ignores any state information |
| 6188 | * in the ARQ event info, instead choosing to always |
| 6189 | * issue the AQ update link status command. |
| 6190 | */ |
| 6191 | i40e_link_event(pf); |
| 6192 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6193 | /* check for unqualified module, if link is down */ |
| 6194 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6195 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6196 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6197 | dev_err(&pf->pdev->dev, |
| 6198 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | /** |
| 6202 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6203 | * @pf: board private structure |
| 6204 | **/ |
| 6205 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6206 | { |
| 6207 | struct i40e_arq_event_info event; |
| 6208 | struct i40e_hw *hw = &pf->hw; |
| 6209 | u16 pending, i = 0; |
| 6210 | i40e_status ret; |
| 6211 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6212 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6213 | u32 val; |
| 6214 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6215 | /* Do not run clean AQ when PF reset fails */ |
| 6216 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 6217 | return; |
| 6218 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6219 | /* check for error indications */ |
| 6220 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6221 | oldval = val; |
| 6222 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6223 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6224 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6225 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6226 | } |
| 6227 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6228 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6229 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6230 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6231 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6232 | } |
| 6233 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6234 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6235 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6236 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6237 | } |
| 6238 | if (oldval != val) |
| 6239 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6240 | |
| 6241 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6242 | oldval = val; |
| 6243 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6244 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6245 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6246 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6247 | } |
| 6248 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6249 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6250 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6251 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6252 | } |
| 6253 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6254 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6255 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6256 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6257 | } |
| 6258 | if (oldval != val) |
| 6259 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6260 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6261 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6262 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6263 | if (!event.msg_buf) |
| 6264 | return; |
| 6265 | |
| 6266 | do { |
| 6267 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6268 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6269 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6270 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6271 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6272 | break; |
| 6273 | } |
| 6274 | |
| 6275 | opcode = le16_to_cpu(event.desc.opcode); |
| 6276 | switch (opcode) { |
| 6277 | |
| 6278 | case i40e_aqc_opc_get_link_status: |
| 6279 | i40e_handle_link_event(pf, &event); |
| 6280 | break; |
| 6281 | case i40e_aqc_opc_send_msg_to_pf: |
| 6282 | ret = i40e_vc_process_vf_msg(pf, |
| 6283 | le16_to_cpu(event.desc.retval), |
| 6284 | le32_to_cpu(event.desc.cookie_high), |
| 6285 | le32_to_cpu(event.desc.cookie_low), |
| 6286 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6287 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6288 | break; |
| 6289 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6290 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6291 | #ifdef CONFIG_I40E_DCB |
| 6292 | rtnl_lock(); |
| 6293 | ret = i40e_handle_lldp_event(pf, &event); |
| 6294 | rtnl_unlock(); |
| 6295 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6296 | break; |
| 6297 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6298 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6299 | i40e_handle_lan_overflow_event(pf, &event); |
| 6300 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6301 | case i40e_aqc_opc_send_msg_to_peer: |
| 6302 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6303 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6304 | case i40e_aqc_opc_nvm_erase: |
| 6305 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6306 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 6307 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 6308 | "ARQ NVM operation 0x%04x completed\n", |
| 6309 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6310 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6311 | default: |
| 6312 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 6313 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6314 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6315 | break; |
| 6316 | } |
| 6317 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 6318 | |
| 6319 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 6320 | /* re-enable Admin queue interrupt cause */ |
| 6321 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6322 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6323 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6324 | i40e_flush(hw); |
| 6325 | |
| 6326 | kfree(event.msg_buf); |
| 6327 | } |
| 6328 | |
| 6329 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6330 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6331 | * @pf: board private structure |
| 6332 | **/ |
| 6333 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6334 | { |
| 6335 | int err; |
| 6336 | |
| 6337 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6338 | if (err) { |
| 6339 | /* retry in case of garbage read */ |
| 6340 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6341 | if (err) { |
| 6342 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6343 | err); |
| 6344 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6345 | } |
| 6346 | } |
| 6347 | |
| 6348 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 6349 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 6350 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6351 | } |
| 6352 | } |
| 6353 | |
| 6354 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6355 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6356 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6357 | * |
| 6358 | * enable switch loop back or die - no point in a return value |
| 6359 | **/ |
| 6360 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6361 | { |
| 6362 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6363 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6364 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6365 | |
| 6366 | ctxt.seid = pf->main_vsi_seid; |
| 6367 | ctxt.pf_num = pf->hw.pf_id; |
| 6368 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6369 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6370 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6371 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6372 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6373 | i40e_stat_str(&pf->hw, ret), |
| 6374 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6375 | return; |
| 6376 | } |
| 6377 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6378 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6379 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6380 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6381 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6382 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6383 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6384 | "update vsi switch failed, err %s aq_err %s\n", |
| 6385 | i40e_stat_str(&pf->hw, ret), |
| 6386 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6387 | } |
| 6388 | } |
| 6389 | |
| 6390 | /** |
| 6391 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6392 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6393 | * |
| 6394 | * disable switch loop back or die - no point in a return value |
| 6395 | **/ |
| 6396 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6397 | { |
| 6398 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6399 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6400 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6401 | |
| 6402 | ctxt.seid = pf->main_vsi_seid; |
| 6403 | ctxt.pf_num = pf->hw.pf_id; |
| 6404 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6405 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6406 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6407 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6408 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6409 | i40e_stat_str(&pf->hw, ret), |
| 6410 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6411 | return; |
| 6412 | } |
| 6413 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6414 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6415 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6416 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6417 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6418 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6419 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6420 | "update vsi switch failed, err %s aq_err %s\n", |
| 6421 | i40e_stat_str(&pf->hw, ret), |
| 6422 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6423 | } |
| 6424 | } |
| 6425 | |
| 6426 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6427 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6428 | * @veb: pointer to the bridge instance |
| 6429 | * |
| 6430 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6431 | * specified HW bridge instance. It is expected this function is called |
| 6432 | * when a new HW bridge is instantiated. |
| 6433 | **/ |
| 6434 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6435 | { |
| 6436 | struct i40e_pf *pf = veb->pf; |
| 6437 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6438 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6439 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6440 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6441 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6442 | i40e_disable_pf_switch_lb(pf); |
| 6443 | else |
| 6444 | i40e_enable_pf_switch_lb(pf); |
| 6445 | } |
| 6446 | |
| 6447 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6448 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6449 | * @veb: pointer to the VEB instance |
| 6450 | * |
| 6451 | * This is a recursive function that first builds the attached VSIs then |
| 6452 | * recurses in to build the next layer of VEB. We track the connections |
| 6453 | * through our own index numbers because the seid's from the HW could |
| 6454 | * change across the reset. |
| 6455 | **/ |
| 6456 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6457 | { |
| 6458 | struct i40e_vsi *ctl_vsi = NULL; |
| 6459 | struct i40e_pf *pf = veb->pf; |
| 6460 | int v, veb_idx; |
| 6461 | int ret; |
| 6462 | |
| 6463 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6464 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6465 | if (pf->vsi[v] && |
| 6466 | pf->vsi[v]->veb_idx == veb->idx && |
| 6467 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6468 | ctl_vsi = pf->vsi[v]; |
| 6469 | break; |
| 6470 | } |
| 6471 | } |
| 6472 | if (!ctl_vsi) { |
| 6473 | dev_info(&pf->pdev->dev, |
| 6474 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6475 | ret = -ENOENT; |
| 6476 | goto end_reconstitute; |
| 6477 | } |
| 6478 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6479 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6480 | ret = i40e_add_vsi(ctl_vsi); |
| 6481 | if (ret) { |
| 6482 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6483 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6484 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6485 | goto end_reconstitute; |
| 6486 | } |
| 6487 | i40e_vsi_reset_stats(ctl_vsi); |
| 6488 | |
| 6489 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6490 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6491 | if (ret) |
| 6492 | goto end_reconstitute; |
| 6493 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6494 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6495 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6496 | else |
| 6497 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6498 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6499 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6500 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6501 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6502 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6503 | continue; |
| 6504 | |
| 6505 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6506 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6507 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6508 | vsi->uplink_seid = veb->seid; |
| 6509 | ret = i40e_add_vsi(vsi); |
| 6510 | if (ret) { |
| 6511 | dev_info(&pf->pdev->dev, |
| 6512 | "rebuild of vsi_idx %d failed: %d\n", |
| 6513 | v, ret); |
| 6514 | goto end_reconstitute; |
| 6515 | } |
| 6516 | i40e_vsi_reset_stats(vsi); |
| 6517 | } |
| 6518 | } |
| 6519 | |
| 6520 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6521 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6522 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6523 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6524 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6525 | if (ret) |
| 6526 | break; |
| 6527 | } |
| 6528 | } |
| 6529 | |
| 6530 | end_reconstitute: |
| 6531 | return ret; |
| 6532 | } |
| 6533 | |
| 6534 | /** |
| 6535 | * i40e_get_capabilities - get info about the HW |
| 6536 | * @pf: the PF struct |
| 6537 | **/ |
| 6538 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6539 | { |
| 6540 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6541 | u16 data_size; |
| 6542 | int buf_len; |
| 6543 | int err; |
| 6544 | |
| 6545 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6546 | do { |
| 6547 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6548 | if (!cap_buf) |
| 6549 | return -ENOMEM; |
| 6550 | |
| 6551 | /* this loads the data into the hw struct for us */ |
| 6552 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6553 | &data_size, |
| 6554 | i40e_aqc_opc_list_func_capabilities, |
| 6555 | NULL); |
| 6556 | /* data loaded, buffer no longer needed */ |
| 6557 | kfree(cap_buf); |
| 6558 | |
| 6559 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6560 | /* retry with a larger buffer */ |
| 6561 | buf_len = data_size; |
| 6562 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6563 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6564 | "capability discovery failed, err %s aq_err %s\n", |
| 6565 | i40e_stat_str(&pf->hw, err), |
| 6566 | i40e_aq_str(&pf->hw, |
| 6567 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6568 | return -ENODEV; |
| 6569 | } |
| 6570 | } while (err); |
| 6571 | |
| 6572 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6573 | dev_info(&pf->pdev->dev, |
| 6574 | "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", |
| 6575 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6576 | pf->hw.func_caps.num_msix_vectors, |
| 6577 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6578 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6579 | pf->hw.func_caps.fd_filters_best_effort, |
| 6580 | pf->hw.func_caps.num_tx_qp, |
| 6581 | pf->hw.func_caps.num_vsis); |
| 6582 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6583 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6584 | + pf->hw.func_caps.num_vfs) |
| 6585 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6586 | dev_info(&pf->pdev->dev, |
| 6587 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6588 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6589 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6590 | } |
| 6591 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6592 | return 0; |
| 6593 | } |
| 6594 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6595 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6596 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6597 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6598 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6599 | * @pf: board private structure |
| 6600 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6601 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6602 | { |
| 6603 | struct i40e_vsi *vsi; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6604 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6605 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6606 | /* quick workaround for an NVM issue that leaves a critical register |
| 6607 | * uninitialized |
| 6608 | */ |
| 6609 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6610 | static const u32 hkey[] = { |
| 6611 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6612 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6613 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6614 | 0x95b3a76d}; |
| 6615 | |
| 6616 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6617 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6618 | } |
| 6619 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6620 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6621 | return; |
| 6622 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6623 | /* find existing VSI and see if it needs configuring */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6624 | vsi = NULL; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6625 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6626 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6627 | vsi = pf->vsi[i]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6628 | break; |
| 6629 | } |
| 6630 | } |
| 6631 | |
| 6632 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6633 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6634 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6635 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6636 | if (!vsi) { |
| 6637 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6638 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6639 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6640 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6641 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6642 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6643 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6644 | } |
| 6645 | |
| 6646 | /** |
| 6647 | * i40e_fdir_teardown - release the Flow Director resources |
| 6648 | * @pf: board private structure |
| 6649 | **/ |
| 6650 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6651 | { |
| 6652 | int i; |
| 6653 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6654 | i40e_fdir_filter_exit(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6655 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6656 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 6657 | i40e_vsi_release(pf->vsi[i]); |
| 6658 | break; |
| 6659 | } |
| 6660 | } |
| 6661 | } |
| 6662 | |
| 6663 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6664 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6665 | * @pf: board private structure |
| 6666 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6667 | * 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] | 6668 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6669 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6670 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6671 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6672 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6673 | u32 v; |
| 6674 | |
| 6675 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6676 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6677 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 6678 | if (i40e_check_asq_alive(&pf->hw)) |
| 6679 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6680 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6681 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6682 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6683 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6684 | i40e_pf_quiesce_all_vsi(pf); |
| 6685 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6686 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6687 | if (pf->vsi[v]) |
| 6688 | pf->vsi[v]->seid = 0; |
| 6689 | } |
| 6690 | |
| 6691 | i40e_shutdown_adminq(&pf->hw); |
| 6692 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6693 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6694 | if (hw->hmc.hmc_obj) { |
| 6695 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6696 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6697 | dev_warn(&pf->pdev->dev, |
| 6698 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6699 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6700 | } |
| 6701 | |
| 6702 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6703 | * i40e_send_version - update firmware with driver version |
| 6704 | * @pf: PF struct |
| 6705 | */ |
| 6706 | static void i40e_send_version(struct i40e_pf *pf) |
| 6707 | { |
| 6708 | struct i40e_driver_version dv; |
| 6709 | |
| 6710 | dv.major_version = DRV_VERSION_MAJOR; |
| 6711 | dv.minor_version = DRV_VERSION_MINOR; |
| 6712 | dv.build_version = DRV_VERSION_BUILD; |
| 6713 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 6714 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6715 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 6716 | } |
| 6717 | |
| 6718 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 6719 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6720 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6721 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6722 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6723 | 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] | 6724 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6725 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6726 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6727 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6728 | u32 val; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6729 | u32 v; |
| 6730 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6731 | /* Now we wait for GRST to settle out. |
| 6732 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 6733 | * because the reset will make them disappear. |
| 6734 | */ |
| 6735 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6736 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6737 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6738 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 6739 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6740 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6741 | pf->pfr_count++; |
| 6742 | |
| 6743 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6744 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6745 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6746 | |
| 6747 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 6748 | ret = i40e_init_adminq(&pf->hw); |
| 6749 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6750 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 6751 | i40e_stat_str(&pf->hw, ret), |
| 6752 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6753 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6754 | } |
| 6755 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6756 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 6757 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6758 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6759 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 6760 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6761 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6762 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6763 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6764 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6765 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 6766 | hw->func_caps.num_rx_qp, |
| 6767 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 6768 | if (ret) { |
| 6769 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 6770 | goto end_core_reset; |
| 6771 | } |
| 6772 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 6773 | if (ret) { |
| 6774 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 6775 | goto end_core_reset; |
| 6776 | } |
| 6777 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6778 | #ifdef CONFIG_I40E_DCB |
| 6779 | ret = i40e_init_pf_dcb(pf); |
| 6780 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6781 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 6782 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 6783 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6784 | } |
| 6785 | #endif /* CONFIG_I40E_DCB */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6786 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 6787 | i40e_init_pf_fcoe(pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6788 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6789 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6790 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6791 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6792 | if (ret) |
| 6793 | goto end_core_reset; |
| 6794 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6795 | /* The driver only wants link up/down and module qualification |
| 6796 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6797 | */ |
| 6798 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6799 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 6800 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6801 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6802 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6803 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 6804 | i40e_stat_str(&pf->hw, ret), |
| 6805 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6806 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6807 | /* make sure our flow control settings are restored */ |
| 6808 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 6809 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 6810 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 6811 | i40e_stat_str(&pf->hw, ret), |
| 6812 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6813 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6814 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 6815 | * They are still in our local switch element arrays, so only |
| 6816 | * need to rebuild the switch model in the HW. |
| 6817 | * |
| 6818 | * If there were VEBs but the reconstitution failed, we'll try |
| 6819 | * try to recover minimal use by getting the basic PF VSI working. |
| 6820 | */ |
| 6821 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6822 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6823 | /* find the one VEB connected to the MAC, and find orphans */ |
| 6824 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6825 | if (!pf->veb[v]) |
| 6826 | continue; |
| 6827 | |
| 6828 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 6829 | pf->veb[v]->uplink_seid == 0) { |
| 6830 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 6831 | |
| 6832 | if (!ret) |
| 6833 | continue; |
| 6834 | |
| 6835 | /* If Main VEB failed, we're in deep doodoo, |
| 6836 | * so give up rebuilding the switch and set up |
| 6837 | * for minimal rebuild of PF VSI. |
| 6838 | * If orphan failed, we'll report the error |
| 6839 | * but try to keep going. |
| 6840 | */ |
| 6841 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 6842 | dev_info(&pf->pdev->dev, |
| 6843 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 6844 | ret); |
| 6845 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 6846 | = pf->mac_seid; |
| 6847 | break; |
| 6848 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 6849 | dev_info(&pf->pdev->dev, |
| 6850 | "rebuild of orphan VEB failed: %d\n", |
| 6851 | ret); |
| 6852 | } |
| 6853 | } |
| 6854 | } |
| 6855 | } |
| 6856 | |
| 6857 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 6858 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6859 | /* no VEB, so rebuild only the Main VSI */ |
| 6860 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 6861 | if (ret) { |
| 6862 | dev_info(&pf->pdev->dev, |
| 6863 | "rebuild of Main VSI failed: %d\n", ret); |
| 6864 | goto end_core_reset; |
| 6865 | } |
| 6866 | } |
| 6867 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6868 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 6869 | * of TSO, so that we avoid the MDD being fired and causing |
| 6870 | * a reset in the case of small MSS+TSO. |
| 6871 | */ |
| 6872 | #define I40E_REG_MSS 0x000E64DC |
| 6873 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 6874 | #define I40E_64BYTE_MSS 0x400000 |
| 6875 | val = rd32(hw, I40E_REG_MSS); |
| 6876 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 6877 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 6878 | val |= I40E_64BYTE_MSS; |
| 6879 | wr32(hw, I40E_REG_MSS, val); |
| 6880 | } |
| 6881 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 6882 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 6883 | msleep(75); |
| 6884 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 6885 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6886 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 6887 | i40e_stat_str(&pf->hw, ret), |
| 6888 | i40e_aq_str(&pf->hw, |
| 6889 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6890 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6891 | /* reinit the misc interrupt */ |
| 6892 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 6893 | ret = i40e_setup_misc_vector(pf); |
| 6894 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 6895 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 6896 | * transmitted. By doing so we stop a malicious VF from sending out |
| 6897 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 6898 | * PF/VF VSIs. |
| 6899 | * The FW can still send Flow control frames if enabled. |
| 6900 | */ |
| 6901 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 6902 | pf->main_vsi_seid); |
| 6903 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6904 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 6905 | i40e_pf_unquiesce_all_vsi(pf); |
| 6906 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 6907 | if (pf->num_alloc_vfs) { |
| 6908 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 6909 | i40e_reset_vf(&pf->vf[v], true); |
| 6910 | } |
| 6911 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6912 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6913 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6914 | |
| 6915 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6916 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 6917 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6918 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 6919 | } |
| 6920 | |
| 6921 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6922 | * 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] | 6923 | * @pf: board private structure |
| 6924 | * |
| 6925 | * Close up the VFs and other things in prep for a Core Reset, |
| 6926 | * then get ready to rebuild the world. |
| 6927 | **/ |
| 6928 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 6929 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6930 | i40e_prep_for_reset(pf); |
| 6931 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6932 | } |
| 6933 | |
| 6934 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6935 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6936 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6937 | * |
| 6938 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 6939 | **/ |
| 6940 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 6941 | { |
| 6942 | struct i40e_hw *hw = &pf->hw; |
| 6943 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 6944 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6945 | struct i40e_vf *vf; |
| 6946 | u32 reg; |
| 6947 | int i; |
| 6948 | |
| 6949 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 6950 | return; |
| 6951 | |
| 6952 | /* find what triggered the MDD event */ |
| 6953 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 6954 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6955 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 6956 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6957 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6958 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 6959 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6960 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6961 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 6962 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 6963 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6964 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6965 | 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] | 6966 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6967 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 6968 | mdd_detected = true; |
| 6969 | } |
| 6970 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 6971 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6972 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 6973 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 6974 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6975 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6976 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 6977 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 6978 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6979 | if (netif_msg_rx_err(pf)) |
| 6980 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 6981 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6982 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 6983 | mdd_detected = true; |
| 6984 | } |
| 6985 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 6986 | if (mdd_detected) { |
| 6987 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 6988 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 6989 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6990 | 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] | 6991 | pf_mdd_detected = true; |
| 6992 | } |
| 6993 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 6994 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 6995 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6996 | 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] | 6997 | pf_mdd_detected = true; |
| 6998 | } |
| 6999 | /* Queue belongs to the PF, initiate a reset */ |
| 7000 | if (pf_mdd_detected) { |
| 7001 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 7002 | i40e_service_event_schedule(pf); |
| 7003 | } |
| 7004 | } |
| 7005 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7006 | /* see if one of the VFs needs its hand slapped */ |
| 7007 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7008 | vf = &(pf->vf[i]); |
| 7009 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7010 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7011 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7012 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7013 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7014 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7015 | } |
| 7016 | |
| 7017 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7018 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7019 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7020 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7021 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7022 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7023 | } |
| 7024 | |
| 7025 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7026 | dev_info(&pf->pdev->dev, |
| 7027 | "Too many MDD events on VF %d, disabled\n", i); |
| 7028 | dev_info(&pf->pdev->dev, |
| 7029 | "Use PF Control I/F to re-enable the VF\n"); |
| 7030 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 7031 | } |
| 7032 | } |
| 7033 | |
| 7034 | /* re-enable mdd interrupt cause */ |
| 7035 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 7036 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7037 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7038 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7039 | i40e_flush(hw); |
| 7040 | } |
| 7041 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7042 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7043 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7044 | * @pf: board private structure |
| 7045 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7046 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7047 | { |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7048 | struct i40e_hw *hw = &pf->hw; |
| 7049 | i40e_status ret; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7050 | __be16 port; |
| 7051 | int i; |
| 7052 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7053 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7054 | return; |
| 7055 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7056 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7057 | |
| 7058 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7059 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7060 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
| 7061 | port = pf->udp_ports[i].index; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7062 | if (port) |
| 7063 | ret = i40e_aq_add_udp_tunnel(hw, ntohs(port), |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7064 | pf->udp_ports[i].type, |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7065 | NULL, NULL); |
| 7066 | else |
| 7067 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7068 | |
| 7069 | if (ret) { |
Carolyn Wyborny | 730a8f8 | 2016-02-17 16:12:16 -0800 | [diff] [blame] | 7070 | dev_dbg(&pf->pdev->dev, |
| 7071 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 7072 | pf->udp_ports[i].type ? "vxlan" : "geneve", |
| 7073 | port ? "add" : "delete", |
| 7074 | ntohs(port), i, |
| 7075 | i40e_stat_str(&pf->hw, ret), |
| 7076 | i40e_aq_str(&pf->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7077 | pf->hw.aq.asq_last_status)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7078 | pf->udp_ports[i].index = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7079 | } |
| 7080 | } |
| 7081 | } |
| 7082 | } |
| 7083 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7084 | /** |
| 7085 | * i40e_service_task - Run the driver's async subtasks |
| 7086 | * @work: pointer to work_struct containing our data |
| 7087 | **/ |
| 7088 | static void i40e_service_task(struct work_struct *work) |
| 7089 | { |
| 7090 | struct i40e_pf *pf = container_of(work, |
| 7091 | struct i40e_pf, |
| 7092 | service_task); |
| 7093 | unsigned long start_time = jiffies; |
| 7094 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7095 | /* don't bother with service tasks if a reset is in progress */ |
| 7096 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7097 | i40e_service_event_complete(pf); |
| 7098 | return; |
| 7099 | } |
| 7100 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7101 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 7102 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7103 | i40e_reset_subtask(pf); |
| 7104 | i40e_handle_mdd_event(pf); |
| 7105 | i40e_vc_process_vflr_event(pf); |
| 7106 | i40e_watchdog_subtask(pf); |
| 7107 | i40e_fdir_reinit_subtask(pf); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7108 | i40e_client_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7109 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7110 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7111 | i40e_clean_adminq_subtask(pf); |
| 7112 | |
| 7113 | i40e_service_event_complete(pf); |
| 7114 | |
| 7115 | /* If the tasks have taken longer than one timer cycle or there |
| 7116 | * is more work to be done, reschedule the service task now |
| 7117 | * rather than wait for the timer to tick again. |
| 7118 | */ |
| 7119 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 7120 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 7121 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 7122 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 7123 | i40e_service_event_schedule(pf); |
| 7124 | } |
| 7125 | |
| 7126 | /** |
| 7127 | * i40e_service_timer - timer callback |
| 7128 | * @data: pointer to PF struct |
| 7129 | **/ |
| 7130 | static void i40e_service_timer(unsigned long data) |
| 7131 | { |
| 7132 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7133 | |
| 7134 | mod_timer(&pf->service_timer, |
| 7135 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7136 | i40e_service_event_schedule(pf); |
| 7137 | } |
| 7138 | |
| 7139 | /** |
| 7140 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7141 | * @vsi: the VSI being configured |
| 7142 | **/ |
| 7143 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7144 | { |
| 7145 | struct i40e_pf *pf = vsi->back; |
| 7146 | |
| 7147 | switch (vsi->type) { |
| 7148 | case I40E_VSI_MAIN: |
| 7149 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7150 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7151 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7152 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7153 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7154 | else |
| 7155 | vsi->num_q_vectors = 1; |
| 7156 | |
| 7157 | break; |
| 7158 | |
| 7159 | case I40E_VSI_FDIR: |
| 7160 | vsi->alloc_queue_pairs = 1; |
| 7161 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7162 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7163 | vsi->num_q_vectors = 1; |
| 7164 | break; |
| 7165 | |
| 7166 | case I40E_VSI_VMDQ2: |
| 7167 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7168 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7169 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7170 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7171 | break; |
| 7172 | |
| 7173 | case I40E_VSI_SRIOV: |
| 7174 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7175 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7176 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7177 | break; |
| 7178 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7179 | #ifdef I40E_FCOE |
| 7180 | case I40E_VSI_FCOE: |
| 7181 | vsi->alloc_queue_pairs = pf->num_fcoe_qps; |
| 7182 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7183 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7184 | vsi->num_q_vectors = pf->num_fcoe_msix; |
| 7185 | break; |
| 7186 | |
| 7187 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7188 | default: |
| 7189 | WARN_ON(1); |
| 7190 | return -ENODATA; |
| 7191 | } |
| 7192 | |
| 7193 | return 0; |
| 7194 | } |
| 7195 | |
| 7196 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7197 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7198 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7199 | * @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] | 7200 | * |
| 7201 | * On error: returns error code (negative) |
| 7202 | * On success: returns 0 |
| 7203 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7204 | 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] | 7205 | { |
| 7206 | int size; |
| 7207 | int ret = 0; |
| 7208 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7209 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7210 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 7211 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7212 | if (!vsi->tx_rings) |
| 7213 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7214 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 7215 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7216 | if (alloc_qvectors) { |
| 7217 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7218 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7219 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7220 | if (!vsi->q_vectors) { |
| 7221 | ret = -ENOMEM; |
| 7222 | goto err_vectors; |
| 7223 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7224 | } |
| 7225 | return ret; |
| 7226 | |
| 7227 | err_vectors: |
| 7228 | kfree(vsi->tx_rings); |
| 7229 | return ret; |
| 7230 | } |
| 7231 | |
| 7232 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7233 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7234 | * @pf: board private structure |
| 7235 | * @type: type of VSI |
| 7236 | * |
| 7237 | * On error: returns error code (negative) |
| 7238 | * On success: returns vsi index in PF (positive) |
| 7239 | **/ |
| 7240 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7241 | { |
| 7242 | int ret = -ENODEV; |
| 7243 | struct i40e_vsi *vsi; |
| 7244 | int vsi_idx; |
| 7245 | int i; |
| 7246 | |
| 7247 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7248 | mutex_lock(&pf->switch_mutex); |
| 7249 | |
| 7250 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7251 | * been happening. We can afford to do a quick scan to look |
| 7252 | * for any free VSIs in the list. |
| 7253 | * |
| 7254 | * find next empty vsi slot, looping back around if necessary |
| 7255 | */ |
| 7256 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7257 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7258 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7259 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7260 | i = 0; |
| 7261 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7262 | i++; |
| 7263 | } |
| 7264 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7265 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7266 | vsi_idx = i; /* Found one! */ |
| 7267 | } else { |
| 7268 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7269 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7270 | } |
| 7271 | pf->next_vsi = ++i; |
| 7272 | |
| 7273 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7274 | if (!vsi) { |
| 7275 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7276 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7277 | } |
| 7278 | vsi->type = type; |
| 7279 | vsi->back = pf; |
| 7280 | set_bit(__I40E_DOWN, &vsi->state); |
| 7281 | vsi->flags = 0; |
| 7282 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7283 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7284 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7285 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7286 | vsi->netdev_registered = false; |
| 7287 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
| 7288 | INIT_LIST_HEAD(&vsi->mac_filter_list); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7289 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7290 | |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7291 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7292 | if (ret) |
| 7293 | goto err_rings; |
| 7294 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7295 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7296 | if (ret) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7297 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7298 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7299 | /* Setup default MSIX irq handler for VSI */ |
| 7300 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7301 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7302 | /* Initialize VSI lock */ |
| 7303 | spin_lock_init(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7304 | pf->vsi[vsi_idx] = vsi; |
| 7305 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7306 | goto unlock_pf; |
| 7307 | |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7308 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7309 | pf->next_vsi = i - 1; |
| 7310 | kfree(vsi); |
| 7311 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7312 | mutex_unlock(&pf->switch_mutex); |
| 7313 | return ret; |
| 7314 | } |
| 7315 | |
| 7316 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7317 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7318 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7319 | * @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] | 7320 | * |
| 7321 | * On error: returns error code (negative) |
| 7322 | * On success: returns 0 |
| 7323 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7324 | 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] | 7325 | { |
| 7326 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7327 | if (free_qvectors) { |
| 7328 | kfree(vsi->q_vectors); |
| 7329 | vsi->q_vectors = NULL; |
| 7330 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7331 | kfree(vsi->tx_rings); |
| 7332 | vsi->tx_rings = NULL; |
| 7333 | vsi->rx_rings = NULL; |
| 7334 | } |
| 7335 | |
| 7336 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7337 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7338 | * and lookup table |
| 7339 | * @vsi: Pointer to VSI structure |
| 7340 | */ |
| 7341 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7342 | { |
| 7343 | if (!vsi) |
| 7344 | return; |
| 7345 | |
| 7346 | kfree(vsi->rss_hkey_user); |
| 7347 | vsi->rss_hkey_user = NULL; |
| 7348 | |
| 7349 | kfree(vsi->rss_lut_user); |
| 7350 | vsi->rss_lut_user = NULL; |
| 7351 | } |
| 7352 | |
| 7353 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7354 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7355 | * @vsi: the VSI being un-configured |
| 7356 | **/ |
| 7357 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7358 | { |
| 7359 | struct i40e_pf *pf; |
| 7360 | |
| 7361 | if (!vsi) |
| 7362 | return 0; |
| 7363 | |
| 7364 | if (!vsi->back) |
| 7365 | goto free_vsi; |
| 7366 | pf = vsi->back; |
| 7367 | |
| 7368 | mutex_lock(&pf->switch_mutex); |
| 7369 | if (!pf->vsi[vsi->idx]) { |
| 7370 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7371 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7372 | goto unlock_vsi; |
| 7373 | } |
| 7374 | |
| 7375 | if (pf->vsi[vsi->idx] != vsi) { |
| 7376 | dev_err(&pf->pdev->dev, |
| 7377 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7378 | pf->vsi[vsi->idx]->idx, |
| 7379 | pf->vsi[vsi->idx], |
| 7380 | pf->vsi[vsi->idx]->type, |
| 7381 | vsi->idx, vsi, vsi->type); |
| 7382 | goto unlock_vsi; |
| 7383 | } |
| 7384 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7385 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7386 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7387 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7388 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7389 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7390 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7391 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7392 | pf->vsi[vsi->idx] = NULL; |
| 7393 | if (vsi->idx < pf->next_vsi) |
| 7394 | pf->next_vsi = vsi->idx; |
| 7395 | |
| 7396 | unlock_vsi: |
| 7397 | mutex_unlock(&pf->switch_mutex); |
| 7398 | free_vsi: |
| 7399 | kfree(vsi); |
| 7400 | |
| 7401 | return 0; |
| 7402 | } |
| 7403 | |
| 7404 | /** |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7405 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7406 | * @vsi: the VSI being cleaned |
| 7407 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7408 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7409 | { |
| 7410 | int i; |
| 7411 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7412 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7413 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7414 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7415 | vsi->tx_rings[i] = NULL; |
| 7416 | vsi->rx_rings[i] = NULL; |
| 7417 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7418 | } |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7419 | } |
| 7420 | |
| 7421 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7422 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7423 | * @vsi: the VSI being configured |
| 7424 | **/ |
| 7425 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7426 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7427 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7428 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7429 | int i; |
| 7430 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7431 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7432 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7433 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7434 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7435 | if (!tx_ring) |
| 7436 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7437 | |
| 7438 | tx_ring->queue_index = i; |
| 7439 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7440 | tx_ring->ring_active = false; |
| 7441 | tx_ring->vsi = vsi; |
| 7442 | tx_ring->netdev = vsi->netdev; |
| 7443 | tx_ring->dev = &pf->pdev->dev; |
| 7444 | tx_ring->count = vsi->num_desc; |
| 7445 | tx_ring->size = 0; |
| 7446 | tx_ring->dcb_tc = 0; |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 7447 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 7448 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7449 | tx_ring->tx_itr_setting = pf->tx_itr_default; |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7450 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7451 | |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7452 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7453 | rx_ring->queue_index = i; |
| 7454 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7455 | rx_ring->ring_active = false; |
| 7456 | rx_ring->vsi = vsi; |
| 7457 | rx_ring->netdev = vsi->netdev; |
| 7458 | rx_ring->dev = &pf->pdev->dev; |
| 7459 | rx_ring->count = vsi->num_desc; |
| 7460 | rx_ring->size = 0; |
| 7461 | rx_ring->dcb_tc = 0; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7462 | rx_ring->rx_itr_setting = pf->rx_itr_default; |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7463 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7464 | } |
| 7465 | |
| 7466 | return 0; |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7467 | |
| 7468 | err_out: |
| 7469 | i40e_vsi_clear_rings(vsi); |
| 7470 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7471 | } |
| 7472 | |
| 7473 | /** |
| 7474 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7475 | * @pf: board private structure |
| 7476 | * @vectors: the number of MSI-X vectors to request |
| 7477 | * |
| 7478 | * Returns the number of vectors reserved, or error |
| 7479 | **/ |
| 7480 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7481 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7482 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7483 | I40E_MIN_MSIX, vectors); |
| 7484 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7485 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7486 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7487 | vectors = 0; |
| 7488 | } |
| 7489 | |
| 7490 | return vectors; |
| 7491 | } |
| 7492 | |
| 7493 | /** |
| 7494 | * i40e_init_msix - Setup the MSIX capability |
| 7495 | * @pf: board private structure |
| 7496 | * |
| 7497 | * Work with the OS to set up the MSIX vectors needed. |
| 7498 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7499 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7500 | **/ |
| 7501 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7502 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7503 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7504 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7505 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7506 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7507 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7508 | |
| 7509 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7510 | return -ENODEV; |
| 7511 | |
| 7512 | /* The number of vectors we'll request will be comprised of: |
| 7513 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7514 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7515 | * - Queues being used for RSS. |
| 7516 | * We don't need as many as max_rss_size vectors. |
| 7517 | * use rss_size instead in the calculation since that |
| 7518 | * is governed by number of cpus in the system. |
| 7519 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7520 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7521 | * - The CPU count within the NUMA node if iWARP is enabled |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7522 | #ifdef I40E_FCOE |
| 7523 | * - The number of FCOE qps. |
| 7524 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7525 | * Once we count this up, try the request. |
| 7526 | * |
| 7527 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7528 | * and try again. If that still fails, we punt. |
| 7529 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7530 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7531 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7532 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7533 | /* reserve one vector for miscellaneous handler */ |
| 7534 | if (vectors_left) { |
| 7535 | v_budget++; |
| 7536 | vectors_left--; |
| 7537 | } |
| 7538 | |
| 7539 | /* reserve vectors for the main PF traffic queues */ |
| 7540 | pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left); |
| 7541 | vectors_left -= pf->num_lan_msix; |
| 7542 | v_budget += pf->num_lan_msix; |
| 7543 | |
| 7544 | /* reserve one vector for sideband flow director */ |
| 7545 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7546 | if (vectors_left) { |
| 7547 | v_budget++; |
| 7548 | vectors_left--; |
| 7549 | } else { |
| 7550 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7551 | } |
| 7552 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7553 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7554 | #ifdef I40E_FCOE |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7555 | /* can we reserve enough for FCoE? */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7556 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7557 | if (!vectors_left) |
| 7558 | pf->num_fcoe_msix = 0; |
| 7559 | else if (vectors_left >= pf->num_fcoe_qps) |
| 7560 | pf->num_fcoe_msix = pf->num_fcoe_qps; |
| 7561 | else |
| 7562 | pf->num_fcoe_msix = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7563 | v_budget += pf->num_fcoe_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7564 | vectors_left -= pf->num_fcoe_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7565 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7566 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7567 | #endif |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7568 | /* can we reserve enough for iWARP? */ |
| 7569 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7570 | if (!vectors_left) |
| 7571 | pf->num_iwarp_msix = 0; |
| 7572 | else if (vectors_left < pf->num_iwarp_msix) |
| 7573 | pf->num_iwarp_msix = 1; |
| 7574 | v_budget += pf->num_iwarp_msix; |
| 7575 | vectors_left -= pf->num_iwarp_msix; |
| 7576 | } |
| 7577 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7578 | /* any vectors left over go for VMDq support */ |
| 7579 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7580 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7581 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7582 | |
| 7583 | /* if we're short on vectors for what's desired, we limit |
| 7584 | * the queues per vmdq. If this is still more than are |
| 7585 | * available, the user will need to change the number of |
| 7586 | * queues/vectors used by the PF later with the ethtool |
| 7587 | * channels command |
| 7588 | */ |
| 7589 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7590 | pf->num_vmdq_qps = 1; |
| 7591 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
| 7592 | |
| 7593 | v_budget += vmdq_vecs; |
| 7594 | vectors_left -= vmdq_vecs; |
| 7595 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7596 | |
| 7597 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7598 | GFP_KERNEL); |
| 7599 | if (!pf->msix_entries) |
| 7600 | return -ENOMEM; |
| 7601 | |
| 7602 | for (i = 0; i < v_budget; i++) |
| 7603 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7604 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7605 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7606 | if (v_actual != v_budget) { |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7607 | /* If we have limited resources, we will start with no vectors |
| 7608 | * for the special features and then allocate vectors to some |
| 7609 | * of these features based on the policy and at the end disable |
| 7610 | * the features that did not get any vectors. |
| 7611 | */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7612 | iwarp_requested = pf->num_iwarp_msix; |
| 7613 | pf->num_iwarp_msix = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7614 | #ifdef I40E_FCOE |
| 7615 | pf->num_fcoe_qps = 0; |
| 7616 | pf->num_fcoe_msix = 0; |
| 7617 | #endif |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7618 | pf->num_vmdq_msix = 0; |
| 7619 | } |
| 7620 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7621 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7622 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7623 | kfree(pf->msix_entries); |
| 7624 | pf->msix_entries = NULL; |
| 7625 | return -ENODEV; |
| 7626 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7627 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7628 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7629 | pf->num_vmdq_vsis = 0; |
| 7630 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7631 | pf->num_lan_qps = 1; |
| 7632 | pf->num_lan_msix = 1; |
| 7633 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7634 | } else if (v_actual != v_budget) { |
| 7635 | int vec; |
| 7636 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7637 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7638 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7639 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7640 | /* Scale vector usage down */ |
| 7641 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7642 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7643 | pf->num_vmdq_qps = 1; |
| 7644 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7645 | |
| 7646 | /* partition out the remaining vectors */ |
| 7647 | switch (vec) { |
| 7648 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7649 | pf->num_lan_msix = 1; |
| 7650 | break; |
| 7651 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7652 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7653 | pf->num_lan_msix = 1; |
| 7654 | pf->num_iwarp_msix = 1; |
| 7655 | } else { |
| 7656 | pf->num_lan_msix = 2; |
| 7657 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7658 | #ifdef I40E_FCOE |
| 7659 | /* give one vector to FCoE */ |
| 7660 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7661 | pf->num_lan_msix = 1; |
| 7662 | pf->num_fcoe_msix = 1; |
| 7663 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7664 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7665 | break; |
| 7666 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7667 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7668 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 7669 | iwarp_requested); |
| 7670 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 7671 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7672 | } else { |
| 7673 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 7674 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7675 | } |
| 7676 | pf->num_lan_msix = min_t(int, |
| 7677 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 7678 | pf->num_lan_msix); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7679 | #ifdef I40E_FCOE |
| 7680 | /* give one vector to FCoE */ |
| 7681 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7682 | pf->num_fcoe_msix = 1; |
| 7683 | vec--; |
| 7684 | } |
| 7685 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7686 | break; |
| 7687 | } |
| 7688 | } |
| 7689 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7690 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7691 | (pf->num_vmdq_msix == 0)) { |
| 7692 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 7693 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 7694 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7695 | |
| 7696 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 7697 | (pf->num_iwarp_msix == 0)) { |
| 7698 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 7699 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 7700 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7701 | #ifdef I40E_FCOE |
| 7702 | |
| 7703 | if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { |
| 7704 | dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n"); |
| 7705 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 7706 | } |
| 7707 | #endif |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7708 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7709 | } |
| 7710 | |
| 7711 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7712 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7713 | * @vsi: the VSI being configured |
| 7714 | * @v_idx: index of the vector in the vsi struct |
| 7715 | * |
| 7716 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 7717 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7718 | 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] | 7719 | { |
| 7720 | struct i40e_q_vector *q_vector; |
| 7721 | |
| 7722 | /* allocate q_vector */ |
| 7723 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 7724 | if (!q_vector) |
| 7725 | return -ENOMEM; |
| 7726 | |
| 7727 | q_vector->vsi = vsi; |
| 7728 | q_vector->v_idx = v_idx; |
| 7729 | cpumask_set_cpu(v_idx, &q_vector->affinity_mask); |
| 7730 | if (vsi->netdev) |
| 7731 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 7732 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7733 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 7734 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 7735 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 7736 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7737 | /* tie q_vector and vsi together */ |
| 7738 | vsi->q_vectors[v_idx] = q_vector; |
| 7739 | |
| 7740 | return 0; |
| 7741 | } |
| 7742 | |
| 7743 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7744 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7745 | * @vsi: the VSI being configured |
| 7746 | * |
| 7747 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 7748 | * return -ENOMEM. |
| 7749 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7750 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7751 | { |
| 7752 | struct i40e_pf *pf = vsi->back; |
| 7753 | int v_idx, num_q_vectors; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7754 | int err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7755 | |
| 7756 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 7757 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7758 | num_q_vectors = vsi->num_q_vectors; |
| 7759 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 7760 | num_q_vectors = 1; |
| 7761 | else |
| 7762 | return -EINVAL; |
| 7763 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7764 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7765 | err = i40e_vsi_alloc_q_vector(vsi, v_idx); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7766 | if (err) |
| 7767 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7768 | } |
| 7769 | |
| 7770 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7771 | |
| 7772 | err_out: |
| 7773 | while (v_idx--) |
| 7774 | i40e_free_q_vector(vsi, v_idx); |
| 7775 | |
| 7776 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7777 | } |
| 7778 | |
| 7779 | /** |
| 7780 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 7781 | * @pf: board private structure to initialize |
| 7782 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7783 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7784 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7785 | int vectors = 0; |
| 7786 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7787 | |
| 7788 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7789 | vectors = i40e_init_msix(pf); |
| 7790 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7791 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7792 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7793 | #ifdef I40E_FCOE |
| 7794 | I40E_FLAG_FCOE_ENABLED | |
| 7795 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7796 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7797 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7798 | I40E_FLAG_SRIOV_ENABLED | |
| 7799 | I40E_FLAG_FD_SB_ENABLED | |
| 7800 | I40E_FLAG_FD_ATR_ENABLED | |
| 7801 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7802 | |
| 7803 | /* rework the queue expectations without MSIX */ |
| 7804 | i40e_determine_queue_usage(pf); |
| 7805 | } |
| 7806 | } |
| 7807 | |
| 7808 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 7809 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7810 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7811 | vectors = pci_enable_msi(pf->pdev); |
| 7812 | if (vectors < 0) { |
| 7813 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 7814 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7815 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 7816 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7817 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7818 | } |
| 7819 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 7820 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7821 | 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] | 7822 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7823 | /* set up vector assignment tracking */ |
| 7824 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 7825 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7826 | if (!pf->irq_pile) { |
| 7827 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 7828 | return -ENOMEM; |
| 7829 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7830 | pf->irq_pile->num_entries = vectors; |
| 7831 | pf->irq_pile->search_hint = 0; |
| 7832 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7833 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7834 | (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] | 7835 | |
| 7836 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7837 | } |
| 7838 | |
| 7839 | /** |
| 7840 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 7841 | * @pf: board private structure |
| 7842 | * |
| 7843 | * This sets up the handler for MSIX 0, which is used to manage the |
| 7844 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 7845 | * when in MSI or Legacy interrupt mode. |
| 7846 | **/ |
| 7847 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 7848 | { |
| 7849 | struct i40e_hw *hw = &pf->hw; |
| 7850 | int err = 0; |
| 7851 | |
| 7852 | /* Only request the irq if this is the first time through, and |
| 7853 | * not when we're rebuilding after a Reset |
| 7854 | */ |
| 7855 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7856 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7857 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7858 | if (err) { |
| 7859 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7860 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7861 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7862 | return -EFAULT; |
| 7863 | } |
| 7864 | } |
| 7865 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 7866 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7867 | |
| 7868 | /* associate no queues to the misc vector */ |
| 7869 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 7870 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 7871 | |
| 7872 | i40e_flush(hw); |
| 7873 | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 7874 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7875 | |
| 7876 | return err; |
| 7877 | } |
| 7878 | |
| 7879 | /** |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7880 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 7881 | * @vsi: vsi structure |
| 7882 | * @seed: RSS hash seed |
| 7883 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7884 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 7885 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7886 | { |
| 7887 | struct i40e_aqc_get_set_rss_key_data rss_key; |
| 7888 | struct i40e_pf *pf = vsi->back; |
| 7889 | struct i40e_hw *hw = &pf->hw; |
| 7890 | bool pf_lut = false; |
| 7891 | u8 *rss_lut; |
| 7892 | int ret, i; |
| 7893 | |
| 7894 | memset(&rss_key, 0, sizeof(rss_key)); |
| 7895 | memcpy(&rss_key, seed, sizeof(rss_key)); |
| 7896 | |
| 7897 | rss_lut = kzalloc(pf->rss_table_size, GFP_KERNEL); |
| 7898 | if (!rss_lut) |
| 7899 | return -ENOMEM; |
| 7900 | |
| 7901 | /* Populate the LUT with max no. of queues in round robin fashion */ |
| 7902 | for (i = 0; i < vsi->rss_table_size; i++) |
| 7903 | rss_lut[i] = i % vsi->rss_size; |
| 7904 | |
| 7905 | ret = i40e_aq_set_rss_key(hw, vsi->id, &rss_key); |
| 7906 | if (ret) { |
| 7907 | dev_info(&pf->pdev->dev, |
| 7908 | "Cannot set RSS key, err %s aq_err %s\n", |
| 7909 | i40e_stat_str(&pf->hw, ret), |
| 7910 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai | 126b63d | 2015-08-24 13:26:53 -0700 | [diff] [blame] | 7911 | goto config_rss_aq_out; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7912 | } |
| 7913 | |
| 7914 | if (vsi->type == I40E_VSI_MAIN) |
| 7915 | pf_lut = true; |
| 7916 | |
| 7917 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, rss_lut, |
| 7918 | vsi->rss_table_size); |
| 7919 | if (ret) |
| 7920 | dev_info(&pf->pdev->dev, |
| 7921 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 7922 | i40e_stat_str(&pf->hw, ret), |
| 7923 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 7924 | |
Anjali Singhai | 126b63d | 2015-08-24 13:26:53 -0700 | [diff] [blame] | 7925 | config_rss_aq_out: |
| 7926 | kfree(rss_lut); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7927 | return ret; |
| 7928 | } |
| 7929 | |
| 7930 | /** |
| 7931 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 7932 | * @vsi: VSI structure |
| 7933 | **/ |
| 7934 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 7935 | { |
| 7936 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 7937 | struct i40e_pf *pf = vsi->back; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7938 | u8 *lut; |
| 7939 | int ret; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7940 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7941 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) |
| 7942 | return 0; |
| 7943 | |
| 7944 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 7945 | if (!lut) |
| 7946 | return -ENOMEM; |
| 7947 | |
| 7948 | 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] | 7949 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 7950 | 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] | 7951 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 7952 | kfree(lut); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7953 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7954 | return ret; |
| 7955 | } |
| 7956 | |
| 7957 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 7958 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 7959 | * @vsi: Pointer to vsi structure |
| 7960 | * @seed: Buffter to store the hash keys |
| 7961 | * @lut: Buffer to store the lookup table entries |
| 7962 | * @lut_size: Size of buffer to store the lookup table entries |
| 7963 | * |
| 7964 | * Return 0 on success, negative on failure |
| 7965 | */ |
| 7966 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 7967 | u8 *lut, u16 lut_size) |
| 7968 | { |
| 7969 | struct i40e_pf *pf = vsi->back; |
| 7970 | struct i40e_hw *hw = &pf->hw; |
| 7971 | int ret = 0; |
| 7972 | |
| 7973 | if (seed) { |
| 7974 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 7975 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 7976 | if (ret) { |
| 7977 | dev_info(&pf->pdev->dev, |
| 7978 | "Cannot get RSS key, err %s aq_err %s\n", |
| 7979 | i40e_stat_str(&pf->hw, ret), |
| 7980 | i40e_aq_str(&pf->hw, |
| 7981 | pf->hw.aq.asq_last_status)); |
| 7982 | return ret; |
| 7983 | } |
| 7984 | } |
| 7985 | |
| 7986 | if (lut) { |
| 7987 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 7988 | |
| 7989 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 7990 | if (ret) { |
| 7991 | dev_info(&pf->pdev->dev, |
| 7992 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 7993 | i40e_stat_str(&pf->hw, ret), |
| 7994 | i40e_aq_str(&pf->hw, |
| 7995 | pf->hw.aq.asq_last_status)); |
| 7996 | return ret; |
| 7997 | } |
| 7998 | } |
| 7999 | |
| 8000 | return ret; |
| 8001 | } |
| 8002 | |
| 8003 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8004 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8005 | * @vsi: Pointer to vsi structure |
| 8006 | * @seed: RSS hash seed |
| 8007 | * @lut: Lookup table |
| 8008 | * @lut_size: Lookup table size |
| 8009 | * |
| 8010 | * Returns 0 on success, negative on failure |
| 8011 | **/ |
| 8012 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8013 | const u8 *lut, u16 lut_size) |
| 8014 | { |
| 8015 | struct i40e_pf *pf = vsi->back; |
| 8016 | struct i40e_hw *hw = &pf->hw; |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8017 | u16 vf_id = vsi->vf_id; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8018 | u8 i; |
| 8019 | |
| 8020 | /* Fill out hash function seed */ |
| 8021 | if (seed) { |
| 8022 | u32 *seed_dw = (u32 *)seed; |
| 8023 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8024 | if (vsi->type == I40E_VSI_MAIN) { |
| 8025 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 8026 | i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), |
| 8027 | seed_dw[i]); |
| 8028 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8029 | for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++) |
| 8030 | i40e_write_rx_ctl(hw, |
| 8031 | I40E_VFQF_HKEY1(i, vf_id), |
| 8032 | seed_dw[i]); |
| 8033 | } else { |
| 8034 | dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n"); |
| 8035 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8036 | } |
| 8037 | |
| 8038 | if (lut) { |
| 8039 | u32 *lut_dw = (u32 *)lut; |
| 8040 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8041 | if (vsi->type == I40E_VSI_MAIN) { |
| 8042 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8043 | return -EINVAL; |
| 8044 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8045 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8046 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8047 | if (lut_size != I40E_VF_HLUT_ARRAY_SIZE) |
| 8048 | return -EINVAL; |
| 8049 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8050 | i40e_write_rx_ctl(hw, |
| 8051 | I40E_VFQF_HLUT1(i, vf_id), |
| 8052 | lut_dw[i]); |
| 8053 | } else { |
| 8054 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8055 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8056 | } |
| 8057 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8058 | |
| 8059 | return 0; |
| 8060 | } |
| 8061 | |
| 8062 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8063 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8064 | * @vsi: Pointer to VSI structure |
| 8065 | * @seed: Buffer to store the keys |
| 8066 | * @lut: Buffer to store the lookup table entries |
| 8067 | * @lut_size: Size of buffer to store the lookup table entries |
| 8068 | * |
| 8069 | * Returns 0 on success, negative on failure |
| 8070 | */ |
| 8071 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8072 | u8 *lut, u16 lut_size) |
| 8073 | { |
| 8074 | struct i40e_pf *pf = vsi->back; |
| 8075 | struct i40e_hw *hw = &pf->hw; |
| 8076 | u16 i; |
| 8077 | |
| 8078 | if (seed) { |
| 8079 | u32 *seed_dw = (u32 *)seed; |
| 8080 | |
| 8081 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8082 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8083 | } |
| 8084 | if (lut) { |
| 8085 | u32 *lut_dw = (u32 *)lut; |
| 8086 | |
| 8087 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8088 | return -EINVAL; |
| 8089 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8090 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8091 | } |
| 8092 | |
| 8093 | return 0; |
| 8094 | } |
| 8095 | |
| 8096 | /** |
| 8097 | * i40e_config_rss - Configure RSS keys and lut |
| 8098 | * @vsi: Pointer to VSI structure |
| 8099 | * @seed: RSS hash seed |
| 8100 | * @lut: Lookup table |
| 8101 | * @lut_size: Lookup table size |
| 8102 | * |
| 8103 | * Returns 0 on success, negative on failure |
| 8104 | */ |
| 8105 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8106 | { |
| 8107 | struct i40e_pf *pf = vsi->back; |
| 8108 | |
| 8109 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8110 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8111 | else |
| 8112 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8113 | } |
| 8114 | |
| 8115 | /** |
| 8116 | * i40e_get_rss - Get RSS keys and lut |
| 8117 | * @vsi: Pointer to VSI structure |
| 8118 | * @seed: Buffer to store the keys |
| 8119 | * @lut: Buffer to store the lookup table entries |
| 8120 | * lut_size: Size of buffer to store the lookup table entries |
| 8121 | * |
| 8122 | * Returns 0 on success, negative on failure |
| 8123 | */ |
| 8124 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8125 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8126 | struct i40e_pf *pf = vsi->back; |
| 8127 | |
| 8128 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8129 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8130 | else |
| 8131 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8132 | } |
| 8133 | |
| 8134 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8135 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8136 | * @pf: Pointer to board private structure |
| 8137 | * @lut: Lookup table |
| 8138 | * @rss_table_size: Lookup table size |
| 8139 | * @rss_size: Range of queue number for hashing |
| 8140 | */ |
| 8141 | static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8142 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8143 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8144 | u16 i; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8145 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8146 | for (i = 0; i < rss_table_size; i++) |
| 8147 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8148 | } |
| 8149 | |
| 8150 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8151 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8152 | * @pf: board private structure |
| 8153 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8154 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8155 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8156 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8157 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8158 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8159 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8160 | u32 reg_val; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8161 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8162 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8163 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8164 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8165 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 8166 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8167 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8168 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8169 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8170 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8171 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8172 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8173 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8174 | reg_val = (pf->rss_table_size == 512) ? |
| 8175 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8176 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8177 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8178 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8179 | /* Determine the RSS size of the VSI */ |
| 8180 | if (!vsi->rss_size) |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8181 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8182 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8183 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8184 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8185 | if (!lut) |
| 8186 | return -ENOMEM; |
| 8187 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8188 | /* Use user configured lut if there is one, otherwise use default */ |
| 8189 | if (vsi->rss_lut_user) |
| 8190 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8191 | else |
| 8192 | 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] | 8193 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8194 | /* Use user configured hash key if there is one, otherwise |
| 8195 | * use default. |
| 8196 | */ |
| 8197 | if (vsi->rss_hkey_user) |
| 8198 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8199 | else |
| 8200 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8201 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8202 | kfree(lut); |
| 8203 | |
| 8204 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8205 | } |
| 8206 | |
| 8207 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8208 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8209 | * @pf: board private structure |
| 8210 | * @queue_count: the requested queue count for rss. |
| 8211 | * |
| 8212 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8213 | * count which may be different from the requested queue count. |
| 8214 | **/ |
| 8215 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8216 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8217 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8218 | int new_rss_size; |
| 8219 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8220 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8221 | return 0; |
| 8222 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8223 | 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] | 8224 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8225 | if (queue_count != vsi->num_queue_pairs) { |
| 8226 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8227 | i40e_prep_for_reset(pf); |
| 8228 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8229 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8230 | |
| 8231 | i40e_reset_and_rebuild(pf, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8232 | |
| 8233 | /* Discard the user configured hash keys and lut, if less |
| 8234 | * queues are enabled. |
| 8235 | */ |
| 8236 | if (queue_count < vsi->rss_size) { |
| 8237 | i40e_clear_rss_config_user(vsi); |
| 8238 | dev_dbg(&pf->pdev->dev, |
| 8239 | "discard user configured hash keys and lut\n"); |
| 8240 | } |
| 8241 | |
| 8242 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8243 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8244 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8245 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8246 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8247 | } |
Helin Zhang | e36b0b1 | 2015-10-26 19:44:36 -0400 | [diff] [blame] | 8248 | dev_info(&pf->pdev->dev, "RSS count/HW max RSS count: %d/%d\n", |
| 8249 | pf->alloc_rss_size, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8250 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8251 | } |
| 8252 | |
| 8253 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8254 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 8255 | * @pf: board private structure |
| 8256 | **/ |
| 8257 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 8258 | { |
| 8259 | i40e_status status; |
| 8260 | bool min_valid, max_valid; |
| 8261 | u32 max_bw, min_bw; |
| 8262 | |
| 8263 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8264 | &min_valid, &max_valid); |
| 8265 | |
| 8266 | if (!status) { |
| 8267 | if (min_valid) |
| 8268 | pf->npar_min_bw = min_bw; |
| 8269 | if (max_valid) |
| 8270 | pf->npar_max_bw = max_bw; |
| 8271 | } |
| 8272 | |
| 8273 | return status; |
| 8274 | } |
| 8275 | |
| 8276 | /** |
| 8277 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 8278 | * @pf: board private structure |
| 8279 | **/ |
| 8280 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 8281 | { |
| 8282 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8283 | i40e_status status; |
| 8284 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8285 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8286 | 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] | 8287 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8288 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 8289 | |
| 8290 | /* Set the new bandwidths */ |
| 8291 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8292 | |
| 8293 | return status; |
| 8294 | } |
| 8295 | |
| 8296 | /** |
| 8297 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 8298 | * @pf: board private structure |
| 8299 | **/ |
| 8300 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 8301 | { |
| 8302 | /* Commit temporary BW setting to permanent NVM image */ |
| 8303 | enum i40e_admin_queue_err last_aq_status; |
| 8304 | i40e_status ret; |
| 8305 | u16 nvm_word; |
| 8306 | |
| 8307 | if (pf->hw.partition_id != 1) { |
| 8308 | dev_info(&pf->pdev->dev, |
| 8309 | "Commit BW only works on partition 1! This is partition %d", |
| 8310 | pf->hw.partition_id); |
| 8311 | ret = I40E_NOT_SUPPORTED; |
| 8312 | goto bw_commit_out; |
| 8313 | } |
| 8314 | |
| 8315 | /* Acquire NVM for read access */ |
| 8316 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8317 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8318 | if (ret) { |
| 8319 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8320 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8321 | i40e_stat_str(&pf->hw, ret), |
| 8322 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8323 | goto bw_commit_out; |
| 8324 | } |
| 8325 | |
| 8326 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8327 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8328 | I40E_SR_NVM_CONTROL_WORD, |
| 8329 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8330 | false, NULL); |
| 8331 | /* Save off last admin queue command status before releasing |
| 8332 | * the NVM |
| 8333 | */ |
| 8334 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8335 | i40e_release_nvm(&pf->hw); |
| 8336 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8337 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8338 | i40e_stat_str(&pf->hw, ret), |
| 8339 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8340 | goto bw_commit_out; |
| 8341 | } |
| 8342 | |
| 8343 | /* Wait a bit for NVM release to complete */ |
| 8344 | msleep(50); |
| 8345 | |
| 8346 | /* Acquire NVM for write access */ |
| 8347 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8348 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8349 | if (ret) { |
| 8350 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8351 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8352 | i40e_stat_str(&pf->hw, ret), |
| 8353 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8354 | goto bw_commit_out; |
| 8355 | } |
| 8356 | /* Write it back out unchanged to initiate update NVM, |
| 8357 | * which will force a write of the shadow (alt) RAM to |
| 8358 | * the NVM - thus storing the bandwidth values permanently. |
| 8359 | */ |
| 8360 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8361 | I40E_SR_NVM_CONTROL_WORD, |
| 8362 | 0x10, sizeof(nvm_word), |
| 8363 | &nvm_word, true, NULL); |
| 8364 | /* Save off last admin queue command status before releasing |
| 8365 | * the NVM |
| 8366 | */ |
| 8367 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8368 | i40e_release_nvm(&pf->hw); |
| 8369 | if (ret) |
| 8370 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8371 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8372 | i40e_stat_str(&pf->hw, ret), |
| 8373 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8374 | bw_commit_out: |
| 8375 | |
| 8376 | return ret; |
| 8377 | } |
| 8378 | |
| 8379 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8380 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8381 | * @pf: board private structure to initialize |
| 8382 | * |
| 8383 | * i40e_sw_init initializes the Adapter private data structure. |
| 8384 | * Fields are initialized based on PCI device information and |
| 8385 | * OS network device settings (MTU size). |
| 8386 | **/ |
| 8387 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8388 | { |
| 8389 | int err = 0; |
| 8390 | int size; |
| 8391 | |
| 8392 | pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, |
| 8393 | (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); |
| 8394 | if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { |
| 8395 | if (I40E_DEBUG_USER & debug) |
| 8396 | pf->hw.debug_mask = debug; |
| 8397 | pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), |
| 8398 | I40E_DEFAULT_MSG_ENABLE); |
| 8399 | } |
| 8400 | |
| 8401 | /* Set default capability flags */ |
| 8402 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8403 | I40E_FLAG_MSI_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8404 | I40E_FLAG_MSIX_ENABLED; |
| 8405 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8406 | /* Set default ITR */ |
| 8407 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8408 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8409 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8410 | /* Depending on PF configurations, it is possible that the RSS |
| 8411 | * maximum might end up larger than the available queues |
| 8412 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8413 | 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] | 8414 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8415 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8416 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8417 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8418 | if (pf->hw.func_caps.rss) { |
| 8419 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8420 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8421 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8422 | } |
| 8423 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8424 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8425 | 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] | 8426 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8427 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8428 | if (i40e_get_npar_bw_setting(pf)) |
| 8429 | dev_warn(&pf->pdev->dev, |
| 8430 | "Could not get NPAR bw settings\n"); |
| 8431 | else |
| 8432 | dev_info(&pf->pdev->dev, |
| 8433 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 8434 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8435 | } |
| 8436 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8437 | /* FW/NVM is not yet fixed in this regard */ |
| 8438 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8439 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8440 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8441 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8442 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8443 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8444 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8445 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8446 | else |
| 8447 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8448 | pf->fdir_pf_filter_count = |
| 8449 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8450 | pf->hw.fdir_shared_filter_count = |
| 8451 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8452 | } |
| 8453 | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8454 | if (i40e_is_mac_710(&pf->hw) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8455 | (((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] | 8456 | (pf->hw.aq.fw_maj_ver < 4))) { |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8457 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8458 | /* No DCB support for FW < v4.33 */ |
| 8459 | pf->flags |= I40E_FLAG_NO_DCB_SUPPORT; |
| 8460 | } |
| 8461 | |
| 8462 | /* Disable FW LLDP if FW < v4.3 */ |
| 8463 | if (i40e_is_mac_710(&pf->hw) && |
| 8464 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 8465 | (pf->hw.aq.fw_maj_ver < 4))) |
| 8466 | pf->flags |= I40E_FLAG_STOP_FW_LLDP; |
| 8467 | |
| 8468 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
| 8469 | if (i40e_is_mac_710(&pf->hw) && |
| 8470 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 8471 | (pf->hw.aq.fw_maj_ver >= 5))) |
| 8472 | pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8473 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8474 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8475 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8476 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 8477 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8478 | } |
| 8479 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8480 | if (pf->hw.func_caps.iwarp) { |
| 8481 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 8482 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 8483 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 8484 | } |
| 8485 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8486 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 8487 | i40e_init_pf_fcoe(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8488 | |
| 8489 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8490 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f1 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 8491 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8492 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 8493 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 8494 | pf->num_req_vfs = min_t(int, |
| 8495 | pf->hw.func_caps.num_vfs, |
| 8496 | I40E_MAX_VF_COUNT); |
| 8497 | } |
| 8498 | #endif /* CONFIG_PCI_IOV */ |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8499 | if (pf->hw.mac.type == I40E_MAC_X722) { |
| 8500 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE | |
| 8501 | I40E_FLAG_128_QP_RSS_CAPABLE | |
| 8502 | I40E_FLAG_HW_ATR_EVICT_CAPABLE | |
| 8503 | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE | |
| 8504 | I40E_FLAG_WB_ON_ITR_CAPABLE | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8505 | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
Jesse Brandeburg | 8e2cc0e | 2016-02-29 11:00:24 -0800 | [diff] [blame] | 8506 | I40E_FLAG_NO_PCI_LINK_CHECK | |
Catherine Sullivan | f8db54cc | 2015-12-22 14:25:14 -0800 | [diff] [blame] | 8507 | I40E_FLAG_100M_SGMII_CAPABLE | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8508 | I40E_FLAG_USE_SET_LLDP_MIB | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8509 | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8510 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 8511 | ((pf->hw.aq.api_maj_ver == 1) && |
| 8512 | (pf->hw.aq.api_min_ver > 4))) { |
| 8513 | /* Supported in FW API version higher than 1.4 */ |
| 8514 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 8515 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
| 8516 | } else { |
| 8517 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8518 | } |
Anjali Singhai | a340c78 | 2016-01-06 11:49:28 -0800 | [diff] [blame] | 8519 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8520 | pf->eeprom_version = 0xDEAD; |
| 8521 | pf->lan_veb = I40E_NO_VEB; |
| 8522 | pf->lan_vsi = I40E_NO_VSI; |
| 8523 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 8524 | /* By default FW has this off for performance reasons */ |
| 8525 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 8526 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8527 | /* set up queue assignment tracking */ |
| 8528 | size = sizeof(struct i40e_lump_tracking) |
| 8529 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 8530 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 8531 | if (!pf->qp_pile) { |
| 8532 | err = -ENOMEM; |
| 8533 | goto sw_init_done; |
| 8534 | } |
| 8535 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 8536 | pf->qp_pile->search_hint = 0; |
| 8537 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 8538 | pf->tx_timeout_recovery_level = 1; |
| 8539 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8540 | mutex_init(&pf->switch_mutex); |
| 8541 | |
Greg Rose | c668a12 | 2015-02-26 16:10:39 +0000 | [diff] [blame] | 8542 | /* If NPAR is enabled nudge the Tx scheduler */ |
| 8543 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) |
| 8544 | i40e_set_npar_bw_setting(pf); |
| 8545 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8546 | sw_init_done: |
| 8547 | return err; |
| 8548 | } |
| 8549 | |
| 8550 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8551 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 8552 | * @pf: board private structure to initialize |
| 8553 | * @features: the feature set that the stack is suggesting |
| 8554 | * |
| 8555 | * returns a bool to indicate if reset needs to happen |
| 8556 | **/ |
| 8557 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 8558 | { |
| 8559 | bool need_reset = false; |
| 8560 | |
| 8561 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 8562 | * the state changed, we need to reset. |
| 8563 | */ |
| 8564 | if (features & NETIF_F_NTUPLE) { |
| 8565 | /* Enable filters and mark for reset */ |
| 8566 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 8567 | need_reset = true; |
| 8568 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
| 8569 | } else { |
| 8570 | /* turn off filters, mark for reset and clear SW filter list */ |
| 8571 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8572 | need_reset = true; |
| 8573 | i40e_fdir_filter_exit(pf); |
| 8574 | } |
| 8575 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8576 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 8577 | /* reset fd counters */ |
| 8578 | pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0; |
| 8579 | pf->fdir_pf_active_filters = 0; |
| 8580 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 8581 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 8582 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8583 | /* if ATR was auto disabled it can be re-enabled. */ |
| 8584 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 8585 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 8586 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8587 | } |
| 8588 | return need_reset; |
| 8589 | } |
| 8590 | |
| 8591 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8592 | * i40e_set_features - set the netdev feature flags |
| 8593 | * @netdev: ptr to the netdev being adjusted |
| 8594 | * @features: the feature set that the stack is suggesting |
| 8595 | **/ |
| 8596 | static int i40e_set_features(struct net_device *netdev, |
| 8597 | netdev_features_t features) |
| 8598 | { |
| 8599 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8600 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8601 | struct i40e_pf *pf = vsi->back; |
| 8602 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8603 | |
| 8604 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8605 | i40e_vlan_stripping_enable(vsi); |
| 8606 | else |
| 8607 | i40e_vlan_stripping_disable(vsi); |
| 8608 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8609 | need_reset = i40e_set_ntuple(pf, features); |
| 8610 | |
| 8611 | if (need_reset) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8612 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8613 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8614 | return 0; |
| 8615 | } |
| 8616 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8617 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8618 | * 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] | 8619 | * @pf: board private structure |
| 8620 | * @port: The UDP port to look up |
| 8621 | * |
| 8622 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 8623 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8624 | 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] | 8625 | { |
| 8626 | u8 i; |
| 8627 | |
| 8628 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8629 | if (pf->udp_ports[i].index == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8630 | return i; |
| 8631 | } |
| 8632 | |
| 8633 | return i; |
| 8634 | } |
| 8635 | |
| 8636 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8637 | * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8638 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8639 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8640 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8641 | static void i40e_udp_tunnel_add(struct net_device *netdev, |
| 8642 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8643 | { |
| 8644 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8645 | struct i40e_vsi *vsi = np->vsi; |
| 8646 | struct i40e_pf *pf = vsi->back; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8647 | __be16 port = ti->port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8648 | u8 next_idx; |
| 8649 | u8 idx; |
| 8650 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8651 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8652 | |
| 8653 | /* Check if port already exists */ |
| 8654 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8655 | netdev_info(netdev, "port %d already offloaded\n", |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8656 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8657 | return; |
| 8658 | } |
| 8659 | |
| 8660 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8661 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8662 | |
| 8663 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8664 | netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n", |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8665 | ntohs(port)); |
| 8666 | return; |
| 8667 | } |
| 8668 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8669 | switch (ti->type) { |
| 8670 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8671 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 8672 | break; |
| 8673 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8674 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8675 | return; |
| 8676 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 8677 | break; |
| 8678 | default: |
| 8679 | return; |
| 8680 | } |
| 8681 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8682 | /* New port: add it and mark its index in the bitmap */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8683 | pf->udp_ports[next_idx].index = port; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8684 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8685 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8686 | } |
| 8687 | |
| 8688 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8689 | * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8690 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8691 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8692 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8693 | static void i40e_udp_tunnel_del(struct net_device *netdev, |
| 8694 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8695 | { |
| 8696 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8697 | struct i40e_vsi *vsi = np->vsi; |
| 8698 | struct i40e_pf *pf = vsi->back; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8699 | __be16 port = ti->port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8700 | u8 idx; |
| 8701 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8702 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8703 | |
| 8704 | /* Check if port already exists */ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8705 | if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS) |
| 8706 | goto not_found; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8707 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8708 | switch (ti->type) { |
| 8709 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8710 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN) |
| 8711 | goto not_found; |
| 8712 | break; |
| 8713 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8714 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE) |
| 8715 | goto not_found; |
| 8716 | break; |
| 8717 | default: |
| 8718 | goto not_found; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8719 | } |
| 8720 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8721 | /* if port exists, set it to 0 (mark for deletion) |
| 8722 | * and make it pending |
| 8723 | */ |
| 8724 | pf->udp_ports[idx].index = 0; |
| 8725 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8726 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8727 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8728 | return; |
| 8729 | not_found: |
| 8730 | netdev_warn(netdev, "UDP port %d was not found, not deleting\n", |
| 8731 | ntohs(port)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8732 | } |
| 8733 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8734 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 8735 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8736 | { |
| 8737 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8738 | struct i40e_pf *pf = np->vsi->back; |
| 8739 | struct i40e_hw *hw = &pf->hw; |
| 8740 | |
| 8741 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 8742 | return -EOPNOTSUPP; |
| 8743 | |
| 8744 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 8745 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 8746 | |
| 8747 | return 0; |
| 8748 | } |
| 8749 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 8750 | /** |
| 8751 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 8752 | * @ndm: the input from the stack |
| 8753 | * @tb: pointer to array of nladdr (unused) |
| 8754 | * @dev: the net device pointer |
| 8755 | * @addr: the MAC address entry being added |
| 8756 | * @flags: instructions from stack about fdb operation |
| 8757 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8758 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 8759 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8760 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8761 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8762 | { |
| 8763 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8764 | struct i40e_pf *pf = np->vsi->back; |
| 8765 | int err = 0; |
| 8766 | |
| 8767 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 8768 | return -EOPNOTSUPP; |
| 8769 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 8770 | if (vid) { |
| 8771 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 8772 | return -EINVAL; |
| 8773 | } |
| 8774 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8775 | /* Hardware does not support aging addresses so if a |
| 8776 | * ndm_state is given only allow permanent addresses |
| 8777 | */ |
| 8778 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 8779 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 8780 | return -EINVAL; |
| 8781 | } |
| 8782 | |
| 8783 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 8784 | err = dev_uc_add_excl(dev, addr); |
| 8785 | else if (is_multicast_ether_addr(addr)) |
| 8786 | err = dev_mc_add_excl(dev, addr); |
| 8787 | else |
| 8788 | err = -EINVAL; |
| 8789 | |
| 8790 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 8791 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 8792 | err = 0; |
| 8793 | |
| 8794 | return err; |
| 8795 | } |
| 8796 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8797 | /** |
| 8798 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 8799 | * @dev: the netdev being configured |
| 8800 | * @nlh: RTNL message |
| 8801 | * |
| 8802 | * Inserts a new hardware bridge if not already created and |
| 8803 | * enables the bridging mode requested (VEB or VEPA). If the |
| 8804 | * hardware bridge has already been inserted and the request |
| 8805 | * is to change the mode then that requires a PF reset to |
| 8806 | * allow rebuild of the components with required hardware |
| 8807 | * bridge mode enabled. |
| 8808 | **/ |
| 8809 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 8810 | struct nlmsghdr *nlh, |
| 8811 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8812 | { |
| 8813 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8814 | struct i40e_vsi *vsi = np->vsi; |
| 8815 | struct i40e_pf *pf = vsi->back; |
| 8816 | struct i40e_veb *veb = NULL; |
| 8817 | struct nlattr *attr, *br_spec; |
| 8818 | int i, rem; |
| 8819 | |
| 8820 | /* Only for PF VSI for now */ |
| 8821 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8822 | return -EOPNOTSUPP; |
| 8823 | |
| 8824 | /* Find the HW bridge for PF VSI */ |
| 8825 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8826 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8827 | veb = pf->veb[i]; |
| 8828 | } |
| 8829 | |
| 8830 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 8831 | |
| 8832 | nla_for_each_nested(attr, br_spec, rem) { |
| 8833 | __u16 mode; |
| 8834 | |
| 8835 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 8836 | continue; |
| 8837 | |
| 8838 | mode = nla_get_u16(attr); |
| 8839 | if ((mode != BRIDGE_MODE_VEPA) && |
| 8840 | (mode != BRIDGE_MODE_VEB)) |
| 8841 | return -EINVAL; |
| 8842 | |
| 8843 | /* Insert a new HW bridge */ |
| 8844 | if (!veb) { |
| 8845 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 8846 | vsi->tc_config.enabled_tc); |
| 8847 | if (veb) { |
| 8848 | veb->bridge_mode = mode; |
| 8849 | i40e_config_bridge_mode(veb); |
| 8850 | } else { |
| 8851 | /* No Bridge HW offload available */ |
| 8852 | return -ENOENT; |
| 8853 | } |
| 8854 | break; |
| 8855 | } else if (mode != veb->bridge_mode) { |
| 8856 | /* Existing HW bridge but different mode needs reset */ |
| 8857 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 8858 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 8859 | if (mode == BRIDGE_MODE_VEB) |
| 8860 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 8861 | else |
| 8862 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 8863 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8864 | break; |
| 8865 | } |
| 8866 | } |
| 8867 | |
| 8868 | return 0; |
| 8869 | } |
| 8870 | |
| 8871 | /** |
| 8872 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 8873 | * @skb: skb buff |
| 8874 | * @pid: process id |
| 8875 | * @seq: RTNL message seq # |
| 8876 | * @dev: the netdev being configured |
| 8877 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 8878 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8879 | * |
| 8880 | * Return the mode in which the hardware bridge is operating in |
| 8881 | * i.e VEB or VEPA. |
| 8882 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8883 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 8884 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 8885 | u32 __always_unused filter_mask, |
| 8886 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8887 | { |
| 8888 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8889 | struct i40e_vsi *vsi = np->vsi; |
| 8890 | struct i40e_pf *pf = vsi->back; |
| 8891 | struct i40e_veb *veb = NULL; |
| 8892 | int i; |
| 8893 | |
| 8894 | /* Only for PF VSI for now */ |
| 8895 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8896 | return -EOPNOTSUPP; |
| 8897 | |
| 8898 | /* Find the HW bridge for the PF VSI */ |
| 8899 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8900 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8901 | veb = pf->veb[i]; |
| 8902 | } |
| 8903 | |
| 8904 | if (!veb) |
| 8905 | return 0; |
| 8906 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 8907 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 8908 | nlflags, 0, 0, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8909 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8910 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8911 | /* Hardware supports L4 tunnel length of 128B (=2^7) which includes |
| 8912 | * inner mac plus all inner ethertypes. |
| 8913 | */ |
| 8914 | #define I40E_MAX_TUNNEL_HDR_LEN 128 |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8915 | /** |
| 8916 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 8917 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 8918 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8919 | * @features: Offload features that the stack believes apply |
| 8920 | **/ |
| 8921 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 8922 | struct net_device *dev, |
| 8923 | netdev_features_t features) |
| 8924 | { |
| 8925 | if (skb->encapsulation && |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8926 | ((skb_inner_network_header(skb) - skb_transport_header(skb)) > |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8927 | I40E_MAX_TUNNEL_HDR_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 8928 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8929 | |
| 8930 | return features; |
| 8931 | } |
| 8932 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 8933 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8934 | .ndo_open = i40e_open, |
| 8935 | .ndo_stop = i40e_close, |
| 8936 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 8937 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 8938 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 8939 | .ndo_validate_addr = eth_validate_addr, |
| 8940 | .ndo_set_mac_address = i40e_set_mac, |
| 8941 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 8942 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8943 | .ndo_tx_timeout = i40e_tx_timeout, |
| 8944 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 8945 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 8946 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8947 | .ndo_poll_controller = i40e_netpoll, |
| 8948 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8949 | .ndo_setup_tc = __i40e_setup_tc, |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8950 | #ifdef I40E_FCOE |
| 8951 | .ndo_fcoe_enable = i40e_fcoe_enable, |
| 8952 | .ndo_fcoe_disable = i40e_fcoe_disable, |
| 8953 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8954 | .ndo_set_features = i40e_set_features, |
| 8955 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 8956 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 8957 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8958 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 8959 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 8960 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Anjali Singhai Jain | c3bbbd2 | 2016-04-01 03:56:07 -0700 | [diff] [blame] | 8961 | .ndo_set_vf_trust = i40e_ndo_set_vf_trust, |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8962 | .ndo_udp_tunnel_add = i40e_udp_tunnel_add, |
| 8963 | .ndo_udp_tunnel_del = i40e_udp_tunnel_del, |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8964 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8965 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8966 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8967 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 8968 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8969 | }; |
| 8970 | |
| 8971 | /** |
| 8972 | * i40e_config_netdev - Setup the netdev flags |
| 8973 | * @vsi: the VSI being configured |
| 8974 | * |
| 8975 | * Returns 0 on success, negative value on failure |
| 8976 | **/ |
| 8977 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 8978 | { |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 8979 | u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8980 | struct i40e_pf *pf = vsi->back; |
| 8981 | struct i40e_hw *hw = &pf->hw; |
| 8982 | struct i40e_netdev_priv *np; |
| 8983 | struct net_device *netdev; |
| 8984 | u8 mac_addr[ETH_ALEN]; |
| 8985 | int etherdev_size; |
| 8986 | |
| 8987 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8988 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8989 | if (!netdev) |
| 8990 | return -ENOMEM; |
| 8991 | |
| 8992 | vsi->netdev = netdev; |
| 8993 | np = netdev_priv(netdev); |
| 8994 | np->vsi = vsi; |
| 8995 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 8996 | netdev->hw_enc_features |= NETIF_F_SG | |
| 8997 | NETIF_F_IP_CSUM | |
| 8998 | NETIF_F_IPV6_CSUM | |
| 8999 | NETIF_F_HIGHDMA | |
| 9000 | NETIF_F_SOFT_FEATURES | |
| 9001 | NETIF_F_TSO | |
| 9002 | NETIF_F_TSO_ECN | |
| 9003 | NETIF_F_TSO6 | |
| 9004 | NETIF_F_GSO_GRE | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9005 | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 9006 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 9007 | NETIF_F_GSO_IPXIP6 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9008 | NETIF_F_GSO_UDP_TUNNEL | |
| 9009 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9010 | NETIF_F_GSO_PARTIAL | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9011 | NETIF_F_SCTP_CRC | |
| 9012 | NETIF_F_RXHASH | |
| 9013 | NETIF_F_RXCSUM | |
Jesse Brandeburg | 5afdaaa | 2015-12-10 11:38:50 -0800 | [diff] [blame] | 9014 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9015 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9016 | if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)) |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9017 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
| 9018 | |
| 9019 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9020 | |
| 9021 | /* record features VLANs can make use of */ |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9022 | netdev->vlan_features |= netdev->hw_enc_features | |
| 9023 | NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9024 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9025 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9026 | netdev->hw_features |= NETIF_F_NTUPLE; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9027 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9028 | netdev->hw_features |= netdev->hw_enc_features | |
| 9029 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9030 | NETIF_F_HW_VLAN_CTAG_RX; |
| 9031 | |
| 9032 | netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9033 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9034 | |
| 9035 | if (vsi->type == I40E_VSI_MAIN) { |
| 9036 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9037 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9038 | /* The following steps are necessary to prevent reception |
| 9039 | * of tagged packets - some older NVM configurations load a |
| 9040 | * default a MAC-VLAN filter that accepts any tagged packet |
| 9041 | * which must be replaced by a normal filter. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 9042 | */ |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9043 | if (!i40e_rm_default_mac_filter(vsi, mac_addr)) { |
| 9044 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9045 | i40e_add_filter(vsi, mac_addr, |
| 9046 | I40E_VLAN_ANY, false, true); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9047 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9048 | } |
Anjali Singhai Jain | 3845cce | 2016-03-18 12:18:05 -0700 | [diff] [blame] | 9049 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
| 9050 | ((pf->hw.aq.api_maj_ver == 1) && |
| 9051 | (pf->hw.aq.api_min_ver > 4))) { |
| 9052 | /* Supported in FW API version higher than 1.4 */ |
| 9053 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
| 9054 | pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9055 | } else { |
| 9056 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 9057 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 9058 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9059 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9060 | |
| 9061 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9062 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9063 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9064 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9065 | |
| 9066 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 9067 | i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9068 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9069 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9070 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9071 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9072 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9073 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9074 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9075 | /* Setup netdev TC information */ |
| 9076 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9077 | |
| 9078 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9079 | netdev->watchdog_timeo = 5 * HZ; |
| 9080 | i40e_set_ethtool_ops(netdev); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9081 | #ifdef I40E_FCOE |
| 9082 | i40e_fcoe_config_netdev(netdev, vsi); |
| 9083 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9084 | |
| 9085 | return 0; |
| 9086 | } |
| 9087 | |
| 9088 | /** |
| 9089 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9090 | * @vsi: the VSI being removed |
| 9091 | * |
| 9092 | * Returns 0 on success, negative value on failure |
| 9093 | **/ |
| 9094 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9095 | { |
| 9096 | /* remove default VSI is not allowed */ |
| 9097 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9098 | return; |
| 9099 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9100 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9101 | } |
| 9102 | |
| 9103 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9104 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9105 | * @vsi: the VSI being queried |
| 9106 | * |
| 9107 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9108 | **/ |
| 9109 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9110 | { |
| 9111 | struct i40e_veb *veb; |
| 9112 | struct i40e_pf *pf = vsi->back; |
| 9113 | |
| 9114 | /* Uplink is not a bridge so default to VEB */ |
| 9115 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9116 | return 1; |
| 9117 | |
| 9118 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9119 | if (!veb) { |
| 9120 | dev_info(&pf->pdev->dev, |
| 9121 | "There is no veb associated with the bridge\n"); |
| 9122 | return -ENOENT; |
| 9123 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9124 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9125 | /* Uplink is a bridge in VEPA mode */ |
| 9126 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9127 | return 0; |
| 9128 | } else { |
| 9129 | /* Uplink is a bridge in VEB mode */ |
| 9130 | return 1; |
| 9131 | } |
| 9132 | |
| 9133 | /* VEPA is now default bridge, so return 0 */ |
| 9134 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9135 | } |
| 9136 | |
| 9137 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9138 | * i40e_add_vsi - Add a VSI to the switch |
| 9139 | * @vsi: the VSI being configured |
| 9140 | * |
| 9141 | * This initializes a VSI context depending on the VSI type to be added and |
| 9142 | * passes it down to the add_vsi aq command. |
| 9143 | **/ |
| 9144 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9145 | { |
| 9146 | int ret = -ENODEV; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9147 | u8 laa_macaddr[ETH_ALEN]; |
| 9148 | bool found_laa_mac_filter = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9149 | struct i40e_pf *pf = vsi->back; |
| 9150 | struct i40e_hw *hw = &pf->hw; |
| 9151 | struct i40e_vsi_context ctxt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9152 | struct i40e_mac_filter *f, *ftmp; |
| 9153 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9154 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9155 | int f_count = 0; |
| 9156 | |
| 9157 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9158 | switch (vsi->type) { |
| 9159 | case I40E_VSI_MAIN: |
| 9160 | /* The PF's main VSI is already setup as part of the |
| 9161 | * device initialization, so we'll not bother with |
| 9162 | * the add_vsi call, but we will retrieve the current |
| 9163 | * VSI context. |
| 9164 | */ |
| 9165 | ctxt.seid = pf->main_vsi_seid; |
| 9166 | ctxt.pf_num = pf->hw.pf_id; |
| 9167 | ctxt.vf_num = 0; |
| 9168 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9169 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9170 | if (ret) { |
| 9171 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9172 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9173 | i40e_stat_str(&pf->hw, ret), |
| 9174 | i40e_aq_str(&pf->hw, |
| 9175 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9176 | return -ENOENT; |
| 9177 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9178 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9179 | vsi->info.valid_sections = 0; |
| 9180 | |
| 9181 | vsi->seid = ctxt.seid; |
| 9182 | vsi->id = ctxt.vsi_number; |
| 9183 | |
| 9184 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9185 | |
| 9186 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9187 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9188 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9189 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9190 | ctxt.seid = pf->main_vsi_seid; |
| 9191 | ctxt.pf_num = pf->hw.pf_id; |
| 9192 | ctxt.vf_num = 0; |
| 9193 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9194 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9195 | if (ret) { |
| 9196 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9197 | "update vsi failed, err %s aq_err %s\n", |
| 9198 | i40e_stat_str(&pf->hw, ret), |
| 9199 | i40e_aq_str(&pf->hw, |
| 9200 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9201 | ret = -ENOENT; |
| 9202 | goto err; |
| 9203 | } |
| 9204 | /* update the local VSI info queue map */ |
| 9205 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9206 | vsi->info.valid_sections = 0; |
| 9207 | } else { |
| 9208 | /* Default/Main VSI is only enabled for TC0 |
| 9209 | * reconfigure it to enable all TCs that are |
| 9210 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9211 | * For MFP case the iSCSI PF would use this |
| 9212 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9213 | */ |
| 9214 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9215 | if (ret) { |
| 9216 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9217 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9218 | enabled_tc, |
| 9219 | i40e_stat_str(&pf->hw, ret), |
| 9220 | i40e_aq_str(&pf->hw, |
| 9221 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9222 | ret = -ENOENT; |
| 9223 | } |
| 9224 | } |
| 9225 | break; |
| 9226 | |
| 9227 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9228 | ctxt.pf_num = hw->pf_id; |
| 9229 | ctxt.vf_num = 0; |
| 9230 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9231 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9232 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9233 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9234 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9235 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9236 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9237 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9238 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9239 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9240 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9241 | break; |
| 9242 | |
| 9243 | case I40E_VSI_VMDQ2: |
| 9244 | ctxt.pf_num = hw->pf_id; |
| 9245 | ctxt.vf_num = 0; |
| 9246 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9247 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9248 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9249 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9250 | /* This VSI is connected to VEB so the switch_id |
| 9251 | * should be set to zero by default. |
| 9252 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9253 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9254 | ctxt.info.valid_sections |= |
| 9255 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9256 | ctxt.info.switch_id = |
| 9257 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9258 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9259 | |
| 9260 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9261 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9262 | break; |
| 9263 | |
| 9264 | case I40E_VSI_SRIOV: |
| 9265 | ctxt.pf_num = hw->pf_id; |
| 9266 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9267 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9268 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9269 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9270 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9271 | /* This VSI is connected to VEB so the switch_id |
| 9272 | * should be set to zero by default. |
| 9273 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9274 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9275 | ctxt.info.valid_sections |= |
| 9276 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9277 | ctxt.info.switch_id = |
| 9278 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9279 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9280 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9281 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9282 | ctxt.info.valid_sections |= |
| 9283 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 9284 | ctxt.info.queueing_opt_flags |= |
Ashish Shah | 4b28cdb | 2016-05-03 15:13:17 -0700 | [diff] [blame] | 9285 | (I40E_AQ_VSI_QUE_OPT_TCP_ENA | |
| 9286 | I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9287 | } |
| 9288 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9289 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9290 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9291 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9292 | ctxt.info.valid_sections |= |
| 9293 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9294 | ctxt.info.sec_flags |= |
| 9295 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9296 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9297 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9298 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9299 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9300 | break; |
| 9301 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9302 | #ifdef I40E_FCOE |
| 9303 | case I40E_VSI_FCOE: |
| 9304 | ret = i40e_fcoe_vsi_init(vsi, &ctxt); |
| 9305 | if (ret) { |
| 9306 | dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n"); |
| 9307 | return ret; |
| 9308 | } |
| 9309 | break; |
| 9310 | |
| 9311 | #endif /* I40E_FCOE */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9312 | case I40E_VSI_IWARP: |
| 9313 | /* send down message to iWARP */ |
| 9314 | break; |
| 9315 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9316 | default: |
| 9317 | return -ENODEV; |
| 9318 | } |
| 9319 | |
| 9320 | if (vsi->type != I40E_VSI_MAIN) { |
| 9321 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9322 | if (ret) { |
| 9323 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9324 | "add vsi failed, err %s aq_err %s\n", |
| 9325 | i40e_stat_str(&pf->hw, ret), |
| 9326 | i40e_aq_str(&pf->hw, |
| 9327 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9328 | ret = -ENOENT; |
| 9329 | goto err; |
| 9330 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9331 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9332 | vsi->info.valid_sections = 0; |
| 9333 | vsi->seid = ctxt.seid; |
| 9334 | vsi->id = ctxt.vsi_number; |
| 9335 | } |
| 9336 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9337 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9338 | /* If macvlan filters already exist, force them to get loaded */ |
| 9339 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 9340 | f->changed = true; |
| 9341 | f_count++; |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9342 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9343 | /* Expected to have only one MAC filter entry for LAA in list */ |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9344 | if (f->is_laa && vsi->type == I40E_VSI_MAIN) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9345 | ether_addr_copy(laa_macaddr, f->macaddr); |
| 9346 | found_laa_mac_filter = true; |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9347 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9348 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9349 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9350 | |
| 9351 | if (found_laa_mac_filter) { |
| 9352 | struct i40e_aqc_remove_macvlan_element_data element; |
| 9353 | |
| 9354 | memset(&element, 0, sizeof(element)); |
| 9355 | ether_addr_copy(element.mac_addr, laa_macaddr); |
| 9356 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 9357 | ret = i40e_aq_remove_macvlan(hw, vsi->seid, |
| 9358 | &element, 1, NULL); |
| 9359 | if (ret) { |
| 9360 | /* some older FW has a different default */ |
| 9361 | element.flags |= |
| 9362 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
| 9363 | i40e_aq_remove_macvlan(hw, vsi->seid, |
| 9364 | &element, 1, NULL); |
| 9365 | } |
| 9366 | |
| 9367 | i40e_aq_mac_address_write(hw, |
| 9368 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 9369 | laa_macaddr, NULL); |
| 9370 | } |
| 9371 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9372 | if (f_count) { |
| 9373 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 9374 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 9375 | } |
| 9376 | |
| 9377 | /* Update VSI BW information */ |
| 9378 | ret = i40e_vsi_get_bw_info(vsi); |
| 9379 | if (ret) { |
| 9380 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9381 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 9382 | i40e_stat_str(&pf->hw, ret), |
| 9383 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9384 | /* VSI is already added so not tearing that up */ |
| 9385 | ret = 0; |
| 9386 | } |
| 9387 | |
| 9388 | err: |
| 9389 | return ret; |
| 9390 | } |
| 9391 | |
| 9392 | /** |
| 9393 | * i40e_vsi_release - Delete a VSI and free its resources |
| 9394 | * @vsi: the VSI being removed |
| 9395 | * |
| 9396 | * Returns 0 on success or < 0 on error |
| 9397 | **/ |
| 9398 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 9399 | { |
| 9400 | struct i40e_mac_filter *f, *ftmp; |
| 9401 | struct i40e_veb *veb = NULL; |
| 9402 | struct i40e_pf *pf; |
| 9403 | u16 uplink_seid; |
| 9404 | int i, n; |
| 9405 | |
| 9406 | pf = vsi->back; |
| 9407 | |
| 9408 | /* release of a VEB-owner or last VSI is not allowed */ |
| 9409 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 9410 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 9411 | vsi->seid, vsi->uplink_seid); |
| 9412 | return -ENODEV; |
| 9413 | } |
| 9414 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 9415 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 9416 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 9417 | return -ENODEV; |
| 9418 | } |
| 9419 | |
| 9420 | uplink_seid = vsi->uplink_seid; |
| 9421 | if (vsi->type != I40E_VSI_SRIOV) { |
| 9422 | if (vsi->netdev_registered) { |
| 9423 | vsi->netdev_registered = false; |
| 9424 | if (vsi->netdev) { |
| 9425 | /* results in a call to i40e_close() */ |
| 9426 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9427 | } |
| 9428 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 9429 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9430 | } |
| 9431 | i40e_vsi_disable_irq(vsi); |
| 9432 | } |
| 9433 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9434 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9435 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
| 9436 | i40e_del_filter(vsi, f->macaddr, f->vlan, |
| 9437 | f->is_vf, f->is_netdev); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9438 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9439 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 9440 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9441 | |
| 9442 | i40e_vsi_delete(vsi); |
| 9443 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 9444 | if (vsi->netdev) { |
| 9445 | free_netdev(vsi->netdev); |
| 9446 | vsi->netdev = NULL; |
| 9447 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9448 | i40e_vsi_clear_rings(vsi); |
| 9449 | i40e_vsi_clear(vsi); |
| 9450 | |
| 9451 | /* If this was the last thing on the VEB, except for the |
| 9452 | * controlling VSI, remove the VEB, which puts the controlling |
| 9453 | * VSI onto the next level down in the switch. |
| 9454 | * |
| 9455 | * Well, okay, there's one more exception here: don't remove |
| 9456 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 9457 | * from up the network stack. |
| 9458 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9459 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9460 | if (pf->vsi[i] && |
| 9461 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 9462 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9463 | n++; /* count the VSIs */ |
| 9464 | } |
| 9465 | } |
| 9466 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9467 | if (!pf->veb[i]) |
| 9468 | continue; |
| 9469 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 9470 | n++; /* count the VEBs */ |
| 9471 | if (pf->veb[i]->seid == uplink_seid) |
| 9472 | veb = pf->veb[i]; |
| 9473 | } |
| 9474 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 9475 | i40e_veb_release(veb); |
| 9476 | |
| 9477 | return 0; |
| 9478 | } |
| 9479 | |
| 9480 | /** |
| 9481 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 9482 | * @vsi: ptr to the VSI |
| 9483 | * |
| 9484 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 9485 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 9486 | * newly allocated VSI. |
| 9487 | * |
| 9488 | * Returns 0 on success or negative on failure |
| 9489 | **/ |
| 9490 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 9491 | { |
| 9492 | int ret = -ENOENT; |
| 9493 | struct i40e_pf *pf = vsi->back; |
| 9494 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9495 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9496 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 9497 | vsi->seid); |
| 9498 | return -EEXIST; |
| 9499 | } |
| 9500 | |
| 9501 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 9502 | 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] | 9503 | vsi->seid, vsi->base_vector); |
| 9504 | return -EEXIST; |
| 9505 | } |
| 9506 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9507 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9508 | if (ret) { |
| 9509 | dev_info(&pf->pdev->dev, |
| 9510 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 9511 | vsi->num_q_vectors, vsi->seid, ret); |
| 9512 | vsi->num_q_vectors = 0; |
| 9513 | goto vector_setup_out; |
| 9514 | } |
| 9515 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 9516 | /* In Legacy mode, we do not have to get any other vector since we |
| 9517 | * piggyback on the misc/ICR0 for queue interrupts. |
| 9518 | */ |
| 9519 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9520 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9521 | if (vsi->num_q_vectors) |
| 9522 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 9523 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9524 | if (vsi->base_vector < 0) { |
| 9525 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9526 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 9527 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9528 | i40e_vsi_free_q_vectors(vsi); |
| 9529 | ret = -ENOENT; |
| 9530 | goto vector_setup_out; |
| 9531 | } |
| 9532 | |
| 9533 | vector_setup_out: |
| 9534 | return ret; |
| 9535 | } |
| 9536 | |
| 9537 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9538 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 9539 | * @vsi: pointer to the vsi. |
| 9540 | * |
| 9541 | * This re-allocates a vsi's queue resources. |
| 9542 | * |
| 9543 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 9544 | * on success, otherwise returns NULL on failure. |
| 9545 | **/ |
| 9546 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 9547 | { |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9548 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9549 | u8 enabled_tc; |
| 9550 | int ret; |
| 9551 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9552 | if (!vsi) |
| 9553 | return NULL; |
| 9554 | |
| 9555 | pf = vsi->back; |
| 9556 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9557 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9558 | i40e_vsi_clear_rings(vsi); |
| 9559 | |
| 9560 | i40e_vsi_free_arrays(vsi, false); |
| 9561 | i40e_set_num_rings_in_vsi(vsi); |
| 9562 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 9563 | if (ret) |
| 9564 | goto err_vsi; |
| 9565 | |
| 9566 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 9567 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9568 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9569 | "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] | 9570 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9571 | goto err_vsi; |
| 9572 | } |
| 9573 | vsi->base_queue = ret; |
| 9574 | |
| 9575 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 9576 | * layout configurations. |
| 9577 | */ |
| 9578 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9579 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9580 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9581 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 9582 | |
| 9583 | /* assign it some queues */ |
| 9584 | ret = i40e_alloc_rings(vsi); |
| 9585 | if (ret) |
| 9586 | goto err_rings; |
| 9587 | |
| 9588 | /* map all of the rings to the q_vectors */ |
| 9589 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9590 | return vsi; |
| 9591 | |
| 9592 | err_rings: |
| 9593 | i40e_vsi_free_q_vectors(vsi); |
| 9594 | if (vsi->netdev_registered) { |
| 9595 | vsi->netdev_registered = false; |
| 9596 | unregister_netdev(vsi->netdev); |
| 9597 | free_netdev(vsi->netdev); |
| 9598 | vsi->netdev = NULL; |
| 9599 | } |
| 9600 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9601 | err_vsi: |
| 9602 | i40e_vsi_clear(vsi); |
| 9603 | return NULL; |
| 9604 | } |
| 9605 | |
| 9606 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9607 | * i40e_macaddr_init - explicitly write the mac address filters. |
| 9608 | * |
| 9609 | * @vsi: pointer to the vsi. |
| 9610 | * @macaddr: the MAC address |
| 9611 | * |
| 9612 | * This is needed when the macaddr has been obtained by other |
| 9613 | * means than the default, e.g., from Open Firmware or IDPROM. |
| 9614 | * Returns 0 on success, negative on failure |
| 9615 | **/ |
| 9616 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) |
| 9617 | { |
| 9618 | int ret; |
| 9619 | struct i40e_aqc_add_macvlan_element_data element; |
| 9620 | |
| 9621 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 9622 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 9623 | macaddr, NULL); |
| 9624 | if (ret) { |
| 9625 | dev_info(&vsi->back->pdev->dev, |
| 9626 | "Addr change for VSI failed: %d\n", ret); |
| 9627 | return -EADDRNOTAVAIL; |
| 9628 | } |
| 9629 | |
| 9630 | memset(&element, 0, sizeof(element)); |
| 9631 | ether_addr_copy(element.mac_addr, macaddr); |
| 9632 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 9633 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); |
| 9634 | if (ret) { |
| 9635 | dev_info(&vsi->back->pdev->dev, |
| 9636 | "add filter failed err %s aq_err %s\n", |
| 9637 | i40e_stat_str(&vsi->back->hw, ret), |
| 9638 | i40e_aq_str(&vsi->back->hw, |
| 9639 | vsi->back->hw.aq.asq_last_status)); |
| 9640 | } |
| 9641 | return ret; |
| 9642 | } |
| 9643 | |
| 9644 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9645 | * i40e_vsi_setup - Set up a VSI by a given type |
| 9646 | * @pf: board private structure |
| 9647 | * @type: VSI type |
| 9648 | * @uplink_seid: the switch element to link to |
| 9649 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 9650 | * |
| 9651 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 9652 | * to the identified VEB. |
| 9653 | * |
| 9654 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 9655 | * success, otherwise returns NULL on failure. |
| 9656 | **/ |
| 9657 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 9658 | u16 uplink_seid, u32 param1) |
| 9659 | { |
| 9660 | struct i40e_vsi *vsi = NULL; |
| 9661 | struct i40e_veb *veb = NULL; |
| 9662 | int ret, i; |
| 9663 | int v_idx; |
| 9664 | |
| 9665 | /* The requested uplink_seid must be either |
| 9666 | * - the PF's port seid |
| 9667 | * no VEB is needed because this is the PF |
| 9668 | * or this is a Flow Director special case VSI |
| 9669 | * - seid of an existing VEB |
| 9670 | * - seid of a VSI that owns an existing VEB |
| 9671 | * - seid of a VSI that doesn't own a VEB |
| 9672 | * a new VEB is created and the VSI becomes the owner |
| 9673 | * - seid of the PF VSI, which is what creates the first VEB |
| 9674 | * this is a special case of the previous |
| 9675 | * |
| 9676 | * Find which uplink_seid we were given and create a new VEB if needed |
| 9677 | */ |
| 9678 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9679 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 9680 | veb = pf->veb[i]; |
| 9681 | break; |
| 9682 | } |
| 9683 | } |
| 9684 | |
| 9685 | if (!veb && uplink_seid != pf->mac_seid) { |
| 9686 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9687 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9688 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 9689 | vsi = pf->vsi[i]; |
| 9690 | break; |
| 9691 | } |
| 9692 | } |
| 9693 | if (!vsi) { |
| 9694 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 9695 | uplink_seid); |
| 9696 | return NULL; |
| 9697 | } |
| 9698 | |
| 9699 | if (vsi->uplink_seid == pf->mac_seid) |
| 9700 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 9701 | vsi->tc_config.enabled_tc); |
| 9702 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 9703 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9704 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9705 | if (veb) { |
| 9706 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 9707 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 9708 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9709 | return NULL; |
| 9710 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 9711 | /* We come up by default in VEPA mode if SRIOV is not |
| 9712 | * already enabled, in which case we can't force VEPA |
| 9713 | * mode. |
| 9714 | */ |
| 9715 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 9716 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 9717 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9718 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9719 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9720 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9721 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9722 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9723 | veb = pf->veb[i]; |
| 9724 | } |
| 9725 | if (!veb) { |
| 9726 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 9727 | return NULL; |
| 9728 | } |
| 9729 | |
| 9730 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 9731 | uplink_seid = veb->seid; |
| 9732 | } |
| 9733 | |
| 9734 | /* get vsi sw struct */ |
| 9735 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 9736 | if (v_idx < 0) |
| 9737 | goto err_alloc; |
| 9738 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9739 | if (!vsi) |
| 9740 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9741 | vsi->type = type; |
| 9742 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 9743 | |
| 9744 | if (type == I40E_VSI_MAIN) |
| 9745 | pf->lan_vsi = v_idx; |
| 9746 | else if (type == I40E_VSI_SRIOV) |
| 9747 | vsi->vf_id = param1; |
| 9748 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9749 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 9750 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9751 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9752 | dev_info(&pf->pdev->dev, |
| 9753 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 9754 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9755 | goto err_vsi; |
| 9756 | } |
| 9757 | vsi->base_queue = ret; |
| 9758 | |
| 9759 | /* get a VSI from the hardware */ |
| 9760 | vsi->uplink_seid = uplink_seid; |
| 9761 | ret = i40e_add_vsi(vsi); |
| 9762 | if (ret) |
| 9763 | goto err_vsi; |
| 9764 | |
| 9765 | switch (vsi->type) { |
| 9766 | /* setup the netdev if needed */ |
| 9767 | case I40E_VSI_MAIN: |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9768 | /* Apply relevant filters if a platform-specific mac |
| 9769 | * address was selected. |
| 9770 | */ |
| 9771 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 9772 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 9773 | if (ret) { |
| 9774 | dev_warn(&pf->pdev->dev, |
| 9775 | "could not set up macaddr; err %d\n", |
| 9776 | ret); |
| 9777 | } |
| 9778 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9779 | case I40E_VSI_VMDQ2: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9780 | case I40E_VSI_FCOE: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9781 | ret = i40e_config_netdev(vsi); |
| 9782 | if (ret) |
| 9783 | goto err_netdev; |
| 9784 | ret = register_netdev(vsi->netdev); |
| 9785 | if (ret) |
| 9786 | goto err_netdev; |
| 9787 | vsi->netdev_registered = true; |
| 9788 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9789 | #ifdef CONFIG_I40E_DCB |
| 9790 | /* Setup DCB netlink interface */ |
| 9791 | i40e_dcbnl_setup(vsi); |
| 9792 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9793 | /* fall through */ |
| 9794 | |
| 9795 | case I40E_VSI_FDIR: |
| 9796 | /* set up vectors and rings if needed */ |
| 9797 | ret = i40e_vsi_setup_vectors(vsi); |
| 9798 | if (ret) |
| 9799 | goto err_msix; |
| 9800 | |
| 9801 | ret = i40e_alloc_rings(vsi); |
| 9802 | if (ret) |
| 9803 | goto err_rings; |
| 9804 | |
| 9805 | /* map all of the rings to the q_vectors */ |
| 9806 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9807 | |
| 9808 | i40e_vsi_reset_stats(vsi); |
| 9809 | break; |
| 9810 | |
| 9811 | default: |
| 9812 | /* no netdev or rings for the other VSI types */ |
| 9813 | break; |
| 9814 | } |
| 9815 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9816 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
| 9817 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 9818 | ret = i40e_vsi_config_rss(vsi); |
| 9819 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9820 | return vsi; |
| 9821 | |
| 9822 | err_rings: |
| 9823 | i40e_vsi_free_q_vectors(vsi); |
| 9824 | err_msix: |
| 9825 | if (vsi->netdev_registered) { |
| 9826 | vsi->netdev_registered = false; |
| 9827 | unregister_netdev(vsi->netdev); |
| 9828 | free_netdev(vsi->netdev); |
| 9829 | vsi->netdev = NULL; |
| 9830 | } |
| 9831 | err_netdev: |
| 9832 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9833 | err_vsi: |
| 9834 | i40e_vsi_clear(vsi); |
| 9835 | err_alloc: |
| 9836 | return NULL; |
| 9837 | } |
| 9838 | |
| 9839 | /** |
| 9840 | * i40e_veb_get_bw_info - Query VEB BW information |
| 9841 | * @veb: the veb to query |
| 9842 | * |
| 9843 | * Query the Tx scheduler BW configuration data for given VEB |
| 9844 | **/ |
| 9845 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 9846 | { |
| 9847 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 9848 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 9849 | struct i40e_pf *pf = veb->pf; |
| 9850 | struct i40e_hw *hw = &pf->hw; |
| 9851 | u32 tc_bw_max; |
| 9852 | int ret = 0; |
| 9853 | int i; |
| 9854 | |
| 9855 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 9856 | &bw_data, NULL); |
| 9857 | if (ret) { |
| 9858 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9859 | "query veb bw config failed, err %s aq_err %s\n", |
| 9860 | i40e_stat_str(&pf->hw, ret), |
| 9861 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9862 | goto out; |
| 9863 | } |
| 9864 | |
| 9865 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 9866 | &ets_data, NULL); |
| 9867 | if (ret) { |
| 9868 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9869 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 9870 | i40e_stat_str(&pf->hw, ret), |
| 9871 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9872 | goto out; |
| 9873 | } |
| 9874 | |
| 9875 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 9876 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 9877 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 9878 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9879 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 9880 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 9881 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 9882 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 9883 | veb->bw_tc_limit_credits[i] = |
| 9884 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 9885 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 9886 | } |
| 9887 | |
| 9888 | out: |
| 9889 | return ret; |
| 9890 | } |
| 9891 | |
| 9892 | /** |
| 9893 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 9894 | * @pf: board private structure |
| 9895 | * |
| 9896 | * On error: returns error code (negative) |
| 9897 | * On success: returns vsi index in PF (positive) |
| 9898 | **/ |
| 9899 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 9900 | { |
| 9901 | int ret = -ENOENT; |
| 9902 | struct i40e_veb *veb; |
| 9903 | int i; |
| 9904 | |
| 9905 | /* Need to protect the allocation of switch elements at the PF level */ |
| 9906 | mutex_lock(&pf->switch_mutex); |
| 9907 | |
| 9908 | /* VEB list may be fragmented if VEB creation/destruction has |
| 9909 | * been happening. We can afford to do a quick scan to look |
| 9910 | * for any free slots in the list. |
| 9911 | * |
| 9912 | * find next empty veb slot, looping back around if necessary |
| 9913 | */ |
| 9914 | i = 0; |
| 9915 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 9916 | i++; |
| 9917 | if (i >= I40E_MAX_VEB) { |
| 9918 | ret = -ENOMEM; |
| 9919 | goto err_alloc_veb; /* out of VEB slots! */ |
| 9920 | } |
| 9921 | |
| 9922 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 9923 | if (!veb) { |
| 9924 | ret = -ENOMEM; |
| 9925 | goto err_alloc_veb; |
| 9926 | } |
| 9927 | veb->pf = pf; |
| 9928 | veb->idx = i; |
| 9929 | veb->enabled_tc = 1; |
| 9930 | |
| 9931 | pf->veb[i] = veb; |
| 9932 | ret = i; |
| 9933 | err_alloc_veb: |
| 9934 | mutex_unlock(&pf->switch_mutex); |
| 9935 | return ret; |
| 9936 | } |
| 9937 | |
| 9938 | /** |
| 9939 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 9940 | * @branch: where to start deleting |
| 9941 | * |
| 9942 | * This uses recursion to find the tips of the branch to be |
| 9943 | * removed, deleting until we get back to and can delete this VEB. |
| 9944 | **/ |
| 9945 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 9946 | { |
| 9947 | struct i40e_pf *pf = branch->pf; |
| 9948 | u16 branch_seid = branch->seid; |
| 9949 | u16 veb_idx = branch->idx; |
| 9950 | int i; |
| 9951 | |
| 9952 | /* release any VEBs on this VEB - RECURSION */ |
| 9953 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9954 | if (!pf->veb[i]) |
| 9955 | continue; |
| 9956 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 9957 | i40e_switch_branch_release(pf->veb[i]); |
| 9958 | } |
| 9959 | |
| 9960 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 9961 | * |
| 9962 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 9963 | * the VEB itself, so don't use (*branch) after this loop. |
| 9964 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9965 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9966 | if (!pf->vsi[i]) |
| 9967 | continue; |
| 9968 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 9969 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9970 | i40e_vsi_release(pf->vsi[i]); |
| 9971 | } |
| 9972 | } |
| 9973 | |
| 9974 | /* There's one corner case where the VEB might not have been |
| 9975 | * removed, so double check it here and remove it if needed. |
| 9976 | * This case happens if the veb was created from the debugfs |
| 9977 | * commands and no VSIs were added to it. |
| 9978 | */ |
| 9979 | if (pf->veb[veb_idx]) |
| 9980 | i40e_veb_release(pf->veb[veb_idx]); |
| 9981 | } |
| 9982 | |
| 9983 | /** |
| 9984 | * i40e_veb_clear - remove veb struct |
| 9985 | * @veb: the veb to remove |
| 9986 | **/ |
| 9987 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 9988 | { |
| 9989 | if (!veb) |
| 9990 | return; |
| 9991 | |
| 9992 | if (veb->pf) { |
| 9993 | struct i40e_pf *pf = veb->pf; |
| 9994 | |
| 9995 | mutex_lock(&pf->switch_mutex); |
| 9996 | if (pf->veb[veb->idx] == veb) |
| 9997 | pf->veb[veb->idx] = NULL; |
| 9998 | mutex_unlock(&pf->switch_mutex); |
| 9999 | } |
| 10000 | |
| 10001 | kfree(veb); |
| 10002 | } |
| 10003 | |
| 10004 | /** |
| 10005 | * i40e_veb_release - Delete a VEB and free its resources |
| 10006 | * @veb: the VEB being removed |
| 10007 | **/ |
| 10008 | void i40e_veb_release(struct i40e_veb *veb) |
| 10009 | { |
| 10010 | struct i40e_vsi *vsi = NULL; |
| 10011 | struct i40e_pf *pf; |
| 10012 | int i, n = 0; |
| 10013 | |
| 10014 | pf = veb->pf; |
| 10015 | |
| 10016 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10017 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10018 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 10019 | n++; |
| 10020 | vsi = pf->vsi[i]; |
| 10021 | } |
| 10022 | } |
| 10023 | if (n != 1) { |
| 10024 | dev_info(&pf->pdev->dev, |
| 10025 | "can't remove VEB %d with %d VSIs left\n", |
| 10026 | veb->seid, n); |
| 10027 | return; |
| 10028 | } |
| 10029 | |
| 10030 | /* move the remaining VSI to uplink veb */ |
| 10031 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10032 | if (veb->uplink_seid) { |
| 10033 | vsi->uplink_seid = veb->uplink_seid; |
| 10034 | if (veb->uplink_seid == pf->mac_seid) |
| 10035 | vsi->veb_idx = I40E_NO_VEB; |
| 10036 | else |
| 10037 | vsi->veb_idx = veb->veb_idx; |
| 10038 | } else { |
| 10039 | /* floating VEB */ |
| 10040 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10041 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10042 | } |
| 10043 | |
| 10044 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10045 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10046 | } |
| 10047 | |
| 10048 | /** |
| 10049 | * i40e_add_veb - create the VEB in the switch |
| 10050 | * @veb: the VEB to be instantiated |
| 10051 | * @vsi: the controlling VSI |
| 10052 | **/ |
| 10053 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10054 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10055 | struct i40e_pf *pf = veb->pf; |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 10056 | bool is_default = veb->pf->cur_promisc; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10057 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10058 | int ret; |
| 10059 | |
| 10060 | /* get a VEB from the hardware */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10061 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 10062 | veb->enabled_tc, is_default, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10063 | &veb->seid, enable_stats, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10064 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10065 | dev_info(&pf->pdev->dev, |
| 10066 | "couldn't add VEB, err %s aq_err %s\n", |
| 10067 | i40e_stat_str(&pf->hw, ret), |
| 10068 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10069 | return -EPERM; |
| 10070 | } |
| 10071 | |
| 10072 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10073 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10074 | &veb->stats_idx, NULL, NULL, NULL); |
| 10075 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10076 | dev_info(&pf->pdev->dev, |
| 10077 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10078 | i40e_stat_str(&pf->hw, ret), |
| 10079 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10080 | return -EPERM; |
| 10081 | } |
| 10082 | ret = i40e_veb_get_bw_info(veb); |
| 10083 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10084 | dev_info(&pf->pdev->dev, |
| 10085 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10086 | i40e_stat_str(&pf->hw, ret), |
| 10087 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10088 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10089 | return -ENOENT; |
| 10090 | } |
| 10091 | |
| 10092 | vsi->uplink_seid = veb->seid; |
| 10093 | vsi->veb_idx = veb->idx; |
| 10094 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10095 | |
| 10096 | return 0; |
| 10097 | } |
| 10098 | |
| 10099 | /** |
| 10100 | * i40e_veb_setup - Set up a VEB |
| 10101 | * @pf: board private structure |
| 10102 | * @flags: VEB setup flags |
| 10103 | * @uplink_seid: the switch element to link to |
| 10104 | * @vsi_seid: the initial VSI seid |
| 10105 | * @enabled_tc: Enabled TC bit-map |
| 10106 | * |
| 10107 | * This allocates the sw VEB structure and links it into the switch |
| 10108 | * It is possible and legal for this to be a duplicate of an already |
| 10109 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10110 | * to be zero, in order to create a floating VEB. |
| 10111 | * |
| 10112 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10113 | * success, otherwise returns NULL on failure. |
| 10114 | **/ |
| 10115 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10116 | u16 uplink_seid, u16 vsi_seid, |
| 10117 | u8 enabled_tc) |
| 10118 | { |
| 10119 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10120 | int vsi_idx, veb_idx; |
| 10121 | int ret; |
| 10122 | |
| 10123 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10124 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10125 | (uplink_seid + vsi_seid != 0)) { |
| 10126 | dev_info(&pf->pdev->dev, |
| 10127 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10128 | uplink_seid, vsi_seid); |
| 10129 | return NULL; |
| 10130 | } |
| 10131 | |
| 10132 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10133 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10134 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10135 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10136 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10137 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10138 | vsi_seid); |
| 10139 | return NULL; |
| 10140 | } |
| 10141 | |
| 10142 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10143 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10144 | if (pf->veb[veb_idx] && |
| 10145 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10146 | uplink_veb = pf->veb[veb_idx]; |
| 10147 | break; |
| 10148 | } |
| 10149 | } |
| 10150 | if (!uplink_veb) { |
| 10151 | dev_info(&pf->pdev->dev, |
| 10152 | "uplink seid %d not found\n", uplink_seid); |
| 10153 | return NULL; |
| 10154 | } |
| 10155 | } |
| 10156 | |
| 10157 | /* get veb sw struct */ |
| 10158 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10159 | if (veb_idx < 0) |
| 10160 | goto err_alloc; |
| 10161 | veb = pf->veb[veb_idx]; |
| 10162 | veb->flags = flags; |
| 10163 | veb->uplink_seid = uplink_seid; |
| 10164 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10165 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10166 | |
| 10167 | /* create the VEB in the switch */ |
| 10168 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10169 | if (ret) |
| 10170 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10171 | if (vsi_idx == pf->lan_vsi) |
| 10172 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10173 | |
| 10174 | return veb; |
| 10175 | |
| 10176 | err_veb: |
| 10177 | i40e_veb_clear(veb); |
| 10178 | err_alloc: |
| 10179 | return NULL; |
| 10180 | } |
| 10181 | |
| 10182 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10183 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10184 | * @pf: board private structure |
| 10185 | * @ele: element we are building info from |
| 10186 | * @num_reported: total number of elements |
| 10187 | * @printconfig: should we print the contents |
| 10188 | * |
| 10189 | * helper function to assist in extracting a few useful SEID values. |
| 10190 | **/ |
| 10191 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10192 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10193 | u16 num_reported, bool printconfig) |
| 10194 | { |
| 10195 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10196 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10197 | u8 element_type = ele->element_type; |
| 10198 | u16 seid = le16_to_cpu(ele->seid); |
| 10199 | |
| 10200 | if (printconfig) |
| 10201 | dev_info(&pf->pdev->dev, |
| 10202 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10203 | element_type, seid, uplink_seid, downlink_seid); |
| 10204 | |
| 10205 | switch (element_type) { |
| 10206 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10207 | pf->mac_seid = seid; |
| 10208 | break; |
| 10209 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10210 | /* Main VEB? */ |
| 10211 | if (uplink_seid != pf->mac_seid) |
| 10212 | break; |
| 10213 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10214 | int v; |
| 10215 | |
| 10216 | /* find existing or else empty VEB */ |
| 10217 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10218 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10219 | pf->lan_veb = v; |
| 10220 | break; |
| 10221 | } |
| 10222 | } |
| 10223 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10224 | v = i40e_veb_mem_alloc(pf); |
| 10225 | if (v < 0) |
| 10226 | break; |
| 10227 | pf->lan_veb = v; |
| 10228 | } |
| 10229 | } |
| 10230 | |
| 10231 | pf->veb[pf->lan_veb]->seid = seid; |
| 10232 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10233 | pf->veb[pf->lan_veb]->pf = pf; |
| 10234 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10235 | break; |
| 10236 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10237 | if (num_reported != 1) |
| 10238 | break; |
| 10239 | /* This is immediately after a reset so we can assume this is |
| 10240 | * the PF's VSI |
| 10241 | */ |
| 10242 | pf->mac_seid = uplink_seid; |
| 10243 | pf->pf_seid = downlink_seid; |
| 10244 | pf->main_vsi_seid = seid; |
| 10245 | if (printconfig) |
| 10246 | dev_info(&pf->pdev->dev, |
| 10247 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10248 | pf->pf_seid, pf->main_vsi_seid); |
| 10249 | break; |
| 10250 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10251 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10252 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10253 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10254 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10255 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10256 | /* ignore these for now */ |
| 10257 | break; |
| 10258 | default: |
| 10259 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10260 | element_type, seid); |
| 10261 | break; |
| 10262 | } |
| 10263 | } |
| 10264 | |
| 10265 | /** |
| 10266 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10267 | * @pf: board private structure |
| 10268 | * @printconfig: should we print the contents |
| 10269 | * |
| 10270 | * Get the current switch configuration from the device and |
| 10271 | * extract a few useful SEID values. |
| 10272 | **/ |
| 10273 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10274 | { |
| 10275 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10276 | u16 next_seid = 0; |
| 10277 | int ret = 0; |
| 10278 | u8 *aq_buf; |
| 10279 | int i; |
| 10280 | |
| 10281 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10282 | if (!aq_buf) |
| 10283 | return -ENOMEM; |
| 10284 | |
| 10285 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10286 | do { |
| 10287 | u16 num_reported, num_total; |
| 10288 | |
| 10289 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10290 | I40E_AQ_LARGE_BUF, |
| 10291 | &next_seid, NULL); |
| 10292 | if (ret) { |
| 10293 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10294 | "get switch config failed err %s aq_err %s\n", |
| 10295 | i40e_stat_str(&pf->hw, ret), |
| 10296 | i40e_aq_str(&pf->hw, |
| 10297 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10298 | kfree(aq_buf); |
| 10299 | return -ENOENT; |
| 10300 | } |
| 10301 | |
| 10302 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10303 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10304 | |
| 10305 | if (printconfig) |
| 10306 | dev_info(&pf->pdev->dev, |
| 10307 | "header: %d reported %d total\n", |
| 10308 | num_reported, num_total); |
| 10309 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10310 | for (i = 0; i < num_reported; i++) { |
| 10311 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10312 | &sw_config->element[i]; |
| 10313 | |
| 10314 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10315 | printconfig); |
| 10316 | } |
| 10317 | } while (next_seid != 0); |
| 10318 | |
| 10319 | kfree(aq_buf); |
| 10320 | return ret; |
| 10321 | } |
| 10322 | |
| 10323 | /** |
| 10324 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10325 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10326 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10327 | * |
| 10328 | * Returns 0 on success, negative value on failure |
| 10329 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10330 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10331 | { |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10332 | u16 flags = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10333 | int ret; |
| 10334 | |
| 10335 | /* find out what's out there already */ |
| 10336 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10337 | if (ret) { |
| 10338 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10339 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10340 | i40e_stat_str(&pf->hw, ret), |
| 10341 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10342 | return ret; |
| 10343 | } |
| 10344 | i40e_pf_reset_stats(pf); |
| 10345 | |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10346 | /* set the switch config bit for the whole device to |
| 10347 | * support limited promisc or true promisc |
| 10348 | * when user requests promisc. The default is limited |
| 10349 | * promisc. |
| 10350 | */ |
| 10351 | |
| 10352 | if ((pf->hw.pf_id == 0) && |
| 10353 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) |
| 10354 | flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10355 | |
| 10356 | if (pf->hw.pf_id == 0) { |
| 10357 | u16 valid_flags; |
| 10358 | |
| 10359 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10360 | ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, |
| 10361 | NULL); |
| 10362 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { |
| 10363 | dev_info(&pf->pdev->dev, |
| 10364 | "couldn't set switch config bits, err %s aq_err %s\n", |
| 10365 | i40e_stat_str(&pf->hw, ret), |
| 10366 | i40e_aq_str(&pf->hw, |
| 10367 | pf->hw.aq.asq_last_status)); |
| 10368 | /* not a fatal problem, just keep going */ |
| 10369 | } |
| 10370 | } |
| 10371 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10372 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10373 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10374 | struct i40e_vsi *vsi = NULL; |
| 10375 | u16 uplink_seid; |
| 10376 | |
| 10377 | /* Set up the PF VSI associated with the PF's main VSI |
| 10378 | * that is already in the HW switch |
| 10379 | */ |
| 10380 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10381 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10382 | else |
| 10383 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10384 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10385 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10386 | else if (reinit) |
| 10387 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10388 | if (!vsi) { |
| 10389 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10390 | i40e_fdir_teardown(pf); |
| 10391 | return -EAGAIN; |
| 10392 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10393 | } else { |
| 10394 | /* force a reset of TC and queue layout configurations */ |
| 10395 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10396 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10397 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10398 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10399 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10400 | } |
| 10401 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 10402 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10403 | i40e_fdir_sb_setup(pf); |
| 10404 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10405 | /* Setup static PF queue filter control settings */ |
| 10406 | ret = i40e_setup_pf_filter_control(pf); |
| 10407 | if (ret) { |
| 10408 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 10409 | ret); |
| 10410 | /* Failure here should not stop continuing other steps */ |
| 10411 | } |
| 10412 | |
| 10413 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 10414 | * the hash |
| 10415 | */ |
| 10416 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 10417 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10418 | |
| 10419 | /* fill in link information and enable LSE reporting */ |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 10420 | i40e_update_link_info(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10421 | i40e_link_event(pf); |
| 10422 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10423 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10424 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 10425 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10426 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10427 | i40e_ptp_init(pf); |
| 10428 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10429 | return ret; |
| 10430 | } |
| 10431 | |
| 10432 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10433 | * i40e_determine_queue_usage - Work out queue distribution |
| 10434 | * @pf: board private structure |
| 10435 | **/ |
| 10436 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 10437 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10438 | int queues_left; |
| 10439 | |
| 10440 | pf->num_lan_qps = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10441 | #ifdef I40E_FCOE |
| 10442 | pf->num_fcoe_qps = 0; |
| 10443 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10444 | |
| 10445 | /* Find the max queues to be put into basic use. We'll always be |
| 10446 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 10447 | * big RSS set. |
| 10448 | */ |
| 10449 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 10450 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10451 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10452 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10453 | /* one qp for PF, no queues for anything else */ |
| 10454 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10455 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10456 | |
| 10457 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10458 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10459 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10460 | #ifdef I40E_FCOE |
| 10461 | I40E_FLAG_FCOE_ENABLED | |
| 10462 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10463 | I40E_FLAG_FD_SB_ENABLED | |
| 10464 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10465 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10466 | I40E_FLAG_SRIOV_ENABLED | |
| 10467 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10468 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 10469 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 10470 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10471 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10472 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10473 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10474 | queues_left -= pf->num_lan_qps; |
| 10475 | |
| 10476 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10477 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10478 | #ifdef I40E_FCOE |
| 10479 | I40E_FLAG_FCOE_ENABLED | |
| 10480 | #endif |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10481 | I40E_FLAG_FD_SB_ENABLED | |
| 10482 | I40E_FLAG_FD_ATR_ENABLED | |
| 10483 | I40E_FLAG_DCB_ENABLED | |
| 10484 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10485 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10486 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10487 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10488 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10489 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10490 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 10491 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 10492 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 10493 | num_online_cpus()); |
| 10494 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 10495 | pf->hw.func_caps.num_tx_qp); |
| 10496 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10497 | queues_left -= pf->num_lan_qps; |
| 10498 | } |
| 10499 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10500 | #ifdef I40E_FCOE |
| 10501 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 10502 | if (I40E_DEFAULT_FCOE <= queues_left) { |
| 10503 | pf->num_fcoe_qps = I40E_DEFAULT_FCOE; |
| 10504 | } else if (I40E_MINIMUM_FCOE <= queues_left) { |
| 10505 | pf->num_fcoe_qps = I40E_MINIMUM_FCOE; |
| 10506 | } else { |
| 10507 | pf->num_fcoe_qps = 0; |
| 10508 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 10509 | dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n"); |
| 10510 | } |
| 10511 | |
| 10512 | queues_left -= pf->num_fcoe_qps; |
| 10513 | } |
| 10514 | |
| 10515 | #endif |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10516 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10517 | if (queues_left > 1) { |
| 10518 | queues_left -= 1; /* save 1 queue for FD */ |
| 10519 | } else { |
| 10520 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 10521 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 10522 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10523 | } |
| 10524 | |
| 10525 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10526 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10527 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 10528 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10529 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 10530 | } |
| 10531 | |
| 10532 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 10533 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 10534 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 10535 | (queues_left / pf->num_vmdq_qps)); |
| 10536 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 10537 | } |
| 10538 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10539 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10540 | dev_dbg(&pf->pdev->dev, |
| 10541 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 10542 | pf->hw.func_caps.num_tx_qp, |
| 10543 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10544 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 10545 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 10546 | queues_left); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10547 | #ifdef I40E_FCOE |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10548 | 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] | 10549 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10550 | } |
| 10551 | |
| 10552 | /** |
| 10553 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 10554 | * @pf: PF to be setup |
| 10555 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10556 | * 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] | 10557 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 10558 | * based filter sizes required for them. It also enables Flow director, |
| 10559 | * ethertype and macvlan type filter settings for the pf. |
| 10560 | * |
| 10561 | * Returns 0 on success, negative on failure |
| 10562 | **/ |
| 10563 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 10564 | { |
| 10565 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 10566 | |
| 10567 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 10568 | |
| 10569 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10570 | 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] | 10571 | settings->enable_fdir = true; |
| 10572 | |
| 10573 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 10574 | settings->enable_ethtype = true; |
| 10575 | settings->enable_macvlan = true; |
| 10576 | |
| 10577 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 10578 | return -ENOENT; |
| 10579 | |
| 10580 | return 0; |
| 10581 | } |
| 10582 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10583 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10584 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10585 | static void i40e_print_features(struct i40e_pf *pf) |
| 10586 | { |
| 10587 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10588 | char *buf; |
| 10589 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10590 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10591 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 10592 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10593 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10594 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10595 | 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] | 10596 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10597 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10598 | #endif |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10599 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10600 | pf->hw.func_caps.num_vsis, |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10601 | pf->vsi[pf->lan_vsi]->num_queue_pairs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10602 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10603 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10604 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10605 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10606 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10607 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 10608 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10609 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10610 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10611 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10612 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10613 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10614 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10615 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10616 | #ifdef I40E_FCOE |
| 10617 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10618 | i += snprintf(&buf[i], REMAIN(i), " FCOE"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10619 | #endif |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10620 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10621 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10622 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10623 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10624 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10625 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 10626 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10627 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10628 | } |
| 10629 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10630 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10631 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
| 10632 | * |
| 10633 | * @pdev: PCI device information struct |
| 10634 | * @pf: board private structure |
| 10635 | * |
| 10636 | * Look up the MAC address in Open Firmware on systems that support it, |
| 10637 | * and use IDPROM on SPARC if no OF address is found. On return, the |
| 10638 | * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value |
| 10639 | * has been selected. |
| 10640 | **/ |
| 10641 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 10642 | { |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10643 | pf->flags &= ~I40E_FLAG_PF_MAC; |
Sowmini Varadhan | ba94272 | 2016-01-12 19:32:31 -0800 | [diff] [blame] | 10644 | if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10645 | pf->flags |= I40E_FLAG_PF_MAC; |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10646 | } |
| 10647 | |
| 10648 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10649 | * i40e_probe - Device initialization routine |
| 10650 | * @pdev: PCI device information struct |
| 10651 | * @ent: entry in i40e_pci_tbl |
| 10652 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10653 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 10654 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10655 | * and a hardware reset occur. |
| 10656 | * |
| 10657 | * Returns 0 on success, negative on failure |
| 10658 | **/ |
| 10659 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 10660 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 10661 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10662 | struct i40e_pf *pf; |
| 10663 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10664 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10665 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10666 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 10667 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10668 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10669 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10670 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10671 | |
| 10672 | err = pci_enable_device_mem(pdev); |
| 10673 | if (err) |
| 10674 | return err; |
| 10675 | |
| 10676 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10677 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10678 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 10679 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10680 | if (err) { |
| 10681 | dev_err(&pdev->dev, |
| 10682 | "DMA configuration failed: 0x%x\n", err); |
| 10683 | goto err_dma; |
| 10684 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10685 | } |
| 10686 | |
| 10687 | /* set up pci connections */ |
| 10688 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 10689 | IORESOURCE_MEM), i40e_driver_name); |
| 10690 | if (err) { |
| 10691 | dev_info(&pdev->dev, |
| 10692 | "pci_request_selected_regions failed %d\n", err); |
| 10693 | goto err_pci_reg; |
| 10694 | } |
| 10695 | |
| 10696 | pci_enable_pcie_error_reporting(pdev); |
| 10697 | pci_set_master(pdev); |
| 10698 | |
| 10699 | /* Now that we have a PCI connection, we need to do the |
| 10700 | * low level device setup. This is primarily setting up |
| 10701 | * the Admin Queue structures and then querying for the |
| 10702 | * device's current profile information. |
| 10703 | */ |
| 10704 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 10705 | if (!pf) { |
| 10706 | err = -ENOMEM; |
| 10707 | goto err_pf_alloc; |
| 10708 | } |
| 10709 | pf->next_vsi = 0; |
| 10710 | pf->pdev = pdev; |
| 10711 | set_bit(__I40E_DOWN, &pf->state); |
| 10712 | |
| 10713 | hw = &pf->hw; |
| 10714 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10715 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10716 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 10717 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10718 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10719 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10720 | if (!hw->hw_addr) { |
| 10721 | err = -EIO; |
| 10722 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 10723 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10724 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10725 | goto err_ioremap; |
| 10726 | } |
| 10727 | hw->vendor_id = pdev->vendor; |
| 10728 | hw->device_id = pdev->device; |
| 10729 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 10730 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 10731 | hw->subsystem_device_id = pdev->subsystem_device; |
| 10732 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 10733 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10734 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10735 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 10736 | /* set up the locks for the AQ, do this only once in probe |
| 10737 | * and destroy them only once in remove |
| 10738 | */ |
| 10739 | mutex_init(&hw->aq.asq_mutex); |
| 10740 | mutex_init(&hw->aq.arq_mutex); |
| 10741 | |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 10742 | if (debug != -1) { |
| 10743 | pf->msg_enable = pf->hw.debug_mask; |
| 10744 | pf->msg_enable = debug; |
| 10745 | } |
| 10746 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10747 | /* do a special CORER for clearing PXE mode once at init */ |
| 10748 | if (hw->revision_id == 0 && |
| 10749 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 10750 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 10751 | i40e_flush(hw); |
| 10752 | msleep(200); |
| 10753 | pf->corer_count++; |
| 10754 | |
| 10755 | i40e_clear_pxe_mode(hw); |
| 10756 | } |
| 10757 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10758 | /* 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] | 10759 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10760 | err = i40e_pf_reset(hw); |
| 10761 | if (err) { |
| 10762 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 10763 | goto err_pf_reset; |
| 10764 | } |
| 10765 | pf->pfr_count++; |
| 10766 | |
| 10767 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 10768 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 10769 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10770 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10771 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10772 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 10773 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10774 | "%s-%s:misc", |
| 10775 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10776 | |
| 10777 | err = i40e_init_shared_code(hw); |
| 10778 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 10779 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 10780 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10781 | goto err_pf_reset; |
| 10782 | } |
| 10783 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10784 | /* set up a default setting for link flow control */ |
| 10785 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 10786 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10787 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 10788 | if (err) { |
| 10789 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 10790 | dev_info(&pdev->dev, |
| 10791 | "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"); |
| 10792 | else |
| 10793 | dev_info(&pdev->dev, |
| 10794 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 10795 | |
| 10796 | goto err_pf_reset; |
| 10797 | } |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10798 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10799 | /* provide nvm, fw, api versions */ |
| 10800 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 10801 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 10802 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 10803 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10804 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10805 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 10806 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10807 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10808 | "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"); |
| 10809 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 10810 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10811 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10812 | "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] | 10813 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 10814 | i40e_verify_eeprom(pf); |
| 10815 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 10816 | /* Rev 0 hardware was never productized */ |
| 10817 | if (hw->revision_id < 1) |
| 10818 | 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"); |
| 10819 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 10820 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10821 | err = i40e_get_capabilities(pf); |
| 10822 | if (err) |
| 10823 | goto err_adminq_setup; |
| 10824 | |
| 10825 | err = i40e_sw_init(pf); |
| 10826 | if (err) { |
| 10827 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 10828 | goto err_sw_init; |
| 10829 | } |
| 10830 | |
| 10831 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 10832 | hw->func_caps.num_rx_qp, |
| 10833 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 10834 | if (err) { |
| 10835 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 10836 | goto err_init_lan_hmc; |
| 10837 | } |
| 10838 | |
| 10839 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 10840 | if (err) { |
| 10841 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 10842 | err = -ENOENT; |
| 10843 | goto err_configure_lan_hmc; |
| 10844 | } |
| 10845 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10846 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 10847 | * Ignore error return codes because if it was already disabled via |
| 10848 | * hardware settings this will fail |
| 10849 | */ |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 10850 | if (pf->flags & I40E_FLAG_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10851 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 10852 | i40e_aq_stop_lldp(hw, true, NULL); |
| 10853 | } |
| 10854 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10855 | i40e_get_mac_addr(hw, hw->mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10856 | /* allow a platform config to override the HW addr */ |
| 10857 | i40e_get_platform_mac_addr(pdev, pf); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 10858 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10859 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 10860 | err = -EIO; |
| 10861 | goto err_mac_addr; |
| 10862 | } |
| 10863 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 10864 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10865 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 10866 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 10867 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10868 | #ifdef I40E_FCOE |
| 10869 | err = i40e_get_san_mac_addr(hw, hw->mac.san_addr); |
| 10870 | if (err) |
| 10871 | dev_info(&pdev->dev, |
| 10872 | "(non-fatal) SAN MAC retrieval failed: %d\n", err); |
| 10873 | if (!is_valid_ether_addr(hw->mac.san_addr)) { |
| 10874 | dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n", |
| 10875 | hw->mac.san_addr); |
| 10876 | ether_addr_copy(hw->mac.san_addr, hw->mac.addr); |
| 10877 | } |
| 10878 | dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr); |
| 10879 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10880 | |
| 10881 | pci_set_drvdata(pdev, pf); |
| 10882 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10883 | #ifdef CONFIG_I40E_DCB |
| 10884 | err = i40e_init_pf_dcb(pf); |
| 10885 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 10886 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10887 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 10888 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10889 | } |
| 10890 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10891 | |
| 10892 | /* set up periodic task facility */ |
| 10893 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 10894 | pf->service_timer_period = HZ; |
| 10895 | |
| 10896 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 10897 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 10898 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10899 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10900 | /* NVM bit on means WoL disabled for the port */ |
| 10901 | 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] | 10902 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10903 | pf->wol_en = false; |
| 10904 | else |
| 10905 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 10906 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 10907 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10908 | /* set up the main switch operations */ |
| 10909 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 10910 | err = i40e_init_interrupt_scheme(pf); |
| 10911 | if (err) |
| 10912 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10913 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10914 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 10915 | * to us; HW supports far more and we share the remaining pool with |
| 10916 | * the other PFs. We allocate space for more than the guarantee with |
| 10917 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10918 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10919 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 10920 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 10921 | else |
| 10922 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 10923 | |
| 10924 | /* 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] | 10925 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 10926 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 10927 | if (!pf->vsi) { |
| 10928 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10929 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 10930 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10931 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 10932 | #ifdef CONFIG_PCI_IOV |
| 10933 | /* prep for VF support */ |
| 10934 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10935 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 10936 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 10937 | if (pci_num_vf(pdev)) |
| 10938 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 10939 | } |
| 10940 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10941 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10942 | if (err) { |
| 10943 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 10944 | goto err_vsis; |
| 10945 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10946 | |
| 10947 | /* Make sure flow control is set according to current settings */ |
| 10948 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 10949 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 10950 | dev_dbg(&pf->pdev->dev, |
| 10951 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 10952 | i40e_stat_str(hw, err), |
| 10953 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 10954 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 10955 | dev_dbg(&pf->pdev->dev, |
| 10956 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 10957 | i40e_stat_str(hw, err), |
| 10958 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 10959 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 10960 | dev_dbg(&pf->pdev->dev, |
| 10961 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 10962 | i40e_stat_str(hw, err), |
| 10963 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 10964 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10965 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10966 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10967 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 10968 | i40e_vsi_open(pf->vsi[i]); |
| 10969 | break; |
| 10970 | } |
| 10971 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10972 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 10973 | /* The driver only wants link up/down and module qualification |
| 10974 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 10975 | */ |
| 10976 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 10977 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 10978 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 10979 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 10980 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10981 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 10982 | i40e_stat_str(&pf->hw, err), |
| 10983 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 10984 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10985 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 10986 | * of TSO, so that we avoid the MDD being fired and causing |
| 10987 | * a reset in the case of small MSS+TSO. |
| 10988 | */ |
| 10989 | val = rd32(hw, I40E_REG_MSS); |
| 10990 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 10991 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 10992 | val |= I40E_64BYTE_MSS; |
| 10993 | wr32(hw, I40E_REG_MSS, val); |
| 10994 | } |
| 10995 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 10996 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 10997 | msleep(75); |
| 10998 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 10999 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 11000 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 11001 | i40e_stat_str(&pf->hw, err), |
| 11002 | i40e_aq_str(&pf->hw, |
| 11003 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 11004 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11005 | /* The main driver is (mostly) up and happy. We need to set this state |
| 11006 | * before setting up the misc vector or we get a race and the vector |
| 11007 | * ends up disabled forever. |
| 11008 | */ |
| 11009 | clear_bit(__I40E_DOWN, &pf->state); |
| 11010 | |
| 11011 | /* In case of MSIX we are going to setup the misc vector right here |
| 11012 | * to handle admin queue events etc. In case of legacy and MSI |
| 11013 | * the misc functionality and queue processing is combined in |
| 11014 | * the same vector and that gets setup at open. |
| 11015 | */ |
| 11016 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 11017 | err = i40e_setup_misc_vector(pf); |
| 11018 | if (err) { |
| 11019 | dev_info(&pdev->dev, |
| 11020 | "setup of misc vector failed: %d\n", err); |
| 11021 | goto err_vsis; |
| 11022 | } |
| 11023 | } |
| 11024 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11025 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11026 | /* prep for VF support */ |
| 11027 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 11028 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 11029 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11030 | /* disable link interrupts for VFs */ |
| 11031 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11032 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11033 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11034 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11035 | |
| 11036 | if (pci_num_vf(pdev)) { |
| 11037 | dev_info(&pdev->dev, |
| 11038 | "Active VFs found, allocating resources.\n"); |
| 11039 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11040 | if (err) |
| 11041 | dev_info(&pdev->dev, |
| 11042 | "Error %d allocating resources for existing VFs\n", |
| 11043 | err); |
| 11044 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11045 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11046 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11047 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11048 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11049 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11050 | pf->num_iwarp_msix, |
| 11051 | I40E_IWARP_IRQ_PILE_ID); |
| 11052 | if (pf->iwarp_base_vector < 0) { |
| 11053 | dev_info(&pdev->dev, |
| 11054 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 11055 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 11056 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 11057 | } |
| 11058 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11059 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11060 | i40e_dbg_pf_init(pf); |
| 11061 | |
| 11062 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11063 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11064 | |
| 11065 | /* since everything's happy, start the service_task timer */ |
| 11066 | mod_timer(&pf->service_timer, |
| 11067 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11068 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11069 | /* add this PF to client device list and launch a client service task */ |
| 11070 | err = i40e_lan_add_device(pf); |
| 11071 | if (err) |
| 11072 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 11073 | err); |
| 11074 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11075 | #ifdef I40E_FCOE |
| 11076 | /* create FCoE interface */ |
| 11077 | i40e_fcoe_vsi_setup(pf); |
| 11078 | |
| 11079 | #endif |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11080 | #define PCI_SPEED_SIZE 8 |
| 11081 | #define PCI_WIDTH_SIZE 8 |
| 11082 | /* Devices on the IOSF bus do not have this information |
| 11083 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11084 | * checking them. |
| 11085 | */ |
| 11086 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { |
| 11087 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11088 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11089 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11090 | /* Get the negotiated link width and speed from PCI config |
| 11091 | * space |
| 11092 | */ |
| 11093 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11094 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11095 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11096 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11097 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11098 | switch (hw->bus.speed) { |
| 11099 | case i40e_bus_speed_8000: |
| 11100 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11101 | case i40e_bus_speed_5000: |
| 11102 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11103 | case i40e_bus_speed_2500: |
| 11104 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11105 | default: |
| 11106 | break; |
| 11107 | } |
| 11108 | switch (hw->bus.width) { |
| 11109 | case i40e_bus_width_pcie_x8: |
| 11110 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11111 | case i40e_bus_width_pcie_x4: |
| 11112 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11113 | case i40e_bus_width_pcie_x2: |
| 11114 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11115 | case i40e_bus_width_pcie_x1: |
| 11116 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11117 | default: |
| 11118 | break; |
| 11119 | } |
| 11120 | |
| 11121 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11122 | speed, width); |
| 11123 | |
| 11124 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11125 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11126 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11127 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11128 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11129 | } |
| 11130 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11131 | /* get the requested speeds from the fw */ |
| 11132 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11133 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11134 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11135 | i40e_stat_str(&pf->hw, err), |
| 11136 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11137 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11138 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11139 | /* get the supported phy types from the fw */ |
| 11140 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11141 | if (err) |
| 11142 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11143 | i40e_stat_str(&pf->hw, err), |
| 11144 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 11145 | pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type); |
| 11146 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11147 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11148 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11149 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11150 | * PF/VF VSIs. |
| 11151 | * The FW can still send Flow control frames if enabled. |
| 11152 | */ |
| 11153 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11154 | pf->main_vsi_seid); |
| 11155 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 11156 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
| 11157 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
| 11158 | pf->flags |= I40E_FLAG_HAVE_10GBASET_PHY; |
| 11159 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11160 | /* print a string summarizing features */ |
| 11161 | i40e_print_features(pf); |
| 11162 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11163 | return 0; |
| 11164 | |
| 11165 | /* Unwind what we've done if something failed in the setup */ |
| 11166 | err_vsis: |
| 11167 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11168 | i40e_clear_interrupt_scheme(pf); |
| 11169 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11170 | err_switch_setup: |
| 11171 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11172 | del_timer_sync(&pf->service_timer); |
| 11173 | err_mac_addr: |
| 11174 | err_configure_lan_hmc: |
| 11175 | (void)i40e_shutdown_lan_hmc(hw); |
| 11176 | err_init_lan_hmc: |
| 11177 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11178 | err_sw_init: |
| 11179 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11180 | err_pf_reset: |
| 11181 | iounmap(hw->hw_addr); |
| 11182 | err_ioremap: |
| 11183 | kfree(pf); |
| 11184 | err_pf_alloc: |
| 11185 | pci_disable_pcie_error_reporting(pdev); |
| 11186 | pci_release_selected_regions(pdev, |
| 11187 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 11188 | err_pci_reg: |
| 11189 | err_dma: |
| 11190 | pci_disable_device(pdev); |
| 11191 | return err; |
| 11192 | } |
| 11193 | |
| 11194 | /** |
| 11195 | * i40e_remove - Device removal routine |
| 11196 | * @pdev: PCI device information struct |
| 11197 | * |
| 11198 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11199 | * that is should release a PCI device. This could be caused by a |
| 11200 | * Hot-Plug event, or because the driver is going to be removed from |
| 11201 | * memory. |
| 11202 | **/ |
| 11203 | static void i40e_remove(struct pci_dev *pdev) |
| 11204 | { |
| 11205 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11206 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11207 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11208 | int i; |
| 11209 | |
| 11210 | i40e_dbg_pf_exit(pf); |
| 11211 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11212 | i40e_ptp_stop(pf); |
| 11213 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11214 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 11215 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 11216 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11217 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11218 | /* no more scheduling of any task */ |
Pandi Kumar Maharajan | a4618ec | 2016-02-18 09:19:25 -0800 | [diff] [blame] | 11219 | set_bit(__I40E_SUSPENDED, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11220 | set_bit(__I40E_DOWN, &pf->state); |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 11221 | if (pf->service_timer.data) |
| 11222 | del_timer_sync(&pf->service_timer); |
| 11223 | if (pf->service_task.func) |
| 11224 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11225 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11226 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11227 | i40e_free_vfs(pf); |
| 11228 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11229 | } |
| 11230 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11231 | i40e_fdir_teardown(pf); |
| 11232 | |
| 11233 | /* If there is a switch structure or any orphans, remove them. |
| 11234 | * This will leave only the PF's VSI remaining. |
| 11235 | */ |
| 11236 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11237 | if (!pf->veb[i]) |
| 11238 | continue; |
| 11239 | |
| 11240 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11241 | pf->veb[i]->uplink_seid == 0) |
| 11242 | i40e_switch_branch_release(pf->veb[i]); |
| 11243 | } |
| 11244 | |
| 11245 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11246 | * adminq and hmc. |
| 11247 | */ |
| 11248 | if (pf->vsi[pf->lan_vsi]) |
| 11249 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11250 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11251 | /* remove attached clients */ |
| 11252 | ret_code = i40e_lan_del_device(pf); |
| 11253 | if (ret_code) { |
| 11254 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 11255 | ret_code); |
| 11256 | } |
| 11257 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11258 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11259 | if (hw->hmc.hmc_obj) { |
| 11260 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11261 | if (ret_code) |
| 11262 | dev_warn(&pdev->dev, |
| 11263 | "Failed to destroy the HMC resources: %d\n", |
| 11264 | ret_code); |
| 11265 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11266 | |
| 11267 | /* shutdown the adminq */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11268 | ret_code = i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11269 | if (ret_code) |
| 11270 | dev_warn(&pdev->dev, |
| 11271 | "Failed to destroy the Admin Queue resources: %d\n", |
| 11272 | ret_code); |
| 11273 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11274 | /* destroy the locks only once, here */ |
| 11275 | mutex_destroy(&hw->aq.arq_mutex); |
| 11276 | mutex_destroy(&hw->aq.asq_mutex); |
| 11277 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11278 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11279 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11280 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11281 | if (pf->vsi[i]) { |
| 11282 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11283 | i40e_vsi_clear(pf->vsi[i]); |
| 11284 | pf->vsi[i] = NULL; |
| 11285 | } |
| 11286 | } |
| 11287 | |
| 11288 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11289 | kfree(pf->veb[i]); |
| 11290 | pf->veb[i] = NULL; |
| 11291 | } |
| 11292 | |
| 11293 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11294 | kfree(pf->vsi); |
| 11295 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11296 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11297 | kfree(pf); |
| 11298 | pci_release_selected_regions(pdev, |
| 11299 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 11300 | |
| 11301 | pci_disable_pcie_error_reporting(pdev); |
| 11302 | pci_disable_device(pdev); |
| 11303 | } |
| 11304 | |
| 11305 | /** |
| 11306 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11307 | * @pdev: PCI device information struct |
| 11308 | * |
| 11309 | * Called to warn that something happened and the error handling steps |
| 11310 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11311 | * remediation. |
| 11312 | **/ |
| 11313 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11314 | enum pci_channel_state error) |
| 11315 | { |
| 11316 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11317 | |
| 11318 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11319 | |
| 11320 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11321 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11322 | rtnl_lock(); |
| 11323 | i40e_prep_for_reset(pf); |
| 11324 | rtnl_unlock(); |
| 11325 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11326 | |
| 11327 | /* Request a slot reset */ |
| 11328 | return PCI_ERS_RESULT_NEED_RESET; |
| 11329 | } |
| 11330 | |
| 11331 | /** |
| 11332 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11333 | * @pdev: PCI device information struct |
| 11334 | * |
| 11335 | * Called to find if the driver can work with the device now that |
| 11336 | * the pci slot has been reset. If a basic connection seems good |
| 11337 | * (registers are readable and have sane content) then return a |
| 11338 | * happy little PCI_ERS_RESULT_xxx. |
| 11339 | **/ |
| 11340 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11341 | { |
| 11342 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11343 | pci_ers_result_t result; |
| 11344 | int err; |
| 11345 | u32 reg; |
| 11346 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11347 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11348 | if (pci_enable_device_mem(pdev)) { |
| 11349 | dev_info(&pdev->dev, |
| 11350 | "Cannot re-enable PCI device after reset.\n"); |
| 11351 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11352 | } else { |
| 11353 | pci_set_master(pdev); |
| 11354 | pci_restore_state(pdev); |
| 11355 | pci_save_state(pdev); |
| 11356 | pci_wake_from_d3(pdev, false); |
| 11357 | |
| 11358 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11359 | if (reg == 0) |
| 11360 | result = PCI_ERS_RESULT_RECOVERED; |
| 11361 | else |
| 11362 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11363 | } |
| 11364 | |
| 11365 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11366 | if (err) { |
| 11367 | dev_info(&pdev->dev, |
| 11368 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11369 | err); |
| 11370 | /* non-fatal, continue */ |
| 11371 | } |
| 11372 | |
| 11373 | return result; |
| 11374 | } |
| 11375 | |
| 11376 | /** |
| 11377 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11378 | * @pdev: PCI device information struct |
| 11379 | * |
| 11380 | * Called to allow the driver to bring things back up after PCI error |
| 11381 | * and/or reset recovery has finished. |
| 11382 | **/ |
| 11383 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11384 | { |
| 11385 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11386 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11387 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11388 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 11389 | return; |
| 11390 | |
| 11391 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11392 | i40e_handle_reset_warning(pf); |
Vasily Averin | 4c4935a | 2015-07-08 15:04:26 +0300 | [diff] [blame] | 11393 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11394 | } |
| 11395 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11396 | /** |
| 11397 | * i40e_shutdown - PCI callback for shutting down |
| 11398 | * @pdev: PCI device information struct |
| 11399 | **/ |
| 11400 | static void i40e_shutdown(struct pci_dev *pdev) |
| 11401 | { |
| 11402 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11403 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11404 | |
| 11405 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11406 | set_bit(__I40E_DOWN, &pf->state); |
| 11407 | rtnl_lock(); |
| 11408 | i40e_prep_for_reset(pf); |
| 11409 | rtnl_unlock(); |
| 11410 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11411 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11412 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11413 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11414 | del_timer_sync(&pf->service_timer); |
| 11415 | cancel_work_sync(&pf->service_task); |
| 11416 | i40e_fdir_teardown(pf); |
| 11417 | |
| 11418 | rtnl_lock(); |
| 11419 | i40e_prep_for_reset(pf); |
| 11420 | rtnl_unlock(); |
| 11421 | |
| 11422 | wr32(hw, I40E_PFPM_APM, |
| 11423 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11424 | wr32(hw, I40E_PFPM_WUFC, |
| 11425 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11426 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 11427 | i40e_clear_interrupt_scheme(pf); |
| 11428 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11429 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11430 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11431 | pci_set_power_state(pdev, PCI_D3hot); |
| 11432 | } |
| 11433 | } |
| 11434 | |
| 11435 | #ifdef CONFIG_PM |
| 11436 | /** |
| 11437 | * i40e_suspend - PCI callback for moving to D3 |
| 11438 | * @pdev: PCI device information struct |
| 11439 | **/ |
| 11440 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11441 | { |
| 11442 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11443 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11444 | |
| 11445 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11446 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 11447 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11448 | rtnl_lock(); |
| 11449 | i40e_prep_for_reset(pf); |
| 11450 | rtnl_unlock(); |
| 11451 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11452 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11453 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11454 | |
Greg Rose | b33d3b7 | 2016-05-16 10:26:37 -0700 | [diff] [blame^] | 11455 | i40e_stop_misc_vector(pf); |
| 11456 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11457 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11458 | pci_set_power_state(pdev, PCI_D3hot); |
| 11459 | |
| 11460 | return 0; |
| 11461 | } |
| 11462 | |
| 11463 | /** |
| 11464 | * i40e_resume - PCI callback for waking up from D3 |
| 11465 | * @pdev: PCI device information struct |
| 11466 | **/ |
| 11467 | static int i40e_resume(struct pci_dev *pdev) |
| 11468 | { |
| 11469 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11470 | u32 err; |
| 11471 | |
| 11472 | pci_set_power_state(pdev, PCI_D0); |
| 11473 | pci_restore_state(pdev); |
| 11474 | /* pci_restore_state() clears dev->state_saves, so |
| 11475 | * call pci_save_state() again to restore it. |
| 11476 | */ |
| 11477 | pci_save_state(pdev); |
| 11478 | |
| 11479 | err = pci_enable_device_mem(pdev); |
| 11480 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11481 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11482 | return err; |
| 11483 | } |
| 11484 | pci_set_master(pdev); |
| 11485 | |
| 11486 | /* no wakeup events while running */ |
| 11487 | pci_wake_from_d3(pdev, false); |
| 11488 | |
| 11489 | /* handling the reset will rebuild the device state */ |
| 11490 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11491 | clear_bit(__I40E_DOWN, &pf->state); |
| 11492 | rtnl_lock(); |
| 11493 | i40e_reset_and_rebuild(pf, false); |
| 11494 | rtnl_unlock(); |
| 11495 | } |
| 11496 | |
| 11497 | return 0; |
| 11498 | } |
| 11499 | |
| 11500 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11501 | static const struct pci_error_handlers i40e_err_handler = { |
| 11502 | .error_detected = i40e_pci_error_detected, |
| 11503 | .slot_reset = i40e_pci_error_slot_reset, |
| 11504 | .resume = i40e_pci_error_resume, |
| 11505 | }; |
| 11506 | |
| 11507 | static struct pci_driver i40e_driver = { |
| 11508 | .name = i40e_driver_name, |
| 11509 | .id_table = i40e_pci_tbl, |
| 11510 | .probe = i40e_probe, |
| 11511 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11512 | #ifdef CONFIG_PM |
| 11513 | .suspend = i40e_suspend, |
| 11514 | .resume = i40e_resume, |
| 11515 | #endif |
| 11516 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11517 | .err_handler = &i40e_err_handler, |
| 11518 | .sriov_configure = i40e_pci_sriov_configure, |
| 11519 | }; |
| 11520 | |
| 11521 | /** |
| 11522 | * i40e_init_module - Driver registration routine |
| 11523 | * |
| 11524 | * i40e_init_module is the first routine called when the driver is |
| 11525 | * loaded. All it does is register with the PCI subsystem. |
| 11526 | **/ |
| 11527 | static int __init i40e_init_module(void) |
| 11528 | { |
| 11529 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 11530 | i40e_driver_string, i40e_driver_version_str); |
| 11531 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 11532 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11533 | /* we will see if single thread per module is enough for now, |
| 11534 | * it can't be any worse than using the system workqueue which |
| 11535 | * was already single threaded |
| 11536 | */ |
| 11537 | i40e_wq = create_singlethread_workqueue(i40e_driver_name); |
| 11538 | if (!i40e_wq) { |
| 11539 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 11540 | return -ENOMEM; |
| 11541 | } |
| 11542 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11543 | i40e_dbg_init(); |
| 11544 | return pci_register_driver(&i40e_driver); |
| 11545 | } |
| 11546 | module_init(i40e_init_module); |
| 11547 | |
| 11548 | /** |
| 11549 | * i40e_exit_module - Driver exit cleanup routine |
| 11550 | * |
| 11551 | * i40e_exit_module is called just before the driver is removed |
| 11552 | * from memory. |
| 11553 | **/ |
| 11554 | static void __exit i40e_exit_module(void) |
| 11555 | { |
| 11556 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11557 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11558 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11559 | } |
| 11560 | module_exit(i40e_exit_module); |