Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2016 Intel Corporation. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 27 | #include <linux/etherdevice.h> |
| 28 | #include <linux/of_net.h> |
| 29 | #include <linux/pci.h> |
| 30 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 31 | /* Local includes */ |
| 32 | #include "i40e.h" |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 33 | #include "i40e_diag.h" |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 34 | #include <net/udp_tunnel.h> |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 35 | |
| 36 | const char i40e_driver_name[] = "i40e"; |
| 37 | static const char i40e_driver_string[] = |
| 38 | "Intel(R) Ethernet Connection XL710 Network Driver"; |
| 39 | |
| 40 | #define DRV_KERN "-k" |
| 41 | |
Catherine Sullivan | e8e724d | 2014-07-10 07:58:26 +0000 | [diff] [blame] | 42 | #define DRV_VERSION_MAJOR 1 |
Bimmy Pujari | 0706195 | 2016-05-16 10:26:45 -0700 | [diff] [blame] | 43 | #define DRV_VERSION_MINOR 6 |
Bimmy Pujari | cf465fe | 2016-09-27 11:28:54 -0700 | [diff] [blame] | 44 | #define DRV_VERSION_BUILD 21 |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 45 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 46 | __stringify(DRV_VERSION_MINOR) "." \ |
| 47 | __stringify(DRV_VERSION_BUILD) DRV_KERN |
| 48 | const char i40e_driver_version_str[] = DRV_VERSION; |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 49 | static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation."; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 50 | |
| 51 | /* a bit of forward declarations */ |
| 52 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); |
| 53 | static void i40e_handle_reset_warning(struct i40e_pf *pf); |
| 54 | static int i40e_add_vsi(struct i40e_vsi *vsi); |
| 55 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 56 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 57 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
| 58 | static void i40e_determine_queue_usage(struct i40e_pf *pf); |
| 59 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 60 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 61 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 62 | |
| 63 | /* i40e_pci_tbl - PCI Device ID Table |
| 64 | * |
| 65 | * Last entry must be all 0s |
| 66 | * |
| 67 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 68 | * Class, Class Mask, private data (not used) } |
| 69 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 70 | static const struct pci_device_id i40e_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 71 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 72 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 73 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, |
| 74 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 75 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, |
| 76 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, |
| 77 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 78 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0}, |
Shannon Nelson | bc5166b9 | 2015-08-26 15:14:10 -0400 | [diff] [blame] | 79 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0}, |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 80 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
Anjali Singhai Jain | 35dae51 | 2015-12-22 14:25:03 -0800 | [diff] [blame] | 81 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0}, |
| 82 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame] | 83 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0}, |
| 84 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0}, |
| 85 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0}, |
Catherine Sullivan | d6bf58c | 2016-03-18 12:18:08 -0700 | [diff] [blame] | 86 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0}, |
Shannon Nelson | 48a3b51 | 2015-07-23 16:54:39 -0400 | [diff] [blame] | 87 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
| 88 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 89 | /* required last entry */ |
| 90 | {0, } |
| 91 | }; |
| 92 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 93 | |
| 94 | #define I40E_MAX_VF_COUNT 128 |
| 95 | static int debug = -1; |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 96 | module_param(debug, uint, 0); |
| 97 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 98 | |
| 99 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 100 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 101 | MODULE_LICENSE("GPL"); |
| 102 | MODULE_VERSION(DRV_VERSION); |
| 103 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 104 | static struct workqueue_struct *i40e_wq; |
| 105 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 106 | /** |
| 107 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 108 | * @hw: pointer to the HW structure |
| 109 | * @mem: ptr to mem struct to fill out |
| 110 | * @size: size of memory requested |
| 111 | * @alignment: what to align the allocation to |
| 112 | **/ |
| 113 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 114 | u64 size, u32 alignment) |
| 115 | { |
| 116 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 117 | |
| 118 | mem->size = ALIGN(size, alignment); |
| 119 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 120 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 121 | if (!mem->va) |
| 122 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 123 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 124 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /** |
| 128 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 129 | * @hw: pointer to the HW structure |
| 130 | * @mem: ptr to mem struct to free |
| 131 | **/ |
| 132 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 133 | { |
| 134 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 135 | |
| 136 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 137 | mem->va = NULL; |
| 138 | mem->pa = 0; |
| 139 | mem->size = 0; |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 146 | * @hw: pointer to the HW structure |
| 147 | * @mem: ptr to mem struct to fill out |
| 148 | * @size: size of memory requested |
| 149 | **/ |
| 150 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 151 | u32 size) |
| 152 | { |
| 153 | mem->size = size; |
| 154 | mem->va = kzalloc(size, GFP_KERNEL); |
| 155 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 156 | if (!mem->va) |
| 157 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 158 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 159 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /** |
| 163 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 164 | * @hw: pointer to the HW structure |
| 165 | * @mem: ptr to mem struct to free |
| 166 | **/ |
| 167 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 168 | { |
| 169 | /* it's ok to kfree a NULL pointer */ |
| 170 | kfree(mem->va); |
| 171 | mem->va = NULL; |
| 172 | mem->size = 0; |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * i40e_get_lump - find a lump of free generic resource |
| 179 | * @pf: board private structure |
| 180 | * @pile: the pile of resource to search |
| 181 | * @needed: the number of items needed |
| 182 | * @id: an owner id to stick on the items assigned |
| 183 | * |
| 184 | * Returns the base item index of the lump, or negative for error |
| 185 | * |
| 186 | * The search_hint trick and lack of advanced fit-finding only work |
| 187 | * because we're highly likely to have all the same size lump requests. |
| 188 | * Linear search time and any fragmentation should be minimal. |
| 189 | **/ |
| 190 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 191 | u16 needed, u16 id) |
| 192 | { |
| 193 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 194 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 195 | |
| 196 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 197 | dev_info(&pf->pdev->dev, |
| 198 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 199 | pile, needed, id); |
| 200 | return -EINVAL; |
| 201 | } |
| 202 | |
| 203 | /* start the linear search with an imperfect hint */ |
| 204 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 205 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 206 | /* skip already allocated entries */ |
| 207 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 208 | i++; |
| 209 | continue; |
| 210 | } |
| 211 | |
| 212 | /* do we have enough in this lump? */ |
| 213 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 214 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 215 | break; |
| 216 | } |
| 217 | |
| 218 | if (j == needed) { |
| 219 | /* there was enough, so assign it to the requestor */ |
| 220 | for (j = 0; j < needed; j++) |
| 221 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 222 | ret = i; |
| 223 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 224 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 225 | } |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 226 | |
| 227 | /* not enough, so skip over it and continue looking */ |
| 228 | i += j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | return ret; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * i40e_put_lump - return a lump of generic resource |
| 236 | * @pile: the pile of resource to search |
| 237 | * @index: the base item index |
| 238 | * @id: the owner id of the items assigned |
| 239 | * |
| 240 | * Returns the count of items in the lump |
| 241 | **/ |
| 242 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 243 | { |
| 244 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 245 | int count = 0; |
| 246 | int i; |
| 247 | |
| 248 | if (!pile || index >= pile->num_entries) |
| 249 | return -EINVAL; |
| 250 | |
| 251 | for (i = index; |
| 252 | i < pile->num_entries && pile->list[i] == valid_id; |
| 253 | i++) { |
| 254 | pile->list[i] = 0; |
| 255 | count++; |
| 256 | } |
| 257 | |
| 258 | if (count && index < pile->search_hint) |
| 259 | pile->search_hint = index; |
| 260 | |
| 261 | return count; |
| 262 | } |
| 263 | |
| 264 | /** |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 265 | * i40e_find_vsi_from_id - searches for the vsi with the given id |
| 266 | * @pf - the pf structure to search for the vsi |
| 267 | * @id - id of the vsi it is searching for |
| 268 | **/ |
| 269 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) |
| 270 | { |
| 271 | int i; |
| 272 | |
| 273 | for (i = 0; i < pf->num_alloc_vsi; i++) |
| 274 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) |
| 275 | return pf->vsi[i]; |
| 276 | |
| 277 | return NULL; |
| 278 | } |
| 279 | |
| 280 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 281 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 282 | * @pf: board private structure |
| 283 | * |
| 284 | * If not already scheduled, this puts the task into the work queue |
| 285 | **/ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 286 | void i40e_service_event_schedule(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 287 | { |
| 288 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 289 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && |
| 290 | !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 291 | queue_work(i40e_wq, &pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /** |
| 295 | * i40e_tx_timeout - Respond to a Tx Hang |
| 296 | * @netdev: network interface device structure |
| 297 | * |
| 298 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 299 | * device is munged, not just the one netdev port, so go for the full |
| 300 | * reset. |
| 301 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 302 | #ifdef I40E_FCOE |
| 303 | void i40e_tx_timeout(struct net_device *netdev) |
| 304 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 305 | static void i40e_tx_timeout(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 306 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 307 | { |
| 308 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 309 | struct i40e_vsi *vsi = np->vsi; |
| 310 | struct i40e_pf *pf = vsi->back; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 311 | struct i40e_ring *tx_ring = NULL; |
| 312 | unsigned int i, hung_queue = 0; |
| 313 | u32 head, val; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 314 | |
| 315 | pf->tx_timeout_count++; |
| 316 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 317 | /* find the stopped queue the same way the stack does */ |
| 318 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 319 | struct netdev_queue *q; |
| 320 | unsigned long trans_start; |
| 321 | |
| 322 | q = netdev_get_tx_queue(netdev, i); |
Florian Westphal | 9b36627 | 2016-05-03 16:33:14 +0200 | [diff] [blame] | 323 | trans_start = q->trans_start; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 324 | if (netif_xmit_stopped(q) && |
| 325 | time_after(jiffies, |
| 326 | (trans_start + netdev->watchdog_timeo))) { |
| 327 | hung_queue = i; |
| 328 | break; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | if (i == netdev->num_tx_queues) { |
| 333 | netdev_info(netdev, "tx_timeout: no netdev hung queue found\n"); |
| 334 | } else { |
| 335 | /* now that we have an index, find the tx_ring struct */ |
| 336 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 337 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 338 | if (hung_queue == |
| 339 | vsi->tx_rings[i]->queue_index) { |
| 340 | tx_ring = vsi->tx_rings[i]; |
| 341 | break; |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 347 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 348 | pf->tx_timeout_recovery_level = 1; /* reset after some time */ |
| 349 | else if (time_before(jiffies, |
| 350 | (pf->tx_timeout_last_recovery + netdev->watchdog_timeo))) |
| 351 | return; /* don't do any new action before the next timeout */ |
| 352 | |
| 353 | if (tx_ring) { |
| 354 | head = i40e_get_head(tx_ring); |
| 355 | /* Read interrupt register */ |
| 356 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 357 | val = rd32(&pf->hw, |
| 358 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 359 | tx_ring->vsi->base_vector - 1)); |
| 360 | else |
| 361 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 362 | |
| 363 | netdev_info(netdev, "tx_timeout: VSI_seid: %d, Q %d, NTC: 0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x, INT: 0x%x\n", |
| 364 | vsi->seid, hung_queue, tx_ring->next_to_clean, |
| 365 | head, tx_ring->next_to_use, |
| 366 | readl(tx_ring->tail), val); |
| 367 | } |
| 368 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 369 | pf->tx_timeout_last_recovery = jiffies; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 370 | netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n", |
| 371 | pf->tx_timeout_recovery_level, hung_queue); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 372 | |
| 373 | switch (pf->tx_timeout_recovery_level) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 374 | case 1: |
| 375 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 376 | break; |
| 377 | case 2: |
| 378 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 379 | break; |
| 380 | case 3: |
| 381 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 382 | break; |
| 383 | default: |
| 384 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 385 | break; |
| 386 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 387 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 388 | i40e_service_event_schedule(pf); |
| 389 | pf->tx_timeout_recovery_level++; |
| 390 | } |
| 391 | |
| 392 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 393 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 394 | * @vsi: the VSI we care about |
| 395 | * |
| 396 | * Returns the address of the device statistics structure. |
| 397 | * The statistics are actually updated from the service task. |
| 398 | **/ |
| 399 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 400 | { |
| 401 | return &vsi->net_stats; |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 406 | * @netdev: network interface device structure |
| 407 | * |
| 408 | * Returns the address of the device statistics structure. |
| 409 | * The statistics are actually updated from the service task. |
| 410 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 411 | #ifdef I40E_FCOE |
| 412 | struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 413 | struct net_device *netdev, |
| 414 | struct rtnl_link_stats64 *stats) |
| 415 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 416 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 417 | struct net_device *netdev, |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 418 | struct rtnl_link_stats64 *stats) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 419 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 420 | { |
| 421 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 422 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 423 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 424 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 425 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 426 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 427 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 428 | return stats; |
| 429 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 430 | if (!vsi->tx_rings) |
| 431 | return stats; |
| 432 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 433 | rcu_read_lock(); |
| 434 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 435 | u64 bytes, packets; |
| 436 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 437 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 438 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 439 | if (!tx_ring) |
| 440 | continue; |
| 441 | |
| 442 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 443 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 444 | packets = tx_ring->stats.packets; |
| 445 | bytes = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 446 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 447 | |
| 448 | stats->tx_packets += packets; |
| 449 | stats->tx_bytes += bytes; |
| 450 | rx_ring = &tx_ring[1]; |
| 451 | |
| 452 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 453 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 454 | packets = rx_ring->stats.packets; |
| 455 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 456 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 457 | |
| 458 | stats->rx_packets += packets; |
| 459 | stats->rx_bytes += bytes; |
| 460 | } |
| 461 | rcu_read_unlock(); |
| 462 | |
Akeem G Abodunrin | a5282f4 | 2014-05-10 04:49:03 +0000 | [diff] [blame] | 463 | /* following stats updated by i40e_watchdog_subtask() */ |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 464 | stats->multicast = vsi_stats->multicast; |
| 465 | stats->tx_errors = vsi_stats->tx_errors; |
| 466 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 467 | stats->rx_errors = vsi_stats->rx_errors; |
Jesse Brandeburg | d8201e2 | 2015-07-23 16:54:35 -0400 | [diff] [blame] | 468 | stats->rx_dropped = vsi_stats->rx_dropped; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 469 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 470 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
| 471 | |
| 472 | return stats; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /** |
| 476 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 477 | * @vsi: the VSI to have its stats reset |
| 478 | **/ |
| 479 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 480 | { |
| 481 | struct rtnl_link_stats64 *ns; |
| 482 | int i; |
| 483 | |
| 484 | if (!vsi) |
| 485 | return; |
| 486 | |
| 487 | ns = i40e_get_vsi_stats_struct(vsi); |
| 488 | memset(ns, 0, sizeof(*ns)); |
| 489 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 490 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 491 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 492 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 493 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 494 | memset(&vsi->rx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 495 | sizeof(vsi->rx_rings[i]->stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 496 | memset(&vsi->rx_rings[i]->rx_stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 497 | sizeof(vsi->rx_rings[i]->rx_stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 498 | memset(&vsi->tx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 499 | sizeof(vsi->tx_rings[i]->stats)); |
| 500 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 501 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 502 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 503 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 504 | vsi->stat_offsets_loaded = false; |
| 505 | } |
| 506 | |
| 507 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 508 | * i40e_pf_reset_stats - Reset all of the stats for the given PF |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 509 | * @pf: the PF to be reset |
| 510 | **/ |
| 511 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 512 | { |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 513 | int i; |
| 514 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 515 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 516 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 517 | pf->stat_offsets_loaded = false; |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 518 | |
| 519 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 520 | if (pf->veb[i]) { |
| 521 | memset(&pf->veb[i]->stats, 0, |
| 522 | sizeof(pf->veb[i]->stats)); |
| 523 | memset(&pf->veb[i]->stats_offsets, 0, |
| 524 | sizeof(pf->veb[i]->stats_offsets)); |
| 525 | pf->veb[i]->stat_offsets_loaded = false; |
| 526 | } |
| 527 | } |
Catherine Sullivan | 42bce04 | 2016-07-27 12:02:32 -0700 | [diff] [blame] | 528 | pf->hw_csum_rx_error = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /** |
| 532 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 533 | * @hw: ptr to the hardware info |
| 534 | * @hireg: the high 32 bit reg to read |
| 535 | * @loreg: the low 32 bit reg to read |
| 536 | * @offset_loaded: has the initial offset been loaded yet |
| 537 | * @offset: ptr to current offset value |
| 538 | * @stat: ptr to the stat |
| 539 | * |
| 540 | * Since the device stats are not reset at PFReset, they likely will not |
| 541 | * be zeroed when the driver starts. We'll save the first values read |
| 542 | * and use them as offsets to be subtracted from the raw values in order |
| 543 | * to report stats that count from zero. In the process, we also manage |
| 544 | * the potential roll-over. |
| 545 | **/ |
| 546 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 547 | bool offset_loaded, u64 *offset, u64 *stat) |
| 548 | { |
| 549 | u64 new_data; |
| 550 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 551 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 552 | new_data = rd32(hw, loreg); |
| 553 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 554 | } else { |
| 555 | new_data = rd64(hw, loreg); |
| 556 | } |
| 557 | if (!offset_loaded) |
| 558 | *offset = new_data; |
| 559 | if (likely(new_data >= *offset)) |
| 560 | *stat = new_data - *offset; |
| 561 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 562 | *stat = (new_data + BIT_ULL(48)) - *offset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 563 | *stat &= 0xFFFFFFFFFFFFULL; |
| 564 | } |
| 565 | |
| 566 | /** |
| 567 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 568 | * @hw: ptr to the hardware info |
| 569 | * @reg: the hw reg to read |
| 570 | * @offset_loaded: has the initial offset been loaded yet |
| 571 | * @offset: ptr to current offset value |
| 572 | * @stat: ptr to the stat |
| 573 | **/ |
| 574 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 575 | bool offset_loaded, u64 *offset, u64 *stat) |
| 576 | { |
| 577 | u32 new_data; |
| 578 | |
| 579 | new_data = rd32(hw, reg); |
| 580 | if (!offset_loaded) |
| 581 | *offset = new_data; |
| 582 | if (likely(new_data >= *offset)) |
| 583 | *stat = (u32)(new_data - *offset); |
| 584 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 585 | *stat = (u32)((new_data + BIT_ULL(32)) - *offset); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /** |
| 589 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 590 | * @vsi: the VSI to be updated |
| 591 | **/ |
| 592 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 593 | { |
| 594 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 595 | struct i40e_pf *pf = vsi->back; |
| 596 | struct i40e_hw *hw = &pf->hw; |
| 597 | struct i40e_eth_stats *oes; |
| 598 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 599 | |
| 600 | es = &vsi->eth_stats; |
| 601 | oes = &vsi->eth_stats_offsets; |
| 602 | |
| 603 | /* Gather up the stats that the hw collects */ |
| 604 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 605 | vsi->stat_offsets_loaded, |
| 606 | &oes->tx_errors, &es->tx_errors); |
| 607 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 608 | vsi->stat_offsets_loaded, |
| 609 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 610 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 611 | vsi->stat_offsets_loaded, |
| 612 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 613 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 614 | vsi->stat_offsets_loaded, |
| 615 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 616 | |
| 617 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 618 | I40E_GLV_GORCL(stat_idx), |
| 619 | vsi->stat_offsets_loaded, |
| 620 | &oes->rx_bytes, &es->rx_bytes); |
| 621 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 622 | I40E_GLV_UPRCL(stat_idx), |
| 623 | vsi->stat_offsets_loaded, |
| 624 | &oes->rx_unicast, &es->rx_unicast); |
| 625 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 626 | I40E_GLV_MPRCL(stat_idx), |
| 627 | vsi->stat_offsets_loaded, |
| 628 | &oes->rx_multicast, &es->rx_multicast); |
| 629 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 630 | I40E_GLV_BPRCL(stat_idx), |
| 631 | vsi->stat_offsets_loaded, |
| 632 | &oes->rx_broadcast, &es->rx_broadcast); |
| 633 | |
| 634 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 635 | I40E_GLV_GOTCL(stat_idx), |
| 636 | vsi->stat_offsets_loaded, |
| 637 | &oes->tx_bytes, &es->tx_bytes); |
| 638 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 639 | I40E_GLV_UPTCL(stat_idx), |
| 640 | vsi->stat_offsets_loaded, |
| 641 | &oes->tx_unicast, &es->tx_unicast); |
| 642 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 643 | I40E_GLV_MPTCL(stat_idx), |
| 644 | vsi->stat_offsets_loaded, |
| 645 | &oes->tx_multicast, &es->tx_multicast); |
| 646 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 647 | I40E_GLV_BPTCL(stat_idx), |
| 648 | vsi->stat_offsets_loaded, |
| 649 | &oes->tx_broadcast, &es->tx_broadcast); |
| 650 | vsi->stat_offsets_loaded = true; |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * i40e_update_veb_stats - Update Switch component statistics |
| 655 | * @veb: the VEB being updated |
| 656 | **/ |
| 657 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 658 | { |
| 659 | struct i40e_pf *pf = veb->pf; |
| 660 | struct i40e_hw *hw = &pf->hw; |
| 661 | struct i40e_eth_stats *oes; |
| 662 | struct i40e_eth_stats *es; /* device's eth stats */ |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 663 | struct i40e_veb_tc_stats *veb_oes; |
| 664 | struct i40e_veb_tc_stats *veb_es; |
| 665 | int i, idx = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 666 | |
| 667 | idx = veb->stats_idx; |
| 668 | es = &veb->stats; |
| 669 | oes = &veb->stats_offsets; |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 670 | veb_es = &veb->tc_stats; |
| 671 | veb_oes = &veb->tc_stats_offsets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 672 | |
| 673 | /* Gather up the stats that the hw collects */ |
| 674 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 675 | veb->stat_offsets_loaded, |
| 676 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 677 | if (hw->revision_id > 0) |
| 678 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 679 | veb->stat_offsets_loaded, |
| 680 | &oes->rx_unknown_protocol, |
| 681 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 682 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 683 | veb->stat_offsets_loaded, |
| 684 | &oes->rx_bytes, &es->rx_bytes); |
| 685 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 686 | veb->stat_offsets_loaded, |
| 687 | &oes->rx_unicast, &es->rx_unicast); |
| 688 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 689 | veb->stat_offsets_loaded, |
| 690 | &oes->rx_multicast, &es->rx_multicast); |
| 691 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 692 | veb->stat_offsets_loaded, |
| 693 | &oes->rx_broadcast, &es->rx_broadcast); |
| 694 | |
| 695 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 696 | veb->stat_offsets_loaded, |
| 697 | &oes->tx_bytes, &es->tx_bytes); |
| 698 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 699 | veb->stat_offsets_loaded, |
| 700 | &oes->tx_unicast, &es->tx_unicast); |
| 701 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 702 | veb->stat_offsets_loaded, |
| 703 | &oes->tx_multicast, &es->tx_multicast); |
| 704 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 705 | veb->stat_offsets_loaded, |
| 706 | &oes->tx_broadcast, &es->tx_broadcast); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 707 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 708 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), |
| 709 | I40E_GLVEBTC_RPCL(i, idx), |
| 710 | veb->stat_offsets_loaded, |
| 711 | &veb_oes->tc_rx_packets[i], |
| 712 | &veb_es->tc_rx_packets[i]); |
| 713 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), |
| 714 | I40E_GLVEBTC_RBCL(i, idx), |
| 715 | veb->stat_offsets_loaded, |
| 716 | &veb_oes->tc_rx_bytes[i], |
| 717 | &veb_es->tc_rx_bytes[i]); |
| 718 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), |
| 719 | I40E_GLVEBTC_TPCL(i, idx), |
| 720 | veb->stat_offsets_loaded, |
| 721 | &veb_oes->tc_tx_packets[i], |
| 722 | &veb_es->tc_tx_packets[i]); |
| 723 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), |
| 724 | I40E_GLVEBTC_TBCL(i, idx), |
| 725 | veb->stat_offsets_loaded, |
| 726 | &veb_oes->tc_tx_bytes[i], |
| 727 | &veb_es->tc_tx_bytes[i]); |
| 728 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 729 | veb->stat_offsets_loaded = true; |
| 730 | } |
| 731 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 732 | #ifdef I40E_FCOE |
| 733 | /** |
| 734 | * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters. |
| 735 | * @vsi: the VSI that is capable of doing FCoE |
| 736 | **/ |
| 737 | static void i40e_update_fcoe_stats(struct i40e_vsi *vsi) |
| 738 | { |
| 739 | struct i40e_pf *pf = vsi->back; |
| 740 | struct i40e_hw *hw = &pf->hw; |
| 741 | struct i40e_fcoe_stats *ofs; |
| 742 | struct i40e_fcoe_stats *fs; /* device's eth stats */ |
| 743 | int idx; |
| 744 | |
| 745 | if (vsi->type != I40E_VSI_FCOE) |
| 746 | return; |
| 747 | |
Kiran Patil | 4147e2c | 2016-01-15 14:33:14 -0800 | [diff] [blame] | 748 | idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 749 | fs = &vsi->fcoe_stats; |
| 750 | ofs = &vsi->fcoe_stats_offsets; |
| 751 | |
| 752 | i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx), |
| 753 | vsi->fcoe_stat_offsets_loaded, |
| 754 | &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets); |
| 755 | i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx), |
| 756 | vsi->fcoe_stat_offsets_loaded, |
| 757 | &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords); |
| 758 | i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx), |
| 759 | vsi->fcoe_stat_offsets_loaded, |
| 760 | &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped); |
| 761 | i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx), |
| 762 | vsi->fcoe_stat_offsets_loaded, |
| 763 | &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets); |
| 764 | i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx), |
| 765 | vsi->fcoe_stat_offsets_loaded, |
| 766 | &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords); |
| 767 | i40e_stat_update32(hw, I40E_GL_FCOECRC(idx), |
| 768 | vsi->fcoe_stat_offsets_loaded, |
| 769 | &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc); |
| 770 | i40e_stat_update32(hw, I40E_GL_FCOELAST(idx), |
| 771 | vsi->fcoe_stat_offsets_loaded, |
| 772 | &ofs->fcoe_last_error, &fs->fcoe_last_error); |
| 773 | i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx), |
| 774 | vsi->fcoe_stat_offsets_loaded, |
| 775 | &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count); |
| 776 | |
| 777 | vsi->fcoe_stat_offsets_loaded = true; |
| 778 | } |
| 779 | |
| 780 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 781 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 782 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 783 | * @vsi: the VSI to be updated |
| 784 | * |
| 785 | * There are a few instances where we store the same stat in a |
| 786 | * couple of different structs. This is partly because we have |
| 787 | * the netdev stats that need to be filled out, which is slightly |
| 788 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 789 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 790 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 791 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 792 | { |
| 793 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 794 | struct rtnl_link_stats64 *ons; |
| 795 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 796 | struct i40e_eth_stats *oes; |
| 797 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 798 | u32 tx_restart, tx_busy; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 799 | u64 tx_lost_interrupt; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 800 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 801 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 802 | u64 bytes, packets; |
| 803 | unsigned int start; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 804 | u64 tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 805 | u64 tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 806 | u64 rx_p, rx_b; |
| 807 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 808 | u16 q; |
| 809 | |
| 810 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 811 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 812 | return; |
| 813 | |
| 814 | ns = i40e_get_vsi_stats_struct(vsi); |
| 815 | ons = &vsi->net_stats_offsets; |
| 816 | es = &vsi->eth_stats; |
| 817 | oes = &vsi->eth_stats_offsets; |
| 818 | |
| 819 | /* Gather up the netdev and vsi stats that the driver collects |
| 820 | * on the fly during packet processing |
| 821 | */ |
| 822 | rx_b = rx_p = 0; |
| 823 | tx_b = tx_p = 0; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 824 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 825 | tx_lost_interrupt = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 826 | rx_page = 0; |
| 827 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 828 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 829 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 830 | /* locate Tx ring */ |
| 831 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 832 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 833 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 834 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 835 | packets = p->stats.packets; |
| 836 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 837 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 838 | tx_b += bytes; |
| 839 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 840 | tx_restart += p->tx_stats.restart_queue; |
| 841 | tx_busy += p->tx_stats.tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 842 | tx_linearize += p->tx_stats.tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 843 | tx_force_wb += p->tx_stats.tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 844 | tx_lost_interrupt += p->tx_stats.tx_lost_interrupt; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 845 | |
| 846 | /* Rx queue is part of the same block as Tx queue */ |
| 847 | p = &p[1]; |
| 848 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 849 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 850 | packets = p->stats.packets; |
| 851 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 852 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 853 | rx_b += bytes; |
| 854 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 855 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 856 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 857 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 858 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 859 | vsi->tx_restart = tx_restart; |
| 860 | vsi->tx_busy = tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 861 | vsi->tx_linearize = tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 862 | vsi->tx_force_wb = tx_force_wb; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 863 | vsi->tx_lost_interrupt = tx_lost_interrupt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 864 | vsi->rx_page_failed = rx_page; |
| 865 | vsi->rx_buf_failed = rx_buf; |
| 866 | |
| 867 | ns->rx_packets = rx_p; |
| 868 | ns->rx_bytes = rx_b; |
| 869 | ns->tx_packets = tx_p; |
| 870 | ns->tx_bytes = tx_b; |
| 871 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 872 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 873 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 874 | ons->tx_errors = oes->tx_errors; |
| 875 | ns->tx_errors = es->tx_errors; |
| 876 | ons->multicast = oes->rx_multicast; |
| 877 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 878 | ons->rx_dropped = oes->rx_discards; |
| 879 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 880 | ons->tx_dropped = oes->tx_discards; |
| 881 | ns->tx_dropped = es->tx_discards; |
| 882 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 883 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 884 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 885 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 886 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 887 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 888 | } |
| 889 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 890 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 891 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 892 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 893 | * @pf: the PF to be updated |
| 894 | **/ |
| 895 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 896 | { |
| 897 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 898 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 899 | struct i40e_hw *hw = &pf->hw; |
| 900 | u32 val; |
| 901 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 902 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 903 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 904 | I40E_GLPRT_GORCL(hw->port), |
| 905 | pf->stat_offsets_loaded, |
| 906 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 907 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 908 | I40E_GLPRT_GOTCL(hw->port), |
| 909 | pf->stat_offsets_loaded, |
| 910 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 911 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 912 | pf->stat_offsets_loaded, |
| 913 | &osd->eth.rx_discards, |
| 914 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 915 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 916 | I40E_GLPRT_UPRCL(hw->port), |
| 917 | pf->stat_offsets_loaded, |
| 918 | &osd->eth.rx_unicast, |
| 919 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 920 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 921 | I40E_GLPRT_MPRCL(hw->port), |
| 922 | pf->stat_offsets_loaded, |
| 923 | &osd->eth.rx_multicast, |
| 924 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 925 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 926 | I40E_GLPRT_BPRCL(hw->port), |
| 927 | pf->stat_offsets_loaded, |
| 928 | &osd->eth.rx_broadcast, |
| 929 | &nsd->eth.rx_broadcast); |
| 930 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 931 | I40E_GLPRT_UPTCL(hw->port), |
| 932 | pf->stat_offsets_loaded, |
| 933 | &osd->eth.tx_unicast, |
| 934 | &nsd->eth.tx_unicast); |
| 935 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 936 | I40E_GLPRT_MPTCL(hw->port), |
| 937 | pf->stat_offsets_loaded, |
| 938 | &osd->eth.tx_multicast, |
| 939 | &nsd->eth.tx_multicast); |
| 940 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 941 | I40E_GLPRT_BPTCL(hw->port), |
| 942 | pf->stat_offsets_loaded, |
| 943 | &osd->eth.tx_broadcast, |
| 944 | &nsd->eth.tx_broadcast); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 945 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 946 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 947 | pf->stat_offsets_loaded, |
| 948 | &osd->tx_dropped_link_down, |
| 949 | &nsd->tx_dropped_link_down); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 950 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 951 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 952 | pf->stat_offsets_loaded, |
| 953 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 954 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 955 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 956 | pf->stat_offsets_loaded, |
| 957 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 958 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 959 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 960 | pf->stat_offsets_loaded, |
| 961 | &osd->mac_local_faults, |
| 962 | &nsd->mac_local_faults); |
| 963 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 964 | pf->stat_offsets_loaded, |
| 965 | &osd->mac_remote_faults, |
| 966 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 967 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 968 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 969 | pf->stat_offsets_loaded, |
| 970 | &osd->rx_length_errors, |
| 971 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 972 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 973 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 974 | pf->stat_offsets_loaded, |
| 975 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 976 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 977 | pf->stat_offsets_loaded, |
| 978 | &osd->link_xon_tx, &nsd->link_xon_tx); |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 979 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 980 | pf->stat_offsets_loaded, |
| 981 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 982 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 983 | pf->stat_offsets_loaded, |
| 984 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 985 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 986 | for (i = 0; i < 8; i++) { |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 987 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 988 | pf->stat_offsets_loaded, |
| 989 | &osd->priority_xoff_rx[i], |
| 990 | &nsd->priority_xoff_rx[i]); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 991 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 992 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 993 | &osd->priority_xon_rx[i], |
| 994 | &nsd->priority_xon_rx[i]); |
| 995 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 996 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 997 | &osd->priority_xon_tx[i], |
| 998 | &nsd->priority_xon_tx[i]); |
| 999 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1000 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1001 | &osd->priority_xoff_tx[i], |
| 1002 | &nsd->priority_xoff_tx[i]); |
| 1003 | i40e_stat_update32(hw, |
| 1004 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1005 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1006 | &osd->priority_xon_2_xoff[i], |
| 1007 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1010 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 1011 | I40E_GLPRT_PRC64L(hw->port), |
| 1012 | pf->stat_offsets_loaded, |
| 1013 | &osd->rx_size_64, &nsd->rx_size_64); |
| 1014 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 1015 | I40E_GLPRT_PRC127L(hw->port), |
| 1016 | pf->stat_offsets_loaded, |
| 1017 | &osd->rx_size_127, &nsd->rx_size_127); |
| 1018 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 1019 | I40E_GLPRT_PRC255L(hw->port), |
| 1020 | pf->stat_offsets_loaded, |
| 1021 | &osd->rx_size_255, &nsd->rx_size_255); |
| 1022 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 1023 | I40E_GLPRT_PRC511L(hw->port), |
| 1024 | pf->stat_offsets_loaded, |
| 1025 | &osd->rx_size_511, &nsd->rx_size_511); |
| 1026 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 1027 | I40E_GLPRT_PRC1023L(hw->port), |
| 1028 | pf->stat_offsets_loaded, |
| 1029 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 1030 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 1031 | I40E_GLPRT_PRC1522L(hw->port), |
| 1032 | pf->stat_offsets_loaded, |
| 1033 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 1034 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 1035 | I40E_GLPRT_PRC9522L(hw->port), |
| 1036 | pf->stat_offsets_loaded, |
| 1037 | &osd->rx_size_big, &nsd->rx_size_big); |
| 1038 | |
| 1039 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 1040 | I40E_GLPRT_PTC64L(hw->port), |
| 1041 | pf->stat_offsets_loaded, |
| 1042 | &osd->tx_size_64, &nsd->tx_size_64); |
| 1043 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 1044 | I40E_GLPRT_PTC127L(hw->port), |
| 1045 | pf->stat_offsets_loaded, |
| 1046 | &osd->tx_size_127, &nsd->tx_size_127); |
| 1047 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 1048 | I40E_GLPRT_PTC255L(hw->port), |
| 1049 | pf->stat_offsets_loaded, |
| 1050 | &osd->tx_size_255, &nsd->tx_size_255); |
| 1051 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 1052 | I40E_GLPRT_PTC511L(hw->port), |
| 1053 | pf->stat_offsets_loaded, |
| 1054 | &osd->tx_size_511, &nsd->tx_size_511); |
| 1055 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 1056 | I40E_GLPRT_PTC1023L(hw->port), |
| 1057 | pf->stat_offsets_loaded, |
| 1058 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 1059 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 1060 | I40E_GLPRT_PTC1522L(hw->port), |
| 1061 | pf->stat_offsets_loaded, |
| 1062 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1063 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1064 | I40E_GLPRT_PTC9522L(hw->port), |
| 1065 | pf->stat_offsets_loaded, |
| 1066 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1067 | |
| 1068 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1069 | pf->stat_offsets_loaded, |
| 1070 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1071 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1072 | pf->stat_offsets_loaded, |
| 1073 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1074 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1075 | pf->stat_offsets_loaded, |
| 1076 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1077 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1078 | pf->stat_offsets_loaded, |
| 1079 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1080 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1081 | /* FDIR stats */ |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1082 | i40e_stat_update32(hw, |
| 1083 | I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)), |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1084 | pf->stat_offsets_loaded, |
| 1085 | &osd->fd_atr_match, &nsd->fd_atr_match); |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1086 | i40e_stat_update32(hw, |
| 1087 | I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)), |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1088 | pf->stat_offsets_loaded, |
| 1089 | &osd->fd_sb_match, &nsd->fd_sb_match); |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 1090 | i40e_stat_update32(hw, |
| 1091 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), |
| 1092 | pf->stat_offsets_loaded, |
| 1093 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1094 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1095 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1096 | nsd->tx_lpi_status = |
| 1097 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1098 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1099 | nsd->rx_lpi_status = |
| 1100 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1101 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1102 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1103 | pf->stat_offsets_loaded, |
| 1104 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1105 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1106 | pf->stat_offsets_loaded, |
| 1107 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1108 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1109 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
| 1110 | !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) |
| 1111 | nsd->fd_sb_status = true; |
| 1112 | else |
| 1113 | nsd->fd_sb_status = false; |
| 1114 | |
| 1115 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
| 1116 | !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 1117 | nsd->fd_atr_status = true; |
| 1118 | else |
| 1119 | nsd->fd_atr_status = false; |
| 1120 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1121 | pf->stat_offsets_loaded = true; |
| 1122 | } |
| 1123 | |
| 1124 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1125 | * i40e_update_stats - Update the various statistics counters. |
| 1126 | * @vsi: the VSI to be updated |
| 1127 | * |
| 1128 | * Update the various stats for this VSI and its related entities. |
| 1129 | **/ |
| 1130 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1131 | { |
| 1132 | struct i40e_pf *pf = vsi->back; |
| 1133 | |
| 1134 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1135 | i40e_update_pf_stats(pf); |
| 1136 | |
| 1137 | i40e_update_vsi_stats(vsi); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1138 | #ifdef I40E_FCOE |
| 1139 | i40e_update_fcoe_stats(vsi); |
| 1140 | #endif |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1144 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1145 | * @vsi: the VSI to be searched |
| 1146 | * @macaddr: the MAC address |
| 1147 | * @vlan: the vlan |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1148 | * |
| 1149 | * Returns ptr to the filter object or NULL |
| 1150 | **/ |
| 1151 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1152 | u8 *macaddr, s16 vlan) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1153 | { |
| 1154 | struct i40e_mac_filter *f; |
| 1155 | |
| 1156 | if (!vsi || !macaddr) |
| 1157 | return NULL; |
| 1158 | |
| 1159 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1160 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1161 | (vlan == f->vlan)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1162 | return f; |
| 1163 | } |
| 1164 | return NULL; |
| 1165 | } |
| 1166 | |
| 1167 | /** |
| 1168 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1169 | * @vsi: the VSI to be searched |
| 1170 | * @macaddr: the MAC address we are searching for |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1171 | * |
| 1172 | * Returns the first filter with the provided MAC address or NULL if |
| 1173 | * MAC address was not found |
| 1174 | **/ |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1175 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1176 | { |
| 1177 | struct i40e_mac_filter *f; |
| 1178 | |
| 1179 | if (!vsi || !macaddr) |
| 1180 | return NULL; |
| 1181 | |
| 1182 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1183 | if ((ether_addr_equal(macaddr, f->macaddr))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1184 | return f; |
| 1185 | } |
| 1186 | return NULL; |
| 1187 | } |
| 1188 | |
| 1189 | /** |
| 1190 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1191 | * @vsi: the VSI to be searched |
| 1192 | * |
| 1193 | * Returns true if VSI is in vlan mode or false otherwise |
| 1194 | **/ |
| 1195 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1196 | { |
| 1197 | struct i40e_mac_filter *f; |
| 1198 | |
| 1199 | /* Only -1 for all the filters denotes not in vlan mode |
| 1200 | * so we have to go through all the list in order to make sure |
| 1201 | */ |
| 1202 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Greg Rose | d9b68f8 | 2015-07-23 16:54:31 -0400 | [diff] [blame] | 1203 | if (f->vlan >= 0 || vsi->info.pvid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1204 | return true; |
| 1205 | } |
| 1206 | |
| 1207 | return false; |
| 1208 | } |
| 1209 | |
| 1210 | /** |
| 1211 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1212 | * @vsi: the VSI to be searched |
| 1213 | * @macaddr: the mac address to be filtered |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1214 | * |
| 1215 | * Goes through all the macvlan filters and adds a |
| 1216 | * macvlan filter for each unique vlan that already exists |
| 1217 | * |
| 1218 | * Returns first filter found on success, else NULL |
| 1219 | **/ |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1220 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1221 | { |
| 1222 | struct i40e_mac_filter *f; |
| 1223 | |
| 1224 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Mitch Williams | ecbb44e | 2015-07-10 19:35:56 -0400 | [diff] [blame] | 1225 | if (vsi->info.pvid) |
| 1226 | f->vlan = le16_to_cpu(vsi->info.pvid); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1227 | if (!i40e_find_filter(vsi, macaddr, f->vlan)) { |
| 1228 | if (!i40e_add_filter(vsi, macaddr, f->vlan)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1229 | return NULL; |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | return list_first_entry_or_null(&vsi->mac_filter_list, |
| 1234 | struct i40e_mac_filter, list); |
| 1235 | } |
| 1236 | |
| 1237 | /** |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1238 | * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS |
| 1239 | * @vsi: the VSI to be searched |
| 1240 | * @macaddr: the mac address to be removed |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1241 | * |
| 1242 | * Removes a given MAC address from a VSI, regardless of VLAN |
| 1243 | * |
| 1244 | * Returns 0 for success, or error |
| 1245 | **/ |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1246 | int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr) |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1247 | { |
| 1248 | struct i40e_mac_filter *f = NULL; |
| 1249 | int changed = 0; |
| 1250 | |
| 1251 | WARN(!spin_is_locked(&vsi->mac_filter_list_lock), |
| 1252 | "Missing mac_filter_list_lock\n"); |
| 1253 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1254 | if ((ether_addr_equal(macaddr, f->macaddr))) { |
| 1255 | f->state = I40E_FILTER_REMOVE; |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1256 | } |
| 1257 | } |
| 1258 | if (changed) { |
| 1259 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1260 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1261 | return 0; |
| 1262 | } |
| 1263 | return -ENOENT; |
| 1264 | } |
| 1265 | |
| 1266 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1267 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1268 | * @vsi: the VSI to be searched |
| 1269 | * @macaddr: the MAC address |
| 1270 | * @vlan: the vlan |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1271 | * |
| 1272 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1273 | * |
| 1274 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1275 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1276 | **/ |
| 1277 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1278 | u8 *macaddr, s16 vlan) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1279 | { |
| 1280 | struct i40e_mac_filter *f; |
| 1281 | |
| 1282 | if (!vsi || !macaddr) |
| 1283 | return NULL; |
| 1284 | |
Kiran Patil | f6bd096 | 2016-06-20 09:10:34 -0700 | [diff] [blame] | 1285 | /* Do not allow broadcast filter to be added since broadcast filter |
| 1286 | * is added as part of add VSI for any newly created VSI except |
| 1287 | * FDIR VSI |
| 1288 | */ |
| 1289 | if (is_broadcast_ether_addr(macaddr)) |
| 1290 | return NULL; |
| 1291 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1292 | f = i40e_find_filter(vsi, macaddr, vlan); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1293 | if (!f) { |
| 1294 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1295 | if (!f) |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1296 | return NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1297 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1298 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1299 | f->vlan = vlan; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1300 | /* If we're in overflow promisc mode, set the state directly |
| 1301 | * to failed, so we don't bother to try sending the filter |
| 1302 | * to the hardware. |
| 1303 | */ |
| 1304 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state)) |
| 1305 | f->state = I40E_FILTER_FAILED; |
| 1306 | else |
| 1307 | f->state = I40E_FILTER_NEW; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1308 | INIT_LIST_HEAD(&f->list); |
Kiran Patil | 04d5a21 | 2015-12-09 15:50:23 -0800 | [diff] [blame] | 1309 | list_add_tail(&f->list, &vsi->mac_filter_list); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1310 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1311 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1312 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1313 | } |
| 1314 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1315 | /* If we're asked to add a filter that has been marked for removal, it |
| 1316 | * is safe to simply restore it to active state. __i40e_del_filter |
| 1317 | * will have simply deleted any filters which were previously marked |
| 1318 | * NEW or FAILED, so if it is currently marked REMOVE it must have |
| 1319 | * previously been ACTIVE. Since we haven't yet run the sync filters |
| 1320 | * task, just restore this filter to the ACTIVE state so that the |
| 1321 | * sync task leaves it in place |
| 1322 | */ |
| 1323 | if (f->state == I40E_FILTER_REMOVE) |
| 1324 | f->state = I40E_FILTER_ACTIVE; |
| 1325 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1326 | return f; |
| 1327 | } |
| 1328 | |
| 1329 | /** |
| 1330 | * i40e_del_filter - Remove a mac/vlan filter from the VSI |
| 1331 | * @vsi: the VSI to be searched |
| 1332 | * @macaddr: the MAC address |
| 1333 | * @vlan: the vlan |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1334 | * |
| 1335 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1336 | * being held. |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1337 | * ANOTHER NOTE: This function MUST be called from within the context of |
| 1338 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() |
| 1339 | * instead of list_for_each_entry(). |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1340 | **/ |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1341 | void i40e_del_filter(struct i40e_vsi *vsi, u8 *macaddr, s16 vlan) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1342 | { |
| 1343 | struct i40e_mac_filter *f; |
| 1344 | |
| 1345 | if (!vsi || !macaddr) |
| 1346 | return; |
| 1347 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1348 | f = i40e_find_filter(vsi, macaddr, vlan); |
| 1349 | if (!f) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1350 | return; |
| 1351 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1352 | if ((f->state == I40E_FILTER_FAILED) || |
| 1353 | (f->state == I40E_FILTER_NEW)) { |
| 1354 | /* this one never got added by the FW. Just remove it, |
| 1355 | * no need to sync anything. |
| 1356 | */ |
| 1357 | list_del(&f->list); |
| 1358 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1359 | } else { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1360 | f->state = I40E_FILTER_REMOVE; |
| 1361 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1362 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1363 | } |
| 1364 | } |
| 1365 | |
| 1366 | /** |
| 1367 | * i40e_set_mac - NDO callback to set mac address |
| 1368 | * @netdev: network interface device structure |
| 1369 | * @p: pointer to an address structure |
| 1370 | * |
| 1371 | * Returns 0 on success, negative on failure |
| 1372 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1373 | #ifdef I40E_FCOE |
| 1374 | int i40e_set_mac(struct net_device *netdev, void *p) |
| 1375 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1376 | static int i40e_set_mac(struct net_device *netdev, void *p) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1377 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1378 | { |
| 1379 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1380 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1381 | struct i40e_pf *pf = vsi->back; |
| 1382 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1383 | struct sockaddr *addr = p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1384 | |
| 1385 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1386 | return -EADDRNOTAVAIL; |
| 1387 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1388 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1389 | netdev_info(netdev, "already using mac address %pM\n", |
| 1390 | addr->sa_data); |
| 1391 | return 0; |
| 1392 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1393 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1394 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1395 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1396 | return -EADDRNOTAVAIL; |
| 1397 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1398 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1399 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1400 | hw->mac.addr); |
| 1401 | else |
| 1402 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1403 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1404 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1405 | i40e_del_mac_all_vlan(vsi, netdev->dev_addr); |
| 1406 | i40e_put_mac_in_vlan(vsi, addr->sa_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1407 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 1408 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1409 | if (vsi->type == I40E_VSI_MAIN) { |
| 1410 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1411 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1412 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1413 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1414 | addr->sa_data, NULL); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1415 | if (ret) |
| 1416 | netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n", |
| 1417 | i40e_stat_str(hw, ret), |
| 1418 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1419 | } |
| 1420 | |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1421 | /* schedule our worker thread which will take care of |
| 1422 | * applying the new filter changes |
| 1423 | */ |
| 1424 | i40e_service_event_schedule(vsi->back); |
| 1425 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1430 | * @vsi: the VSI being setup |
| 1431 | * @ctxt: VSI context structure |
| 1432 | * @enabled_tc: Enabled TCs bitmap |
| 1433 | * @is_add: True if called before Add VSI |
| 1434 | * |
| 1435 | * Setup VSI queue mapping for enabled traffic classes. |
| 1436 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1437 | #ifdef I40E_FCOE |
| 1438 | void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1439 | struct i40e_vsi_context *ctxt, |
| 1440 | u8 enabled_tc, |
| 1441 | bool is_add) |
| 1442 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1443 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1444 | struct i40e_vsi_context *ctxt, |
| 1445 | u8 enabled_tc, |
| 1446 | bool is_add) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1447 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1448 | { |
| 1449 | struct i40e_pf *pf = vsi->back; |
| 1450 | u16 sections = 0; |
| 1451 | u8 netdev_tc = 0; |
| 1452 | u16 numtc = 0; |
| 1453 | u16 qcount; |
| 1454 | u8 offset; |
| 1455 | u16 qmap; |
| 1456 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1457 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1458 | |
| 1459 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1460 | offset = 0; |
| 1461 | |
| 1462 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1463 | /* Find numtc from enabled TC bitmap */ |
| 1464 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1465 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1466 | numtc++; |
| 1467 | } |
| 1468 | if (!numtc) { |
| 1469 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1470 | numtc = 1; |
| 1471 | } |
| 1472 | } else { |
| 1473 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1474 | numtc = 1; |
| 1475 | } |
| 1476 | |
| 1477 | vsi->tc_config.numtc = numtc; |
| 1478 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1479 | /* Number of queues per enabled TC */ |
Catherine Sullivan | 7d64402 | 2016-05-16 10:26:41 -0700 | [diff] [blame] | 1480 | qcount = vsi->alloc_queue_pairs; |
| 1481 | |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1482 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1483 | 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] | 1484 | |
| 1485 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1486 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1487 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1488 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1489 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1490 | int pow, num_qps; |
| 1491 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1492 | switch (vsi->type) { |
| 1493 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1494 | qcount = min_t(int, pf->alloc_rss_size, |
| 1495 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1496 | break; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1497 | #ifdef I40E_FCOE |
| 1498 | case I40E_VSI_FCOE: |
| 1499 | qcount = num_tc_qps; |
| 1500 | break; |
| 1501 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1502 | case I40E_VSI_FDIR: |
| 1503 | case I40E_VSI_SRIOV: |
| 1504 | case I40E_VSI_VMDQ2: |
| 1505 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1506 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1507 | WARN_ON(i != 0); |
| 1508 | break; |
| 1509 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1510 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1511 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1512 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1513 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1514 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1515 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1516 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1517 | pow++; |
| 1518 | num_qps >>= 1; |
| 1519 | } |
| 1520 | |
| 1521 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1522 | qmap = |
| 1523 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1524 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1525 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1526 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1527 | } else { |
| 1528 | /* TC is not enabled so set the offset to |
| 1529 | * default queue and allocate one queue |
| 1530 | * for the given TC. |
| 1531 | */ |
| 1532 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1533 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1534 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1535 | |
| 1536 | qmap = 0; |
| 1537 | } |
| 1538 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1539 | } |
| 1540 | |
| 1541 | /* Set actual Tx/Rx queue pairs */ |
| 1542 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1543 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1544 | if (vsi->req_queue_pairs > 0) |
| 1545 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1546 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1547 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1548 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1549 | |
| 1550 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1551 | if (is_add) { |
| 1552 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1553 | |
| 1554 | ctxt->info.up_enable_bits = enabled_tc; |
| 1555 | } |
| 1556 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1557 | ctxt->info.mapping_flags |= |
| 1558 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1559 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1560 | ctxt->info.queue_mapping[i] = |
| 1561 | cpu_to_le16(vsi->base_queue + i); |
| 1562 | } else { |
| 1563 | ctxt->info.mapping_flags |= |
| 1564 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1565 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1566 | } |
| 1567 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1568 | } |
| 1569 | |
| 1570 | /** |
| 1571 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1572 | * @netdev: network interface device structure |
| 1573 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1574 | #ifdef I40E_FCOE |
| 1575 | void i40e_set_rx_mode(struct net_device *netdev) |
| 1576 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1577 | static void i40e_set_rx_mode(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1578 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1579 | { |
| 1580 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1581 | struct i40e_mac_filter *f, *ftmp; |
| 1582 | struct i40e_vsi *vsi = np->vsi; |
| 1583 | struct netdev_hw_addr *uca; |
| 1584 | struct netdev_hw_addr *mca; |
| 1585 | struct netdev_hw_addr *ha; |
| 1586 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1587 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1588 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1589 | /* add addr if not already in the filter list */ |
| 1590 | netdev_for_each_uc_addr(uca, netdev) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1591 | if (!i40e_find_mac(vsi, uca->addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1592 | if (i40e_is_vsi_in_vlan(vsi)) |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1593 | i40e_put_mac_in_vlan(vsi, uca->addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1594 | else |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1595 | i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | netdev_for_each_mc_addr(mca, netdev) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1600 | if (!i40e_find_mac(vsi, mca->addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1601 | if (i40e_is_vsi_in_vlan(vsi)) |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1602 | i40e_put_mac_in_vlan(vsi, mca->addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1603 | else |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1604 | i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | /* remove filter if not in netdev list */ |
| 1609 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1610 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1611 | netdev_for_each_mc_addr(mca, netdev) |
| 1612 | if (ether_addr_equal(mca->addr, f->macaddr)) |
| 1613 | goto bottom_of_search_loop; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1614 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1615 | netdev_for_each_uc_addr(uca, netdev) |
| 1616 | if (ether_addr_equal(uca->addr, f->macaddr)) |
| 1617 | goto bottom_of_search_loop; |
| 1618 | |
| 1619 | for_each_dev_addr(netdev, ha) |
| 1620 | if (ether_addr_equal(ha->addr, f->macaddr)) |
| 1621 | goto bottom_of_search_loop; |
| 1622 | |
| 1623 | /* f->macaddr wasn't found in uc, mc, or ha list so delete it */ |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 1624 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY); |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1625 | |
| 1626 | bottom_of_search_loop: |
| 1627 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1628 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1629 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1630 | |
| 1631 | /* check for other flag changes */ |
| 1632 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1633 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1634 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1635 | } |
Jesse Brandeburg | c53934c | 2016-01-04 10:33:06 -0800 | [diff] [blame] | 1636 | |
| 1637 | /* schedule our worker thread which will take care of |
| 1638 | * applying the new filter changes |
| 1639 | */ |
| 1640 | i40e_service_event_schedule(vsi->back); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1641 | } |
| 1642 | |
| 1643 | /** |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1644 | * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries |
| 1645 | * @vsi: pointer to vsi struct |
| 1646 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1647 | * those entries needs to be undone. |
| 1648 | * |
| 1649 | * MAC filter entries from list were slated to be removed from device. |
| 1650 | **/ |
| 1651 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1652 | struct list_head *from) |
| 1653 | { |
| 1654 | struct i40e_mac_filter *f, *ftmp; |
| 1655 | |
| 1656 | list_for_each_entry_safe(f, ftmp, from, list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1657 | /* Move the element back into MAC filter list*/ |
| 1658 | list_move_tail(&f->list, &vsi->mac_filter_list); |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | /** |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1663 | * i40e_update_filter_state - Update filter state based on return data |
| 1664 | * from firmware |
| 1665 | * @count: Number of filters added |
| 1666 | * @add_list: return data from fw |
| 1667 | * @head: pointer to first filter in current batch |
| 1668 | * @aq_err: status from fw |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1669 | * |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1670 | * MAC filter entries from list were slated to be added to device. Returns |
| 1671 | * number of successful filters. Note that 0 does NOT mean success! |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1672 | **/ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1673 | static int |
| 1674 | i40e_update_filter_state(int count, |
| 1675 | struct i40e_aqc_add_macvlan_element_data *add_list, |
| 1676 | struct i40e_mac_filter *add_head, int aq_err) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1677 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1678 | int retval = 0; |
| 1679 | int i; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1680 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1681 | |
| 1682 | if (!aq_err) { |
| 1683 | retval = count; |
| 1684 | /* Everything's good, mark all filters active. */ |
| 1685 | for (i = 0; i < count ; i++) { |
| 1686 | add_head->state = I40E_FILTER_ACTIVE; |
| 1687 | add_head = list_next_entry(add_head, list); |
| 1688 | } |
| 1689 | } else if (aq_err == I40E_AQ_RC_ENOSPC) { |
| 1690 | /* Device ran out of filter space. Check the return value |
| 1691 | * for each filter to see which ones are active. |
| 1692 | */ |
| 1693 | for (i = 0; i < count ; i++) { |
| 1694 | if (add_list[i].match_method == |
| 1695 | I40E_AQC_MM_ERR_NO_RES) { |
| 1696 | add_head->state = I40E_FILTER_FAILED; |
| 1697 | } else { |
| 1698 | add_head->state = I40E_FILTER_ACTIVE; |
| 1699 | retval++; |
| 1700 | } |
| 1701 | add_head = list_next_entry(add_head, list); |
| 1702 | } |
| 1703 | } else { |
| 1704 | /* Some other horrible thing happened, fail all filters */ |
| 1705 | retval = 0; |
| 1706 | for (i = 0; i < count ; i++) { |
| 1707 | add_head->state = I40E_FILTER_FAILED; |
| 1708 | add_head = list_next_entry(add_head, list); |
| 1709 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1710 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1711 | return retval; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1715 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1716 | * @vsi: ptr to the VSI |
| 1717 | * |
| 1718 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1719 | * |
| 1720 | * Returns 0 or error value |
| 1721 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 1722 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1723 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1724 | struct i40e_mac_filter *f, *ftmp, *add_head = NULL; |
| 1725 | struct list_head tmp_add_list, tmp_del_list; |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1726 | struct i40e_hw *hw = &vsi->back->hw; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1727 | bool promisc_changed = false; |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1728 | char vsi_name[16] = "PF"; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1729 | int filter_list_len = 0; |
| 1730 | u32 changed_flags = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1731 | i40e_status aq_ret = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1732 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1733 | struct i40e_pf *pf; |
| 1734 | int num_add = 0; |
| 1735 | int num_del = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1736 | int aq_err = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1737 | u16 cmd_flags; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1738 | int list_size; |
| 1739 | int fcnt; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1740 | |
| 1741 | /* empty array typed pointers, kcalloc later */ |
| 1742 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1743 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1744 | |
| 1745 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1746 | usleep_range(1000, 2000); |
| 1747 | pf = vsi->back; |
| 1748 | |
| 1749 | if (vsi->netdev) { |
| 1750 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1751 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1752 | } |
| 1753 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1754 | INIT_LIST_HEAD(&tmp_add_list); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1755 | INIT_LIST_HEAD(&tmp_del_list); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1756 | |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1757 | if (vsi->type == I40E_VSI_SRIOV) |
| 1758 | snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id); |
| 1759 | else if (vsi->type != I40E_VSI_MAIN) |
| 1760 | snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid); |
| 1761 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1762 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1763 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1764 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1765 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1766 | /* Create a list of filters to delete. */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1767 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1768 | if (f->state == I40E_FILTER_REMOVE) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1769 | /* Move the element into temporary del_list */ |
| 1770 | list_move_tail(&f->list, &tmp_del_list); |
| 1771 | vsi->active_filters--; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1772 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1773 | if (f->state == I40E_FILTER_NEW) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1774 | /* Move the element into temporary add_list */ |
| 1775 | list_move_tail(&f->list, &tmp_add_list); |
| 1776 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1777 | } |
| 1778 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | /* Now process 'del_list' outside the lock */ |
| 1782 | if (!list_empty(&tmp_del_list)) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1783 | filter_list_len = hw->aq.asq_buf_size / |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1784 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1785 | list_size = filter_list_len * |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1786 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1787 | del_list = kzalloc(list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1788 | if (!del_list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1789 | /* Undo VSI's MAC filter entry element updates */ |
| 1790 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1791 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1792 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1793 | retval = -ENOMEM; |
| 1794 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1798 | cmd_flags = 0; |
| 1799 | |
| 1800 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1801 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1802 | if (f->vlan == I40E_VLAN_ANY) { |
| 1803 | del_list[num_del].vlan_tag = 0; |
Alan Brady | a6cb914 | 2016-09-06 18:05:07 -0700 | [diff] [blame] | 1804 | cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1805 | } else { |
| 1806 | del_list[num_del].vlan_tag = |
| 1807 | cpu_to_le16((u16)(f->vlan)); |
| 1808 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1809 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1810 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1811 | del_list[num_del].flags = cmd_flags; |
| 1812 | num_del++; |
| 1813 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1814 | /* flush a full buffer */ |
| 1815 | if (num_del == filter_list_len) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1816 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, |
| 1817 | del_list, |
| 1818 | num_del, NULL); |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1819 | aq_err = hw->aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1820 | num_del = 0; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1821 | memset(del_list, 0, list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1822 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1823 | /* Explicitly ignore and do not report when |
| 1824 | * firmware returns ENOENT. |
| 1825 | */ |
| 1826 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1827 | retval = -EIO; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1828 | dev_info(&pf->pdev->dev, |
| 1829 | "ignoring delete macvlan error on %s, err %s, aq_err %s\n", |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1830 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1831 | i40e_stat_str(hw, aq_ret), |
| 1832 | i40e_aq_str(hw, aq_err)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1833 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1834 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1835 | /* Release memory for MAC filter entries which were |
| 1836 | * synced up with HW. |
| 1837 | */ |
| 1838 | list_del(&f->list); |
| 1839 | kfree(f); |
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 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1842 | if (num_del) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1843 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, del_list, |
| 1844 | num_del, NULL); |
| 1845 | aq_err = hw->aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1846 | num_del = 0; |
| 1847 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1848 | /* Explicitly ignore and do not report when firmware |
| 1849 | * returns ENOENT. |
| 1850 | */ |
| 1851 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { |
| 1852 | retval = -EIO; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1853 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1854 | "ignoring delete macvlan error on %s, err %s aq_err %s\n", |
| 1855 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1856 | i40e_stat_str(hw, aq_ret), |
| 1857 | i40e_aq_str(hw, aq_err)); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1858 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | kfree(del_list); |
| 1862 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | if (!list_empty(&tmp_add_list)) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1866 | /* Do all the adds now. */ |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1867 | filter_list_len = hw->aq.asq_buf_size / |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1868 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1869 | list_size = filter_list_len * |
| 1870 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
| 1871 | add_list = kzalloc(list_size, GFP_ATOMIC); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1872 | if (!add_list) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1873 | retval = -ENOMEM; |
| 1874 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1875 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1876 | num_add = 0; |
| 1877 | list_for_each_entry(f, &tmp_add_list, list) { |
| 1878 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1879 | &vsi->state)) { |
| 1880 | f->state = I40E_FILTER_FAILED; |
| 1881 | continue; |
| 1882 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1883 | /* add to add array */ |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1884 | if (num_add == 0) |
| 1885 | add_head = f; |
| 1886 | cmd_flags = 0; |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1887 | ether_addr_copy(add_list[num_add].mac_addr, f->macaddr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1888 | if (f->vlan == I40E_VLAN_ANY) { |
| 1889 | add_list[num_add].vlan_tag = 0; |
| 1890 | cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; |
| 1891 | } else { |
| 1892 | add_list[num_add].vlan_tag = |
| 1893 | cpu_to_le16((u16)(f->vlan)); |
| 1894 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1895 | add_list[num_add].queue_number = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1896 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1897 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 1898 | num_add++; |
| 1899 | |
| 1900 | /* flush a full buffer */ |
| 1901 | if (num_add == filter_list_len) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1902 | aq_ret = i40e_aq_add_macvlan(hw, vsi->seid, |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1903 | add_list, num_add, |
| 1904 | NULL); |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1905 | aq_err = hw->aq.asq_last_status; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1906 | fcnt = i40e_update_filter_state(num_add, |
| 1907 | add_list, |
| 1908 | add_head, |
| 1909 | aq_ret); |
| 1910 | vsi->active_filters += fcnt; |
| 1911 | |
| 1912 | if (fcnt != num_add) { |
| 1913 | promisc_changed = true; |
| 1914 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1915 | &vsi->state); |
| 1916 | vsi->promisc_threshold = |
| 1917 | (vsi->active_filters * 3) / 4; |
| 1918 | dev_warn(&pf->pdev->dev, |
| 1919 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", |
| 1920 | i40e_aq_str(hw, aq_err), |
| 1921 | vsi_name); |
| 1922 | } |
| 1923 | memset(add_list, 0, list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1924 | num_add = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1925 | } |
| 1926 | } |
| 1927 | if (num_add) { |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1928 | aq_ret = i40e_aq_add_macvlan(hw, vsi->seid, |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1929 | add_list, num_add, NULL); |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1930 | aq_err = hw->aq.asq_last_status; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1931 | fcnt = i40e_update_filter_state(num_add, add_list, |
| 1932 | add_head, aq_ret); |
| 1933 | vsi->active_filters += fcnt; |
| 1934 | if (fcnt != num_add) { |
| 1935 | promisc_changed = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1936 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1937 | &vsi->state); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1938 | vsi->promisc_threshold = |
| 1939 | (vsi->active_filters * 3) / 4; |
| 1940 | dev_warn(&pf->pdev->dev, |
| 1941 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", |
| 1942 | i40e_aq_str(hw, aq_err), vsi_name); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1943 | } |
| 1944 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 1945 | /* Now move all of the filters from the temp add list back to |
| 1946 | * the VSI's list. |
| 1947 | */ |
| 1948 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1949 | list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) { |
| 1950 | list_move_tail(&f->list, &vsi->mac_filter_list); |
| 1951 | } |
| 1952 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 1953 | kfree(add_list); |
| 1954 | add_list = NULL; |
| 1955 | } |
| 1956 | |
| 1957 | /* Check to see if we can drop out of overflow promiscuous mode. */ |
| 1958 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) && |
| 1959 | (vsi->active_filters < vsi->promisc_threshold)) { |
| 1960 | int failed_count = 0; |
| 1961 | /* See if we have any failed filters. We can't drop out of |
| 1962 | * promiscuous until these have all been deleted. |
| 1963 | */ |
| 1964 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1965 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1966 | if (f->state == I40E_FILTER_FAILED) |
| 1967 | failed_count++; |
| 1968 | } |
| 1969 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 1970 | if (!failed_count) { |
| 1971 | dev_info(&pf->pdev->dev, |
| 1972 | "filter logjam cleared on %s, leaving overflow promiscuous mode\n", |
| 1973 | vsi_name); |
| 1974 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 1975 | promisc_changed = true; |
| 1976 | vsi->promisc_threshold = 0; |
| 1977 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1978 | } |
| 1979 | |
Anjali Singhai Jain | a856b5c | 2016-04-13 03:08:23 -0700 | [diff] [blame] | 1980 | /* if the VF is not trusted do not do promisc */ |
| 1981 | if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) { |
| 1982 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
| 1983 | goto out; |
| 1984 | } |
| 1985 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1986 | /* check for changes in promiscuous modes */ |
| 1987 | if (changed_flags & IFF_ALLMULTI) { |
| 1988 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1989 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1990 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1991 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 1992 | vsi->seid, |
| 1993 | cur_multipromisc, |
| 1994 | NULL); |
| 1995 | if (aq_ret) { |
| 1996 | retval = i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 1997 | hw->aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1998 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 1999 | "set multi promisc failed on %s, err %s aq_err %s\n", |
| 2000 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2001 | i40e_stat_str(hw, aq_ret), |
| 2002 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2003 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2004 | } |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2005 | if ((changed_flags & IFF_PROMISC) || |
| 2006 | (promisc_changed && |
| 2007 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2008 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2009 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2010 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 2011 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2012 | &vsi->state)); |
Anjali Singhai Jain | 6784ed5 | 2016-01-15 14:33:13 -0800 | [diff] [blame] | 2013 | if ((vsi->type == I40E_VSI_MAIN) && |
| 2014 | (pf->lan_veb != I40E_NO_VEB) && |
| 2015 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2016 | /* set defport ON for Main VSI instead of true promisc |
| 2017 | * this way we will get all unicast/multicast and VLAN |
| 2018 | * promisc behavior but will not get VF or VMDq traffic |
| 2019 | * replicated on the Main VSI. |
| 2020 | */ |
| 2021 | if (pf->cur_promisc != cur_promisc) { |
| 2022 | pf->cur_promisc = cur_promisc; |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2023 | if (cur_promisc) |
| 2024 | aq_ret = |
| 2025 | i40e_aq_set_default_vsi(hw, |
| 2026 | vsi->seid, |
| 2027 | NULL); |
| 2028 | else |
| 2029 | aq_ret = |
| 2030 | i40e_aq_clear_default_vsi(hw, |
| 2031 | vsi->seid, |
| 2032 | NULL); |
| 2033 | if (aq_ret) { |
| 2034 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2035 | hw->aq.asq_last_status); |
| 2036 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2037 | "Set default VSI failed on %s, err %s, aq_err %s\n", |
| 2038 | vsi_name, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 2039 | i40e_stat_str(hw, aq_ret), |
| 2040 | i40e_aq_str(hw, |
| 2041 | hw->aq.asq_last_status)); |
| 2042 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2043 | } |
| 2044 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2045 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2046 | hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2047 | vsi->seid, |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 2048 | cur_promisc, NULL, |
| 2049 | true); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2050 | if (aq_ret) { |
| 2051 | retval = |
| 2052 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2053 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2054 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2055 | "set unicast promisc failed on %s, err %s, aq_err %s\n", |
| 2056 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2057 | i40e_stat_str(hw, aq_ret), |
| 2058 | i40e_aq_str(hw, |
| 2059 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2060 | } |
| 2061 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2062 | hw, |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2063 | vsi->seid, |
| 2064 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2065 | if (aq_ret) { |
| 2066 | retval = |
| 2067 | i40e_aq_rc_to_posix(aq_ret, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2068 | hw->aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2069 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 2d1de82 | 2016-05-16 10:26:44 -0700 | [diff] [blame] | 2070 | "set multicast promisc failed on %s, err %s, aq_err %s\n", |
| 2071 | vsi_name, |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2072 | i40e_stat_str(hw, aq_ret), |
| 2073 | i40e_aq_str(hw, |
| 2074 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2075 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2076 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2077 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2078 | vsi->seid, |
| 2079 | cur_promisc, NULL); |
| 2080 | if (aq_ret) { |
| 2081 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2082 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2083 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2084 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | 3e25a8f | 2016-05-16 10:26:32 -0700 | [diff] [blame] | 2085 | i40e_stat_str(hw, aq_ret), |
| 2086 | i40e_aq_str(hw, |
| 2087 | hw->aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2088 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2089 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2090 | out: |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 2091 | /* if something went wrong then set the changed flag so we try again */ |
| 2092 | if (retval) |
| 2093 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 2094 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2095 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2096 | return retval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | /** |
| 2100 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2101 | * @pf: board private structure |
| 2102 | **/ |
| 2103 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2104 | { |
| 2105 | int v; |
| 2106 | |
| 2107 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2108 | return; |
| 2109 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2110 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2111 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2112 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2113 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2114 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2115 | |
| 2116 | if (ret) { |
| 2117 | /* come back and try again later */ |
| 2118 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2119 | break; |
| 2120 | } |
| 2121 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | /** |
| 2126 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2127 | * @netdev: network interface device structure |
| 2128 | * @new_mtu: new value for maximum frame size |
| 2129 | * |
| 2130 | * Returns 0 on success, negative on failure |
| 2131 | **/ |
| 2132 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2133 | { |
| 2134 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2135 | struct i40e_vsi *vsi = np->vsi; |
| 2136 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2137 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2138 | netdev->mtu, new_mtu); |
| 2139 | netdev->mtu = new_mtu; |
| 2140 | if (netif_running(netdev)) |
| 2141 | i40e_vsi_reinit_locked(vsi); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 2142 | i40e_notify_client_of_l2_param_changes(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2143 | return 0; |
| 2144 | } |
| 2145 | |
| 2146 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2147 | * i40e_ioctl - Access the hwtstamp interface |
| 2148 | * @netdev: network interface device structure |
| 2149 | * @ifr: interface request data |
| 2150 | * @cmd: ioctl command |
| 2151 | **/ |
| 2152 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2153 | { |
| 2154 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2155 | struct i40e_pf *pf = np->vsi->back; |
| 2156 | |
| 2157 | switch (cmd) { |
| 2158 | case SIOCGHWTSTAMP: |
| 2159 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2160 | case SIOCSHWTSTAMP: |
| 2161 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2162 | default: |
| 2163 | return -EOPNOTSUPP; |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2168 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2169 | * @vsi: the vsi being adjusted |
| 2170 | **/ |
| 2171 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2172 | { |
| 2173 | struct i40e_vsi_context ctxt; |
| 2174 | i40e_status ret; |
| 2175 | |
| 2176 | if ((vsi->info.valid_sections & |
| 2177 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2178 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2179 | return; /* already enabled */ |
| 2180 | |
| 2181 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2182 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2183 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2184 | |
| 2185 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2186 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2187 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2188 | if (ret) { |
| 2189 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2190 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2191 | i40e_stat_str(&vsi->back->hw, ret), |
| 2192 | i40e_aq_str(&vsi->back->hw, |
| 2193 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | /** |
| 2198 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2199 | * @vsi: the vsi being adjusted |
| 2200 | **/ |
| 2201 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2202 | { |
| 2203 | struct i40e_vsi_context ctxt; |
| 2204 | i40e_status ret; |
| 2205 | |
| 2206 | if ((vsi->info.valid_sections & |
| 2207 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2208 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2209 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2210 | return; /* already disabled */ |
| 2211 | |
| 2212 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2213 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2214 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2215 | |
| 2216 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2217 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2218 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2219 | if (ret) { |
| 2220 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2221 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2222 | i40e_stat_str(&vsi->back->hw, ret), |
| 2223 | i40e_aq_str(&vsi->back->hw, |
| 2224 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | /** |
| 2229 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2230 | * @netdev: network interface to be adjusted |
| 2231 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2232 | **/ |
| 2233 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2234 | { |
| 2235 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2236 | struct i40e_vsi *vsi = np->vsi; |
| 2237 | |
| 2238 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2239 | i40e_vlan_stripping_enable(vsi); |
| 2240 | else |
| 2241 | i40e_vlan_stripping_disable(vsi); |
| 2242 | } |
| 2243 | |
| 2244 | /** |
| 2245 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 2246 | * @vsi: the vsi being configured |
| 2247 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 2248 | **/ |
| 2249 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2250 | { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2251 | struct i40e_mac_filter *f, *ftmp, *add_f; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2252 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2253 | /* Locked once because all functions invoked below iterates list*/ |
| 2254 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2255 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 2256 | if (vsi->netdev) { |
| 2257 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2258 | if (!add_f) { |
| 2259 | dev_info(&vsi->back->pdev->dev, |
| 2260 | "Could not add vlan filter %d for %pM\n", |
| 2261 | vid, vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2262 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2263 | return -ENOMEM; |
| 2264 | } |
| 2265 | } |
| 2266 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2267 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 2268 | add_f = i40e_add_filter(vsi, f->macaddr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2269 | if (!add_f) { |
| 2270 | dev_info(&vsi->back->pdev->dev, |
| 2271 | "Could not add vlan filter %d for %pM\n", |
| 2272 | vid, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2273 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2274 | return -ENOMEM; |
| 2275 | } |
| 2276 | } |
| 2277 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2278 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 2279 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 2280 | * with 0, so we now accept untagged and specified tagged traffic |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2281 | * (and not all tags along with untagged) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2282 | */ |
| 2283 | if (vid > 0) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 2284 | if (vsi->netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 2285 | I40E_VLAN_ANY)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2286 | i40e_del_filter(vsi, vsi->netdev->dev_addr, |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 2287 | I40E_VLAN_ANY); |
| 2288 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2289 | if (!add_f) { |
| 2290 | dev_info(&vsi->back->pdev->dev, |
| 2291 | "Could not add filter 0 for %pM\n", |
| 2292 | vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2293 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2294 | return -ENOMEM; |
| 2295 | } |
| 2296 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2297 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2298 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2299 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
| 2300 | if (vid > 0 && !vsi->info.pvid) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2301 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 2302 | if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY)) |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2303 | continue; |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 2304 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY); |
| 2305 | add_f = i40e_add_filter(vsi, f->macaddr, 0); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2306 | if (!add_f) { |
| 2307 | dev_info(&vsi->back->pdev->dev, |
| 2308 | "Could not add filter 0 for %pM\n", |
| 2309 | f->macaddr); |
| 2310 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2311 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2312 | } |
| 2313 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2314 | } |
| 2315 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2316 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2317 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2318 | /* schedule our worker thread which will take care of |
| 2319 | * applying the new filter changes |
| 2320 | */ |
| 2321 | i40e_service_event_schedule(vsi->back); |
| 2322 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | /** |
| 2326 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 2327 | * @vsi: the vsi being configured |
| 2328 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2329 | * |
| 2330 | * Return: 0 on success or negative otherwise |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2331 | **/ |
| 2332 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2333 | { |
| 2334 | struct net_device *netdev = vsi->netdev; |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2335 | struct i40e_mac_filter *f, *ftmp, *add_f; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2336 | int filter_count = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2337 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2338 | /* Locked once because all functions invoked below iterates list */ |
| 2339 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2340 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 2341 | if (vsi->netdev) |
| 2342 | i40e_del_filter(vsi, netdev->dev_addr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2343 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2344 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 2345 | i40e_del_filter(vsi, f->macaddr, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2346 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2347 | /* go through all the filters for this VSI and if there is only |
| 2348 | * vid == 0 it means there are no other filters, so vid 0 must |
| 2349 | * be replaced with -1. This signifies that we should from now |
| 2350 | * on accept any traffic (with any tag present, or untagged) |
| 2351 | */ |
| 2352 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 2353 | if (vsi->netdev) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2354 | if (f->vlan && |
| 2355 | ether_addr_equal(netdev->dev_addr, f->macaddr)) |
| 2356 | filter_count++; |
| 2357 | } |
| 2358 | |
| 2359 | if (f->vlan) |
| 2360 | filter_count++; |
| 2361 | } |
| 2362 | |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 2363 | if (!filter_count && vsi->netdev) { |
| 2364 | i40e_del_filter(vsi, netdev->dev_addr, 0); |
| 2365 | f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2366 | if (!f) { |
| 2367 | dev_info(&vsi->back->pdev->dev, |
| 2368 | "Could not add filter %d for %pM\n", |
| 2369 | I40E_VLAN_ANY, netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2370 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2371 | return -ENOMEM; |
| 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | if (!filter_count) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 2376 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 2377 | i40e_del_filter(vsi, f->macaddr, 0); |
| 2378 | add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2379 | if (!add_f) { |
| 2380 | dev_info(&vsi->back->pdev->dev, |
| 2381 | "Could not add filter %d for %pM\n", |
| 2382 | I40E_VLAN_ANY, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2383 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2384 | return -ENOMEM; |
| 2385 | } |
| 2386 | } |
| 2387 | } |
| 2388 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2389 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2390 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2391 | /* schedule our worker thread which will take care of |
| 2392 | * applying the new filter changes |
| 2393 | */ |
| 2394 | i40e_service_event_schedule(vsi->back); |
| 2395 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | /** |
| 2399 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2400 | * @netdev: network interface to be adjusted |
| 2401 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2402 | * |
| 2403 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2404 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2405 | #ifdef I40E_FCOE |
| 2406 | int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2407 | __always_unused __be16 proto, u16 vid) |
| 2408 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2409 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2410 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2411 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2412 | { |
| 2413 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2414 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2415 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2416 | |
| 2417 | if (vid > 4095) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2418 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2419 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2420 | /* If the network stack called us with vid = 0 then |
| 2421 | * it is asking to receive priority tagged packets with |
| 2422 | * vlan id 0. Our HW receives them by default when configured |
| 2423 | * to receive untagged packets so there is no need to add an |
| 2424 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2425 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2426 | if (vid) |
| 2427 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2428 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2429 | if (!ret && (vid < VLAN_N_VID)) |
| 2430 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2431 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2432 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | /** |
| 2436 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2437 | * @netdev: network interface to be adjusted |
| 2438 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2439 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2440 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2441 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2442 | #ifdef I40E_FCOE |
| 2443 | int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2444 | __always_unused __be16 proto, u16 vid) |
| 2445 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2446 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2447 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2448 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2449 | { |
| 2450 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2451 | struct i40e_vsi *vsi = np->vsi; |
| 2452 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2453 | /* return code is ignored as there is nothing a user |
| 2454 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2455 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2456 | */ |
| 2457 | i40e_vsi_kill_vlan(vsi, vid); |
| 2458 | |
| 2459 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2460 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2461 | return 0; |
| 2462 | } |
| 2463 | |
| 2464 | /** |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 2465 | * i40e_macaddr_init - explicitly write the mac address filters |
| 2466 | * |
| 2467 | * @vsi: pointer to the vsi |
| 2468 | * @macaddr: the MAC address |
| 2469 | * |
| 2470 | * This is needed when the macaddr has been obtained by other |
| 2471 | * means than the default, e.g., from Open Firmware or IDPROM. |
| 2472 | * Returns 0 on success, negative on failure |
| 2473 | **/ |
| 2474 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) |
| 2475 | { |
| 2476 | int ret; |
| 2477 | struct i40e_aqc_add_macvlan_element_data element; |
| 2478 | |
| 2479 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 2480 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 2481 | macaddr, NULL); |
| 2482 | if (ret) { |
| 2483 | dev_info(&vsi->back->pdev->dev, |
| 2484 | "Addr change for VSI failed: %d\n", ret); |
| 2485 | return -EADDRNOTAVAIL; |
| 2486 | } |
| 2487 | |
| 2488 | memset(&element, 0, sizeof(element)); |
| 2489 | ether_addr_copy(element.mac_addr, macaddr); |
| 2490 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 2491 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); |
| 2492 | if (ret) { |
| 2493 | dev_info(&vsi->back->pdev->dev, |
| 2494 | "add filter failed err %s aq_err %s\n", |
| 2495 | i40e_stat_str(&vsi->back->hw, ret), |
| 2496 | i40e_aq_str(&vsi->back->hw, |
| 2497 | vsi->back->hw.aq.asq_last_status)); |
| 2498 | } |
| 2499 | return ret; |
| 2500 | } |
| 2501 | |
| 2502 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2503 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2504 | * @vsi: the vsi being brought back up |
| 2505 | **/ |
| 2506 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2507 | { |
| 2508 | u16 vid; |
| 2509 | |
| 2510 | if (!vsi->netdev) |
| 2511 | return; |
| 2512 | |
| 2513 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2514 | |
| 2515 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2516 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2517 | vid); |
| 2518 | } |
| 2519 | |
| 2520 | /** |
| 2521 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2522 | * @vsi: the vsi being adjusted |
| 2523 | * @vid: the vlan id to set as a PVID |
| 2524 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2525 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2526 | { |
| 2527 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2528 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2529 | |
| 2530 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2531 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2532 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2533 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2534 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2535 | |
| 2536 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2537 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2538 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2539 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2540 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2541 | "add pvid failed, err %s aq_err %s\n", |
| 2542 | i40e_stat_str(&vsi->back->hw, ret), |
| 2543 | i40e_aq_str(&vsi->back->hw, |
| 2544 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2545 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2546 | } |
| 2547 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2548 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | /** |
| 2552 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2553 | * @vsi: the vsi being adjusted |
| 2554 | * |
| 2555 | * Just use the vlan_rx_register() service to put it back to normal |
| 2556 | **/ |
| 2557 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2558 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2559 | i40e_vlan_stripping_disable(vsi); |
| 2560 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2561 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | /** |
| 2565 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2566 | * @vsi: ptr to the VSI |
| 2567 | * |
| 2568 | * If this function returns with an error, then it's possible one or |
| 2569 | * more of the rings is populated (while the rest are not). It is the |
| 2570 | * callers duty to clean those orphaned rings. |
| 2571 | * |
| 2572 | * Return 0 on success, negative on failure |
| 2573 | **/ |
| 2574 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2575 | { |
| 2576 | int i, err = 0; |
| 2577 | |
| 2578 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2579 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2580 | |
| 2581 | return err; |
| 2582 | } |
| 2583 | |
| 2584 | /** |
| 2585 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2586 | * @vsi: ptr to the VSI |
| 2587 | * |
| 2588 | * Free VSI's transmit software resources |
| 2589 | **/ |
| 2590 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2591 | { |
| 2592 | int i; |
| 2593 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2594 | if (!vsi->tx_rings) |
| 2595 | return; |
| 2596 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2597 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2598 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2599 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | /** |
| 2603 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2604 | * @vsi: ptr to the VSI |
| 2605 | * |
| 2606 | * If this function returns with an error, then it's possible one or |
| 2607 | * more of the rings is populated (while the rest are not). It is the |
| 2608 | * callers duty to clean those orphaned rings. |
| 2609 | * |
| 2610 | * Return 0 on success, negative on failure |
| 2611 | **/ |
| 2612 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2613 | { |
| 2614 | int i, err = 0; |
| 2615 | |
| 2616 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2617 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2618 | #ifdef I40E_FCOE |
| 2619 | i40e_fcoe_setup_ddp_resources(vsi); |
| 2620 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2621 | return err; |
| 2622 | } |
| 2623 | |
| 2624 | /** |
| 2625 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2626 | * @vsi: ptr to the VSI |
| 2627 | * |
| 2628 | * Free all receive software resources |
| 2629 | **/ |
| 2630 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2631 | { |
| 2632 | int i; |
| 2633 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2634 | if (!vsi->rx_rings) |
| 2635 | return; |
| 2636 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2637 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2638 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2639 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2640 | #ifdef I40E_FCOE |
| 2641 | i40e_fcoe_free_ddp_resources(vsi); |
| 2642 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2646 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2647 | * @ring: The Tx ring to configure |
| 2648 | * |
| 2649 | * This enables/disables XPS for a given Tx descriptor ring |
| 2650 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2651 | **/ |
| 2652 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2653 | { |
| 2654 | struct i40e_vsi *vsi = ring->vsi; |
| 2655 | cpumask_var_t mask; |
| 2656 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2657 | if (!ring->q_vector || !ring->netdev) |
| 2658 | return; |
| 2659 | |
| 2660 | /* Single TC mode enable XPS */ |
| 2661 | if (vsi->tc_config.numtc <= 1) { |
| 2662 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2663 | netif_set_xps_queue(ring->netdev, |
| 2664 | &ring->q_vector->affinity_mask, |
| 2665 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2666 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2667 | /* Disable XPS to allow selection based on TC */ |
| 2668 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2669 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2670 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2671 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2672 | |
| 2673 | /* schedule our worker thread which will take care of |
| 2674 | * applying the new filter changes |
| 2675 | */ |
| 2676 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2680 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2681 | * @ring: The Tx ring to configure |
| 2682 | * |
| 2683 | * Configure the Tx descriptor ring in the HMC context. |
| 2684 | **/ |
| 2685 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2686 | { |
| 2687 | struct i40e_vsi *vsi = ring->vsi; |
| 2688 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2689 | struct i40e_hw *hw = &vsi->back->hw; |
| 2690 | struct i40e_hmc_obj_txq tx_ctx; |
| 2691 | i40e_status err = 0; |
| 2692 | u32 qtx_ctl = 0; |
| 2693 | |
| 2694 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2695 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2696 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2697 | ring->atr_count = 0; |
| 2698 | } else { |
| 2699 | ring->atr_sample_rate = 0; |
| 2700 | } |
| 2701 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2702 | /* configure XPS */ |
| 2703 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2704 | |
| 2705 | /* clear the context structure first */ |
| 2706 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2707 | |
| 2708 | tx_ctx.new_context = 1; |
| 2709 | tx_ctx.base = (ring->dma / 128); |
| 2710 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2711 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2712 | I40E_FLAG_FD_ATR_ENABLED)); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2713 | #ifdef I40E_FCOE |
| 2714 | tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2715 | #endif |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2716 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2717 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2718 | if (vsi->type != I40E_VSI_FDIR) |
| 2719 | tx_ctx.head_wb_ena = 1; |
| 2720 | tx_ctx.head_wb_addr = ring->dma + |
| 2721 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2722 | |
| 2723 | /* As part of VSI creation/update, FW allocates certain |
| 2724 | * Tx arbitration queue sets for each TC enabled for |
| 2725 | * the VSI. The FW returns the handles to these queue |
| 2726 | * sets as part of the response buffer to Add VSI, |
| 2727 | * Update VSI, etc. AQ commands. It is expected that |
| 2728 | * these queue set handles be associated with the Tx |
| 2729 | * queues by the driver as part of the TX queue context |
| 2730 | * initialization. This has to be done regardless of |
| 2731 | * DCB as by default everything is mapped to TC0. |
| 2732 | */ |
| 2733 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2734 | tx_ctx.rdylist_act = 0; |
| 2735 | |
| 2736 | /* clear the context in the HMC */ |
| 2737 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2738 | if (err) { |
| 2739 | dev_info(&vsi->back->pdev->dev, |
| 2740 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2741 | ring->queue_index, pf_q, err); |
| 2742 | return -ENOMEM; |
| 2743 | } |
| 2744 | |
| 2745 | /* set the context in the HMC */ |
| 2746 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2747 | if (err) { |
| 2748 | dev_info(&vsi->back->pdev->dev, |
| 2749 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2750 | ring->queue_index, pf_q, err); |
| 2751 | return -ENOMEM; |
| 2752 | } |
| 2753 | |
| 2754 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2755 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2756 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2757 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2758 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2759 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2760 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2761 | } |
| 2762 | |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2763 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2764 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2765 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2766 | i40e_flush(hw); |
| 2767 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2768 | /* cache tail off for easier writes later */ |
| 2769 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2770 | |
| 2771 | return 0; |
| 2772 | } |
| 2773 | |
| 2774 | /** |
| 2775 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2776 | * @ring: The Rx ring to configure |
| 2777 | * |
| 2778 | * Configure the Rx descriptor ring in the HMC context. |
| 2779 | **/ |
| 2780 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2781 | { |
| 2782 | struct i40e_vsi *vsi = ring->vsi; |
| 2783 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2784 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2785 | struct i40e_hw *hw = &vsi->back->hw; |
| 2786 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2787 | i40e_status err = 0; |
| 2788 | |
| 2789 | ring->state = 0; |
| 2790 | |
| 2791 | /* clear the context structure first */ |
| 2792 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2793 | |
| 2794 | ring->rx_buf_len = vsi->rx_buf_len; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2795 | |
| 2796 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2797 | |
| 2798 | rx_ctx.base = (ring->dma / 128); |
| 2799 | rx_ctx.qlen = ring->count; |
| 2800 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 2801 | /* use 32 byte descriptors */ |
| 2802 | rx_ctx.dsize = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2803 | |
Jesse Brandeburg | bec60fc | 2016-04-18 11:33:47 -0700 | [diff] [blame] | 2804 | /* descriptor type is always zero |
| 2805 | * rx_ctx.dtype = 0; |
| 2806 | */ |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 2807 | rx_ctx.hsplit_0 = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2808 | |
Jesse Brandeburg | b32bfa1 | 2016-04-18 11:33:42 -0700 | [diff] [blame] | 2809 | 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] | 2810 | if (hw->revision_id == 0) |
| 2811 | rx_ctx.lrxqthresh = 0; |
| 2812 | else |
| 2813 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2814 | rx_ctx.crcstrip = 1; |
| 2815 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 2816 | /* this controls whether VLAN is stripped from inner headers */ |
| 2817 | rx_ctx.showiv = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2818 | #ifdef I40E_FCOE |
| 2819 | rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2820 | #endif |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 2821 | /* set the prefena field to 1 because the manual says to */ |
| 2822 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2823 | |
| 2824 | /* clear the context in the HMC */ |
| 2825 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 2826 | if (err) { |
| 2827 | dev_info(&vsi->back->pdev->dev, |
| 2828 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2829 | ring->queue_index, pf_q, err); |
| 2830 | return -ENOMEM; |
| 2831 | } |
| 2832 | |
| 2833 | /* set the context in the HMC */ |
| 2834 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 2835 | if (err) { |
| 2836 | dev_info(&vsi->back->pdev->dev, |
| 2837 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2838 | ring->queue_index, pf_q, err); |
| 2839 | return -ENOMEM; |
| 2840 | } |
| 2841 | |
| 2842 | /* cache tail for quicker writes, and clear the reg before use */ |
| 2843 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 2844 | writel(0, ring->tail); |
| 2845 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 2846 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2847 | |
| 2848 | return 0; |
| 2849 | } |
| 2850 | |
| 2851 | /** |
| 2852 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 2853 | * @vsi: VSI structure describing this set of rings and resources |
| 2854 | * |
| 2855 | * Configure the Tx VSI for operation. |
| 2856 | **/ |
| 2857 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 2858 | { |
| 2859 | int err = 0; |
| 2860 | u16 i; |
| 2861 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2862 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 2863 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2864 | |
| 2865 | return err; |
| 2866 | } |
| 2867 | |
| 2868 | /** |
| 2869 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 2870 | * @vsi: the VSI being configured |
| 2871 | * |
| 2872 | * Configure the Rx VSI for operation. |
| 2873 | **/ |
| 2874 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 2875 | { |
| 2876 | int err = 0; |
| 2877 | u16 i; |
| 2878 | |
| 2879 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 2880 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 2881 | + ETH_FCS_LEN + VLAN_HLEN; |
| 2882 | else |
| 2883 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 2884 | |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 2885 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2886 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2887 | #ifdef I40E_FCOE |
| 2888 | /* setup rx buffer for FCoE */ |
| 2889 | if ((vsi->type == I40E_VSI_FCOE) && |
| 2890 | (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) { |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2891 | vsi->rx_buf_len = I40E_RXBUFFER_3072; |
| 2892 | vsi->max_frame = I40E_RXBUFFER_3072; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2896 | /* round up for the chip's needs */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2897 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2898 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2899 | |
| 2900 | /* set up individual rings */ |
| 2901 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2902 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2903 | |
| 2904 | return err; |
| 2905 | } |
| 2906 | |
| 2907 | /** |
| 2908 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 2909 | * @vsi: ptr to the VSI |
| 2910 | **/ |
| 2911 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 2912 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 2913 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2914 | u16 qoffset, qcount; |
| 2915 | int i, n; |
| 2916 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 2917 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 2918 | /* Reset the TC information */ |
| 2919 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 2920 | rx_ring = vsi->rx_rings[i]; |
| 2921 | tx_ring = vsi->tx_rings[i]; |
| 2922 | rx_ring->dcb_tc = 0; |
| 2923 | tx_ring->dcb_tc = 0; |
| 2924 | } |
| 2925 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2926 | |
| 2927 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2928 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2929 | continue; |
| 2930 | |
| 2931 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 2932 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 2933 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 2934 | rx_ring = vsi->rx_rings[i]; |
| 2935 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2936 | rx_ring->dcb_tc = n; |
| 2937 | tx_ring->dcb_tc = n; |
| 2938 | } |
| 2939 | } |
| 2940 | } |
| 2941 | |
| 2942 | /** |
| 2943 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 2944 | * @vsi: ptr to the VSI |
| 2945 | **/ |
| 2946 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 2947 | { |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 2948 | struct i40e_pf *pf = vsi->back; |
| 2949 | int err; |
| 2950 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2951 | if (vsi->netdev) |
| 2952 | i40e_set_rx_mode(vsi->netdev); |
Tushar Dave | b1b15df | 2016-07-01 10:11:20 -0700 | [diff] [blame] | 2953 | |
| 2954 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 2955 | err = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 2956 | if (err) { |
| 2957 | dev_warn(&pf->pdev->dev, |
| 2958 | "could not set up macaddr; err %d\n", err); |
| 2959 | } |
| 2960 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2964 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 2965 | * @vsi: Pointer to the targeted VSI |
| 2966 | * |
| 2967 | * This function replays the hlist on the hw where all the SB Flow Director |
| 2968 | * filters were saved. |
| 2969 | **/ |
| 2970 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 2971 | { |
| 2972 | struct i40e_fdir_filter *filter; |
| 2973 | struct i40e_pf *pf = vsi->back; |
| 2974 | struct hlist_node *node; |
| 2975 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 2976 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 2977 | return; |
| 2978 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2979 | hlist_for_each_entry_safe(filter, node, |
| 2980 | &pf->fdir_filter_list, fdir_node) { |
| 2981 | i40e_add_del_fdir(vsi, filter, true); |
| 2982 | } |
| 2983 | } |
| 2984 | |
| 2985 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2986 | * i40e_vsi_configure - Set up the VSI for action |
| 2987 | * @vsi: the VSI being configured |
| 2988 | **/ |
| 2989 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 2990 | { |
| 2991 | int err; |
| 2992 | |
| 2993 | i40e_set_vsi_rx_mode(vsi); |
| 2994 | i40e_restore_vlan(vsi); |
| 2995 | i40e_vsi_config_dcb_rings(vsi); |
| 2996 | err = i40e_vsi_configure_tx(vsi); |
| 2997 | if (!err) |
| 2998 | err = i40e_vsi_configure_rx(vsi); |
| 2999 | |
| 3000 | return err; |
| 3001 | } |
| 3002 | |
| 3003 | /** |
| 3004 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3005 | * @vsi: the VSI being configured |
| 3006 | **/ |
| 3007 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3008 | { |
| 3009 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3010 | struct i40e_hw *hw = &pf->hw; |
| 3011 | u16 vector; |
| 3012 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3013 | u32 qp; |
| 3014 | |
| 3015 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3016 | * and PFINT_LNKLSTn registers, e.g.: |
| 3017 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3018 | */ |
| 3019 | qp = vsi->base_queue; |
| 3020 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3021 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3022 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3023 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3024 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3025 | 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] | 3026 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3027 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3028 | q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3029 | 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] | 3030 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3031 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3032 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3033 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
| 3034 | INTRL_USEC_TO_REG(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3035 | |
| 3036 | /* Linked list for the queuepairs assigned to this vector */ |
| 3037 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3038 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3039 | u32 val; |
| 3040 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3041 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3042 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3043 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3044 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 3045 | (I40E_QUEUE_TYPE_TX |
| 3046 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 3047 | |
| 3048 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3049 | |
| 3050 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3051 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3052 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3053 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 3054 | (I40E_QUEUE_TYPE_RX |
| 3055 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3056 | |
| 3057 | /* Terminate the linked list */ |
| 3058 | if (q == (q_vector->num_ringpairs - 1)) |
| 3059 | val |= (I40E_QUEUE_END_OF_LIST |
| 3060 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3061 | |
| 3062 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3063 | qp++; |
| 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | i40e_flush(hw); |
| 3068 | } |
| 3069 | |
| 3070 | /** |
| 3071 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3072 | * @hw: ptr to the hardware info |
| 3073 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3074 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3075 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3076 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3077 | u32 val; |
| 3078 | |
| 3079 | /* clear things first */ |
| 3080 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3081 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3082 | |
| 3083 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3084 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3085 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3086 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3087 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3088 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3089 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3090 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3091 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3092 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3093 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3094 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3095 | if (pf->flags & I40E_FLAG_PTP) |
| 3096 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3097 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3098 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3099 | |
| 3100 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3101 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3102 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3103 | |
| 3104 | /* OTHER_ITR_IDX = 0 */ |
| 3105 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3106 | } |
| 3107 | |
| 3108 | /** |
| 3109 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3110 | * @vsi: the VSI being configured |
| 3111 | **/ |
| 3112 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3113 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3114 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3115 | struct i40e_pf *pf = vsi->back; |
| 3116 | struct i40e_hw *hw = &pf->hw; |
| 3117 | u32 val; |
| 3118 | |
| 3119 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3120 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3121 | 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] | 3122 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3123 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 3124 | 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] | 3125 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3126 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3127 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3128 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3129 | |
| 3130 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3131 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3132 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3133 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3134 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3135 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3136 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3137 | |
| 3138 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3139 | |
| 3140 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3141 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3142 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3143 | |
| 3144 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3145 | i40e_flush(hw); |
| 3146 | } |
| 3147 | |
| 3148 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3149 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3150 | * @pf: board private structure |
| 3151 | **/ |
| 3152 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3153 | { |
| 3154 | struct i40e_hw *hw = &pf->hw; |
| 3155 | |
| 3156 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3157 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3158 | i40e_flush(hw); |
| 3159 | } |
| 3160 | |
| 3161 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3162 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3163 | * @pf: board private structure |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3164 | * @clearpba: true when all pending interrupt events should be cleared |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3165 | **/ |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3166 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3167 | { |
| 3168 | struct i40e_hw *hw = &pf->hw; |
| 3169 | u32 val; |
| 3170 | |
| 3171 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3172 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3173 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3174 | |
| 3175 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3176 | i40e_flush(hw); |
| 3177 | } |
| 3178 | |
| 3179 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3180 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3181 | * @irq: interrupt number |
| 3182 | * @data: pointer to a q_vector |
| 3183 | **/ |
| 3184 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3185 | { |
| 3186 | struct i40e_q_vector *q_vector = data; |
| 3187 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3188 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3189 | return IRQ_HANDLED; |
| 3190 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3191 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3192 | |
| 3193 | return IRQ_HANDLED; |
| 3194 | } |
| 3195 | |
| 3196 | /** |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3197 | * i40e_irq_affinity_notify - Callback for affinity changes |
| 3198 | * @notify: context as to what irq was changed |
| 3199 | * @mask: the new affinity mask |
| 3200 | * |
| 3201 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3202 | * so that we may register to receive changes to the irq affinity masks. |
| 3203 | **/ |
| 3204 | static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify, |
| 3205 | const cpumask_t *mask) |
| 3206 | { |
| 3207 | struct i40e_q_vector *q_vector = |
| 3208 | container_of(notify, struct i40e_q_vector, affinity_notify); |
| 3209 | |
| 3210 | q_vector->affinity_mask = *mask; |
| 3211 | } |
| 3212 | |
| 3213 | /** |
| 3214 | * i40e_irq_affinity_release - Callback for affinity notifier release |
| 3215 | * @ref: internal core kernel usage |
| 3216 | * |
| 3217 | * This is a callback function used by the irq_set_affinity_notifier function |
| 3218 | * to inform the current notification subscriber that they will no longer |
| 3219 | * receive notifications. |
| 3220 | **/ |
| 3221 | static void i40e_irq_affinity_release(struct kref *ref) {} |
| 3222 | |
| 3223 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3224 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3225 | * @vsi: the VSI being configured |
| 3226 | * @basename: name for the vector |
| 3227 | * |
| 3228 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3229 | **/ |
| 3230 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3231 | { |
| 3232 | int q_vectors = vsi->num_q_vectors; |
| 3233 | struct i40e_pf *pf = vsi->back; |
| 3234 | int base = vsi->base_vector; |
| 3235 | int rx_int_idx = 0; |
| 3236 | int tx_int_idx = 0; |
| 3237 | int vector, err; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3238 | int irq_num; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3239 | |
| 3240 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3241 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3242 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3243 | irq_num = pf->msix_entries[base + vector].vector; |
| 3244 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3245 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3246 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3247 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3248 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3249 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3250 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3251 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3252 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3253 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3254 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3255 | } else { |
| 3256 | /* skip this unused q_vector */ |
| 3257 | continue; |
| 3258 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3259 | err = request_irq(irq_num, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3260 | vsi->irq_handler, |
| 3261 | 0, |
| 3262 | q_vector->name, |
| 3263 | q_vector); |
| 3264 | if (err) { |
| 3265 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3266 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3267 | goto free_queue_irqs; |
| 3268 | } |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3269 | |
| 3270 | /* register for affinity change notifications */ |
| 3271 | q_vector->affinity_notify.notify = i40e_irq_affinity_notify; |
| 3272 | q_vector->affinity_notify.release = i40e_irq_affinity_release; |
| 3273 | irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3274 | /* assign the mask for this irq */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3275 | irq_set_affinity_hint(irq_num, &q_vector->affinity_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3276 | } |
| 3277 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3278 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3279 | return 0; |
| 3280 | |
| 3281 | free_queue_irqs: |
| 3282 | while (vector) { |
| 3283 | vector--; |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3284 | irq_num = pf->msix_entries[base + vector].vector; |
| 3285 | irq_set_affinity_notifier(irq_num, NULL); |
| 3286 | irq_set_affinity_hint(irq_num, NULL); |
| 3287 | free_irq(irq_num, &vsi->q_vectors[vector]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3288 | } |
| 3289 | return err; |
| 3290 | } |
| 3291 | |
| 3292 | /** |
| 3293 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3294 | * @vsi: the VSI being un-configured |
| 3295 | **/ |
| 3296 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3297 | { |
| 3298 | struct i40e_pf *pf = vsi->back; |
| 3299 | struct i40e_hw *hw = &pf->hw; |
| 3300 | int base = vsi->base_vector; |
| 3301 | int i; |
| 3302 | |
| 3303 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3304 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3305 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3306 | } |
| 3307 | |
| 3308 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3309 | for (i = vsi->base_vector; |
| 3310 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3311 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3312 | |
| 3313 | i40e_flush(hw); |
| 3314 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3315 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3316 | } else { |
| 3317 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3318 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3319 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3320 | i40e_flush(hw); |
| 3321 | synchronize_irq(pf->pdev->irq); |
| 3322 | } |
| 3323 | } |
| 3324 | |
| 3325 | /** |
| 3326 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3327 | * @vsi: the VSI being configured |
| 3328 | **/ |
| 3329 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3330 | { |
| 3331 | struct i40e_pf *pf = vsi->back; |
| 3332 | int i; |
| 3333 | |
| 3334 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3335 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3336 | i40e_irq_dynamic_enable(vsi, i); |
| 3337 | } else { |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3338 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3339 | } |
| 3340 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3341 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3342 | return 0; |
| 3343 | } |
| 3344 | |
| 3345 | /** |
| 3346 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3347 | * @pf: board private structure |
| 3348 | **/ |
| 3349 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3350 | { |
| 3351 | /* Disable ICR 0 */ |
| 3352 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3353 | i40e_flush(&pf->hw); |
| 3354 | } |
| 3355 | |
| 3356 | /** |
| 3357 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3358 | * @irq: interrupt number |
| 3359 | * @data: pointer to a q_vector |
| 3360 | * |
| 3361 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3362 | * with both queue and non-queue interrupts. This is also used in |
| 3363 | * MSIX mode to handle the non-queue interrupts. |
| 3364 | **/ |
| 3365 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3366 | { |
| 3367 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3368 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3369 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3370 | u32 icr0, icr0_remaining; |
| 3371 | u32 val, ena_mask; |
| 3372 | |
| 3373 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3374 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3375 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3376 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3377 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3378 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3379 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3380 | /* if interrupt but no bits showing, must be SWINT */ |
| 3381 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3382 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3383 | pf->sw_int_count++; |
| 3384 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3385 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 3386 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
| 3387 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3388 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3389 | dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
| 3390 | } |
| 3391 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3392 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3393 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3394 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3395 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3396 | |
Anjali Singhai Jain | a16ae2d | 2016-01-15 14:33:16 -0800 | [diff] [blame] | 3397 | /* We do not have a way to disarm Queue causes while leaving |
| 3398 | * interrupt enabled for all other causes, ideally |
| 3399 | * interrupt should be disabled while we are in NAPI but |
| 3400 | * this is not a performance path and napi_schedule() |
| 3401 | * can deal with rescheduling. |
| 3402 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3403 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3404 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3405 | } |
| 3406 | |
| 3407 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3408 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3409 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 3410 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3411 | } |
| 3412 | |
| 3413 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3414 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3415 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3416 | } |
| 3417 | |
| 3418 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3419 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3420 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3421 | } |
| 3422 | |
| 3423 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3424 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3425 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3426 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3427 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3428 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3429 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3430 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3431 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3432 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3433 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3434 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3435 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3436 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3437 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3438 | } |
| 3439 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3440 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3441 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3442 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3443 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3444 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3445 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3446 | } |
| 3447 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3448 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3449 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3450 | |
| 3451 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3452 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3453 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3454 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3455 | } |
| 3456 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3457 | /* If a critical error is pending we have no choice but to reset the |
| 3458 | * device. |
| 3459 | * Report and mask out any remaining unexpected interrupts. |
| 3460 | */ |
| 3461 | icr0_remaining = icr0 & ena_mask; |
| 3462 | if (icr0_remaining) { |
| 3463 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3464 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3465 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3466 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3467 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3468 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3469 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3470 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3471 | } |
| 3472 | ena_mask &= ~icr0_remaining; |
| 3473 | } |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3474 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3475 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3476 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3477 | /* re-enable interrupt causes */ |
| 3478 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3479 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3480 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 3481 | i40e_irq_dynamic_enable_icr0(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3482 | } |
| 3483 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3484 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3488 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3489 | * @tx_ring: tx ring to clean |
| 3490 | * @budget: how many cleans we're allowed |
| 3491 | * |
| 3492 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3493 | **/ |
| 3494 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3495 | { |
| 3496 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3497 | u16 i = tx_ring->next_to_clean; |
| 3498 | struct i40e_tx_buffer *tx_buf; |
| 3499 | struct i40e_tx_desc *tx_desc; |
| 3500 | |
| 3501 | tx_buf = &tx_ring->tx_bi[i]; |
| 3502 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3503 | i -= tx_ring->count; |
| 3504 | |
| 3505 | do { |
| 3506 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3507 | |
| 3508 | /* if next_to_watch is not set then there is no work pending */ |
| 3509 | if (!eop_desc) |
| 3510 | break; |
| 3511 | |
| 3512 | /* prevent any other reads prior to eop_desc */ |
| 3513 | read_barrier_depends(); |
| 3514 | |
| 3515 | /* if the descriptor isn't done, no work yet to do */ |
| 3516 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3517 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3518 | break; |
| 3519 | |
| 3520 | /* clear next_to_watch to prevent false hangs */ |
| 3521 | tx_buf->next_to_watch = NULL; |
| 3522 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3523 | tx_desc->buffer_addr = 0; |
| 3524 | tx_desc->cmd_type_offset_bsz = 0; |
| 3525 | /* move past filter desc */ |
| 3526 | tx_buf++; |
| 3527 | tx_desc++; |
| 3528 | i++; |
| 3529 | if (unlikely(!i)) { |
| 3530 | i -= tx_ring->count; |
| 3531 | tx_buf = tx_ring->tx_bi; |
| 3532 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3533 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3534 | /* unmap skb header data */ |
| 3535 | dma_unmap_single(tx_ring->dev, |
| 3536 | dma_unmap_addr(tx_buf, dma), |
| 3537 | dma_unmap_len(tx_buf, len), |
| 3538 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3539 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3540 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3541 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3542 | tx_buf->raw_buf = NULL; |
| 3543 | tx_buf->tx_flags = 0; |
| 3544 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3545 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3546 | tx_desc->buffer_addr = 0; |
| 3547 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3548 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3549 | /* 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] | 3550 | tx_buf++; |
| 3551 | tx_desc++; |
| 3552 | i++; |
| 3553 | if (unlikely(!i)) { |
| 3554 | i -= tx_ring->count; |
| 3555 | tx_buf = tx_ring->tx_bi; |
| 3556 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3557 | } |
| 3558 | |
| 3559 | /* update budget accounting */ |
| 3560 | budget--; |
| 3561 | } while (likely(budget)); |
| 3562 | |
| 3563 | i += tx_ring->count; |
| 3564 | tx_ring->next_to_clean = i; |
| 3565 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3566 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3567 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3568 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3569 | return budget > 0; |
| 3570 | } |
| 3571 | |
| 3572 | /** |
| 3573 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3574 | * @irq: interrupt number |
| 3575 | * @data: pointer to a q_vector |
| 3576 | **/ |
| 3577 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3578 | { |
| 3579 | struct i40e_q_vector *q_vector = data; |
| 3580 | struct i40e_vsi *vsi; |
| 3581 | |
| 3582 | if (!q_vector->tx.ring) |
| 3583 | return IRQ_HANDLED; |
| 3584 | |
| 3585 | vsi = q_vector->tx.ring->vsi; |
| 3586 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3587 | |
| 3588 | return IRQ_HANDLED; |
| 3589 | } |
| 3590 | |
| 3591 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3592 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3593 | * @vsi: the VSI being configured |
| 3594 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3595 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3596 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3597 | 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] | 3598 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3599 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3600 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3601 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3602 | |
| 3603 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3604 | tx_ring->next = q_vector->tx.ring; |
| 3605 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3606 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3607 | |
| 3608 | rx_ring->q_vector = q_vector; |
| 3609 | rx_ring->next = q_vector->rx.ring; |
| 3610 | q_vector->rx.ring = rx_ring; |
| 3611 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | /** |
| 3615 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3616 | * @vsi: the VSI being configured |
| 3617 | * |
| 3618 | * This function maps descriptor rings to the queue-specific vectors |
| 3619 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3620 | * one vector per queue pair, but on a constrained vector budget, we |
| 3621 | * group the queue pairs as "efficiently" as possible. |
| 3622 | **/ |
| 3623 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3624 | { |
| 3625 | int qp_remaining = vsi->num_queue_pairs; |
| 3626 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3627 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3628 | int v_start = 0; |
| 3629 | int qp_idx = 0; |
| 3630 | |
| 3631 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3632 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3633 | * It is also important to go through all the vectors available to be |
| 3634 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3635 | * are cleared. This is especially important when decreasing the |
| 3636 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3637 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3638 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3639 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3640 | |
| 3641 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3642 | |
| 3643 | q_vector->num_ringpairs = num_ringpairs; |
| 3644 | |
| 3645 | q_vector->rx.count = 0; |
| 3646 | q_vector->tx.count = 0; |
| 3647 | q_vector->rx.ring = NULL; |
| 3648 | q_vector->tx.ring = NULL; |
| 3649 | |
| 3650 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3651 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3652 | qp_idx++; |
| 3653 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3654 | } |
| 3655 | } |
| 3656 | } |
| 3657 | |
| 3658 | /** |
| 3659 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3660 | * @vsi: the VSI being configured |
| 3661 | * @basename: name for the vector |
| 3662 | **/ |
| 3663 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3664 | { |
| 3665 | struct i40e_pf *pf = vsi->back; |
| 3666 | int err; |
| 3667 | |
| 3668 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3669 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3670 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3671 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3672 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3673 | else |
| 3674 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3675 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3676 | |
| 3677 | if (err) |
| 3678 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3679 | |
| 3680 | return err; |
| 3681 | } |
| 3682 | |
| 3683 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3684 | /** |
Jesse Brandeburg | d89d967 | 2016-01-04 10:33:02 -0800 | [diff] [blame] | 3685 | * i40e_netpoll - A Polling 'interrupt' handler |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3686 | * @netdev: network interface device structure |
| 3687 | * |
| 3688 | * This is used by netconsole to send skbs without having to re-enable |
| 3689 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3690 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3691 | #ifdef I40E_FCOE |
| 3692 | void i40e_netpoll(struct net_device *netdev) |
| 3693 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3694 | static void i40e_netpoll(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3695 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3696 | { |
| 3697 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3698 | struct i40e_vsi *vsi = np->vsi; |
| 3699 | struct i40e_pf *pf = vsi->back; |
| 3700 | int i; |
| 3701 | |
| 3702 | /* if interface is down do nothing */ |
| 3703 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3704 | return; |
| 3705 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3706 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3707 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3708 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3709 | } else { |
| 3710 | i40e_intr(pf->pdev->irq, netdev); |
| 3711 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3712 | } |
| 3713 | #endif |
| 3714 | |
| 3715 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3716 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3717 | * @pf: the PF being configured |
| 3718 | * @pf_q: the PF queue |
| 3719 | * @enable: enable or disable state of the queue |
| 3720 | * |
| 3721 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3722 | * enabled or disabled state. |
| 3723 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3724 | * multiple retries; else will return 0 in case of success. |
| 3725 | **/ |
| 3726 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3727 | { |
| 3728 | int i; |
| 3729 | u32 tx_reg; |
| 3730 | |
| 3731 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3732 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3733 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3734 | break; |
| 3735 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3736 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3737 | } |
| 3738 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3739 | return -ETIMEDOUT; |
| 3740 | |
| 3741 | return 0; |
| 3742 | } |
| 3743 | |
| 3744 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3745 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3746 | * @vsi: the VSI being configured |
| 3747 | * @enable: start or stop the rings |
| 3748 | **/ |
| 3749 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3750 | { |
| 3751 | struct i40e_pf *pf = vsi->back; |
| 3752 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3753 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3754 | u32 tx_reg; |
| 3755 | |
| 3756 | pf_q = vsi->base_queue; |
| 3757 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3758 | |
| 3759 | /* warn the TX unit of coming changes */ |
| 3760 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3761 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3762 | usleep_range(10, 20); |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3763 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3764 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3765 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3766 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3767 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3768 | break; |
| 3769 | usleep_range(1000, 2000); |
| 3770 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3771 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3772 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3773 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3774 | |
| 3775 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3776 | if (enable) { |
| 3777 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3778 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3779 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3780 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3781 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3782 | |
| 3783 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 3784 | /* No waiting for the Tx queue to disable */ |
| 3785 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3786 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3787 | |
| 3788 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3789 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 3790 | if (ret) { |
| 3791 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3792 | "VSI seid %d Tx ring %d %sable timeout\n", |
| 3793 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3794 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3795 | } |
| 3796 | } |
| 3797 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3798 | if (hw->revision_id == 0) |
| 3799 | mdelay(50); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3800 | return ret; |
| 3801 | } |
| 3802 | |
| 3803 | /** |
| 3804 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 3805 | * @pf: the PF being configured |
| 3806 | * @pf_q: the PF queue |
| 3807 | * @enable: enable or disable state of the queue |
| 3808 | * |
| 3809 | * This routine will wait for the given Rx queue of the PF to reach the |
| 3810 | * enabled or disabled state. |
| 3811 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3812 | * multiple retries; else will return 0 in case of success. |
| 3813 | **/ |
| 3814 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3815 | { |
| 3816 | int i; |
| 3817 | u32 rx_reg; |
| 3818 | |
| 3819 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3820 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 3821 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3822 | break; |
| 3823 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3824 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3825 | } |
| 3826 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3827 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3828 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3829 | return 0; |
| 3830 | } |
| 3831 | |
| 3832 | /** |
| 3833 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 3834 | * @vsi: the VSI being configured |
| 3835 | * @enable: start or stop the rings |
| 3836 | **/ |
| 3837 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 3838 | { |
| 3839 | struct i40e_pf *pf = vsi->back; |
| 3840 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3841 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3842 | u32 rx_reg; |
| 3843 | |
| 3844 | pf_q = vsi->base_queue; |
| 3845 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3846 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3847 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3848 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3849 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3850 | break; |
| 3851 | usleep_range(1000, 2000); |
| 3852 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3853 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3854 | /* Skip if the queue is already in the requested state */ |
| 3855 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3856 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3857 | |
| 3858 | /* turn on/off the queue */ |
| 3859 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3860 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3861 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3862 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3863 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 3864 | /* No waiting for the Tx queue to disable */ |
| 3865 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3866 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3867 | |
| 3868 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3869 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 3870 | if (ret) { |
| 3871 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3872 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 3873 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3874 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3875 | } |
| 3876 | } |
| 3877 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3878 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | /** |
| 3882 | * i40e_vsi_control_rings - Start or stop a VSI's rings |
| 3883 | * @vsi: the VSI being configured |
| 3884 | * @enable: start or stop the rings |
| 3885 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 3886 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3887 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3888 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3889 | |
| 3890 | /* do rx first for enable and last for disable */ |
| 3891 | if (request) { |
| 3892 | ret = i40e_vsi_control_rx(vsi, request); |
| 3893 | if (ret) |
| 3894 | return ret; |
| 3895 | ret = i40e_vsi_control_tx(vsi, request); |
| 3896 | } else { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3897 | /* Ignore return value, we need to shutdown whatever we can */ |
| 3898 | i40e_vsi_control_tx(vsi, request); |
| 3899 | i40e_vsi_control_rx(vsi, request); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | return ret; |
| 3903 | } |
| 3904 | |
| 3905 | /** |
| 3906 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 3907 | * @vsi: the VSI being configured |
| 3908 | **/ |
| 3909 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 3910 | { |
| 3911 | struct i40e_pf *pf = vsi->back; |
| 3912 | struct i40e_hw *hw = &pf->hw; |
| 3913 | int base = vsi->base_vector; |
| 3914 | u32 val, qp; |
| 3915 | int i; |
| 3916 | |
| 3917 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3918 | if (!vsi->q_vectors) |
| 3919 | return; |
| 3920 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3921 | if (!vsi->irqs_ready) |
| 3922 | return; |
| 3923 | |
| 3924 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3925 | for (i = 0; i < vsi->num_q_vectors; i++) { |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3926 | int irq_num; |
| 3927 | u16 vector; |
| 3928 | |
| 3929 | vector = i + base; |
| 3930 | irq_num = pf->msix_entries[vector].vector; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3931 | |
| 3932 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 3933 | if (!vsi->q_vectors[i] || |
| 3934 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3935 | continue; |
| 3936 | |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3937 | /* clear the affinity notifier in the IRQ descriptor */ |
| 3938 | irq_set_affinity_notifier(irq_num, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3939 | /* clear the affinity_mask in the IRQ descriptor */ |
Alan Brady | 96db776 | 2016-09-14 16:24:38 -0700 | [diff] [blame] | 3940 | irq_set_affinity_hint(irq_num, NULL); |
| 3941 | synchronize_irq(irq_num); |
| 3942 | free_irq(irq_num, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3943 | |
| 3944 | /* Tear down the interrupt queue link list |
| 3945 | * |
| 3946 | * We know that they come in pairs and always |
| 3947 | * the Rx first, then the Tx. To clear the |
| 3948 | * link list, stick the EOL value into the |
| 3949 | * next_q field of the registers. |
| 3950 | */ |
| 3951 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 3952 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 3953 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3954 | val |= I40E_QUEUE_END_OF_LIST |
| 3955 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3956 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 3957 | |
| 3958 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 3959 | u32 next; |
| 3960 | |
| 3961 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 3962 | |
| 3963 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 3964 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 3965 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3966 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 3967 | |
| 3968 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 3969 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 3970 | |
| 3971 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3972 | |
| 3973 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 3974 | |
| 3975 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 3976 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 3977 | |
| 3978 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 3979 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 3980 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3981 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 3982 | |
| 3983 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 3984 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 3985 | |
| 3986 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3987 | qp = next; |
| 3988 | } |
| 3989 | } |
| 3990 | } else { |
| 3991 | free_irq(pf->pdev->irq, pf); |
| 3992 | |
| 3993 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 3994 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 3995 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3996 | val |= I40E_QUEUE_END_OF_LIST |
| 3997 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 3998 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 3999 | |
| 4000 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4001 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4002 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4003 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4004 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4005 | |
| 4006 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4007 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4008 | |
| 4009 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4010 | |
| 4011 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4012 | |
| 4013 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4014 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4015 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4016 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4017 | |
| 4018 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4019 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4020 | |
| 4021 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4022 | } |
| 4023 | } |
| 4024 | |
| 4025 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4026 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4027 | * @vsi: the VSI being configured |
| 4028 | * @v_idx: Index of vector to be freed |
| 4029 | * |
| 4030 | * This function frees the memory allocated to the q_vector. In addition if |
| 4031 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4032 | * to freeing the q_vector. |
| 4033 | **/ |
| 4034 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4035 | { |
| 4036 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4037 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4038 | |
| 4039 | if (!q_vector) |
| 4040 | return; |
| 4041 | |
| 4042 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4043 | i40e_for_each_ring(ring, q_vector->tx) |
| 4044 | ring->q_vector = NULL; |
| 4045 | |
| 4046 | i40e_for_each_ring(ring, q_vector->rx) |
| 4047 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4048 | |
| 4049 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4050 | if (vsi->netdev) |
| 4051 | netif_napi_del(&q_vector->napi); |
| 4052 | |
| 4053 | vsi->q_vectors[v_idx] = NULL; |
| 4054 | |
| 4055 | kfree_rcu(q_vector, rcu); |
| 4056 | } |
| 4057 | |
| 4058 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4059 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4060 | * @vsi: the VSI being un-configured |
| 4061 | * |
| 4062 | * This frees the memory allocated to the q_vectors and |
| 4063 | * deletes references to the NAPI struct. |
| 4064 | **/ |
| 4065 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4066 | { |
| 4067 | int v_idx; |
| 4068 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4069 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4070 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | /** |
| 4074 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4075 | * @pf: board private structure |
| 4076 | **/ |
| 4077 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4078 | { |
| 4079 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4080 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4081 | pci_disable_msix(pf->pdev); |
| 4082 | kfree(pf->msix_entries); |
| 4083 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4084 | kfree(pf->irq_pile); |
| 4085 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4086 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4087 | pci_disable_msi(pf->pdev); |
| 4088 | } |
| 4089 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4090 | } |
| 4091 | |
| 4092 | /** |
| 4093 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4094 | * @pf: board private structure |
| 4095 | * |
| 4096 | * We go through and clear interrupt specific resources and reset the structure |
| 4097 | * to pre-load conditions |
| 4098 | **/ |
| 4099 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4100 | { |
| 4101 | int i; |
| 4102 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4103 | i40e_stop_misc_vector(pf); |
Shannon Nelson | 6927839 | 2016-03-10 14:59:43 -0800 | [diff] [blame] | 4104 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4105 | synchronize_irq(pf->msix_entries[0].vector); |
| 4106 | free_irq(pf->msix_entries[0].vector, pf); |
| 4107 | } |
| 4108 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4109 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
| 4110 | I40E_IWARP_IRQ_PILE_ID); |
| 4111 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4112 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4113 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4114 | if (pf->vsi[i]) |
| 4115 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4116 | i40e_reset_interrupt_capability(pf); |
| 4117 | } |
| 4118 | |
| 4119 | /** |
| 4120 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4121 | * @vsi: the VSI being configured |
| 4122 | **/ |
| 4123 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4124 | { |
| 4125 | int q_idx; |
| 4126 | |
| 4127 | if (!vsi->netdev) |
| 4128 | return; |
| 4129 | |
| 4130 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4131 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4132 | } |
| 4133 | |
| 4134 | /** |
| 4135 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4136 | * @vsi: the VSI being configured |
| 4137 | **/ |
| 4138 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4139 | { |
| 4140 | int q_idx; |
| 4141 | |
| 4142 | if (!vsi->netdev) |
| 4143 | return; |
| 4144 | |
| 4145 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4146 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4150 | * i40e_vsi_close - Shut down a VSI |
| 4151 | * @vsi: the vsi to be quelled |
| 4152 | **/ |
| 4153 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4154 | { |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4155 | bool reset = false; |
| 4156 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4157 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4158 | i40e_down(vsi); |
| 4159 | i40e_vsi_free_irq(vsi); |
| 4160 | i40e_vsi_free_tx_resources(vsi); |
| 4161 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4162 | vsi->current_netdev_flags = 0; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4163 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4164 | reset = true; |
| 4165 | i40e_notify_client_of_netdev_close(vsi, reset); |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4169 | * i40e_quiesce_vsi - Pause a given VSI |
| 4170 | * @vsi: the VSI being paused |
| 4171 | **/ |
| 4172 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4173 | { |
| 4174 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4175 | return; |
| 4176 | |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4177 | /* No need to disable FCoE VSI when Tx suspended */ |
| 4178 | if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) && |
| 4179 | vsi->type == I40E_VSI_FCOE) { |
| 4180 | dev_dbg(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4181 | "VSI seid %d skipping FCoE VSI disable\n", vsi->seid); |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4182 | return; |
| 4183 | } |
| 4184 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4185 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4186 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4187 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4188 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4189 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4190 | } |
| 4191 | |
| 4192 | /** |
| 4193 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4194 | * @vsi: the VSI being resumed |
| 4195 | **/ |
| 4196 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4197 | { |
| 4198 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 4199 | return; |
| 4200 | |
| 4201 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4202 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4203 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4204 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4205 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | /** |
| 4209 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4210 | * @pf: the PF |
| 4211 | **/ |
| 4212 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4213 | { |
| 4214 | int v; |
| 4215 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4216 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4217 | if (pf->vsi[v]) |
| 4218 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4219 | } |
| 4220 | } |
| 4221 | |
| 4222 | /** |
| 4223 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4224 | * @pf: the PF |
| 4225 | **/ |
| 4226 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4227 | { |
| 4228 | int v; |
| 4229 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4230 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4231 | if (pf->vsi[v]) |
| 4232 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4233 | } |
| 4234 | } |
| 4235 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4236 | #ifdef CONFIG_I40E_DCB |
| 4237 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4238 | * 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] | 4239 | * @vsi: the VSI being configured |
| 4240 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4241 | * This function waits for the given VSI's queues to be disabled. |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4242 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4243 | static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4244 | { |
| 4245 | struct i40e_pf *pf = vsi->back; |
| 4246 | int i, pf_q, ret; |
| 4247 | |
| 4248 | pf_q = vsi->base_queue; |
| 4249 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4250 | /* Check and wait for the disable status of the queue */ |
| 4251 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4252 | if (ret) { |
| 4253 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4254 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4255 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4256 | return ret; |
| 4257 | } |
| 4258 | } |
| 4259 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4260 | pf_q = vsi->base_queue; |
| 4261 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4262 | /* Check and wait for the disable status of the queue */ |
| 4263 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
| 4264 | if (ret) { |
| 4265 | dev_info(&pf->pdev->dev, |
| 4266 | "VSI seid %d Rx ring %d disable timeout\n", |
| 4267 | vsi->seid, pf_q); |
| 4268 | return ret; |
| 4269 | } |
| 4270 | } |
| 4271 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4272 | return 0; |
| 4273 | } |
| 4274 | |
| 4275 | /** |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4276 | * 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] | 4277 | * @pf: the PF |
| 4278 | * |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4279 | * 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] | 4280 | * VSIs that are managed by this PF. |
| 4281 | **/ |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4282 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4283 | { |
| 4284 | int v, ret = 0; |
| 4285 | |
| 4286 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4287 | /* No need to wait for FCoE VSI queues */ |
| 4288 | if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) { |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 4289 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4290 | if (ret) |
| 4291 | break; |
| 4292 | } |
| 4293 | } |
| 4294 | |
| 4295 | return ret; |
| 4296 | } |
| 4297 | |
| 4298 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4299 | |
| 4300 | /** |
| 4301 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4302 | * @q_idx: TX queue number |
| 4303 | * @vsi: Pointer to VSI struct |
| 4304 | * |
| 4305 | * This function checks specified queue for given VSI. Detects hung condition. |
| 4306 | * Sets hung bit since it is two step process. Before next run of service task |
| 4307 | * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not, |
| 4308 | * hung condition remain unchanged and during subsequent run, this function |
| 4309 | * issues SW interrupt to recover from hung condition. |
| 4310 | **/ |
| 4311 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4312 | { |
| 4313 | struct i40e_ring *tx_ring = NULL; |
| 4314 | struct i40e_pf *pf; |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4315 | u32 head, val, tx_pending_hw; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4316 | int i; |
| 4317 | |
| 4318 | pf = vsi->back; |
| 4319 | |
| 4320 | /* now that we have an index, find the tx_ring struct */ |
| 4321 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4322 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4323 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4324 | tx_ring = vsi->tx_rings[i]; |
| 4325 | break; |
| 4326 | } |
| 4327 | } |
| 4328 | } |
| 4329 | |
| 4330 | if (!tx_ring) |
| 4331 | return; |
| 4332 | |
| 4333 | /* Read interrupt register */ |
| 4334 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4335 | val = rd32(&pf->hw, |
| 4336 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4337 | tx_ring->vsi->base_vector - 1)); |
| 4338 | else |
| 4339 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4340 | |
| 4341 | head = i40e_get_head(tx_ring); |
| 4342 | |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4343 | tx_pending_hw = i40e_get_tx_pending(tx_ring, false); |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4344 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4345 | /* HW is done executing descriptors, updated HEAD write back, |
| 4346 | * but SW hasn't processed those descriptors. If interrupt is |
| 4347 | * not generated from this point ON, it could result into |
| 4348 | * dev_watchdog detecting timeout on those netdev_queue, |
| 4349 | * hence proactively trigger SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4350 | */ |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4351 | if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4352 | /* NAPI Poll didn't run and clear since it was set */ |
| 4353 | if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4354 | &tx_ring->q_vector->hung_detected)) { |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4355 | 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", |
| 4356 | vsi->seid, q_idx, tx_pending_hw, |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4357 | tx_ring->next_to_clean, head, |
| 4358 | tx_ring->next_to_use, |
| 4359 | readl(tx_ring->tail)); |
| 4360 | netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n", |
| 4361 | vsi->seid, q_idx, val); |
| 4362 | i40e_force_wb(vsi, tx_ring->q_vector); |
| 4363 | } else { |
| 4364 | /* First Chance - detected possible hung */ |
| 4365 | set_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4366 | &tx_ring->q_vector->hung_detected); |
| 4367 | } |
| 4368 | } |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 4369 | |
| 4370 | /* This is the case where we have interrupts missing, |
| 4371 | * so the tx_pending in HW will most likely be 0, but we |
| 4372 | * will have tx_pending in SW since the WB happened but the |
| 4373 | * interrupt got lost. |
| 4374 | */ |
| 4375 | if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) && |
| 4376 | (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) { |
| 4377 | if (napi_reschedule(&tx_ring->q_vector->napi)) |
| 4378 | tx_ring->tx_stats.tx_lost_interrupt++; |
| 4379 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4380 | } |
| 4381 | |
| 4382 | /** |
| 4383 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4384 | * @pf: pointer to PF struct |
| 4385 | * |
| 4386 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4387 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4388 | * SW interrupt. |
| 4389 | **/ |
| 4390 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4391 | { |
| 4392 | struct net_device *netdev; |
| 4393 | struct i40e_vsi *vsi; |
| 4394 | int i; |
| 4395 | |
| 4396 | /* Only for LAN VSI */ |
| 4397 | vsi = pf->vsi[pf->lan_vsi]; |
| 4398 | |
| 4399 | if (!vsi) |
| 4400 | return; |
| 4401 | |
| 4402 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
| 4403 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 4404 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4405 | return; |
| 4406 | |
| 4407 | /* Make sure type is MAIN VSI */ |
| 4408 | if (vsi->type != I40E_VSI_MAIN) |
| 4409 | return; |
| 4410 | |
| 4411 | netdev = vsi->netdev; |
| 4412 | if (!netdev) |
| 4413 | return; |
| 4414 | |
| 4415 | /* Bail out if netif_carrier is not OK */ |
| 4416 | if (!netif_carrier_ok(netdev)) |
| 4417 | return; |
| 4418 | |
| 4419 | /* Go thru' TX queues for netdev */ |
| 4420 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4421 | struct netdev_queue *q; |
| 4422 | |
| 4423 | q = netdev_get_tx_queue(netdev, i); |
| 4424 | if (q) |
| 4425 | i40e_detect_recover_hung_queue(i, vsi); |
| 4426 | } |
| 4427 | } |
| 4428 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4429 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4430 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4431 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4432 | * |
| 4433 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4434 | * and LAN TC. |
| 4435 | **/ |
| 4436 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4437 | { |
| 4438 | struct i40e_dcb_app_priority_table app; |
| 4439 | struct i40e_hw *hw = &pf->hw; |
| 4440 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4441 | u8 tc, i; |
| 4442 | /* Get the iSCSI APP TLV */ |
| 4443 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4444 | |
| 4445 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4446 | app = dcbcfg->app[i]; |
| 4447 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4448 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4449 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4450 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4451 | break; |
| 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | return enabled_tc; |
| 4456 | } |
| 4457 | |
| 4458 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4459 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4460 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4461 | * |
| 4462 | * Return the number of TCs from given DCBx configuration |
| 4463 | **/ |
| 4464 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4465 | { |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4466 | int i, tc_unused = 0; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4467 | u8 num_tc = 0; |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4468 | u8 ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4469 | |
| 4470 | /* Scan the ETS Config Priority Table to find |
| 4471 | * traffic class enabled for a given priority |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4472 | * and create a bitmask of enabled TCs |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4473 | */ |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4474 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) |
| 4475 | num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]); |
| 4476 | |
| 4477 | /* Now scan the bitmask to check for |
| 4478 | * contiguous TCs starting with TC0 |
| 4479 | */ |
| 4480 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4481 | if (num_tc & BIT(i)) { |
| 4482 | if (!tc_unused) { |
| 4483 | ret++; |
| 4484 | } else { |
| 4485 | pr_err("Non-contiguous TC - Disabling DCB\n"); |
| 4486 | return 1; |
| 4487 | } |
| 4488 | } else { |
| 4489 | tc_unused = 1; |
| 4490 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4491 | } |
| 4492 | |
Dave Ertman | fbfe12c | 2016-08-12 09:56:32 -0700 | [diff] [blame] | 4493 | /* There is always at least TC0 */ |
| 4494 | if (!ret) |
| 4495 | ret = 1; |
| 4496 | |
| 4497 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4498 | } |
| 4499 | |
| 4500 | /** |
| 4501 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4502 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4503 | * |
| 4504 | * Query the current DCB configuration and return the number of |
| 4505 | * traffic classes enabled from the given DCBX config |
| 4506 | **/ |
| 4507 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4508 | { |
| 4509 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4510 | u8 enabled_tc = 1; |
| 4511 | u8 i; |
| 4512 | |
| 4513 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4514 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4515 | |
| 4516 | return enabled_tc; |
| 4517 | } |
| 4518 | |
| 4519 | /** |
| 4520 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4521 | * @pf: PF being queried |
| 4522 | * |
| 4523 | * Return number of traffic classes enabled for the given PF |
| 4524 | **/ |
| 4525 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4526 | { |
| 4527 | struct i40e_hw *hw = &pf->hw; |
Dave Ertman | 52a08ca | 2016-07-27 12:02:34 -0700 | [diff] [blame] | 4528 | u8 i, enabled_tc = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4529 | u8 num_tc = 0; |
| 4530 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4531 | |
| 4532 | /* If DCB is not enabled then always in single TC */ |
| 4533 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4534 | return 1; |
| 4535 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4536 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4537 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4538 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4539 | |
| 4540 | /* MFP mode return count of enabled TCs for this PF */ |
| 4541 | if (pf->hw.func_caps.iscsi) |
| 4542 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4543 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4544 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4545 | |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 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 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4554 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4555 | * @pf: PF being queried |
| 4556 | * |
| 4557 | * Return a bitmap for enabled traffic classes for this PF. |
| 4558 | **/ |
| 4559 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4560 | { |
| 4561 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4562 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4563 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4564 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4565 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4566 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4567 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4568 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4569 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4570 | if (pf->hw.func_caps.iscsi) |
| 4571 | return i40e_get_iscsi_tc_map(pf); |
| 4572 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4573 | return I40E_DEFAULT_TRAFFIC_CLASS; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | /** |
| 4577 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4578 | * @vsi: the VSI being queried |
| 4579 | * |
| 4580 | * Returns 0 on success, negative value on failure |
| 4581 | **/ |
| 4582 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4583 | { |
| 4584 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4585 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4586 | struct i40e_pf *pf = vsi->back; |
| 4587 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4588 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4589 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4590 | int i; |
| 4591 | |
| 4592 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4593 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4594 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4595 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4596 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4597 | i40e_stat_str(&pf->hw, ret), |
| 4598 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4599 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4603 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4604 | NULL); |
| 4605 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4606 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4607 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4608 | i40e_stat_str(&pf->hw, ret), |
| 4609 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4610 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4614 | dev_info(&pf->pdev->dev, |
| 4615 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4616 | bw_config.tc_valid_bits, |
| 4617 | bw_ets_config.tc_valid_bits); |
| 4618 | /* Still continuing */ |
| 4619 | } |
| 4620 | |
| 4621 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4622 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4623 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4624 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4625 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4626 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4627 | vsi->bw_ets_limit_credits[i] = |
| 4628 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4629 | /* 3 bits out of 4 for each TC */ |
| 4630 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4631 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4632 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4633 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4634 | } |
| 4635 | |
| 4636 | /** |
| 4637 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4638 | * @vsi: the VSI being configured |
| 4639 | * @enabled_tc: TC bitmap |
| 4640 | * @bw_credits: BW shared credits per TC |
| 4641 | * |
| 4642 | * Returns 0 on success, negative value on failure |
| 4643 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4644 | 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] | 4645 | u8 *bw_share) |
| 4646 | { |
| 4647 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4648 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4649 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4650 | |
| 4651 | bw_data.tc_valid_bits = enabled_tc; |
| 4652 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4653 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4654 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4655 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4656 | NULL); |
| 4657 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4658 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4659 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4660 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4661 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4662 | } |
| 4663 | |
| 4664 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4665 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4666 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4667 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | /** |
| 4671 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4672 | * @vsi: the VSI being configured |
| 4673 | * @enabled_tc: TC map to be enabled |
| 4674 | * |
| 4675 | **/ |
| 4676 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4677 | { |
| 4678 | struct net_device *netdev = vsi->netdev; |
| 4679 | struct i40e_pf *pf = vsi->back; |
| 4680 | struct i40e_hw *hw = &pf->hw; |
| 4681 | u8 netdev_tc = 0; |
| 4682 | int i; |
| 4683 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4684 | |
| 4685 | if (!netdev) |
| 4686 | return; |
| 4687 | |
| 4688 | if (!enabled_tc) { |
| 4689 | netdev_reset_tc(netdev); |
| 4690 | return; |
| 4691 | } |
| 4692 | |
| 4693 | /* Set up actual enabled TCs on the VSI */ |
| 4694 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 4695 | return; |
| 4696 | |
| 4697 | /* set per TC queues for the VSI */ |
| 4698 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4699 | /* Only set TC queues for enabled tcs |
| 4700 | * |
| 4701 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 4702 | * enabled_tc bitmap would be 0x00001001; the driver |
| 4703 | * will set the numtc for netdev as 2 that will be |
| 4704 | * referenced by the netdev layer as TC 0 and 1. |
| 4705 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4706 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4707 | netdev_set_tc_queue(netdev, |
| 4708 | vsi->tc_config.tc_info[i].netdev_tc, |
| 4709 | vsi->tc_config.tc_info[i].qcount, |
| 4710 | vsi->tc_config.tc_info[i].qoffset); |
| 4711 | } |
| 4712 | |
| 4713 | /* Assign UP2TC map for the VSI */ |
| 4714 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4715 | /* Get the actual TC# for the UP */ |
| 4716 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4717 | /* Get the mapped netdev TC# for the UP */ |
| 4718 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 4719 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 4720 | } |
| 4721 | } |
| 4722 | |
| 4723 | /** |
| 4724 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 4725 | * @vsi: the VSI being configured |
| 4726 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 4727 | **/ |
| 4728 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 4729 | struct i40e_vsi_context *ctxt) |
| 4730 | { |
| 4731 | /* copy just the sections touched not the entire info |
| 4732 | * since not all sections are valid as returned by |
| 4733 | * update vsi params |
| 4734 | */ |
| 4735 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 4736 | memcpy(&vsi->info.queue_mapping, |
| 4737 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 4738 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 4739 | sizeof(vsi->info.tc_mapping)); |
| 4740 | } |
| 4741 | |
| 4742 | /** |
| 4743 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 4744 | * @vsi: VSI to be configured |
| 4745 | * @enabled_tc: TC bitmap |
| 4746 | * |
| 4747 | * This configures a particular VSI for TCs that are mapped to the |
| 4748 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 4749 | * VSIs to configure TC for a particular VSI. |
| 4750 | * |
| 4751 | * NOTE: |
| 4752 | * It is expected that the VSI queues have been quisced before calling |
| 4753 | * this function. |
| 4754 | **/ |
| 4755 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4756 | { |
| 4757 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 4758 | struct i40e_vsi_context ctxt; |
| 4759 | int ret = 0; |
| 4760 | int i; |
| 4761 | |
| 4762 | /* Check if enabled_tc is same as existing or new TCs */ |
| 4763 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 4764 | return ret; |
| 4765 | |
| 4766 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 4767 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4768 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4769 | bw_share[i] = 1; |
| 4770 | } |
| 4771 | |
| 4772 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 4773 | if (ret) { |
| 4774 | dev_info(&vsi->back->pdev->dev, |
| 4775 | "Failed configuring TC map %d for VSI %d\n", |
| 4776 | enabled_tc, vsi->seid); |
| 4777 | goto out; |
| 4778 | } |
| 4779 | |
| 4780 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 4781 | ctxt.seid = vsi->seid; |
| 4782 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 4783 | ctxt.vf_num = 0; |
| 4784 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 4785 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4786 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 4787 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 4788 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 4789 | ctxt.info.valid_sections |= |
| 4790 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 4791 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; |
| 4792 | } |
| 4793 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4794 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 4795 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 4796 | if (ret) { |
| 4797 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4798 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 4799 | i40e_stat_str(&vsi->back->hw, ret), |
| 4800 | i40e_aq_str(&vsi->back->hw, |
| 4801 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4802 | goto out; |
| 4803 | } |
| 4804 | /* update the local VSI info with updated queue map */ |
| 4805 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 4806 | vsi->info.valid_sections = 0; |
| 4807 | |
| 4808 | /* Update current VSI BW information */ |
| 4809 | ret = i40e_vsi_get_bw_info(vsi); |
| 4810 | if (ret) { |
| 4811 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4812 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 4813 | i40e_stat_str(&vsi->back->hw, ret), |
| 4814 | i40e_aq_str(&vsi->back->hw, |
| 4815 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4816 | goto out; |
| 4817 | } |
| 4818 | |
| 4819 | /* Update the netdev TC setup */ |
| 4820 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 4821 | out: |
| 4822 | return ret; |
| 4823 | } |
| 4824 | |
| 4825 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4826 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 4827 | * @veb: given VEB |
| 4828 | * @enabled_tc: TC bitmap |
| 4829 | * |
| 4830 | * Configures given TC bitmap for VEB (switching) element |
| 4831 | **/ |
| 4832 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 4833 | { |
| 4834 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 4835 | struct i40e_pf *pf = veb->pf; |
| 4836 | int ret = 0; |
| 4837 | int i; |
| 4838 | |
| 4839 | /* No TCs or already enabled TCs just return */ |
| 4840 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 4841 | return ret; |
| 4842 | |
| 4843 | bw_data.tc_valid_bits = enabled_tc; |
| 4844 | /* bw_data.absolute_credits is not set (relative) */ |
| 4845 | |
| 4846 | /* Enable ETS TCs with equal BW Share for now */ |
| 4847 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4848 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4849 | bw_data.tc_bw_share_credits[i] = 1; |
| 4850 | } |
| 4851 | |
| 4852 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 4853 | &bw_data, NULL); |
| 4854 | if (ret) { |
| 4855 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4856 | "VEB bw config failed, err %s aq_err %s\n", |
| 4857 | i40e_stat_str(&pf->hw, ret), |
| 4858 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4859 | goto out; |
| 4860 | } |
| 4861 | |
| 4862 | /* Update the BW information */ |
| 4863 | ret = i40e_veb_get_bw_info(veb); |
| 4864 | if (ret) { |
| 4865 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4866 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 4867 | i40e_stat_str(&pf->hw, ret), |
| 4868 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | out: |
| 4872 | return ret; |
| 4873 | } |
| 4874 | |
| 4875 | #ifdef CONFIG_I40E_DCB |
| 4876 | /** |
| 4877 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 4878 | * @pf: PF struct |
| 4879 | * |
| 4880 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 4881 | * the caller would've quiesce all the VSIs before calling |
| 4882 | * this function |
| 4883 | **/ |
| 4884 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 4885 | { |
| 4886 | u8 tc_map = 0; |
| 4887 | int ret; |
| 4888 | u8 v; |
| 4889 | |
| 4890 | /* Enable the TCs available on PF to all VEBs */ |
| 4891 | tc_map = i40e_pf_get_tc_map(pf); |
| 4892 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 4893 | if (!pf->veb[v]) |
| 4894 | continue; |
| 4895 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 4896 | if (ret) { |
| 4897 | dev_info(&pf->pdev->dev, |
| 4898 | "Failed configuring TC for VEB seid=%d\n", |
| 4899 | pf->veb[v]->seid); |
| 4900 | /* Will try to configure as many components */ |
| 4901 | } |
| 4902 | } |
| 4903 | |
| 4904 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4905 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4906 | if (!pf->vsi[v]) |
| 4907 | continue; |
| 4908 | |
| 4909 | /* - Enable all TCs for the LAN VSI |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4910 | #ifdef I40E_FCOE |
| 4911 | * - For FCoE VSI only enable the TC configured |
| 4912 | * as per the APP TLV |
| 4913 | #endif |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4914 | * - For all others keep them at TC0 for now |
| 4915 | */ |
| 4916 | if (v == pf->lan_vsi) |
| 4917 | tc_map = i40e_pf_get_tc_map(pf); |
| 4918 | else |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 4919 | tc_map = I40E_DEFAULT_TRAFFIC_CLASS; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4920 | #ifdef I40E_FCOE |
| 4921 | if (pf->vsi[v]->type == I40E_VSI_FCOE) |
| 4922 | tc_map = i40e_get_fcoe_tc_map(pf); |
| 4923 | #endif /* #ifdef I40E_FCOE */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4924 | |
| 4925 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 4926 | if (ret) { |
| 4927 | dev_info(&pf->pdev->dev, |
| 4928 | "Failed configuring TC for VSI seid=%d\n", |
| 4929 | pf->vsi[v]->seid); |
| 4930 | /* Will try to configure as many components */ |
| 4931 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 4932 | /* Re-configure VSI vectors based on updated TC map */ |
| 4933 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4934 | if (pf->vsi[v]->netdev) |
| 4935 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 4936 | } |
| 4937 | } |
| 4938 | } |
| 4939 | |
| 4940 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 4941 | * i40e_resume_port_tx - Resume port Tx |
| 4942 | * @pf: PF struct |
| 4943 | * |
| 4944 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 4945 | * resume. |
| 4946 | **/ |
| 4947 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 4948 | { |
| 4949 | struct i40e_hw *hw = &pf->hw; |
| 4950 | int ret; |
| 4951 | |
| 4952 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 4953 | if (ret) { |
| 4954 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4955 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 4956 | i40e_stat_str(&pf->hw, ret), |
| 4957 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 4958 | /* Schedule PF reset to recover */ |
| 4959 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 4960 | i40e_service_event_schedule(pf); |
| 4961 | } |
| 4962 | |
| 4963 | return ret; |
| 4964 | } |
| 4965 | |
| 4966 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4967 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 4968 | * @pf: PF being configured |
| 4969 | * |
| 4970 | * Query the current DCB configuration and cache it |
| 4971 | * in the hardware structure |
| 4972 | **/ |
| 4973 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 4974 | { |
| 4975 | struct i40e_hw *hw = &pf->hw; |
| 4976 | int err = 0; |
| 4977 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 4978 | /* 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] | 4979 | if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT) |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 4980 | goto out; |
| 4981 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4982 | /* Get the initial DCB configuration */ |
| 4983 | err = i40e_init_dcb(hw); |
| 4984 | if (!err) { |
| 4985 | /* Device/Function is not DCBX capable */ |
| 4986 | if ((!hw->func_caps.dcb) || |
| 4987 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 4988 | dev_info(&pf->pdev->dev, |
| 4989 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 4990 | |
| 4991 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 4992 | goto out; |
| 4993 | |
| 4994 | } else { |
| 4995 | /* When status is not DISABLED then DCBX in FW */ |
| 4996 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 4997 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 4998 | |
| 4999 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5000 | /* Enable DCB tagging only when more than one TC |
| 5001 | * or explicitly disable if only one TC |
| 5002 | */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5003 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5004 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 5005 | else |
| 5006 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5007 | dev_dbg(&pf->pdev->dev, |
| 5008 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5009 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5010 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5011 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5012 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5013 | i40e_stat_str(&pf->hw, err), |
| 5014 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | out: |
| 5018 | return err; |
| 5019 | } |
| 5020 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5021 | #define SPEED_SIZE 14 |
| 5022 | #define FC_SIZE 8 |
| 5023 | /** |
| 5024 | * i40e_print_link_message - print link up or down |
| 5025 | * @vsi: the VSI for which link needs a message |
| 5026 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5027 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5028 | { |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5029 | char *speed = "Unknown"; |
| 5030 | char *fc = "Unknown"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5031 | |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5032 | if (vsi->current_isup == isup) |
| 5033 | return; |
| 5034 | vsi->current_isup = isup; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5035 | if (!isup) { |
| 5036 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5037 | return; |
| 5038 | } |
| 5039 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5040 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5041 | * least 10GB |
| 5042 | */ |
| 5043 | if (vsi->back->hw.func_caps.npar_enable && |
| 5044 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5045 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5046 | netdev_warn(vsi->netdev, |
| 5047 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5048 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5049 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5050 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5051 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5052 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5053 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5054 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5055 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5056 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5057 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5058 | break; |
| 5059 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5060 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5061 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5062 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5063 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5064 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5065 | default: |
| 5066 | break; |
| 5067 | } |
| 5068 | |
| 5069 | switch (vsi->back->hw.fc.current_mode) { |
| 5070 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5071 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5072 | break; |
| 5073 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5074 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5075 | break; |
| 5076 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5077 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5078 | break; |
| 5079 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5080 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5081 | break; |
| 5082 | } |
| 5083 | |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5084 | 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] | 5085 | speed, fc); |
| 5086 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5087 | |
| 5088 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5089 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5090 | * @vsi: the VSI being configured |
| 5091 | **/ |
| 5092 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5093 | { |
| 5094 | struct i40e_pf *pf = vsi->back; |
| 5095 | int err; |
| 5096 | |
| 5097 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5098 | i40e_vsi_configure_msix(vsi); |
| 5099 | else |
| 5100 | i40e_configure_msi_and_legacy(vsi); |
| 5101 | |
| 5102 | /* start rings */ |
| 5103 | err = i40e_vsi_control_rings(vsi, true); |
| 5104 | if (err) |
| 5105 | return err; |
| 5106 | |
| 5107 | clear_bit(__I40E_DOWN, &vsi->state); |
| 5108 | i40e_napi_enable_all(vsi); |
| 5109 | i40e_vsi_enable_irq(vsi); |
| 5110 | |
| 5111 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5112 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5113 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5114 | netif_tx_start_all_queues(vsi->netdev); |
| 5115 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5116 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5117 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5118 | /* need to check for qualified module here*/ |
| 5119 | if ((pf->hw.phy.link_info.link_info & |
| 5120 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5121 | (!(pf->hw.phy.link_info.an_info & |
| 5122 | I40E_AQ_QUALIFIED_MODULE))) |
| 5123 | netdev_err(vsi->netdev, |
| 5124 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5125 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5126 | |
| 5127 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5128 | if (vsi->type == I40E_VSI_FDIR) { |
| 5129 | /* reset fd counters */ |
| 5130 | pf->fd_add_err = pf->fd_atr_cnt = 0; |
| 5131 | if (pf->fd_tcp_rule > 0) { |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 5132 | pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5133 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5134 | 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] | 5135 | pf->fd_tcp_rule = 0; |
| 5136 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5137 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5138 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5139 | |
| 5140 | /* On the next run of the service_task, notify any clients of the new |
| 5141 | * opened netdev |
| 5142 | */ |
| 5143 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5144 | i40e_service_event_schedule(pf); |
| 5145 | |
| 5146 | return 0; |
| 5147 | } |
| 5148 | |
| 5149 | /** |
| 5150 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5151 | * @vsi: the VSI being configured |
| 5152 | * |
| 5153 | * Rebuild the ring structs after some configuration |
| 5154 | * has changed, e.g. MTU size. |
| 5155 | **/ |
| 5156 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5157 | { |
| 5158 | struct i40e_pf *pf = vsi->back; |
| 5159 | |
| 5160 | WARN_ON(in_interrupt()); |
| 5161 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5162 | usleep_range(1000, 2000); |
| 5163 | i40e_down(vsi); |
| 5164 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5165 | i40e_up(vsi); |
| 5166 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 5167 | } |
| 5168 | |
| 5169 | /** |
| 5170 | * i40e_up - Bring the connection back up after being down |
| 5171 | * @vsi: the VSI being configured |
| 5172 | **/ |
| 5173 | int i40e_up(struct i40e_vsi *vsi) |
| 5174 | { |
| 5175 | int err; |
| 5176 | |
| 5177 | err = i40e_vsi_configure(vsi); |
| 5178 | if (!err) |
| 5179 | err = i40e_up_complete(vsi); |
| 5180 | |
| 5181 | return err; |
| 5182 | } |
| 5183 | |
| 5184 | /** |
| 5185 | * i40e_down - Shutdown the connection processing |
| 5186 | * @vsi: the VSI being stopped |
| 5187 | **/ |
| 5188 | void i40e_down(struct i40e_vsi *vsi) |
| 5189 | { |
| 5190 | int i; |
| 5191 | |
| 5192 | /* It is assumed that the caller of this function |
| 5193 | * sets the vsi->state __I40E_DOWN bit. |
| 5194 | */ |
| 5195 | if (vsi->netdev) { |
| 5196 | netif_carrier_off(vsi->netdev); |
| 5197 | netif_tx_disable(vsi->netdev); |
| 5198 | } |
| 5199 | i40e_vsi_disable_irq(vsi); |
| 5200 | i40e_vsi_control_rings(vsi, false); |
| 5201 | i40e_napi_disable_all(vsi); |
| 5202 | |
| 5203 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5204 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 5205 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5206 | } |
Catherine Sullivan | f980d44 | 2016-05-16 10:26:34 -0700 | [diff] [blame] | 5207 | |
| 5208 | i40e_notify_client_of_netdev_close(vsi, false); |
| 5209 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5210 | } |
| 5211 | |
| 5212 | /** |
| 5213 | * i40e_setup_tc - configure multiple traffic classes |
| 5214 | * @netdev: net device to configure |
| 5215 | * @tc: number of traffic classes to enable |
| 5216 | **/ |
| 5217 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5218 | { |
| 5219 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5220 | struct i40e_vsi *vsi = np->vsi; |
| 5221 | struct i40e_pf *pf = vsi->back; |
| 5222 | u8 enabled_tc = 0; |
| 5223 | int ret = -EINVAL; |
| 5224 | int i; |
| 5225 | |
| 5226 | /* Check if DCB enabled to continue */ |
| 5227 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5228 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5229 | goto exit; |
| 5230 | } |
| 5231 | |
| 5232 | /* Check if MFP enabled */ |
| 5233 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5234 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5235 | goto exit; |
| 5236 | } |
| 5237 | |
| 5238 | /* Check whether tc count is within enabled limit */ |
| 5239 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5240 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5241 | goto exit; |
| 5242 | } |
| 5243 | |
| 5244 | /* Generate TC map for number of tc requested */ |
| 5245 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5246 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5247 | |
| 5248 | /* Requesting same TC configuration as already enabled */ |
| 5249 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5250 | return 0; |
| 5251 | |
| 5252 | /* Quiesce VSI queues */ |
| 5253 | i40e_quiesce_vsi(vsi); |
| 5254 | |
| 5255 | /* Configure VSI for enabled TCs */ |
| 5256 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5257 | if (ret) { |
| 5258 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5259 | vsi->seid); |
| 5260 | goto exit; |
| 5261 | } |
| 5262 | |
| 5263 | /* Unquiesce VSI */ |
| 5264 | i40e_unquiesce_vsi(vsi); |
| 5265 | |
| 5266 | exit: |
| 5267 | return ret; |
| 5268 | } |
| 5269 | |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5270 | #ifdef I40E_FCOE |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5271 | int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5272 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5273 | #else |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5274 | static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
| 5275 | struct tc_to_netdev *tc) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5276 | #endif |
| 5277 | { |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5278 | if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5279 | return -EINVAL; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 5280 | return i40e_setup_tc(netdev, tc->tc); |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 5281 | } |
| 5282 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5283 | /** |
| 5284 | * i40e_open - Called when a network interface is made active |
| 5285 | * @netdev: network interface device structure |
| 5286 | * |
| 5287 | * The open entry point is called when a network interface is made |
| 5288 | * active by the system (IFF_UP). At this point all resources needed |
| 5289 | * for transmit and receive operations are allocated, the interrupt |
| 5290 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5291 | * enabled, and the stack is notified that the interface is ready. |
| 5292 | * |
| 5293 | * Returns 0 on success, negative value on failure |
| 5294 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5295 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5296 | { |
| 5297 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5298 | struct i40e_vsi *vsi = np->vsi; |
| 5299 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5300 | int err; |
| 5301 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5302 | /* disallow open during test or if eeprom is broken */ |
| 5303 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 5304 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5305 | return -EBUSY; |
| 5306 | |
| 5307 | netif_carrier_off(netdev); |
| 5308 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5309 | err = i40e_vsi_open(vsi); |
| 5310 | if (err) |
| 5311 | return err; |
| 5312 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5313 | /* configure global TSO hardware offload settings */ |
| 5314 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5315 | TCP_FLAG_FIN) >> 16); |
| 5316 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5317 | TCP_FLAG_FIN | |
| 5318 | TCP_FLAG_CWR) >> 16); |
| 5319 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5320 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 5321 | udp_tunnel_get_rx_info(netdev); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5322 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5323 | return 0; |
| 5324 | } |
| 5325 | |
| 5326 | /** |
| 5327 | * i40e_vsi_open - |
| 5328 | * @vsi: the VSI to open |
| 5329 | * |
| 5330 | * Finish initialization of the VSI. |
| 5331 | * |
| 5332 | * Returns 0 on success, negative value on failure |
| 5333 | **/ |
| 5334 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5335 | { |
| 5336 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5337 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5338 | int err; |
| 5339 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5340 | /* allocate descriptors */ |
| 5341 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5342 | if (err) |
| 5343 | goto err_setup_tx; |
| 5344 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5345 | if (err) |
| 5346 | goto err_setup_rx; |
| 5347 | |
| 5348 | err = i40e_vsi_configure(vsi); |
| 5349 | if (err) |
| 5350 | goto err_setup_rx; |
| 5351 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5352 | if (vsi->netdev) { |
| 5353 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5354 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5355 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5356 | if (err) |
| 5357 | goto err_setup_rx; |
| 5358 | |
| 5359 | /* Notify the stack of the actual queue counts. */ |
| 5360 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5361 | vsi->num_queue_pairs); |
| 5362 | if (err) |
| 5363 | goto err_set_queues; |
| 5364 | |
| 5365 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5366 | vsi->num_queue_pairs); |
| 5367 | if (err) |
| 5368 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5369 | |
| 5370 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5371 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5372 | dev_driver_string(&pf->pdev->dev), |
| 5373 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5374 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5375 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5376 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5377 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5378 | goto err_setup_rx; |
| 5379 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5380 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5381 | err = i40e_up_complete(vsi); |
| 5382 | if (err) |
| 5383 | goto err_up_complete; |
| 5384 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5385 | return 0; |
| 5386 | |
| 5387 | err_up_complete: |
| 5388 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5389 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5390 | i40e_vsi_free_irq(vsi); |
| 5391 | err_setup_rx: |
| 5392 | i40e_vsi_free_rx_resources(vsi); |
| 5393 | err_setup_tx: |
| 5394 | i40e_vsi_free_tx_resources(vsi); |
| 5395 | if (vsi == pf->vsi[pf->lan_vsi]) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5396 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5397 | |
| 5398 | return err; |
| 5399 | } |
| 5400 | |
| 5401 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5402 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5403 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5404 | * |
| 5405 | * This function destroys the hlist where all the Flow Director |
| 5406 | * filters were saved. |
| 5407 | **/ |
| 5408 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5409 | { |
| 5410 | struct i40e_fdir_filter *filter; |
| 5411 | struct hlist_node *node2; |
| 5412 | |
| 5413 | hlist_for_each_entry_safe(filter, node2, |
| 5414 | &pf->fdir_filter_list, fdir_node) { |
| 5415 | hlist_del(&filter->fdir_node); |
| 5416 | kfree(filter); |
| 5417 | } |
| 5418 | pf->fdir_pf_active_filters = 0; |
| 5419 | } |
| 5420 | |
| 5421 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5422 | * i40e_close - Disables a network interface |
| 5423 | * @netdev: network interface device structure |
| 5424 | * |
| 5425 | * The close entry point is called when an interface is de-activated |
| 5426 | * by the OS. The hardware is still under the driver's control, but |
| 5427 | * this netdev interface is disabled. |
| 5428 | * |
| 5429 | * Returns 0, this is not allowed to fail |
| 5430 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5431 | int i40e_close(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5432 | { |
| 5433 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5434 | struct i40e_vsi *vsi = np->vsi; |
| 5435 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5436 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5437 | |
| 5438 | return 0; |
| 5439 | } |
| 5440 | |
| 5441 | /** |
| 5442 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5443 | * @pf: board private structure |
| 5444 | * @reset_flags: which reset is requested |
| 5445 | * |
| 5446 | * The essential difference in resets is that the PF Reset |
| 5447 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5448 | * firmware, and doesn't bother the other PFs on the chip. |
| 5449 | **/ |
| 5450 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5451 | { |
| 5452 | u32 val; |
| 5453 | |
| 5454 | WARN_ON(in_interrupt()); |
| 5455 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5456 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5457 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5458 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5459 | |
| 5460 | /* Request a Global Reset |
| 5461 | * |
| 5462 | * This will start the chip's countdown to the actual full |
| 5463 | * chip reset event, and a warning interrupt to be sent |
| 5464 | * to all PFs, including the requestor. Our handler |
| 5465 | * for the warning interrupt will deal with the shutdown |
| 5466 | * and recovery of the switch setup. |
| 5467 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5468 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5469 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5470 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5471 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5472 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5473 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5474 | |
| 5475 | /* Request a Core Reset |
| 5476 | * |
| 5477 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5478 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5479 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5480 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5481 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5482 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5483 | i40e_flush(&pf->hw); |
| 5484 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5485 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5486 | |
| 5487 | /* Request a PF Reset |
| 5488 | * |
| 5489 | * Resets only the PF-specific registers |
| 5490 | * |
| 5491 | * This goes directly to the tear-down and rebuild of |
| 5492 | * the switch, since we need to do all the recovery as |
| 5493 | * for the Core Reset. |
| 5494 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5495 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5496 | i40e_handle_reset_warning(pf); |
| 5497 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5498 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5499 | int v; |
| 5500 | |
| 5501 | /* Find the VSI(s) that requested a re-init */ |
| 5502 | dev_info(&pf->pdev->dev, |
| 5503 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5504 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5505 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5506 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5507 | if (vsi != NULL && |
| 5508 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5509 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5510 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5511 | } |
| 5512 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5513 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5514 | int v; |
| 5515 | |
| 5516 | /* Find the VSI(s) that needs to be brought down */ |
| 5517 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5518 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5519 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5520 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5521 | if (vsi != NULL && |
| 5522 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5523 | set_bit(__I40E_DOWN, &vsi->state); |
| 5524 | i40e_down(vsi); |
| 5525 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5526 | } |
| 5527 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5528 | } else { |
| 5529 | dev_info(&pf->pdev->dev, |
| 5530 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5531 | } |
| 5532 | } |
| 5533 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5534 | #ifdef CONFIG_I40E_DCB |
| 5535 | /** |
| 5536 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5537 | * @pf: board private structure |
| 5538 | * @old_cfg: current DCB config |
| 5539 | * @new_cfg: new DCB config |
| 5540 | **/ |
| 5541 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5542 | struct i40e_dcbx_config *old_cfg, |
| 5543 | struct i40e_dcbx_config *new_cfg) |
| 5544 | { |
| 5545 | bool need_reconfig = false; |
| 5546 | |
| 5547 | /* Check if ETS configuration has changed */ |
| 5548 | if (memcmp(&new_cfg->etscfg, |
| 5549 | &old_cfg->etscfg, |
| 5550 | sizeof(new_cfg->etscfg))) { |
| 5551 | /* If Priority Table has changed reconfig is needed */ |
| 5552 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5553 | &old_cfg->etscfg.prioritytable, |
| 5554 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5555 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5556 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5557 | } |
| 5558 | |
| 5559 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5560 | &old_cfg->etscfg.tcbwtable, |
| 5561 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5562 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5563 | |
| 5564 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5565 | &old_cfg->etscfg.tsatable, |
| 5566 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5567 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | /* Check if PFC configuration has changed */ |
| 5571 | if (memcmp(&new_cfg->pfc, |
| 5572 | &old_cfg->pfc, |
| 5573 | sizeof(new_cfg->pfc))) { |
| 5574 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5575 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5576 | } |
| 5577 | |
| 5578 | /* Check if APP Table has changed */ |
| 5579 | if (memcmp(&new_cfg->app, |
| 5580 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5581 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5582 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5583 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5584 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5585 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5586 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5587 | return need_reconfig; |
| 5588 | } |
| 5589 | |
| 5590 | /** |
| 5591 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5592 | * @pf: board private structure |
| 5593 | * @e: event info posted on ARQ |
| 5594 | **/ |
| 5595 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5596 | struct i40e_arq_event_info *e) |
| 5597 | { |
| 5598 | struct i40e_aqc_lldp_get_mib *mib = |
| 5599 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5600 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5601 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5602 | bool need_reconfig = false; |
| 5603 | int ret = 0; |
| 5604 | u8 type; |
| 5605 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5606 | /* Not DCB capable or capability disabled */ |
David Ertman | ea6acb7 | 2016-09-20 07:10:50 -0700 | [diff] [blame] | 5607 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5608 | return ret; |
| 5609 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5610 | /* Ignore if event is not for Nearest Bridge */ |
| 5611 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5612 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5613 | 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] | 5614 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5615 | return ret; |
| 5616 | |
| 5617 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5618 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5619 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5620 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5621 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5622 | /* Update the remote cached instance and return */ |
| 5623 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5624 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5625 | &hw->remote_dcbx_config); |
| 5626 | goto exit; |
| 5627 | } |
| 5628 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5629 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5630 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5631 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5632 | /* Reset the old DCBx configuration data */ |
| 5633 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5634 | /* Get updated DCBX data from firmware */ |
| 5635 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5636 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5637 | dev_info(&pf->pdev->dev, |
| 5638 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 5639 | i40e_stat_str(&pf->hw, ret), |
| 5640 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5641 | goto exit; |
| 5642 | } |
| 5643 | |
| 5644 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5645 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5646 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5647 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5648 | goto exit; |
| 5649 | } |
| 5650 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5651 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5652 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5653 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5654 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5655 | |
| 5656 | if (!need_reconfig) |
| 5657 | goto exit; |
| 5658 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5659 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5660 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5661 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5662 | else |
| 5663 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5664 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5665 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5666 | /* Reconfiguration needed quiesce all VSIs */ |
| 5667 | i40e_pf_quiesce_all_vsi(pf); |
| 5668 | |
| 5669 | /* Changes in configuration update VEB/VSI */ |
| 5670 | i40e_dcb_reconfigure(pf); |
| 5671 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5672 | ret = i40e_resume_port_tx(pf); |
| 5673 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5674 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5675 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5676 | if (ret) |
| 5677 | goto exit; |
| 5678 | |
Neerav Parikh | 3fe06f4 | 2016-02-17 16:12:15 -0800 | [diff] [blame] | 5679 | /* Wait for the PF's queues to be disabled */ |
| 5680 | ret = i40e_pf_wait_queues_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5681 | if (ret) { |
| 5682 | /* Schedule PF reset to recover */ |
| 5683 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5684 | i40e_service_event_schedule(pf); |
| 5685 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5686 | i40e_pf_unquiesce_all_vsi(pf); |
Neerav Parikh | 85a1aab | 2016-06-07 09:14:55 -0700 | [diff] [blame] | 5687 | /* Notify the client for the DCB changes */ |
| 5688 | i40e_notify_client_of_l2_param_changes(pf->vsi[pf->lan_vsi]); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5689 | } |
| 5690 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5691 | exit: |
| 5692 | return ret; |
| 5693 | } |
| 5694 | #endif /* CONFIG_I40E_DCB */ |
| 5695 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5696 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5697 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 5698 | * @pf: board private structure |
| 5699 | * @reset_flags: which reset is requested |
| 5700 | * |
| 5701 | **/ |
| 5702 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 5703 | { |
| 5704 | rtnl_lock(); |
| 5705 | i40e_do_reset(pf, reset_flags); |
| 5706 | rtnl_unlock(); |
| 5707 | } |
| 5708 | |
| 5709 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5710 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 5711 | * @pf: board private structure |
| 5712 | * @e: event info posted on ARQ |
| 5713 | * |
| 5714 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 5715 | * and VF queues |
| 5716 | **/ |
| 5717 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 5718 | struct i40e_arq_event_info *e) |
| 5719 | { |
| 5720 | struct i40e_aqc_lan_overflow *data = |
| 5721 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 5722 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 5723 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 5724 | struct i40e_hw *hw = &pf->hw; |
| 5725 | struct i40e_vf *vf; |
| 5726 | u16 vf_id; |
| 5727 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5728 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 5729 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5730 | |
| 5731 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 5732 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 5733 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 5734 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 5735 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 5736 | vf_id -= hw->func_caps.vf_base_id; |
| 5737 | vf = &pf->vf[vf_id]; |
| 5738 | i40e_vc_notify_vf_reset(vf); |
| 5739 | /* Allow VF to process pending reset notification */ |
| 5740 | msleep(20); |
| 5741 | i40e_reset_vf(vf, false); |
| 5742 | } |
| 5743 | } |
| 5744 | |
| 5745 | /** |
| 5746 | * i40e_service_event_complete - Finish up the service event |
| 5747 | * @pf: board private structure |
| 5748 | **/ |
| 5749 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 5750 | { |
Shannon Nelson | b875f99 | 2015-10-21 19:47:03 -0400 | [diff] [blame] | 5751 | WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5752 | |
| 5753 | /* flush memory to make sure state is correct before next watchog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5754 | smp_mb__before_atomic(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5755 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 5756 | } |
| 5757 | |
| 5758 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5759 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 5760 | * @pf: board private structure |
| 5761 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5762 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5763 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5764 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5765 | |
| 5766 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5767 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 5768 | return fcnt_prog; |
| 5769 | } |
| 5770 | |
| 5771 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5772 | * 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] | 5773 | * @pf: board private structure |
| 5774 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5775 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5776 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5777 | u32 val, fcnt_prog; |
| 5778 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5779 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5780 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 5781 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 5782 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 5783 | return fcnt_prog; |
| 5784 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5785 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5786 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5787 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 5788 | * @pf: board private structure |
| 5789 | **/ |
| 5790 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 5791 | { |
| 5792 | u32 val, fcnt_prog; |
| 5793 | |
| 5794 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 5795 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 5796 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 5797 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 5798 | return fcnt_prog; |
| 5799 | } |
| 5800 | |
| 5801 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5802 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 5803 | * @pf: board private structure |
| 5804 | **/ |
| 5805 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 5806 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5807 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5808 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5809 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5810 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5811 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 5812 | return; |
| 5813 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5814 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 5815 | * to re-enable |
| 5816 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5817 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5818 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5819 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 5820 | (pf->fd_add_err == 0) || |
| 5821 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5822 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 5823 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 5824 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5825 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5826 | 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] | 5827 | } |
| 5828 | } |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 5829 | |
| 5830 | /* Wait for some more space to be available to turn on ATR. We also |
| 5831 | * must check that no existing ntuple rules for TCP are in effect |
| 5832 | */ |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5833 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 5834 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 5835 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 5836 | (pf->fd_tcp_rule == 0)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5837 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5838 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
Jacob Keller | a3417d2 | 2016-09-06 18:05:10 -0700 | [diff] [blame] | 5839 | dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n"); |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5840 | } |
| 5841 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5842 | |
| 5843 | /* if hw had a problem adding a filter, delete it */ |
| 5844 | if (pf->fd_inv > 0) { |
| 5845 | hlist_for_each_entry_safe(filter, node, |
| 5846 | &pf->fdir_filter_list, fdir_node) { |
| 5847 | if (filter->fd_id == pf->fd_inv) { |
| 5848 | hlist_del(&filter->fdir_node); |
| 5849 | kfree(filter); |
| 5850 | pf->fdir_pf_active_filters--; |
| 5851 | } |
| 5852 | } |
| 5853 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5854 | } |
| 5855 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5856 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5857 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5858 | /** |
| 5859 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 5860 | * @pf: board private structure |
| 5861 | **/ |
| 5862 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 5863 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5864 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5865 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5866 | bool disable_atr = false; |
| 5867 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5868 | int reg; |
| 5869 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5870 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 5871 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 5872 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5873 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5874 | /* If the flush is happening too quick and we have mostly SB rules we |
| 5875 | * should not re-enable ATR for some time. |
| 5876 | */ |
| 5877 | min_flush_time = pf->fd_flush_timestamp + |
| 5878 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 5879 | 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] | 5880 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5881 | if (!(time_after(jiffies, min_flush_time)) && |
| 5882 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 5883 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5884 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 5885 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5886 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5887 | |
| 5888 | pf->fd_flush_timestamp = jiffies; |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 5889 | pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5890 | /* flush all filters */ |
| 5891 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 5892 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 5893 | i40e_flush(&pf->hw); |
| 5894 | pf->fd_flush_cnt++; |
| 5895 | pf->fd_add_err = 0; |
| 5896 | do { |
| 5897 | /* Check FD flush status every 5-6msec */ |
| 5898 | usleep_range(5000, 6000); |
| 5899 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 5900 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 5901 | break; |
| 5902 | } while (flush_wait_retry--); |
| 5903 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 5904 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 5905 | } else { |
| 5906 | /* replay sideband filters */ |
| 5907 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
| 5908 | if (!disable_atr) |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 5909 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5910 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
| 5911 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5912 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 5913 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | /** |
| 5917 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 5918 | * @pf: board private structure |
| 5919 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5920 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5921 | { |
| 5922 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 5923 | } |
| 5924 | |
| 5925 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 5926 | * being applied really fast; before we see the first |
| 5927 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 5928 | * reacting will make sure we don't cause flush too often. |
| 5929 | */ |
| 5930 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 5931 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5932 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5933 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 5934 | * @pf: board private structure |
| 5935 | **/ |
| 5936 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 5937 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5938 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5939 | /* if interface is down do nothing */ |
| 5940 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 5941 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5942 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5943 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5944 | i40e_fdir_flush_and_replay(pf); |
| 5945 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5946 | i40e_fdir_check_and_reenable(pf); |
| 5947 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5948 | } |
| 5949 | |
| 5950 | /** |
| 5951 | * i40e_vsi_link_event - notify VSI of a link event |
| 5952 | * @vsi: vsi to be notified |
| 5953 | * @link_up: link up or down |
| 5954 | **/ |
| 5955 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 5956 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 5957 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5958 | return; |
| 5959 | |
| 5960 | switch (vsi->type) { |
| 5961 | case I40E_VSI_MAIN: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5962 | #ifdef I40E_FCOE |
| 5963 | case I40E_VSI_FCOE: |
| 5964 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5965 | if (!vsi->netdev || !vsi->netdev_registered) |
| 5966 | break; |
| 5967 | |
| 5968 | if (link_up) { |
| 5969 | netif_carrier_on(vsi->netdev); |
| 5970 | netif_tx_wake_all_queues(vsi->netdev); |
| 5971 | } else { |
| 5972 | netif_carrier_off(vsi->netdev); |
| 5973 | netif_tx_stop_all_queues(vsi->netdev); |
| 5974 | } |
| 5975 | break; |
| 5976 | |
| 5977 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5978 | case I40E_VSI_VMDQ2: |
| 5979 | case I40E_VSI_CTRL: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 5980 | case I40E_VSI_IWARP: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5981 | case I40E_VSI_MIRROR: |
| 5982 | default: |
| 5983 | /* there is no notification for other VSIs */ |
| 5984 | break; |
| 5985 | } |
| 5986 | } |
| 5987 | |
| 5988 | /** |
| 5989 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 5990 | * @veb: veb to be notified |
| 5991 | * @link_up: link up or down |
| 5992 | **/ |
| 5993 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 5994 | { |
| 5995 | struct i40e_pf *pf; |
| 5996 | int i; |
| 5997 | |
| 5998 | if (!veb || !veb->pf) |
| 5999 | return; |
| 6000 | pf = veb->pf; |
| 6001 | |
| 6002 | /* depth first... */ |
| 6003 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6004 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6005 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6006 | |
| 6007 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6008 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6009 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6010 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6011 | } |
| 6012 | |
| 6013 | /** |
| 6014 | * i40e_link_event - Update netif_carrier status |
| 6015 | * @pf: board private structure |
| 6016 | **/ |
| 6017 | static void i40e_link_event(struct i40e_pf *pf) |
| 6018 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6019 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6020 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6021 | i40e_status status; |
| 6022 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6023 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6024 | /* save off old link status information */ |
| 6025 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6026 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6027 | /* set this to force the get_link_status call to refresh state */ |
| 6028 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6029 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6030 | 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] | 6031 | |
| 6032 | status = i40e_get_link_status(&pf->hw, &new_link); |
| 6033 | if (status) { |
| 6034 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6035 | status); |
| 6036 | return; |
| 6037 | } |
| 6038 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6039 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6040 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6041 | |
| 6042 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6043 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6044 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 6045 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6046 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6047 | |
| 6048 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 6049 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6050 | |
| 6051 | /* Notify the base of the switch tree connected to |
| 6052 | * the link. Floating VEBs are not notified. |
| 6053 | */ |
| 6054 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6055 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6056 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6057 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6058 | |
| 6059 | if (pf->vf) |
| 6060 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6061 | |
| 6062 | if (pf->flags & I40E_FLAG_PTP) |
| 6063 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6064 | } |
| 6065 | |
| 6066 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6067 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6068 | * @pf: board private structure |
| 6069 | **/ |
| 6070 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6071 | { |
| 6072 | int i; |
| 6073 | |
| 6074 | /* if interface is down do nothing */ |
| 6075 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 6076 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6077 | return; |
| 6078 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6079 | /* make sure we don't do these things too often */ |
| 6080 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6081 | pf->service_timer_period))) |
| 6082 | return; |
| 6083 | pf->service_timer_previous = jiffies; |
| 6084 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6085 | if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) |
| 6086 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6087 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6088 | /* Update the stats for active netdevs so the network stack |
| 6089 | * can look at updated numbers whenever it cares to |
| 6090 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6091 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6092 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6093 | i40e_update_stats(pf->vsi[i]); |
| 6094 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6095 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6096 | /* Update the stats for the active switching components */ |
| 6097 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6098 | if (pf->veb[i]) |
| 6099 | i40e_update_veb_stats(pf->veb[i]); |
| 6100 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6101 | |
| 6102 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6103 | } |
| 6104 | |
| 6105 | /** |
| 6106 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6107 | * @pf: board private structure |
| 6108 | **/ |
| 6109 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6110 | { |
| 6111 | u32 reset_flags = 0; |
| 6112 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6113 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6114 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6115 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6116 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 6117 | } |
| 6118 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6119 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6120 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6121 | } |
| 6122 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6123 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6124 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 6125 | } |
| 6126 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6127 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6128 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 6129 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6130 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6131 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6132 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 6133 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6134 | |
| 6135 | /* If there's a recovery already waiting, it takes |
| 6136 | * precedence before starting a new reset sequence. |
| 6137 | */ |
| 6138 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 6139 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6140 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | /* If we're already down or resetting, just bail */ |
| 6144 | if (reset_flags && |
| 6145 | !test_bit(__I40E_DOWN, &pf->state) && |
| 6146 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6147 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6148 | |
| 6149 | unlock: |
| 6150 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6151 | } |
| 6152 | |
| 6153 | /** |
| 6154 | * i40e_handle_link_event - Handle link event |
| 6155 | * @pf: board private structure |
| 6156 | * @e: event info posted on ARQ |
| 6157 | **/ |
| 6158 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6159 | struct i40e_arq_event_info *e) |
| 6160 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6161 | struct i40e_aqc_get_link_status *status = |
| 6162 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6163 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6164 | /* Do a new status request to re-enable LSE reporting |
| 6165 | * and load new status information into the hw struct |
| 6166 | * This completely ignores any state information |
| 6167 | * in the ARQ event info, instead choosing to always |
| 6168 | * issue the AQ update link status command. |
| 6169 | */ |
| 6170 | i40e_link_event(pf); |
| 6171 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6172 | /* check for unqualified module, if link is down */ |
| 6173 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6174 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6175 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6176 | dev_err(&pf->pdev->dev, |
| 6177 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6178 | } |
| 6179 | |
| 6180 | /** |
| 6181 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6182 | * @pf: board private structure |
| 6183 | **/ |
| 6184 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6185 | { |
| 6186 | struct i40e_arq_event_info event; |
| 6187 | struct i40e_hw *hw = &pf->hw; |
| 6188 | u16 pending, i = 0; |
| 6189 | i40e_status ret; |
| 6190 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6191 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6192 | u32 val; |
| 6193 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6194 | /* Do not run clean AQ when PF reset fails */ |
| 6195 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 6196 | return; |
| 6197 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6198 | /* check for error indications */ |
| 6199 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6200 | oldval = val; |
| 6201 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6202 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6203 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6204 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6205 | } |
| 6206 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6207 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6208 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6209 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 6210 | pf->arq_overflows++; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6211 | } |
| 6212 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6213 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6214 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6215 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6216 | } |
| 6217 | if (oldval != val) |
| 6218 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6219 | |
| 6220 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6221 | oldval = val; |
| 6222 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6223 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6224 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6225 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6226 | } |
| 6227 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6228 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6229 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6230 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6231 | } |
| 6232 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6233 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6234 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6235 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6236 | } |
| 6237 | if (oldval != val) |
| 6238 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6239 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6240 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6241 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6242 | if (!event.msg_buf) |
| 6243 | return; |
| 6244 | |
| 6245 | do { |
| 6246 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6247 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6248 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6249 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6250 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6251 | break; |
| 6252 | } |
| 6253 | |
| 6254 | opcode = le16_to_cpu(event.desc.opcode); |
| 6255 | switch (opcode) { |
| 6256 | |
| 6257 | case i40e_aqc_opc_get_link_status: |
| 6258 | i40e_handle_link_event(pf, &event); |
| 6259 | break; |
| 6260 | case i40e_aqc_opc_send_msg_to_pf: |
| 6261 | ret = i40e_vc_process_vf_msg(pf, |
| 6262 | le16_to_cpu(event.desc.retval), |
| 6263 | le32_to_cpu(event.desc.cookie_high), |
| 6264 | le32_to_cpu(event.desc.cookie_low), |
| 6265 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6266 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6267 | break; |
| 6268 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6269 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6270 | #ifdef CONFIG_I40E_DCB |
| 6271 | rtnl_lock(); |
| 6272 | ret = i40e_handle_lldp_event(pf, &event); |
| 6273 | rtnl_unlock(); |
| 6274 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6275 | break; |
| 6276 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6277 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6278 | i40e_handle_lan_overflow_event(pf, &event); |
| 6279 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6280 | case i40e_aqc_opc_send_msg_to_peer: |
| 6281 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6282 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6283 | case i40e_aqc_opc_nvm_erase: |
| 6284 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6285 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 6286 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
| 6287 | "ARQ NVM operation 0x%04x completed\n", |
| 6288 | opcode); |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6289 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6290 | default: |
| 6291 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 56e5ca6 | 2016-03-10 14:59:48 -0800 | [diff] [blame] | 6292 | "ARQ: Unknown event 0x%04x ignored\n", |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6293 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6294 | break; |
| 6295 | } |
| 6296 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 6297 | |
| 6298 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 6299 | /* re-enable Admin queue interrupt cause */ |
| 6300 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6301 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6302 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6303 | i40e_flush(hw); |
| 6304 | |
| 6305 | kfree(event.msg_buf); |
| 6306 | } |
| 6307 | |
| 6308 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6309 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6310 | * @pf: board private structure |
| 6311 | **/ |
| 6312 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6313 | { |
| 6314 | int err; |
| 6315 | |
| 6316 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6317 | if (err) { |
| 6318 | /* retry in case of garbage read */ |
| 6319 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6320 | if (err) { |
| 6321 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6322 | err); |
| 6323 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6324 | } |
| 6325 | } |
| 6326 | |
| 6327 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 6328 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 6329 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6330 | } |
| 6331 | } |
| 6332 | |
| 6333 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6334 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6335 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6336 | * |
| 6337 | * enable switch loop back or die - no point in a return value |
| 6338 | **/ |
| 6339 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 6340 | { |
| 6341 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6342 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6343 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6344 | |
| 6345 | ctxt.seid = pf->main_vsi_seid; |
| 6346 | ctxt.pf_num = pf->hw.pf_id; |
| 6347 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6348 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6349 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6350 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6351 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6352 | i40e_stat_str(&pf->hw, ret), |
| 6353 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6354 | return; |
| 6355 | } |
| 6356 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6357 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6358 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6359 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6360 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6361 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6362 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6363 | "update vsi switch failed, err %s aq_err %s\n", |
| 6364 | i40e_stat_str(&pf->hw, ret), |
| 6365 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6366 | } |
| 6367 | } |
| 6368 | |
| 6369 | /** |
| 6370 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6371 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6372 | * |
| 6373 | * disable switch loop back or die - no point in a return value |
| 6374 | **/ |
| 6375 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6376 | { |
| 6377 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6378 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6379 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6380 | |
| 6381 | ctxt.seid = pf->main_vsi_seid; |
| 6382 | ctxt.pf_num = pf->hw.pf_id; |
| 6383 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6384 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6385 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6386 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6387 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6388 | i40e_stat_str(&pf->hw, ret), |
| 6389 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6390 | return; |
| 6391 | } |
| 6392 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6393 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6394 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6395 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6396 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6397 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6398 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6399 | "update vsi switch failed, err %s aq_err %s\n", |
| 6400 | i40e_stat_str(&pf->hw, ret), |
| 6401 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6402 | } |
| 6403 | } |
| 6404 | |
| 6405 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6406 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6407 | * @veb: pointer to the bridge instance |
| 6408 | * |
| 6409 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6410 | * specified HW bridge instance. It is expected this function is called |
| 6411 | * when a new HW bridge is instantiated. |
| 6412 | **/ |
| 6413 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6414 | { |
| 6415 | struct i40e_pf *pf = veb->pf; |
| 6416 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6417 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6418 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6419 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6420 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6421 | i40e_disable_pf_switch_lb(pf); |
| 6422 | else |
| 6423 | i40e_enable_pf_switch_lb(pf); |
| 6424 | } |
| 6425 | |
| 6426 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6427 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6428 | * @veb: pointer to the VEB instance |
| 6429 | * |
| 6430 | * This is a recursive function that first builds the attached VSIs then |
| 6431 | * recurses in to build the next layer of VEB. We track the connections |
| 6432 | * through our own index numbers because the seid's from the HW could |
| 6433 | * change across the reset. |
| 6434 | **/ |
| 6435 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6436 | { |
| 6437 | struct i40e_vsi *ctl_vsi = NULL; |
| 6438 | struct i40e_pf *pf = veb->pf; |
| 6439 | int v, veb_idx; |
| 6440 | int ret; |
| 6441 | |
| 6442 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6443 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6444 | if (pf->vsi[v] && |
| 6445 | pf->vsi[v]->veb_idx == veb->idx && |
| 6446 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6447 | ctl_vsi = pf->vsi[v]; |
| 6448 | break; |
| 6449 | } |
| 6450 | } |
| 6451 | if (!ctl_vsi) { |
| 6452 | dev_info(&pf->pdev->dev, |
| 6453 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6454 | ret = -ENOENT; |
| 6455 | goto end_reconstitute; |
| 6456 | } |
| 6457 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6458 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6459 | ret = i40e_add_vsi(ctl_vsi); |
| 6460 | if (ret) { |
| 6461 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6462 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6463 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6464 | goto end_reconstitute; |
| 6465 | } |
| 6466 | i40e_vsi_reset_stats(ctl_vsi); |
| 6467 | |
| 6468 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6469 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6470 | if (ret) |
| 6471 | goto end_reconstitute; |
| 6472 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6473 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6474 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6475 | else |
| 6476 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6477 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6478 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6479 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6480 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6481 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6482 | continue; |
| 6483 | |
| 6484 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6485 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6486 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6487 | vsi->uplink_seid = veb->seid; |
| 6488 | ret = i40e_add_vsi(vsi); |
| 6489 | if (ret) { |
| 6490 | dev_info(&pf->pdev->dev, |
| 6491 | "rebuild of vsi_idx %d failed: %d\n", |
| 6492 | v, ret); |
| 6493 | goto end_reconstitute; |
| 6494 | } |
| 6495 | i40e_vsi_reset_stats(vsi); |
| 6496 | } |
| 6497 | } |
| 6498 | |
| 6499 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6500 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6501 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6502 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6503 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6504 | if (ret) |
| 6505 | break; |
| 6506 | } |
| 6507 | } |
| 6508 | |
| 6509 | end_reconstitute: |
| 6510 | return ret; |
| 6511 | } |
| 6512 | |
| 6513 | /** |
| 6514 | * i40e_get_capabilities - get info about the HW |
| 6515 | * @pf: the PF struct |
| 6516 | **/ |
| 6517 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6518 | { |
| 6519 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6520 | u16 data_size; |
| 6521 | int buf_len; |
| 6522 | int err; |
| 6523 | |
| 6524 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6525 | do { |
| 6526 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6527 | if (!cap_buf) |
| 6528 | return -ENOMEM; |
| 6529 | |
| 6530 | /* this loads the data into the hw struct for us */ |
| 6531 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6532 | &data_size, |
| 6533 | i40e_aqc_opc_list_func_capabilities, |
| 6534 | NULL); |
| 6535 | /* data loaded, buffer no longer needed */ |
| 6536 | kfree(cap_buf); |
| 6537 | |
| 6538 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6539 | /* retry with a larger buffer */ |
| 6540 | buf_len = data_size; |
| 6541 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6542 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6543 | "capability discovery failed, err %s aq_err %s\n", |
| 6544 | i40e_stat_str(&pf->hw, err), |
| 6545 | i40e_aq_str(&pf->hw, |
| 6546 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6547 | return -ENODEV; |
| 6548 | } |
| 6549 | } while (err); |
| 6550 | |
| 6551 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6552 | dev_info(&pf->pdev->dev, |
| 6553 | "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", |
| 6554 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6555 | pf->hw.func_caps.num_msix_vectors, |
| 6556 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6557 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6558 | pf->hw.func_caps.fd_filters_best_effort, |
| 6559 | pf->hw.func_caps.num_tx_qp, |
| 6560 | pf->hw.func_caps.num_vsis); |
| 6561 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6562 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6563 | + pf->hw.func_caps.num_vfs) |
| 6564 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6565 | dev_info(&pf->pdev->dev, |
| 6566 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6567 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6568 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6569 | } |
| 6570 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6571 | return 0; |
| 6572 | } |
| 6573 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6574 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6575 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6576 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6577 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6578 | * @pf: board private structure |
| 6579 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6580 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6581 | { |
| 6582 | struct i40e_vsi *vsi; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6583 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6584 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6585 | /* quick workaround for an NVM issue that leaves a critical register |
| 6586 | * uninitialized |
| 6587 | */ |
| 6588 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6589 | static const u32 hkey[] = { |
| 6590 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6591 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6592 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6593 | 0x95b3a76d}; |
| 6594 | |
| 6595 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6596 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6597 | } |
| 6598 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6599 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6600 | return; |
| 6601 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6602 | /* find existing VSI and see if it needs configuring */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6603 | vsi = NULL; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6604 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6605 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6606 | vsi = pf->vsi[i]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6607 | break; |
| 6608 | } |
| 6609 | } |
| 6610 | |
| 6611 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6612 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6613 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6614 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6615 | if (!vsi) { |
| 6616 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6617 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6618 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6619 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6620 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6621 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6622 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6623 | } |
| 6624 | |
| 6625 | /** |
| 6626 | * i40e_fdir_teardown - release the Flow Director resources |
| 6627 | * @pf: board private structure |
| 6628 | **/ |
| 6629 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6630 | { |
| 6631 | int i; |
| 6632 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6633 | i40e_fdir_filter_exit(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6634 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6635 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 6636 | i40e_vsi_release(pf->vsi[i]); |
| 6637 | break; |
| 6638 | } |
| 6639 | } |
| 6640 | } |
| 6641 | |
| 6642 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6643 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6644 | * @pf: board private structure |
| 6645 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6646 | * 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] | 6647 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6648 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6649 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6650 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6651 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6652 | u32 v; |
| 6653 | |
| 6654 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6655 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6656 | return; |
Mitch Williams | d3ce5734 | 2016-03-10 14:59:46 -0800 | [diff] [blame] | 6657 | if (i40e_check_asq_alive(&pf->hw)) |
| 6658 | i40e_vc_notify_reset(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6659 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6660 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6661 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6662 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6663 | i40e_pf_quiesce_all_vsi(pf); |
| 6664 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6665 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6666 | if (pf->vsi[v]) |
| 6667 | pf->vsi[v]->seid = 0; |
| 6668 | } |
| 6669 | |
| 6670 | i40e_shutdown_adminq(&pf->hw); |
| 6671 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6672 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6673 | if (hw->hmc.hmc_obj) { |
| 6674 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6675 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6676 | dev_warn(&pf->pdev->dev, |
| 6677 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6678 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6679 | } |
| 6680 | |
| 6681 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6682 | * i40e_send_version - update firmware with driver version |
| 6683 | * @pf: PF struct |
| 6684 | */ |
| 6685 | static void i40e_send_version(struct i40e_pf *pf) |
| 6686 | { |
| 6687 | struct i40e_driver_version dv; |
| 6688 | |
| 6689 | dv.major_version = DRV_VERSION_MAJOR; |
| 6690 | dv.minor_version = DRV_VERSION_MINOR; |
| 6691 | dv.build_version = DRV_VERSION_BUILD; |
| 6692 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 6693 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6694 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 6695 | } |
| 6696 | |
| 6697 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 6698 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6699 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6700 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6701 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6702 | 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] | 6703 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6704 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6705 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6706 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6707 | u32 val; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6708 | u32 v; |
| 6709 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6710 | /* Now we wait for GRST to settle out. |
| 6711 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 6712 | * because the reset will make them disappear. |
| 6713 | */ |
| 6714 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6715 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6716 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6717 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 6718 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6719 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6720 | pf->pfr_count++; |
| 6721 | |
| 6722 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6723 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6724 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6725 | |
| 6726 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 6727 | ret = i40e_init_adminq(&pf->hw); |
| 6728 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6729 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 6730 | i40e_stat_str(&pf->hw, ret), |
| 6731 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6732 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6733 | } |
| 6734 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6735 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 6736 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6737 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6738 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 6739 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6740 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6741 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6742 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6743 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6744 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 6745 | hw->func_caps.num_rx_qp, |
| 6746 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 6747 | if (ret) { |
| 6748 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 6749 | goto end_core_reset; |
| 6750 | } |
| 6751 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 6752 | if (ret) { |
| 6753 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 6754 | goto end_core_reset; |
| 6755 | } |
| 6756 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6757 | #ifdef CONFIG_I40E_DCB |
| 6758 | ret = i40e_init_pf_dcb(pf); |
| 6759 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6760 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 6761 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 6762 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6763 | } |
| 6764 | #endif /* CONFIG_I40E_DCB */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6765 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 6766 | i40e_init_pf_fcoe(pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6767 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6768 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6769 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6770 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6771 | if (ret) |
| 6772 | goto end_core_reset; |
| 6773 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6774 | /* The driver only wants link up/down and module qualification |
| 6775 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6776 | */ |
| 6777 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6778 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 6779 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 6780 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6781 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6782 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 6783 | i40e_stat_str(&pf->hw, ret), |
| 6784 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6785 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6786 | /* make sure our flow control settings are restored */ |
| 6787 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 6788 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 6789 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 6790 | i40e_stat_str(&pf->hw, ret), |
| 6791 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6792 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6793 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 6794 | * They are still in our local switch element arrays, so only |
| 6795 | * need to rebuild the switch model in the HW. |
| 6796 | * |
| 6797 | * If there were VEBs but the reconstitution failed, we'll try |
| 6798 | * try to recover minimal use by getting the basic PF VSI working. |
| 6799 | */ |
| 6800 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6801 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6802 | /* find the one VEB connected to the MAC, and find orphans */ |
| 6803 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6804 | if (!pf->veb[v]) |
| 6805 | continue; |
| 6806 | |
| 6807 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 6808 | pf->veb[v]->uplink_seid == 0) { |
| 6809 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 6810 | |
| 6811 | if (!ret) |
| 6812 | continue; |
| 6813 | |
| 6814 | /* If Main VEB failed, we're in deep doodoo, |
| 6815 | * so give up rebuilding the switch and set up |
| 6816 | * for minimal rebuild of PF VSI. |
| 6817 | * If orphan failed, we'll report the error |
| 6818 | * but try to keep going. |
| 6819 | */ |
| 6820 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 6821 | dev_info(&pf->pdev->dev, |
| 6822 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 6823 | ret); |
| 6824 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 6825 | = pf->mac_seid; |
| 6826 | break; |
| 6827 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 6828 | dev_info(&pf->pdev->dev, |
| 6829 | "rebuild of orphan VEB failed: %d\n", |
| 6830 | ret); |
| 6831 | } |
| 6832 | } |
| 6833 | } |
| 6834 | } |
| 6835 | |
| 6836 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 6837 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6838 | /* no VEB, so rebuild only the Main VSI */ |
| 6839 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 6840 | if (ret) { |
| 6841 | dev_info(&pf->pdev->dev, |
| 6842 | "rebuild of Main VSI failed: %d\n", ret); |
| 6843 | goto end_core_reset; |
| 6844 | } |
| 6845 | } |
| 6846 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6847 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 6848 | * of TSO, so that we avoid the MDD being fired and causing |
| 6849 | * a reset in the case of small MSS+TSO. |
| 6850 | */ |
| 6851 | #define I40E_REG_MSS 0x000E64DC |
| 6852 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 6853 | #define I40E_64BYTE_MSS 0x400000 |
| 6854 | val = rd32(hw, I40E_REG_MSS); |
| 6855 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 6856 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 6857 | val |= I40E_64BYTE_MSS; |
| 6858 | wr32(hw, I40E_REG_MSS, val); |
| 6859 | } |
| 6860 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 6861 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 6862 | msleep(75); |
| 6863 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 6864 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6865 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 6866 | i40e_stat_str(&pf->hw, ret), |
| 6867 | i40e_aq_str(&pf->hw, |
| 6868 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6869 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6870 | /* reinit the misc interrupt */ |
| 6871 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 6872 | ret = i40e_setup_misc_vector(pf); |
| 6873 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 6874 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 6875 | * transmitted. By doing so we stop a malicious VF from sending out |
| 6876 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 6877 | * PF/VF VSIs. |
| 6878 | * The FW can still send Flow control frames if enabled. |
| 6879 | */ |
| 6880 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 6881 | pf->main_vsi_seid); |
| 6882 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6883 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 6884 | i40e_pf_unquiesce_all_vsi(pf); |
| 6885 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 6886 | if (pf->num_alloc_vfs) { |
| 6887 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 6888 | i40e_reset_vf(&pf->vf[v], true); |
| 6889 | } |
| 6890 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6891 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6892 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6893 | |
| 6894 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6895 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 6896 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6897 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 6898 | } |
| 6899 | |
| 6900 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6901 | * 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] | 6902 | * @pf: board private structure |
| 6903 | * |
| 6904 | * Close up the VFs and other things in prep for a Core Reset, |
| 6905 | * then get ready to rebuild the world. |
| 6906 | **/ |
| 6907 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 6908 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6909 | i40e_prep_for_reset(pf); |
| 6910 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6911 | } |
| 6912 | |
| 6913 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6914 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6915 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6916 | * |
| 6917 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 6918 | **/ |
| 6919 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 6920 | { |
| 6921 | struct i40e_hw *hw = &pf->hw; |
| 6922 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 6923 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6924 | struct i40e_vf *vf; |
| 6925 | u32 reg; |
| 6926 | int i; |
| 6927 | |
| 6928 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 6929 | return; |
| 6930 | |
| 6931 | /* find what triggered the MDD event */ |
| 6932 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 6933 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6934 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 6935 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6936 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6937 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 6938 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6939 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6940 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 6941 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 6942 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6943 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6944 | 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] | 6945 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6946 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 6947 | mdd_detected = true; |
| 6948 | } |
| 6949 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 6950 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6951 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 6952 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 6953 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6954 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6955 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 6956 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 6957 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6958 | if (netif_msg_rx_err(pf)) |
| 6959 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 6960 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6961 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 6962 | mdd_detected = true; |
| 6963 | } |
| 6964 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 6965 | if (mdd_detected) { |
| 6966 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 6967 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 6968 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6969 | 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] | 6970 | pf_mdd_detected = true; |
| 6971 | } |
| 6972 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 6973 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 6974 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6975 | 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] | 6976 | pf_mdd_detected = true; |
| 6977 | } |
| 6978 | /* Queue belongs to the PF, initiate a reset */ |
| 6979 | if (pf_mdd_detected) { |
| 6980 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6981 | i40e_service_event_schedule(pf); |
| 6982 | } |
| 6983 | } |
| 6984 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6985 | /* see if one of the VFs needs its hand slapped */ |
| 6986 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 6987 | vf = &(pf->vf[i]); |
| 6988 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 6989 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 6990 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 6991 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6992 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 6993 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6994 | } |
| 6995 | |
| 6996 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 6997 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 6998 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 6999 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7000 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7001 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7002 | } |
| 7003 | |
| 7004 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7005 | dev_info(&pf->pdev->dev, |
| 7006 | "Too many MDD events on VF %d, disabled\n", i); |
| 7007 | dev_info(&pf->pdev->dev, |
| 7008 | "Use PF Control I/F to re-enable the VF\n"); |
| 7009 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 7010 | } |
| 7011 | } |
| 7012 | |
| 7013 | /* re-enable mdd interrupt cause */ |
| 7014 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 7015 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7016 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7017 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7018 | i40e_flush(hw); |
| 7019 | } |
| 7020 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7021 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7022 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7023 | * @pf: board private structure |
| 7024 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7025 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7026 | { |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7027 | struct i40e_hw *hw = &pf->hw; |
| 7028 | i40e_status ret; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7029 | __be16 port; |
| 7030 | int i; |
| 7031 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7032 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7033 | return; |
| 7034 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7035 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7036 | |
| 7037 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7038 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7039 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
| 7040 | port = pf->udp_ports[i].index; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7041 | if (port) |
Carolyn Wyborny | b3f5c7b | 2016-08-24 11:33:51 -0700 | [diff] [blame] | 7042 | ret = i40e_aq_add_udp_tunnel(hw, port, |
| 7043 | pf->udp_ports[i].type, |
| 7044 | NULL, NULL); |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7045 | else |
| 7046 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7047 | |
| 7048 | if (ret) { |
Carolyn Wyborny | 730a8f8 | 2016-02-17 16:12:16 -0800 | [diff] [blame] | 7049 | dev_dbg(&pf->pdev->dev, |
| 7050 | "%s %s port %d, index %d failed, err %s aq_err %s\n", |
| 7051 | pf->udp_ports[i].type ? "vxlan" : "geneve", |
| 7052 | port ? "add" : "delete", |
| 7053 | ntohs(port), i, |
| 7054 | i40e_stat_str(&pf->hw, ret), |
| 7055 | i40e_aq_str(&pf->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7056 | pf->hw.aq.asq_last_status)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7057 | pf->udp_ports[i].index = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7058 | } |
| 7059 | } |
| 7060 | } |
| 7061 | } |
| 7062 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7063 | /** |
| 7064 | * i40e_service_task - Run the driver's async subtasks |
| 7065 | * @work: pointer to work_struct containing our data |
| 7066 | **/ |
| 7067 | static void i40e_service_task(struct work_struct *work) |
| 7068 | { |
| 7069 | struct i40e_pf *pf = container_of(work, |
| 7070 | struct i40e_pf, |
| 7071 | service_task); |
| 7072 | unsigned long start_time = jiffies; |
| 7073 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7074 | /* don't bother with service tasks if a reset is in progress */ |
| 7075 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7076 | i40e_service_event_complete(pf); |
| 7077 | return; |
| 7078 | } |
| 7079 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7080 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 2818ccd | 2016-01-13 16:51:38 -0800 | [diff] [blame] | 7081 | i40e_sync_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7082 | i40e_reset_subtask(pf); |
| 7083 | i40e_handle_mdd_event(pf); |
| 7084 | i40e_vc_process_vflr_event(pf); |
| 7085 | i40e_watchdog_subtask(pf); |
| 7086 | i40e_fdir_reinit_subtask(pf); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7087 | i40e_client_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7088 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7089 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7090 | i40e_clean_adminq_subtask(pf); |
| 7091 | |
| 7092 | i40e_service_event_complete(pf); |
| 7093 | |
| 7094 | /* If the tasks have taken longer than one timer cycle or there |
| 7095 | * is more work to be done, reschedule the service task now |
| 7096 | * rather than wait for the timer to tick again. |
| 7097 | */ |
| 7098 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 7099 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 7100 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 7101 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 7102 | i40e_service_event_schedule(pf); |
| 7103 | } |
| 7104 | |
| 7105 | /** |
| 7106 | * i40e_service_timer - timer callback |
| 7107 | * @data: pointer to PF struct |
| 7108 | **/ |
| 7109 | static void i40e_service_timer(unsigned long data) |
| 7110 | { |
| 7111 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7112 | |
| 7113 | mod_timer(&pf->service_timer, |
| 7114 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7115 | i40e_service_event_schedule(pf); |
| 7116 | } |
| 7117 | |
| 7118 | /** |
| 7119 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7120 | * @vsi: the VSI being configured |
| 7121 | **/ |
| 7122 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7123 | { |
| 7124 | struct i40e_pf *pf = vsi->back; |
| 7125 | |
| 7126 | switch (vsi->type) { |
| 7127 | case I40E_VSI_MAIN: |
| 7128 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7129 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7130 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7131 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7132 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7133 | else |
| 7134 | vsi->num_q_vectors = 1; |
| 7135 | |
| 7136 | break; |
| 7137 | |
| 7138 | case I40E_VSI_FDIR: |
| 7139 | vsi->alloc_queue_pairs = 1; |
| 7140 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7141 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7142 | vsi->num_q_vectors = pf->num_fdsb_msix; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7143 | break; |
| 7144 | |
| 7145 | case I40E_VSI_VMDQ2: |
| 7146 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7147 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7148 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7149 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7150 | break; |
| 7151 | |
| 7152 | case I40E_VSI_SRIOV: |
| 7153 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7154 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7155 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7156 | break; |
| 7157 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7158 | #ifdef I40E_FCOE |
| 7159 | case I40E_VSI_FCOE: |
| 7160 | vsi->alloc_queue_pairs = pf->num_fcoe_qps; |
| 7161 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7162 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7163 | vsi->num_q_vectors = pf->num_fcoe_msix; |
| 7164 | break; |
| 7165 | |
| 7166 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7167 | default: |
| 7168 | WARN_ON(1); |
| 7169 | return -ENODATA; |
| 7170 | } |
| 7171 | |
| 7172 | return 0; |
| 7173 | } |
| 7174 | |
| 7175 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7176 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7177 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7178 | * @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] | 7179 | * |
| 7180 | * On error: returns error code (negative) |
| 7181 | * On success: returns 0 |
| 7182 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7183 | 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] | 7184 | { |
| 7185 | int size; |
| 7186 | int ret = 0; |
| 7187 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7188 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7189 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 7190 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7191 | if (!vsi->tx_rings) |
| 7192 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7193 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 7194 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7195 | if (alloc_qvectors) { |
| 7196 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7197 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7198 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7199 | if (!vsi->q_vectors) { |
| 7200 | ret = -ENOMEM; |
| 7201 | goto err_vectors; |
| 7202 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7203 | } |
| 7204 | return ret; |
| 7205 | |
| 7206 | err_vectors: |
| 7207 | kfree(vsi->tx_rings); |
| 7208 | return ret; |
| 7209 | } |
| 7210 | |
| 7211 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7212 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7213 | * @pf: board private structure |
| 7214 | * @type: type of VSI |
| 7215 | * |
| 7216 | * On error: returns error code (negative) |
| 7217 | * On success: returns vsi index in PF (positive) |
| 7218 | **/ |
| 7219 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7220 | { |
| 7221 | int ret = -ENODEV; |
| 7222 | struct i40e_vsi *vsi; |
| 7223 | int vsi_idx; |
| 7224 | int i; |
| 7225 | |
| 7226 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7227 | mutex_lock(&pf->switch_mutex); |
| 7228 | |
| 7229 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7230 | * been happening. We can afford to do a quick scan to look |
| 7231 | * for any free VSIs in the list. |
| 7232 | * |
| 7233 | * find next empty vsi slot, looping back around if necessary |
| 7234 | */ |
| 7235 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7236 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7237 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7238 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7239 | i = 0; |
| 7240 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7241 | i++; |
| 7242 | } |
| 7243 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7244 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7245 | vsi_idx = i; /* Found one! */ |
| 7246 | } else { |
| 7247 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7248 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7249 | } |
| 7250 | pf->next_vsi = ++i; |
| 7251 | |
| 7252 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7253 | if (!vsi) { |
| 7254 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7255 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7256 | } |
| 7257 | vsi->type = type; |
| 7258 | vsi->back = pf; |
| 7259 | set_bit(__I40E_DOWN, &vsi->state); |
| 7260 | vsi->flags = 0; |
| 7261 | vsi->idx = vsi_idx; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7262 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7263 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7264 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7265 | vsi->netdev_registered = false; |
| 7266 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
| 7267 | INIT_LIST_HEAD(&vsi->mac_filter_list); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7268 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7269 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7270 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7271 | if (ret) |
| 7272 | goto err_rings; |
| 7273 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7274 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7275 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7276 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7277 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7278 | /* Setup default MSIX irq handler for VSI */ |
| 7279 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7280 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7281 | /* Initialize VSI lock */ |
| 7282 | spin_lock_init(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7283 | pf->vsi[vsi_idx] = vsi; |
| 7284 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7285 | goto unlock_pf; |
| 7286 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7287 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7288 | pf->next_vsi = i - 1; |
| 7289 | kfree(vsi); |
| 7290 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7291 | mutex_unlock(&pf->switch_mutex); |
| 7292 | return ret; |
| 7293 | } |
| 7294 | |
| 7295 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7296 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7297 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7298 | * @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] | 7299 | * |
| 7300 | * On error: returns error code (negative) |
| 7301 | * On success: returns 0 |
| 7302 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7303 | 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] | 7304 | { |
| 7305 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7306 | if (free_qvectors) { |
| 7307 | kfree(vsi->q_vectors); |
| 7308 | vsi->q_vectors = NULL; |
| 7309 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7310 | kfree(vsi->tx_rings); |
| 7311 | vsi->tx_rings = NULL; |
| 7312 | vsi->rx_rings = NULL; |
| 7313 | } |
| 7314 | |
| 7315 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7316 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7317 | * and lookup table |
| 7318 | * @vsi: Pointer to VSI structure |
| 7319 | */ |
| 7320 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7321 | { |
| 7322 | if (!vsi) |
| 7323 | return; |
| 7324 | |
| 7325 | kfree(vsi->rss_hkey_user); |
| 7326 | vsi->rss_hkey_user = NULL; |
| 7327 | |
| 7328 | kfree(vsi->rss_lut_user); |
| 7329 | vsi->rss_lut_user = NULL; |
| 7330 | } |
| 7331 | |
| 7332 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7333 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7334 | * @vsi: the VSI being un-configured |
| 7335 | **/ |
| 7336 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7337 | { |
| 7338 | struct i40e_pf *pf; |
| 7339 | |
| 7340 | if (!vsi) |
| 7341 | return 0; |
| 7342 | |
| 7343 | if (!vsi->back) |
| 7344 | goto free_vsi; |
| 7345 | pf = vsi->back; |
| 7346 | |
| 7347 | mutex_lock(&pf->switch_mutex); |
| 7348 | if (!pf->vsi[vsi->idx]) { |
| 7349 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7350 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7351 | goto unlock_vsi; |
| 7352 | } |
| 7353 | |
| 7354 | if (pf->vsi[vsi->idx] != vsi) { |
| 7355 | dev_err(&pf->pdev->dev, |
| 7356 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7357 | pf->vsi[vsi->idx]->idx, |
| 7358 | pf->vsi[vsi->idx], |
| 7359 | pf->vsi[vsi->idx]->type, |
| 7360 | vsi->idx, vsi, vsi->type); |
| 7361 | goto unlock_vsi; |
| 7362 | } |
| 7363 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7364 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7365 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7366 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7367 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7368 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7369 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7370 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7371 | pf->vsi[vsi->idx] = NULL; |
| 7372 | if (vsi->idx < pf->next_vsi) |
| 7373 | pf->next_vsi = vsi->idx; |
| 7374 | |
| 7375 | unlock_vsi: |
| 7376 | mutex_unlock(&pf->switch_mutex); |
| 7377 | free_vsi: |
| 7378 | kfree(vsi); |
| 7379 | |
| 7380 | return 0; |
| 7381 | } |
| 7382 | |
| 7383 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7384 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7385 | * @vsi: the VSI being cleaned |
| 7386 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7387 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7388 | { |
| 7389 | int i; |
| 7390 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7391 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7392 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7393 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7394 | vsi->tx_rings[i] = NULL; |
| 7395 | vsi->rx_rings[i] = NULL; |
| 7396 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7397 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7398 | } |
| 7399 | |
| 7400 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7401 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7402 | * @vsi: the VSI being configured |
| 7403 | **/ |
| 7404 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7405 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7406 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7407 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7408 | int i; |
| 7409 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7410 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7411 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7412 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7413 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7414 | if (!tx_ring) |
| 7415 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7416 | |
| 7417 | tx_ring->queue_index = i; |
| 7418 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7419 | tx_ring->ring_active = false; |
| 7420 | tx_ring->vsi = vsi; |
| 7421 | tx_ring->netdev = vsi->netdev; |
| 7422 | tx_ring->dev = &pf->pdev->dev; |
| 7423 | tx_ring->count = vsi->num_desc; |
| 7424 | tx_ring->size = 0; |
| 7425 | tx_ring->dcb_tc = 0; |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 7426 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 7427 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7428 | tx_ring->tx_itr_setting = pf->tx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7429 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7430 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7431 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7432 | rx_ring->queue_index = i; |
| 7433 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7434 | rx_ring->ring_active = false; |
| 7435 | rx_ring->vsi = vsi; |
| 7436 | rx_ring->netdev = vsi->netdev; |
| 7437 | rx_ring->dev = &pf->pdev->dev; |
| 7438 | rx_ring->count = vsi->num_desc; |
| 7439 | rx_ring->size = 0; |
| 7440 | rx_ring->dcb_tc = 0; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 7441 | rx_ring->rx_itr_setting = pf->rx_itr_default; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7442 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7443 | } |
| 7444 | |
| 7445 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7446 | |
| 7447 | err_out: |
| 7448 | i40e_vsi_clear_rings(vsi); |
| 7449 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7450 | } |
| 7451 | |
| 7452 | /** |
| 7453 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7454 | * @pf: board private structure |
| 7455 | * @vectors: the number of MSI-X vectors to request |
| 7456 | * |
| 7457 | * Returns the number of vectors reserved, or error |
| 7458 | **/ |
| 7459 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7460 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7461 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7462 | I40E_MIN_MSIX, vectors); |
| 7463 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7464 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7465 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7466 | vectors = 0; |
| 7467 | } |
| 7468 | |
| 7469 | return vectors; |
| 7470 | } |
| 7471 | |
| 7472 | /** |
| 7473 | * i40e_init_msix - Setup the MSIX capability |
| 7474 | * @pf: board private structure |
| 7475 | * |
| 7476 | * Work with the OS to set up the MSIX vectors needed. |
| 7477 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7478 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7479 | **/ |
| 7480 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7481 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7482 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7483 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7484 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7485 | int v_actual; |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7486 | int iwarp_requested = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7487 | |
| 7488 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7489 | return -ENODEV; |
| 7490 | |
| 7491 | /* The number of vectors we'll request will be comprised of: |
| 7492 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7493 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7494 | * - Queues being used for RSS. |
| 7495 | * We don't need as many as max_rss_size vectors. |
| 7496 | * use rss_size instead in the calculation since that |
| 7497 | * is governed by number of cpus in the system. |
| 7498 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7499 | * - The number of VMDq pairs |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7500 | * - The CPU count within the NUMA node if iWARP is enabled |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7501 | #ifdef I40E_FCOE |
| 7502 | * - The number of FCOE qps. |
| 7503 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7504 | * Once we count this up, try the request. |
| 7505 | * |
| 7506 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7507 | * and try again. If that still fails, we punt. |
| 7508 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7509 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7510 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7511 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7512 | /* reserve one vector for miscellaneous handler */ |
| 7513 | if (vectors_left) { |
| 7514 | v_budget++; |
| 7515 | vectors_left--; |
| 7516 | } |
| 7517 | |
| 7518 | /* reserve vectors for the main PF traffic queues */ |
| 7519 | pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left); |
| 7520 | vectors_left -= pf->num_lan_msix; |
| 7521 | v_budget += pf->num_lan_msix; |
| 7522 | |
| 7523 | /* reserve one vector for sideband flow director */ |
| 7524 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7525 | if (vectors_left) { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7526 | pf->num_fdsb_msix = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7527 | v_budget++; |
| 7528 | vectors_left--; |
| 7529 | } else { |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 7530 | pf->num_fdsb_msix = 0; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7531 | } |
| 7532 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7533 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7534 | #ifdef I40E_FCOE |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7535 | /* can we reserve enough for FCoE? */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7536 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7537 | if (!vectors_left) |
| 7538 | pf->num_fcoe_msix = 0; |
| 7539 | else if (vectors_left >= pf->num_fcoe_qps) |
| 7540 | pf->num_fcoe_msix = pf->num_fcoe_qps; |
| 7541 | else |
| 7542 | pf->num_fcoe_msix = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7543 | v_budget += pf->num_fcoe_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7544 | vectors_left -= pf->num_fcoe_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7545 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7546 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7547 | #endif |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7548 | /* can we reserve enough for iWARP? */ |
| 7549 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7550 | iwarp_requested = pf->num_iwarp_msix; |
| 7551 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7552 | if (!vectors_left) |
| 7553 | pf->num_iwarp_msix = 0; |
| 7554 | else if (vectors_left < pf->num_iwarp_msix) |
| 7555 | pf->num_iwarp_msix = 1; |
| 7556 | v_budget += pf->num_iwarp_msix; |
| 7557 | vectors_left -= pf->num_iwarp_msix; |
| 7558 | } |
| 7559 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7560 | /* any vectors left over go for VMDq support */ |
| 7561 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7562 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7563 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7564 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 7565 | if (!vectors_left) { |
| 7566 | pf->num_vmdq_msix = 0; |
| 7567 | pf->num_vmdq_qps = 0; |
| 7568 | } else { |
| 7569 | /* if we're short on vectors for what's desired, we limit |
| 7570 | * the queues per vmdq. If this is still more than are |
| 7571 | * available, the user will need to change the number of |
| 7572 | * queues/vectors used by the PF later with the ethtool |
| 7573 | * channels command |
| 7574 | */ |
| 7575 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7576 | pf->num_vmdq_qps = 1; |
| 7577 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7578 | |
Stefan Assmann | 9ca57e9 | 2016-09-19 13:37:49 +0200 | [diff] [blame] | 7579 | v_budget += vmdq_vecs; |
| 7580 | vectors_left -= vmdq_vecs; |
| 7581 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7582 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7583 | |
| 7584 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7585 | GFP_KERNEL); |
| 7586 | if (!pf->msix_entries) |
| 7587 | return -ENOMEM; |
| 7588 | |
| 7589 | for (i = 0; i < v_budget; i++) |
| 7590 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7591 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7592 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7593 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7594 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7595 | kfree(pf->msix_entries); |
| 7596 | pf->msix_entries = NULL; |
Guilherme G Piccoli | 4c95aa5 | 2016-09-22 10:03:58 -0300 | [diff] [blame] | 7597 | pci_disable_msix(pf->pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7598 | return -ENODEV; |
| 7599 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7600 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7601 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7602 | pf->num_vmdq_vsis = 0; |
| 7603 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7604 | pf->num_lan_qps = 1; |
| 7605 | pf->num_lan_msix = 1; |
| 7606 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7607 | } else if (!vectors_left) { |
| 7608 | /* If we have limited resources, we will start with no vectors |
| 7609 | * for the special features and then allocate vectors to some |
| 7610 | * of these features based on the policy and at the end disable |
| 7611 | * the features that did not get any vectors. |
| 7612 | */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7613 | int vec; |
| 7614 | |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7615 | dev_info(&pf->pdev->dev, |
| 7616 | "MSI-X vector limit reached, attempting to redistribute vectors\n"); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7617 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7618 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7619 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7620 | /* Scale vector usage down */ |
| 7621 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7622 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7623 | pf->num_vmdq_qps = 1; |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7624 | #ifdef I40E_FCOE |
| 7625 | pf->num_fcoe_qps = 0; |
| 7626 | pf->num_fcoe_msix = 0; |
| 7627 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7628 | |
| 7629 | /* partition out the remaining vectors */ |
| 7630 | switch (vec) { |
| 7631 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7632 | pf->num_lan_msix = 1; |
| 7633 | break; |
| 7634 | case 3: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7635 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7636 | pf->num_lan_msix = 1; |
| 7637 | pf->num_iwarp_msix = 1; |
| 7638 | } else { |
| 7639 | pf->num_lan_msix = 2; |
| 7640 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7641 | #ifdef I40E_FCOE |
| 7642 | /* give one vector to FCoE */ |
| 7643 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7644 | pf->num_lan_msix = 1; |
| 7645 | pf->num_fcoe_msix = 1; |
| 7646 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7647 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7648 | break; |
| 7649 | default: |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7650 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 7651 | pf->num_iwarp_msix = min_t(int, (vec / 3), |
| 7652 | iwarp_requested); |
| 7653 | pf->num_vmdq_vsis = min_t(int, (vec / 3), |
| 7654 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7655 | } else { |
| 7656 | pf->num_vmdq_vsis = min_t(int, (vec / 2), |
| 7657 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 7658 | } |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 7659 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7660 | pf->num_fdsb_msix = 1; |
| 7661 | vec--; |
| 7662 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7663 | pf->num_lan_msix = min_t(int, |
| 7664 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), |
| 7665 | pf->num_lan_msix); |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7666 | pf->num_lan_qps = pf->num_lan_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7667 | #ifdef I40E_FCOE |
| 7668 | /* give one vector to FCoE */ |
| 7669 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7670 | pf->num_fcoe_msix = 1; |
| 7671 | vec--; |
| 7672 | } |
| 7673 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7674 | break; |
| 7675 | } |
| 7676 | } |
| 7677 | |
Stefan Assmann | abd97a9 | 2016-09-19 13:37:51 +0200 | [diff] [blame] | 7678 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 7679 | (pf->num_fdsb_msix == 0)) { |
| 7680 | dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n"); |
| 7681 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7682 | } |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7683 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7684 | (pf->num_vmdq_msix == 0)) { |
| 7685 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 7686 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 7687 | } |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7688 | |
| 7689 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 7690 | (pf->num_iwarp_msix == 0)) { |
| 7691 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); |
| 7692 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 7693 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7694 | #ifdef I40E_FCOE |
| 7695 | |
| 7696 | if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { |
| 7697 | dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n"); |
| 7698 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 7699 | } |
| 7700 | #endif |
Stefan Assmann | 4ce20ab | 2016-09-19 13:37:50 +0200 | [diff] [blame] | 7701 | i40e_debug(&pf->hw, I40E_DEBUG_INIT, |
| 7702 | "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n", |
| 7703 | pf->num_lan_msix, |
| 7704 | pf->num_vmdq_msix * pf->num_vmdq_vsis, |
| 7705 | pf->num_fdsb_msix, |
| 7706 | pf->num_iwarp_msix); |
| 7707 | |
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 |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7715 | * @cpu: cpu to be used on affinity_mask |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7716 | * |
| 7717 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 7718 | **/ |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7719 | static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7720 | { |
| 7721 | struct i40e_q_vector *q_vector; |
| 7722 | |
| 7723 | /* allocate q_vector */ |
| 7724 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 7725 | if (!q_vector) |
| 7726 | return -ENOMEM; |
| 7727 | |
| 7728 | q_vector->vsi = vsi; |
| 7729 | q_vector->v_idx = v_idx; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7730 | cpumask_set_cpu(cpu, &q_vector->affinity_mask); |
| 7731 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7732 | if (vsi->netdev) |
| 7733 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 7734 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7735 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 7736 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 7737 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 7738 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7739 | /* tie q_vector and vsi together */ |
| 7740 | vsi->q_vectors[v_idx] = q_vector; |
| 7741 | |
| 7742 | return 0; |
| 7743 | } |
| 7744 | |
| 7745 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7746 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7747 | * @vsi: the VSI being configured |
| 7748 | * |
| 7749 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 7750 | * return -ENOMEM. |
| 7751 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7752 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7753 | { |
| 7754 | struct i40e_pf *pf = vsi->back; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7755 | int err, v_idx, num_q_vectors, current_cpu; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7756 | |
| 7757 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 7758 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7759 | num_q_vectors = vsi->num_q_vectors; |
| 7760 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 7761 | num_q_vectors = 1; |
| 7762 | else |
| 7763 | return -EINVAL; |
| 7764 | |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7765 | current_cpu = cpumask_first(cpu_online_mask); |
| 7766 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7767 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7768 | err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7769 | if (err) |
| 7770 | goto err_out; |
Guilherme G. Piccoli | 7f6c553 | 2016-06-27 12:16:43 -0300 | [diff] [blame] | 7771 | current_cpu = cpumask_next(current_cpu, cpu_online_mask); |
| 7772 | if (unlikely(current_cpu >= nr_cpu_ids)) |
| 7773 | current_cpu = cpumask_first(cpu_online_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7774 | } |
| 7775 | |
| 7776 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7777 | |
| 7778 | err_out: |
| 7779 | while (v_idx--) |
| 7780 | i40e_free_q_vector(vsi, v_idx); |
| 7781 | |
| 7782 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7783 | } |
| 7784 | |
| 7785 | /** |
| 7786 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 7787 | * @pf: board private structure to initialize |
| 7788 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7789 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7790 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7791 | int vectors = 0; |
| 7792 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7793 | |
| 7794 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7795 | vectors = i40e_init_msix(pf); |
| 7796 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7797 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 7798 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7799 | #ifdef I40E_FCOE |
| 7800 | I40E_FLAG_FCOE_ENABLED | |
| 7801 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7802 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7803 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 7804 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7805 | I40E_FLAG_SRIOV_ENABLED | |
| 7806 | I40E_FLAG_FD_SB_ENABLED | |
| 7807 | I40E_FLAG_FD_ATR_ENABLED | |
| 7808 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7809 | |
| 7810 | /* rework the queue expectations without MSIX */ |
| 7811 | i40e_determine_queue_usage(pf); |
| 7812 | } |
| 7813 | } |
| 7814 | |
| 7815 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 7816 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7817 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7818 | vectors = pci_enable_msi(pf->pdev); |
| 7819 | if (vectors < 0) { |
| 7820 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 7821 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7822 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 7823 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7824 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7825 | } |
| 7826 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 7827 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7828 | 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] | 7829 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7830 | /* set up vector assignment tracking */ |
| 7831 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 7832 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7833 | if (!pf->irq_pile) { |
| 7834 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 7835 | return -ENOMEM; |
| 7836 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7837 | pf->irq_pile->num_entries = vectors; |
| 7838 | pf->irq_pile->search_hint = 0; |
| 7839 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7840 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7841 | (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] | 7842 | |
| 7843 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7844 | } |
| 7845 | |
| 7846 | /** |
| 7847 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 7848 | * @pf: board private structure |
| 7849 | * |
| 7850 | * This sets up the handler for MSIX 0, which is used to manage the |
| 7851 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 7852 | * when in MSI or Legacy interrupt mode. |
| 7853 | **/ |
| 7854 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 7855 | { |
| 7856 | struct i40e_hw *hw = &pf->hw; |
| 7857 | int err = 0; |
| 7858 | |
| 7859 | /* Only request the irq if this is the first time through, and |
| 7860 | * not when we're rebuilding after a Reset |
| 7861 | */ |
| 7862 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7863 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7864 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7865 | if (err) { |
| 7866 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7867 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7868 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7869 | return -EFAULT; |
| 7870 | } |
| 7871 | } |
| 7872 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 7873 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7874 | |
| 7875 | /* associate no queues to the misc vector */ |
| 7876 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 7877 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 7878 | |
| 7879 | i40e_flush(hw); |
| 7880 | |
Jesse Brandeburg | 40d72a5 | 2016-01-13 16:51:45 -0800 | [diff] [blame] | 7881 | i40e_irq_dynamic_enable_icr0(pf, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7882 | |
| 7883 | return err; |
| 7884 | } |
| 7885 | |
| 7886 | /** |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7887 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 7888 | * @vsi: vsi structure |
| 7889 | * @seed: RSS hash seed |
| 7890 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7891 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 7892 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7893 | { |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7894 | struct i40e_pf *pf = vsi->back; |
| 7895 | struct i40e_hw *hw = &pf->hw; |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 7896 | int ret = 0; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7897 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 7898 | if (seed) { |
| 7899 | struct i40e_aqc_get_set_rss_key_data *seed_dw = |
| 7900 | (struct i40e_aqc_get_set_rss_key_data *)seed; |
| 7901 | ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw); |
| 7902 | if (ret) { |
| 7903 | dev_info(&pf->pdev->dev, |
| 7904 | "Cannot set RSS key, err %s aq_err %s\n", |
| 7905 | i40e_stat_str(hw, ret), |
| 7906 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 7907 | return ret; |
| 7908 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7909 | } |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 7910 | if (lut) { |
| 7911 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7912 | |
Jacob Keller | 776b2e1 | 2016-07-19 16:23:30 -0700 | [diff] [blame] | 7913 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 7914 | if (ret) { |
| 7915 | dev_info(&pf->pdev->dev, |
| 7916 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 7917 | i40e_stat_str(hw, ret), |
| 7918 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 7919 | return ret; |
| 7920 | } |
| 7921 | } |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7922 | return ret; |
| 7923 | } |
| 7924 | |
| 7925 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 7926 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 7927 | * @vsi: Pointer to vsi structure |
| 7928 | * @seed: Buffter to store the hash keys |
| 7929 | * @lut: Buffer to store the lookup table entries |
| 7930 | * @lut_size: Size of buffer to store the lookup table entries |
| 7931 | * |
| 7932 | * Return 0 on success, negative on failure |
| 7933 | */ |
| 7934 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 7935 | u8 *lut, u16 lut_size) |
| 7936 | { |
| 7937 | struct i40e_pf *pf = vsi->back; |
| 7938 | struct i40e_hw *hw = &pf->hw; |
| 7939 | int ret = 0; |
| 7940 | |
| 7941 | if (seed) { |
| 7942 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 7943 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 7944 | if (ret) { |
| 7945 | dev_info(&pf->pdev->dev, |
| 7946 | "Cannot get RSS key, err %s aq_err %s\n", |
| 7947 | i40e_stat_str(&pf->hw, ret), |
| 7948 | i40e_aq_str(&pf->hw, |
| 7949 | pf->hw.aq.asq_last_status)); |
| 7950 | return ret; |
| 7951 | } |
| 7952 | } |
| 7953 | |
| 7954 | if (lut) { |
| 7955 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 7956 | |
| 7957 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 7958 | if (ret) { |
| 7959 | dev_info(&pf->pdev->dev, |
| 7960 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 7961 | i40e_stat_str(&pf->hw, ret), |
| 7962 | i40e_aq_str(&pf->hw, |
| 7963 | pf->hw.aq.asq_last_status)); |
| 7964 | return ret; |
| 7965 | } |
| 7966 | } |
| 7967 | |
| 7968 | return ret; |
| 7969 | } |
| 7970 | |
| 7971 | /** |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 7972 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 7973 | * @vsi: VSI structure |
| 7974 | **/ |
| 7975 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 7976 | { |
| 7977 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 7978 | struct i40e_pf *pf = vsi->back; |
| 7979 | u8 *lut; |
| 7980 | int ret; |
| 7981 | |
| 7982 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) |
| 7983 | return 0; |
| 7984 | |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 7985 | if (!vsi->rss_size) |
| 7986 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 7987 | vsi->num_queue_pairs); |
| 7988 | if (!vsi->rss_size) |
| 7989 | return -EINVAL; |
| 7990 | |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 7991 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 7992 | if (!lut) |
| 7993 | return -ENOMEM; |
Jacob Keller | 552b996 | 2016-07-19 16:23:31 -0700 | [diff] [blame] | 7994 | /* Use the user configured hash keys and lookup table if there is one, |
| 7995 | * otherwise use default |
| 7996 | */ |
| 7997 | if (vsi->rss_lut_user) |
| 7998 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 7999 | else |
| 8000 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
| 8001 | if (vsi->rss_hkey_user) |
| 8002 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8003 | else |
| 8004 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Jacob Keller | 0582b96 | 2016-07-19 16:23:29 -0700 | [diff] [blame] | 8005 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 8006 | kfree(lut); |
| 8007 | |
| 8008 | return ret; |
| 8009 | } |
| 8010 | |
| 8011 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8012 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8013 | * @vsi: Pointer to vsi structure |
| 8014 | * @seed: RSS hash seed |
| 8015 | * @lut: Lookup table |
| 8016 | * @lut_size: Lookup table size |
| 8017 | * |
| 8018 | * Returns 0 on success, negative on failure |
| 8019 | **/ |
| 8020 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 8021 | const u8 *lut, u16 lut_size) |
| 8022 | { |
| 8023 | struct i40e_pf *pf = vsi->back; |
| 8024 | struct i40e_hw *hw = &pf->hw; |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8025 | u16 vf_id = vsi->vf_id; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8026 | u8 i; |
| 8027 | |
| 8028 | /* Fill out hash function seed */ |
| 8029 | if (seed) { |
| 8030 | u32 *seed_dw = (u32 *)seed; |
| 8031 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8032 | if (vsi->type == I40E_VSI_MAIN) { |
| 8033 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 8034 | i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), |
| 8035 | seed_dw[i]); |
| 8036 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8037 | for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++) |
| 8038 | i40e_write_rx_ctl(hw, |
| 8039 | I40E_VFQF_HKEY1(i, vf_id), |
| 8040 | seed_dw[i]); |
| 8041 | } else { |
| 8042 | dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n"); |
| 8043 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8044 | } |
| 8045 | |
| 8046 | if (lut) { |
| 8047 | u32 *lut_dw = (u32 *)lut; |
| 8048 | |
Mitch Williams | c4e1868 | 2016-04-12 08:30:40 -0700 | [diff] [blame] | 8049 | if (vsi->type == I40E_VSI_MAIN) { |
| 8050 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8051 | return -EINVAL; |
| 8052 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8053 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8054 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8055 | if (lut_size != I40E_VF_HLUT_ARRAY_SIZE) |
| 8056 | return -EINVAL; |
| 8057 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8058 | i40e_write_rx_ctl(hw, |
| 8059 | I40E_VFQF_HLUT1(i, vf_id), |
| 8060 | lut_dw[i]); |
| 8061 | } else { |
| 8062 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8063 | } |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8064 | } |
| 8065 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8066 | |
| 8067 | return 0; |
| 8068 | } |
| 8069 | |
| 8070 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8071 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8072 | * @vsi: Pointer to VSI structure |
| 8073 | * @seed: Buffer to store the keys |
| 8074 | * @lut: Buffer to store the lookup table entries |
| 8075 | * @lut_size: Size of buffer to store the lookup table entries |
| 8076 | * |
| 8077 | * Returns 0 on success, negative on failure |
| 8078 | */ |
| 8079 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8080 | u8 *lut, u16 lut_size) |
| 8081 | { |
| 8082 | struct i40e_pf *pf = vsi->back; |
| 8083 | struct i40e_hw *hw = &pf->hw; |
| 8084 | u16 i; |
| 8085 | |
| 8086 | if (seed) { |
| 8087 | u32 *seed_dw = (u32 *)seed; |
| 8088 | |
| 8089 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8090 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8091 | } |
| 8092 | if (lut) { |
| 8093 | u32 *lut_dw = (u32 *)lut; |
| 8094 | |
| 8095 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8096 | return -EINVAL; |
| 8097 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8098 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8099 | } |
| 8100 | |
| 8101 | return 0; |
| 8102 | } |
| 8103 | |
| 8104 | /** |
| 8105 | * i40e_config_rss - Configure RSS keys and lut |
| 8106 | * @vsi: Pointer to VSI structure |
| 8107 | * @seed: RSS hash seed |
| 8108 | * @lut: Lookup table |
| 8109 | * @lut_size: Lookup table size |
| 8110 | * |
| 8111 | * Returns 0 on success, negative on failure |
| 8112 | */ |
| 8113 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8114 | { |
| 8115 | struct i40e_pf *pf = vsi->back; |
| 8116 | |
| 8117 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8118 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8119 | else |
| 8120 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8121 | } |
| 8122 | |
| 8123 | /** |
| 8124 | * i40e_get_rss - Get RSS keys and lut |
| 8125 | * @vsi: Pointer to VSI structure |
| 8126 | * @seed: Buffer to store the keys |
| 8127 | * @lut: Buffer to store the lookup table entries |
| 8128 | * lut_size: Size of buffer to store the lookup table entries |
| 8129 | * |
| 8130 | * Returns 0 on success, negative on failure |
| 8131 | */ |
| 8132 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8133 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8134 | struct i40e_pf *pf = vsi->back; |
| 8135 | |
| 8136 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8137 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8138 | else |
| 8139 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8140 | } |
| 8141 | |
| 8142 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8143 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8144 | * @pf: Pointer to board private structure |
| 8145 | * @lut: Lookup table |
| 8146 | * @rss_table_size: Lookup table size |
| 8147 | * @rss_size: Range of queue number for hashing |
| 8148 | */ |
Alan Brady | f158235 | 2016-08-24 11:33:46 -0700 | [diff] [blame] | 8149 | void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8150 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8151 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8152 | u16 i; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8153 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8154 | for (i = 0; i < rss_table_size; i++) |
| 8155 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8156 | } |
| 8157 | |
| 8158 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8159 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8160 | * @pf: board private structure |
| 8161 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8162 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8163 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8164 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8165 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8166 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8167 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8168 | u32 reg_val; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8169 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8170 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8171 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8172 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8173 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 8174 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8175 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8176 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8177 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8178 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8179 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8180 | /* Determine the RSS table size based on the hardware capabilities */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8181 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8182 | reg_val = (pf->rss_table_size == 512) ? |
| 8183 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8184 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 8185 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8186 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8187 | /* Determine the RSS size of the VSI */ |
| 8188 | if (!vsi->rss_size) |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8189 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8190 | vsi->num_queue_pairs); |
Mitch Williams | a4fa59c | 2016-09-12 14:18:43 -0700 | [diff] [blame] | 8191 | if (!vsi->rss_size) |
| 8192 | return -EINVAL; |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8193 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8194 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8195 | if (!lut) |
| 8196 | return -ENOMEM; |
| 8197 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8198 | /* Use user configured lut if there is one, otherwise use default */ |
| 8199 | if (vsi->rss_lut_user) |
| 8200 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8201 | else |
| 8202 | 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] | 8203 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8204 | /* Use user configured hash key if there is one, otherwise |
| 8205 | * use default. |
| 8206 | */ |
| 8207 | if (vsi->rss_hkey_user) |
| 8208 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8209 | else |
| 8210 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8211 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8212 | kfree(lut); |
| 8213 | |
| 8214 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8215 | } |
| 8216 | |
| 8217 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8218 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8219 | * @pf: board private structure |
| 8220 | * @queue_count: the requested queue count for rss. |
| 8221 | * |
| 8222 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8223 | * count which may be different from the requested queue count. |
| 8224 | **/ |
| 8225 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8226 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8227 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8228 | int new_rss_size; |
| 8229 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8230 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8231 | return 0; |
| 8232 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8233 | 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] | 8234 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8235 | if (queue_count != vsi->num_queue_pairs) { |
| 8236 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8237 | i40e_prep_for_reset(pf); |
| 8238 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8239 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8240 | |
| 8241 | i40e_reset_and_rebuild(pf, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8242 | |
| 8243 | /* Discard the user configured hash keys and lut, if less |
| 8244 | * queues are enabled. |
| 8245 | */ |
| 8246 | if (queue_count < vsi->rss_size) { |
| 8247 | i40e_clear_rss_config_user(vsi); |
| 8248 | dev_dbg(&pf->pdev->dev, |
| 8249 | "discard user configured hash keys and lut\n"); |
| 8250 | } |
| 8251 | |
| 8252 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8253 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8254 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8255 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8256 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8257 | } |
Lihong Yang | 1281505 | 2016-09-27 11:28:48 -0700 | [diff] [blame] | 8258 | dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n", |
| 8259 | vsi->req_queue_pairs, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8260 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8261 | } |
| 8262 | |
| 8263 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8264 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 8265 | * @pf: board private structure |
| 8266 | **/ |
| 8267 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 8268 | { |
| 8269 | i40e_status status; |
| 8270 | bool min_valid, max_valid; |
| 8271 | u32 max_bw, min_bw; |
| 8272 | |
| 8273 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8274 | &min_valid, &max_valid); |
| 8275 | |
| 8276 | if (!status) { |
| 8277 | if (min_valid) |
| 8278 | pf->npar_min_bw = min_bw; |
| 8279 | if (max_valid) |
| 8280 | pf->npar_max_bw = max_bw; |
| 8281 | } |
| 8282 | |
| 8283 | return status; |
| 8284 | } |
| 8285 | |
| 8286 | /** |
| 8287 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 8288 | * @pf: board private structure |
| 8289 | **/ |
| 8290 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 8291 | { |
| 8292 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8293 | i40e_status status; |
| 8294 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8295 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8296 | 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] | 8297 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8298 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 8299 | |
| 8300 | /* Set the new bandwidths */ |
| 8301 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8302 | |
| 8303 | return status; |
| 8304 | } |
| 8305 | |
| 8306 | /** |
| 8307 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 8308 | * @pf: board private structure |
| 8309 | **/ |
| 8310 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 8311 | { |
| 8312 | /* Commit temporary BW setting to permanent NVM image */ |
| 8313 | enum i40e_admin_queue_err last_aq_status; |
| 8314 | i40e_status ret; |
| 8315 | u16 nvm_word; |
| 8316 | |
| 8317 | if (pf->hw.partition_id != 1) { |
| 8318 | dev_info(&pf->pdev->dev, |
| 8319 | "Commit BW only works on partition 1! This is partition %d", |
| 8320 | pf->hw.partition_id); |
| 8321 | ret = I40E_NOT_SUPPORTED; |
| 8322 | goto bw_commit_out; |
| 8323 | } |
| 8324 | |
| 8325 | /* Acquire NVM for read access */ |
| 8326 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8327 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8328 | if (ret) { |
| 8329 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8330 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8331 | i40e_stat_str(&pf->hw, ret), |
| 8332 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8333 | goto bw_commit_out; |
| 8334 | } |
| 8335 | |
| 8336 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8337 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8338 | I40E_SR_NVM_CONTROL_WORD, |
| 8339 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8340 | false, NULL); |
| 8341 | /* Save off last admin queue command status before releasing |
| 8342 | * the NVM |
| 8343 | */ |
| 8344 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8345 | i40e_release_nvm(&pf->hw); |
| 8346 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8347 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8348 | i40e_stat_str(&pf->hw, ret), |
| 8349 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8350 | goto bw_commit_out; |
| 8351 | } |
| 8352 | |
| 8353 | /* Wait a bit for NVM release to complete */ |
| 8354 | msleep(50); |
| 8355 | |
| 8356 | /* Acquire NVM for write access */ |
| 8357 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8358 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8359 | if (ret) { |
| 8360 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8361 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8362 | i40e_stat_str(&pf->hw, ret), |
| 8363 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8364 | goto bw_commit_out; |
| 8365 | } |
| 8366 | /* Write it back out unchanged to initiate update NVM, |
| 8367 | * which will force a write of the shadow (alt) RAM to |
| 8368 | * the NVM - thus storing the bandwidth values permanently. |
| 8369 | */ |
| 8370 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8371 | I40E_SR_NVM_CONTROL_WORD, |
| 8372 | 0x10, sizeof(nvm_word), |
| 8373 | &nvm_word, true, NULL); |
| 8374 | /* Save off last admin queue command status before releasing |
| 8375 | * the NVM |
| 8376 | */ |
| 8377 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8378 | i40e_release_nvm(&pf->hw); |
| 8379 | if (ret) |
| 8380 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8381 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8382 | i40e_stat_str(&pf->hw, ret), |
| 8383 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8384 | bw_commit_out: |
| 8385 | |
| 8386 | return ret; |
| 8387 | } |
| 8388 | |
| 8389 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8390 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8391 | * @pf: board private structure to initialize |
| 8392 | * |
| 8393 | * i40e_sw_init initializes the Adapter private data structure. |
| 8394 | * Fields are initialized based on PCI device information and |
| 8395 | * OS network device settings (MTU size). |
| 8396 | **/ |
| 8397 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8398 | { |
| 8399 | int err = 0; |
| 8400 | int size; |
| 8401 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8402 | /* Set default capability flags */ |
| 8403 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8404 | I40E_FLAG_MSI_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8405 | I40E_FLAG_MSIX_ENABLED; |
| 8406 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8407 | /* Set default ITR */ |
| 8408 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8409 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8410 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8411 | /* Depending on PF configurations, it is possible that the RSS |
| 8412 | * maximum might end up larger than the available queues |
| 8413 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8414 | 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] | 8415 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8416 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8417 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8418 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8419 | if (pf->hw.func_caps.rss) { |
| 8420 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8421 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8422 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8423 | } |
| 8424 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8425 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8426 | 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] | 8427 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8428 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8429 | if (i40e_get_npar_bw_setting(pf)) |
| 8430 | dev_warn(&pf->pdev->dev, |
| 8431 | "Could not get NPAR bw settings\n"); |
| 8432 | else |
| 8433 | dev_info(&pf->pdev->dev, |
| 8434 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 8435 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8436 | } |
| 8437 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8438 | /* FW/NVM is not yet fixed in this regard */ |
| 8439 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8440 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8441 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8442 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8443 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8444 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8445 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8446 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8447 | else |
| 8448 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8449 | pf->fdir_pf_filter_count = |
| 8450 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8451 | pf->hw.fdir_shared_filter_count = |
| 8452 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8453 | } |
| 8454 | |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8455 | if (i40e_is_mac_710(&pf->hw) && |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8456 | (((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] | 8457 | (pf->hw.aq.fw_maj_ver < 4))) { |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8458 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 8459 | /* No DCB support for FW < v4.33 */ |
| 8460 | pf->flags |= I40E_FLAG_NO_DCB_SUPPORT; |
| 8461 | } |
| 8462 | |
| 8463 | /* Disable FW LLDP if FW < v4.3 */ |
| 8464 | if (i40e_is_mac_710(&pf->hw) && |
| 8465 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 8466 | (pf->hw.aq.fw_maj_ver < 4))) |
| 8467 | pf->flags |= I40E_FLAG_STOP_FW_LLDP; |
| 8468 | |
| 8469 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ |
| 8470 | if (i40e_is_mac_710(&pf->hw) && |
| 8471 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
| 8472 | (pf->hw.aq.fw_maj_ver >= 5))) |
| 8473 | pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB; |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8474 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8475 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8476 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8477 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 8478 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8479 | } |
| 8480 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 8481 | if (pf->hw.func_caps.iwarp) { |
| 8482 | pf->flags |= I40E_FLAG_IWARP_ENABLED; |
| 8483 | /* IWARP needs one extra vector for CQP just like MISC.*/ |
| 8484 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; |
| 8485 | } |
| 8486 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8487 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 8488 | i40e_init_pf_fcoe(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8489 | |
| 8490 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8491 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 8492 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8493 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 8494 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 8495 | pf->num_req_vfs = min_t(int, |
| 8496 | pf->hw.func_caps.num_vfs, |
| 8497 | I40E_MAX_VF_COUNT); |
| 8498 | } |
| 8499 | #endif /* CONFIG_PCI_IOV */ |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8500 | if (pf->hw.mac.type == I40E_MAC_X722) { |
| 8501 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE | |
| 8502 | I40E_FLAG_128_QP_RSS_CAPABLE | |
| 8503 | I40E_FLAG_HW_ATR_EVICT_CAPABLE | |
| 8504 | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE | |
| 8505 | I40E_FLAG_WB_ON_ITR_CAPABLE | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8506 | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
Jesse Brandeburg | 8e2cc0e | 2016-02-29 11:00:24 -0800 | [diff] [blame] | 8507 | I40E_FLAG_NO_PCI_LINK_CHECK | |
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; |
Tushar Dave | a70e407 | 2016-05-16 12:40:53 -0700 | [diff] [blame] | 8568 | /* enable FD_SB only if there is MSI-X vector */ |
| 8569 | if (pf->num_fdsb_msix > 0) |
| 8570 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8571 | } else { |
| 8572 | /* turn off filters, mark for reset and clear SW filter list */ |
| 8573 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8574 | need_reset = true; |
| 8575 | i40e_fdir_filter_exit(pf); |
| 8576 | } |
| 8577 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8578 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 8579 | /* reset fd counters */ |
| 8580 | pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0; |
| 8581 | pf->fdir_pf_active_filters = 0; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8582 | /* if ATR was auto disabled it can be re-enabled. */ |
| 8583 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 8584 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8585 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 8586 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 8587 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
| 8588 | } |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8589 | } |
| 8590 | return need_reset; |
| 8591 | } |
| 8592 | |
| 8593 | /** |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8594 | * i40e_clear_rss_lut - clear the rx hash lookup table |
| 8595 | * @vsi: the VSI being configured |
| 8596 | **/ |
| 8597 | static void i40e_clear_rss_lut(struct i40e_vsi *vsi) |
| 8598 | { |
| 8599 | struct i40e_pf *pf = vsi->back; |
| 8600 | struct i40e_hw *hw = &pf->hw; |
| 8601 | u16 vf_id = vsi->vf_id; |
| 8602 | u8 i; |
| 8603 | |
| 8604 | if (vsi->type == I40E_VSI_MAIN) { |
| 8605 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8606 | wr32(hw, I40E_PFQF_HLUT(i), 0); |
| 8607 | } else if (vsi->type == I40E_VSI_SRIOV) { |
| 8608 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) |
| 8609 | i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0); |
| 8610 | } else { |
| 8611 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); |
| 8612 | } |
| 8613 | } |
| 8614 | |
| 8615 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8616 | * i40e_set_features - set the netdev feature flags |
| 8617 | * @netdev: ptr to the netdev being adjusted |
| 8618 | * @features: the feature set that the stack is suggesting |
| 8619 | **/ |
| 8620 | static int i40e_set_features(struct net_device *netdev, |
| 8621 | netdev_features_t features) |
| 8622 | { |
| 8623 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8624 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8625 | struct i40e_pf *pf = vsi->back; |
| 8626 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8627 | |
Alan Brady | d8ec986 | 2016-07-27 12:02:38 -0700 | [diff] [blame] | 8628 | if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH)) |
| 8629 | i40e_pf_config_rss(pf); |
| 8630 | else if (!(features & NETIF_F_RXHASH) && |
| 8631 | netdev->features & NETIF_F_RXHASH) |
| 8632 | i40e_clear_rss_lut(vsi); |
| 8633 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8634 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8635 | i40e_vlan_stripping_enable(vsi); |
| 8636 | else |
| 8637 | i40e_vlan_stripping_disable(vsi); |
| 8638 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8639 | need_reset = i40e_set_ntuple(pf, features); |
| 8640 | |
| 8641 | if (need_reset) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8642 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8643 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8644 | return 0; |
| 8645 | } |
| 8646 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8647 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8648 | * 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] | 8649 | * @pf: board private structure |
| 8650 | * @port: The UDP port to look up |
| 8651 | * |
| 8652 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 8653 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8654 | 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] | 8655 | { |
| 8656 | u8 i; |
| 8657 | |
| 8658 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8659 | if (pf->udp_ports[i].index == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8660 | return i; |
| 8661 | } |
| 8662 | |
| 8663 | return i; |
| 8664 | } |
| 8665 | |
| 8666 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8667 | * 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] | 8668 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8669 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8670 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8671 | static void i40e_udp_tunnel_add(struct net_device *netdev, |
| 8672 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8673 | { |
| 8674 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8675 | struct i40e_vsi *vsi = np->vsi; |
| 8676 | struct i40e_pf *pf = vsi->back; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8677 | __be16 port = ti->port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8678 | u8 next_idx; |
| 8679 | u8 idx; |
| 8680 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8681 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8682 | |
| 8683 | /* Check if port already exists */ |
| 8684 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8685 | netdev_info(netdev, "port %d already offloaded\n", |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8686 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8687 | return; |
| 8688 | } |
| 8689 | |
| 8690 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8691 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8692 | |
| 8693 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8694 | 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] | 8695 | ntohs(port)); |
| 8696 | return; |
| 8697 | } |
| 8698 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8699 | switch (ti->type) { |
| 8700 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8701 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 8702 | break; |
| 8703 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8704 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 8705 | return; |
| 8706 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 8707 | break; |
| 8708 | default: |
| 8709 | return; |
| 8710 | } |
| 8711 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8712 | /* New port: add it and mark its index in the bitmap */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8713 | pf->udp_ports[next_idx].index = port; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8714 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8715 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8716 | } |
| 8717 | |
| 8718 | /** |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8719 | * 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] | 8720 | * @netdev: This physical port's netdev |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8721 | * @ti: Tunnel endpoint information |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8722 | **/ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8723 | static void i40e_udp_tunnel_del(struct net_device *netdev, |
| 8724 | struct udp_tunnel_info *ti) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8725 | { |
| 8726 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8727 | struct i40e_vsi *vsi = np->vsi; |
| 8728 | struct i40e_pf *pf = vsi->back; |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8729 | __be16 port = ti->port; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8730 | u8 idx; |
| 8731 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8732 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8733 | |
| 8734 | /* Check if port already exists */ |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8735 | if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS) |
| 8736 | goto not_found; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8737 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8738 | switch (ti->type) { |
| 8739 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8740 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN) |
| 8741 | goto not_found; |
| 8742 | break; |
| 8743 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8744 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE) |
| 8745 | goto not_found; |
| 8746 | break; |
| 8747 | default: |
| 8748 | goto not_found; |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8749 | } |
| 8750 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8751 | /* if port exists, set it to 0 (mark for deletion) |
| 8752 | * and make it pending |
| 8753 | */ |
| 8754 | pf->udp_ports[idx].index = 0; |
| 8755 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8756 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8757 | |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8758 | return; |
| 8759 | not_found: |
| 8760 | netdev_warn(netdev, "UDP port %d was not found, not deleting\n", |
| 8761 | ntohs(port)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8762 | } |
| 8763 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8764 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 8765 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8766 | { |
| 8767 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8768 | struct i40e_pf *pf = np->vsi->back; |
| 8769 | struct i40e_hw *hw = &pf->hw; |
| 8770 | |
| 8771 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 8772 | return -EOPNOTSUPP; |
| 8773 | |
| 8774 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 8775 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 8776 | |
| 8777 | return 0; |
| 8778 | } |
| 8779 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 8780 | /** |
| 8781 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 8782 | * @ndm: the input from the stack |
| 8783 | * @tb: pointer to array of nladdr (unused) |
| 8784 | * @dev: the net device pointer |
| 8785 | * @addr: the MAC address entry being added |
| 8786 | * @flags: instructions from stack about fdb operation |
| 8787 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8788 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 8789 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8790 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8791 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8792 | { |
| 8793 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8794 | struct i40e_pf *pf = np->vsi->back; |
| 8795 | int err = 0; |
| 8796 | |
| 8797 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 8798 | return -EOPNOTSUPP; |
| 8799 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 8800 | if (vid) { |
| 8801 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 8802 | return -EINVAL; |
| 8803 | } |
| 8804 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8805 | /* Hardware does not support aging addresses so if a |
| 8806 | * ndm_state is given only allow permanent addresses |
| 8807 | */ |
| 8808 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 8809 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 8810 | return -EINVAL; |
| 8811 | } |
| 8812 | |
| 8813 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 8814 | err = dev_uc_add_excl(dev, addr); |
| 8815 | else if (is_multicast_ether_addr(addr)) |
| 8816 | err = dev_mc_add_excl(dev, addr); |
| 8817 | else |
| 8818 | err = -EINVAL; |
| 8819 | |
| 8820 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 8821 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 8822 | err = 0; |
| 8823 | |
| 8824 | return err; |
| 8825 | } |
| 8826 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8827 | /** |
| 8828 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 8829 | * @dev: the netdev being configured |
| 8830 | * @nlh: RTNL message |
| 8831 | * |
| 8832 | * Inserts a new hardware bridge if not already created and |
| 8833 | * enables the bridging mode requested (VEB or VEPA). If the |
| 8834 | * hardware bridge has already been inserted and the request |
| 8835 | * is to change the mode then that requires a PF reset to |
| 8836 | * allow rebuild of the components with required hardware |
| 8837 | * bridge mode enabled. |
| 8838 | **/ |
| 8839 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 8840 | struct nlmsghdr *nlh, |
| 8841 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8842 | { |
| 8843 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8844 | struct i40e_vsi *vsi = np->vsi; |
| 8845 | struct i40e_pf *pf = vsi->back; |
| 8846 | struct i40e_veb *veb = NULL; |
| 8847 | struct nlattr *attr, *br_spec; |
| 8848 | int i, rem; |
| 8849 | |
| 8850 | /* Only for PF VSI for now */ |
| 8851 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8852 | return -EOPNOTSUPP; |
| 8853 | |
| 8854 | /* Find the HW bridge for PF VSI */ |
| 8855 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8856 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8857 | veb = pf->veb[i]; |
| 8858 | } |
| 8859 | |
| 8860 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 8861 | |
| 8862 | nla_for_each_nested(attr, br_spec, rem) { |
| 8863 | __u16 mode; |
| 8864 | |
| 8865 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 8866 | continue; |
| 8867 | |
| 8868 | mode = nla_get_u16(attr); |
| 8869 | if ((mode != BRIDGE_MODE_VEPA) && |
| 8870 | (mode != BRIDGE_MODE_VEB)) |
| 8871 | return -EINVAL; |
| 8872 | |
| 8873 | /* Insert a new HW bridge */ |
| 8874 | if (!veb) { |
| 8875 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 8876 | vsi->tc_config.enabled_tc); |
| 8877 | if (veb) { |
| 8878 | veb->bridge_mode = mode; |
| 8879 | i40e_config_bridge_mode(veb); |
| 8880 | } else { |
| 8881 | /* No Bridge HW offload available */ |
| 8882 | return -ENOENT; |
| 8883 | } |
| 8884 | break; |
| 8885 | } else if (mode != veb->bridge_mode) { |
| 8886 | /* Existing HW bridge but different mode needs reset */ |
| 8887 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 8888 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 8889 | if (mode == BRIDGE_MODE_VEB) |
| 8890 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 8891 | else |
| 8892 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 8893 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8894 | break; |
| 8895 | } |
| 8896 | } |
| 8897 | |
| 8898 | return 0; |
| 8899 | } |
| 8900 | |
| 8901 | /** |
| 8902 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 8903 | * @skb: skb buff |
| 8904 | * @pid: process id |
| 8905 | * @seq: RTNL message seq # |
| 8906 | * @dev: the netdev being configured |
| 8907 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 8908 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8909 | * |
| 8910 | * Return the mode in which the hardware bridge is operating in |
| 8911 | * i.e VEB or VEPA. |
| 8912 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8913 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 8914 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 8915 | u32 __always_unused filter_mask, |
| 8916 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8917 | { |
| 8918 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8919 | struct i40e_vsi *vsi = np->vsi; |
| 8920 | struct i40e_pf *pf = vsi->back; |
| 8921 | struct i40e_veb *veb = NULL; |
| 8922 | int i; |
| 8923 | |
| 8924 | /* Only for PF VSI for now */ |
| 8925 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8926 | return -EOPNOTSUPP; |
| 8927 | |
| 8928 | /* Find the HW bridge for the PF VSI */ |
| 8929 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8930 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8931 | veb = pf->veb[i]; |
| 8932 | } |
| 8933 | |
| 8934 | if (!veb) |
| 8935 | return 0; |
| 8936 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 8937 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Huaibin Wang | 599b076 | 2016-09-26 09:51:18 +0200 | [diff] [blame] | 8938 | 0, 0, nlflags, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8939 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8940 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8941 | /* Hardware supports L4 tunnel length of 128B (=2^7) which includes |
| 8942 | * inner mac plus all inner ethertypes. |
| 8943 | */ |
| 8944 | #define I40E_MAX_TUNNEL_HDR_LEN 128 |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8945 | /** |
| 8946 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 8947 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 8948 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8949 | * @features: Offload features that the stack believes apply |
| 8950 | **/ |
| 8951 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 8952 | struct net_device *dev, |
| 8953 | netdev_features_t features) |
| 8954 | { |
| 8955 | if (skb->encapsulation && |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8956 | ((skb_inner_network_header(skb) - skb_transport_header(skb)) > |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8957 | I40E_MAX_TUNNEL_HDR_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 8958 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8959 | |
| 8960 | return features; |
| 8961 | } |
| 8962 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 8963 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8964 | .ndo_open = i40e_open, |
| 8965 | .ndo_stop = i40e_close, |
| 8966 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 8967 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 8968 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 8969 | .ndo_validate_addr = eth_validate_addr, |
| 8970 | .ndo_set_mac_address = i40e_set_mac, |
| 8971 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 8972 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8973 | .ndo_tx_timeout = i40e_tx_timeout, |
| 8974 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 8975 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 8976 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8977 | .ndo_poll_controller = i40e_netpoll, |
| 8978 | #endif |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 8979 | .ndo_setup_tc = __i40e_setup_tc, |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8980 | #ifdef I40E_FCOE |
| 8981 | .ndo_fcoe_enable = i40e_fcoe_enable, |
| 8982 | .ndo_fcoe_disable = i40e_fcoe_disable, |
| 8983 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8984 | .ndo_set_features = i40e_set_features, |
| 8985 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 8986 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 8987 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8988 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 8989 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 8990 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Anjali Singhai Jain | c3bbbd2 | 2016-04-01 03:56:07 -0700 | [diff] [blame] | 8991 | .ndo_set_vf_trust = i40e_ndo_set_vf_trust, |
Alexander Duyck | 06a5f7f | 2016-06-16 12:22:06 -0700 | [diff] [blame] | 8992 | .ndo_udp_tunnel_add = i40e_udp_tunnel_add, |
| 8993 | .ndo_udp_tunnel_del = i40e_udp_tunnel_del, |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8994 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8995 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8996 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8997 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 8998 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8999 | }; |
| 9000 | |
| 9001 | /** |
| 9002 | * i40e_config_netdev - Setup the netdev flags |
| 9003 | * @vsi: the VSI being configured |
| 9004 | * |
| 9005 | * Returns 0 on success, negative value on failure |
| 9006 | **/ |
| 9007 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 9008 | { |
| 9009 | struct i40e_pf *pf = vsi->back; |
| 9010 | struct i40e_hw *hw = &pf->hw; |
| 9011 | struct i40e_netdev_priv *np; |
| 9012 | struct net_device *netdev; |
| 9013 | u8 mac_addr[ETH_ALEN]; |
| 9014 | int etherdev_size; |
| 9015 | |
| 9016 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9017 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9018 | if (!netdev) |
| 9019 | return -ENOMEM; |
| 9020 | |
| 9021 | vsi->netdev = netdev; |
| 9022 | np = netdev_priv(netdev); |
| 9023 | np->vsi = vsi; |
| 9024 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9025 | netdev->hw_enc_features |= NETIF_F_SG | |
| 9026 | NETIF_F_IP_CSUM | |
| 9027 | NETIF_F_IPV6_CSUM | |
| 9028 | NETIF_F_HIGHDMA | |
| 9029 | NETIF_F_SOFT_FEATURES | |
| 9030 | NETIF_F_TSO | |
| 9031 | NETIF_F_TSO_ECN | |
| 9032 | NETIF_F_TSO6 | |
| 9033 | NETIF_F_GSO_GRE | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9034 | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 9035 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 9036 | NETIF_F_GSO_IPXIP6 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9037 | NETIF_F_GSO_UDP_TUNNEL | |
| 9038 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9039 | NETIF_F_GSO_PARTIAL | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9040 | NETIF_F_SCTP_CRC | |
| 9041 | NETIF_F_RXHASH | |
| 9042 | NETIF_F_RXCSUM | |
Jesse Brandeburg | 5afdaaa | 2015-12-10 11:38:50 -0800 | [diff] [blame] | 9043 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9044 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9045 | if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)) |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9046 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
| 9047 | |
| 9048 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9049 | |
| 9050 | /* record features VLANs can make use of */ |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9051 | netdev->vlan_features |= netdev->hw_enc_features | |
| 9052 | NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9053 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9054 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9055 | netdev->hw_features |= NETIF_F_NTUPLE; |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9056 | |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9057 | netdev->hw_features |= netdev->hw_enc_features | |
| 9058 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9059 | NETIF_F_HW_VLAN_CTAG_RX; |
| 9060 | |
| 9061 | netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; |
Alexander Duyck | 1c7b4a2 | 2016-04-14 17:19:25 -0400 | [diff] [blame] | 9062 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9063 | |
| 9064 | if (vsi->type == I40E_VSI_MAIN) { |
| 9065 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9066 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9067 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 9068 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY); |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9069 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9070 | } else { |
| 9071 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 9072 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 9073 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9074 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9075 | |
| 9076 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 9077 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9078 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9079 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9080 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9081 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9082 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Alexander Duyck | b0fe330 | 2016-04-02 00:05:14 -0700 | [diff] [blame] | 9083 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9084 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9085 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9086 | /* Setup netdev TC information */ |
| 9087 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9088 | |
| 9089 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9090 | netdev->watchdog_timeo = 5 * HZ; |
| 9091 | i40e_set_ethtool_ops(netdev); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9092 | #ifdef I40E_FCOE |
| 9093 | i40e_fcoe_config_netdev(netdev, vsi); |
| 9094 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9095 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 9096 | /* MTU range: 68 - 9706 */ |
| 9097 | netdev->min_mtu = ETH_MIN_MTU; |
| 9098 | netdev->max_mtu = I40E_MAX_RXBUFFER - |
| 9099 | (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
| 9100 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9101 | return 0; |
| 9102 | } |
| 9103 | |
| 9104 | /** |
| 9105 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9106 | * @vsi: the VSI being removed |
| 9107 | * |
| 9108 | * Returns 0 on success, negative value on failure |
| 9109 | **/ |
| 9110 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9111 | { |
| 9112 | /* remove default VSI is not allowed */ |
| 9113 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9114 | return; |
| 9115 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9116 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9117 | } |
| 9118 | |
| 9119 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9120 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9121 | * @vsi: the VSI being queried |
| 9122 | * |
| 9123 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9124 | **/ |
| 9125 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9126 | { |
| 9127 | struct i40e_veb *veb; |
| 9128 | struct i40e_pf *pf = vsi->back; |
| 9129 | |
| 9130 | /* Uplink is not a bridge so default to VEB */ |
| 9131 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9132 | return 1; |
| 9133 | |
| 9134 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9135 | if (!veb) { |
| 9136 | dev_info(&pf->pdev->dev, |
| 9137 | "There is no veb associated with the bridge\n"); |
| 9138 | return -ENOENT; |
| 9139 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9140 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9141 | /* Uplink is a bridge in VEPA mode */ |
| 9142 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9143 | return 0; |
| 9144 | } else { |
| 9145 | /* Uplink is a bridge in VEB mode */ |
| 9146 | return 1; |
| 9147 | } |
| 9148 | |
| 9149 | /* VEPA is now default bridge, so return 0 */ |
| 9150 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9151 | } |
| 9152 | |
| 9153 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9154 | * i40e_add_vsi - Add a VSI to the switch |
| 9155 | * @vsi: the VSI being configured |
| 9156 | * |
| 9157 | * This initializes a VSI context depending on the VSI type to be added and |
| 9158 | * passes it down to the add_vsi aq command. |
| 9159 | **/ |
| 9160 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9161 | { |
| 9162 | int ret = -ENODEV; |
Kiran Patil | f6bd096 | 2016-06-20 09:10:34 -0700 | [diff] [blame] | 9163 | i40e_status aq_ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9164 | struct i40e_pf *pf = vsi->back; |
| 9165 | struct i40e_hw *hw = &pf->hw; |
| 9166 | struct i40e_vsi_context ctxt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9167 | struct i40e_mac_filter *f, *ftmp; |
| 9168 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9169 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9170 | int f_count = 0; |
| 9171 | |
| 9172 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9173 | switch (vsi->type) { |
| 9174 | case I40E_VSI_MAIN: |
| 9175 | /* The PF's main VSI is already setup as part of the |
| 9176 | * device initialization, so we'll not bother with |
| 9177 | * the add_vsi call, but we will retrieve the current |
| 9178 | * VSI context. |
| 9179 | */ |
| 9180 | ctxt.seid = pf->main_vsi_seid; |
| 9181 | ctxt.pf_num = pf->hw.pf_id; |
| 9182 | ctxt.vf_num = 0; |
| 9183 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9184 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9185 | if (ret) { |
| 9186 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9187 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9188 | i40e_stat_str(&pf->hw, ret), |
| 9189 | i40e_aq_str(&pf->hw, |
| 9190 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9191 | return -ENOENT; |
| 9192 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9193 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9194 | vsi->info.valid_sections = 0; |
| 9195 | |
| 9196 | vsi->seid = ctxt.seid; |
| 9197 | vsi->id = ctxt.vsi_number; |
| 9198 | |
| 9199 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9200 | |
| 9201 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9202 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9203 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9204 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9205 | ctxt.seid = pf->main_vsi_seid; |
| 9206 | ctxt.pf_num = pf->hw.pf_id; |
| 9207 | ctxt.vf_num = 0; |
| 9208 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9209 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9210 | if (ret) { |
| 9211 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9212 | "update vsi failed, err %s aq_err %s\n", |
| 9213 | i40e_stat_str(&pf->hw, ret), |
| 9214 | i40e_aq_str(&pf->hw, |
| 9215 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9216 | ret = -ENOENT; |
| 9217 | goto err; |
| 9218 | } |
| 9219 | /* update the local VSI info queue map */ |
| 9220 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9221 | vsi->info.valid_sections = 0; |
| 9222 | } else { |
| 9223 | /* Default/Main VSI is only enabled for TC0 |
| 9224 | * reconfigure it to enable all TCs that are |
| 9225 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9226 | * For MFP case the iSCSI PF would use this |
| 9227 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9228 | */ |
| 9229 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9230 | if (ret) { |
| 9231 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9232 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9233 | enabled_tc, |
| 9234 | i40e_stat_str(&pf->hw, ret), |
| 9235 | i40e_aq_str(&pf->hw, |
| 9236 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9237 | ret = -ENOENT; |
| 9238 | } |
| 9239 | } |
| 9240 | break; |
| 9241 | |
| 9242 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9243 | ctxt.pf_num = hw->pf_id; |
| 9244 | ctxt.vf_num = 0; |
| 9245 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9246 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9247 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9248 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9249 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9250 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9251 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9252 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9253 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9254 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9255 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9256 | break; |
| 9257 | |
| 9258 | case I40E_VSI_VMDQ2: |
| 9259 | ctxt.pf_num = hw->pf_id; |
| 9260 | ctxt.vf_num = 0; |
| 9261 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9262 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9263 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9264 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9265 | /* This VSI is connected to VEB so the switch_id |
| 9266 | * should be set to zero by default. |
| 9267 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9268 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9269 | ctxt.info.valid_sections |= |
| 9270 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9271 | ctxt.info.switch_id = |
| 9272 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9273 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9274 | |
| 9275 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9276 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9277 | break; |
| 9278 | |
| 9279 | case I40E_VSI_SRIOV: |
| 9280 | ctxt.pf_num = hw->pf_id; |
| 9281 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9282 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9283 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9284 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9285 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9286 | /* This VSI is connected to VEB so the switch_id |
| 9287 | * should be set to zero by default. |
| 9288 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9289 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9290 | ctxt.info.valid_sections |= |
| 9291 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9292 | ctxt.info.switch_id = |
| 9293 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9294 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9295 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9296 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
| 9297 | ctxt.info.valid_sections |= |
| 9298 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); |
| 9299 | ctxt.info.queueing_opt_flags |= |
Ashish Shah | 4b28cdb | 2016-05-03 15:13:17 -0700 | [diff] [blame] | 9300 | (I40E_AQ_VSI_QUE_OPT_TCP_ENA | |
| 9301 | I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI); |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9302 | } |
| 9303 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9304 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9305 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9306 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9307 | ctxt.info.valid_sections |= |
| 9308 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9309 | ctxt.info.sec_flags |= |
| 9310 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9311 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9312 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9313 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9314 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9315 | break; |
| 9316 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9317 | #ifdef I40E_FCOE |
| 9318 | case I40E_VSI_FCOE: |
| 9319 | ret = i40e_fcoe_vsi_init(vsi, &ctxt); |
| 9320 | if (ret) { |
| 9321 | dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n"); |
| 9322 | return ret; |
| 9323 | } |
| 9324 | break; |
| 9325 | |
| 9326 | #endif /* I40E_FCOE */ |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 9327 | case I40E_VSI_IWARP: |
| 9328 | /* send down message to iWARP */ |
| 9329 | break; |
| 9330 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9331 | default: |
| 9332 | return -ENODEV; |
| 9333 | } |
| 9334 | |
| 9335 | if (vsi->type != I40E_VSI_MAIN) { |
| 9336 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9337 | if (ret) { |
| 9338 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9339 | "add vsi failed, err %s aq_err %s\n", |
| 9340 | i40e_stat_str(&pf->hw, ret), |
| 9341 | i40e_aq_str(&pf->hw, |
| 9342 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9343 | ret = -ENOENT; |
| 9344 | goto err; |
| 9345 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9346 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9347 | vsi->info.valid_sections = 0; |
| 9348 | vsi->seid = ctxt.seid; |
| 9349 | vsi->id = ctxt.vsi_number; |
| 9350 | } |
Kiran Patil | f6bd096 | 2016-06-20 09:10:34 -0700 | [diff] [blame] | 9351 | /* Except FDIR VSI, for all othet VSI set the broadcast filter */ |
| 9352 | if (vsi->type != I40E_VSI_FDIR) { |
| 9353 | aq_ret = i40e_aq_set_vsi_broadcast(hw, vsi->seid, true, NULL); |
| 9354 | if (aq_ret) { |
| 9355 | ret = i40e_aq_rc_to_posix(aq_ret, |
| 9356 | hw->aq.asq_last_status); |
| 9357 | dev_info(&pf->pdev->dev, |
| 9358 | "set brdcast promisc failed, err %s, aq_err %s\n", |
| 9359 | i40e_stat_str(hw, aq_ret), |
| 9360 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 9361 | } |
| 9362 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9363 | |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9364 | vsi->active_filters = 0; |
| 9365 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9366 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9367 | /* If macvlan filters already exist, force them to get loaded */ |
| 9368 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Mitch Williams | c3c7ea2 | 2016-06-20 09:10:38 -0700 | [diff] [blame] | 9369 | f->state = I40E_FILTER_NEW; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9370 | f_count++; |
| 9371 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9372 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9373 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9374 | if (f_count) { |
| 9375 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 9376 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 9377 | } |
| 9378 | |
| 9379 | /* Update VSI BW information */ |
| 9380 | ret = i40e_vsi_get_bw_info(vsi); |
| 9381 | if (ret) { |
| 9382 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9383 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 9384 | i40e_stat_str(&pf->hw, ret), |
| 9385 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9386 | /* VSI is already added so not tearing that up */ |
| 9387 | ret = 0; |
| 9388 | } |
| 9389 | |
| 9390 | err: |
| 9391 | return ret; |
| 9392 | } |
| 9393 | |
| 9394 | /** |
| 9395 | * i40e_vsi_release - Delete a VSI and free its resources |
| 9396 | * @vsi: the VSI being removed |
| 9397 | * |
| 9398 | * Returns 0 on success or < 0 on error |
| 9399 | **/ |
| 9400 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 9401 | { |
| 9402 | struct i40e_mac_filter *f, *ftmp; |
| 9403 | struct i40e_veb *veb = NULL; |
| 9404 | struct i40e_pf *pf; |
| 9405 | u16 uplink_seid; |
| 9406 | int i, n; |
| 9407 | |
| 9408 | pf = vsi->back; |
| 9409 | |
| 9410 | /* release of a VEB-owner or last VSI is not allowed */ |
| 9411 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 9412 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 9413 | vsi->seid, vsi->uplink_seid); |
| 9414 | return -ENODEV; |
| 9415 | } |
| 9416 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 9417 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 9418 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 9419 | return -ENODEV; |
| 9420 | } |
| 9421 | |
| 9422 | uplink_seid = vsi->uplink_seid; |
| 9423 | if (vsi->type != I40E_VSI_SRIOV) { |
| 9424 | if (vsi->netdev_registered) { |
| 9425 | vsi->netdev_registered = false; |
| 9426 | if (vsi->netdev) { |
| 9427 | /* results in a call to i40e_close() */ |
| 9428 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9429 | } |
| 9430 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 9431 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9432 | } |
| 9433 | i40e_vsi_disable_irq(vsi); |
| 9434 | } |
| 9435 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9436 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9437 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
Jacob Keller | 1bc87e8 | 2016-10-05 09:30:31 -0700 | [diff] [blame^] | 9438 | i40e_del_filter(vsi, f->macaddr, f->vlan); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9439 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9440 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 9441 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9442 | |
| 9443 | i40e_vsi_delete(vsi); |
| 9444 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 9445 | if (vsi->netdev) { |
| 9446 | free_netdev(vsi->netdev); |
| 9447 | vsi->netdev = NULL; |
| 9448 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9449 | i40e_vsi_clear_rings(vsi); |
| 9450 | i40e_vsi_clear(vsi); |
| 9451 | |
| 9452 | /* If this was the last thing on the VEB, except for the |
| 9453 | * controlling VSI, remove the VEB, which puts the controlling |
| 9454 | * VSI onto the next level down in the switch. |
| 9455 | * |
| 9456 | * Well, okay, there's one more exception here: don't remove |
| 9457 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 9458 | * from up the network stack. |
| 9459 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9460 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9461 | if (pf->vsi[i] && |
| 9462 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 9463 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9464 | n++; /* count the VSIs */ |
| 9465 | } |
| 9466 | } |
| 9467 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9468 | if (!pf->veb[i]) |
| 9469 | continue; |
| 9470 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 9471 | n++; /* count the VEBs */ |
| 9472 | if (pf->veb[i]->seid == uplink_seid) |
| 9473 | veb = pf->veb[i]; |
| 9474 | } |
| 9475 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 9476 | i40e_veb_release(veb); |
| 9477 | |
| 9478 | return 0; |
| 9479 | } |
| 9480 | |
| 9481 | /** |
| 9482 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 9483 | * @vsi: ptr to the VSI |
| 9484 | * |
| 9485 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 9486 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 9487 | * newly allocated VSI. |
| 9488 | * |
| 9489 | * Returns 0 on success or negative on failure |
| 9490 | **/ |
| 9491 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 9492 | { |
| 9493 | int ret = -ENOENT; |
| 9494 | struct i40e_pf *pf = vsi->back; |
| 9495 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9496 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9497 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 9498 | vsi->seid); |
| 9499 | return -EEXIST; |
| 9500 | } |
| 9501 | |
| 9502 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 9503 | 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] | 9504 | vsi->seid, vsi->base_vector); |
| 9505 | return -EEXIST; |
| 9506 | } |
| 9507 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9508 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9509 | if (ret) { |
| 9510 | dev_info(&pf->pdev->dev, |
| 9511 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 9512 | vsi->num_q_vectors, vsi->seid, ret); |
| 9513 | vsi->num_q_vectors = 0; |
| 9514 | goto vector_setup_out; |
| 9515 | } |
| 9516 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 9517 | /* In Legacy mode, we do not have to get any other vector since we |
| 9518 | * piggyback on the misc/ICR0 for queue interrupts. |
| 9519 | */ |
| 9520 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9521 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9522 | if (vsi->num_q_vectors) |
| 9523 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 9524 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9525 | if (vsi->base_vector < 0) { |
| 9526 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9527 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 9528 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9529 | i40e_vsi_free_q_vectors(vsi); |
| 9530 | ret = -ENOENT; |
| 9531 | goto vector_setup_out; |
| 9532 | } |
| 9533 | |
| 9534 | vector_setup_out: |
| 9535 | return ret; |
| 9536 | } |
| 9537 | |
| 9538 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9539 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 9540 | * @vsi: pointer to the vsi. |
| 9541 | * |
| 9542 | * This re-allocates a vsi's queue resources. |
| 9543 | * |
| 9544 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 9545 | * on success, otherwise returns NULL on failure. |
| 9546 | **/ |
| 9547 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 9548 | { |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9549 | struct i40e_pf *pf; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9550 | u8 enabled_tc; |
| 9551 | int ret; |
| 9552 | |
John Underwood | f534039 | 2016-02-18 09:19:24 -0800 | [diff] [blame] | 9553 | if (!vsi) |
| 9554 | return NULL; |
| 9555 | |
| 9556 | pf = vsi->back; |
| 9557 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9558 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9559 | i40e_vsi_clear_rings(vsi); |
| 9560 | |
| 9561 | i40e_vsi_free_arrays(vsi, false); |
| 9562 | i40e_set_num_rings_in_vsi(vsi); |
| 9563 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 9564 | if (ret) |
| 9565 | goto err_vsi; |
| 9566 | |
| 9567 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 9568 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9569 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9570 | "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] | 9571 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9572 | goto err_vsi; |
| 9573 | } |
| 9574 | vsi->base_queue = ret; |
| 9575 | |
| 9576 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 9577 | * layout configurations. |
| 9578 | */ |
| 9579 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9580 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9581 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9582 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 9583 | |
| 9584 | /* assign it some queues */ |
| 9585 | ret = i40e_alloc_rings(vsi); |
| 9586 | if (ret) |
| 9587 | goto err_rings; |
| 9588 | |
| 9589 | /* map all of the rings to the q_vectors */ |
| 9590 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9591 | return vsi; |
| 9592 | |
| 9593 | err_rings: |
| 9594 | i40e_vsi_free_q_vectors(vsi); |
| 9595 | if (vsi->netdev_registered) { |
| 9596 | vsi->netdev_registered = false; |
| 9597 | unregister_netdev(vsi->netdev); |
| 9598 | free_netdev(vsi->netdev); |
| 9599 | vsi->netdev = NULL; |
| 9600 | } |
| 9601 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9602 | err_vsi: |
| 9603 | i40e_vsi_clear(vsi); |
| 9604 | return NULL; |
| 9605 | } |
| 9606 | |
| 9607 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9608 | * i40e_vsi_setup - Set up a VSI by a given type |
| 9609 | * @pf: board private structure |
| 9610 | * @type: VSI type |
| 9611 | * @uplink_seid: the switch element to link to |
| 9612 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 9613 | * |
| 9614 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 9615 | * to the identified VEB. |
| 9616 | * |
| 9617 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 9618 | * success, otherwise returns NULL on failure. |
| 9619 | **/ |
| 9620 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 9621 | u16 uplink_seid, u32 param1) |
| 9622 | { |
| 9623 | struct i40e_vsi *vsi = NULL; |
| 9624 | struct i40e_veb *veb = NULL; |
| 9625 | int ret, i; |
| 9626 | int v_idx; |
| 9627 | |
| 9628 | /* The requested uplink_seid must be either |
| 9629 | * - the PF's port seid |
| 9630 | * no VEB is needed because this is the PF |
| 9631 | * or this is a Flow Director special case VSI |
| 9632 | * - seid of an existing VEB |
| 9633 | * - seid of a VSI that owns an existing VEB |
| 9634 | * - seid of a VSI that doesn't own a VEB |
| 9635 | * a new VEB is created and the VSI becomes the owner |
| 9636 | * - seid of the PF VSI, which is what creates the first VEB |
| 9637 | * this is a special case of the previous |
| 9638 | * |
| 9639 | * Find which uplink_seid we were given and create a new VEB if needed |
| 9640 | */ |
| 9641 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9642 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 9643 | veb = pf->veb[i]; |
| 9644 | break; |
| 9645 | } |
| 9646 | } |
| 9647 | |
| 9648 | if (!veb && uplink_seid != pf->mac_seid) { |
| 9649 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9650 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9651 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 9652 | vsi = pf->vsi[i]; |
| 9653 | break; |
| 9654 | } |
| 9655 | } |
| 9656 | if (!vsi) { |
| 9657 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 9658 | uplink_seid); |
| 9659 | return NULL; |
| 9660 | } |
| 9661 | |
| 9662 | if (vsi->uplink_seid == pf->mac_seid) |
| 9663 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 9664 | vsi->tc_config.enabled_tc); |
| 9665 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 9666 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9667 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9668 | if (veb) { |
| 9669 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 9670 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 9671 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9672 | return NULL; |
| 9673 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 9674 | /* We come up by default in VEPA mode if SRIOV is not |
| 9675 | * already enabled, in which case we can't force VEPA |
| 9676 | * mode. |
| 9677 | */ |
| 9678 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 9679 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 9680 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9681 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9682 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9683 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9684 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9685 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9686 | veb = pf->veb[i]; |
| 9687 | } |
| 9688 | if (!veb) { |
| 9689 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 9690 | return NULL; |
| 9691 | } |
| 9692 | |
| 9693 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 9694 | uplink_seid = veb->seid; |
| 9695 | } |
| 9696 | |
| 9697 | /* get vsi sw struct */ |
| 9698 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 9699 | if (v_idx < 0) |
| 9700 | goto err_alloc; |
| 9701 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9702 | if (!vsi) |
| 9703 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9704 | vsi->type = type; |
| 9705 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 9706 | |
| 9707 | if (type == I40E_VSI_MAIN) |
| 9708 | pf->lan_vsi = v_idx; |
| 9709 | else if (type == I40E_VSI_SRIOV) |
| 9710 | vsi->vf_id = param1; |
| 9711 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9712 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 9713 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9714 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9715 | dev_info(&pf->pdev->dev, |
| 9716 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 9717 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9718 | goto err_vsi; |
| 9719 | } |
| 9720 | vsi->base_queue = ret; |
| 9721 | |
| 9722 | /* get a VSI from the hardware */ |
| 9723 | vsi->uplink_seid = uplink_seid; |
| 9724 | ret = i40e_add_vsi(vsi); |
| 9725 | if (ret) |
| 9726 | goto err_vsi; |
| 9727 | |
| 9728 | switch (vsi->type) { |
| 9729 | /* setup the netdev if needed */ |
| 9730 | case I40E_VSI_MAIN: |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9731 | /* Apply relevant filters if a platform-specific mac |
| 9732 | * address was selected. |
| 9733 | */ |
| 9734 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 9735 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 9736 | if (ret) { |
| 9737 | dev_warn(&pf->pdev->dev, |
| 9738 | "could not set up macaddr; err %d\n", |
| 9739 | ret); |
| 9740 | } |
| 9741 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9742 | case I40E_VSI_VMDQ2: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9743 | case I40E_VSI_FCOE: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9744 | ret = i40e_config_netdev(vsi); |
| 9745 | if (ret) |
| 9746 | goto err_netdev; |
| 9747 | ret = register_netdev(vsi->netdev); |
| 9748 | if (ret) |
| 9749 | goto err_netdev; |
| 9750 | vsi->netdev_registered = true; |
| 9751 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9752 | #ifdef CONFIG_I40E_DCB |
| 9753 | /* Setup DCB netlink interface */ |
| 9754 | i40e_dcbnl_setup(vsi); |
| 9755 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9756 | /* fall through */ |
| 9757 | |
| 9758 | case I40E_VSI_FDIR: |
| 9759 | /* set up vectors and rings if needed */ |
| 9760 | ret = i40e_vsi_setup_vectors(vsi); |
| 9761 | if (ret) |
| 9762 | goto err_msix; |
| 9763 | |
| 9764 | ret = i40e_alloc_rings(vsi); |
| 9765 | if (ret) |
| 9766 | goto err_rings; |
| 9767 | |
| 9768 | /* map all of the rings to the q_vectors */ |
| 9769 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9770 | |
| 9771 | i40e_vsi_reset_stats(vsi); |
| 9772 | break; |
| 9773 | |
| 9774 | default: |
| 9775 | /* no netdev or rings for the other VSI types */ |
| 9776 | break; |
| 9777 | } |
| 9778 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9779 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
| 9780 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 9781 | ret = i40e_vsi_config_rss(vsi); |
| 9782 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9783 | return vsi; |
| 9784 | |
| 9785 | err_rings: |
| 9786 | i40e_vsi_free_q_vectors(vsi); |
| 9787 | err_msix: |
| 9788 | if (vsi->netdev_registered) { |
| 9789 | vsi->netdev_registered = false; |
| 9790 | unregister_netdev(vsi->netdev); |
| 9791 | free_netdev(vsi->netdev); |
| 9792 | vsi->netdev = NULL; |
| 9793 | } |
| 9794 | err_netdev: |
| 9795 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9796 | err_vsi: |
| 9797 | i40e_vsi_clear(vsi); |
| 9798 | err_alloc: |
| 9799 | return NULL; |
| 9800 | } |
| 9801 | |
| 9802 | /** |
| 9803 | * i40e_veb_get_bw_info - Query VEB BW information |
| 9804 | * @veb: the veb to query |
| 9805 | * |
| 9806 | * Query the Tx scheduler BW configuration data for given VEB |
| 9807 | **/ |
| 9808 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 9809 | { |
| 9810 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 9811 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 9812 | struct i40e_pf *pf = veb->pf; |
| 9813 | struct i40e_hw *hw = &pf->hw; |
| 9814 | u32 tc_bw_max; |
| 9815 | int ret = 0; |
| 9816 | int i; |
| 9817 | |
| 9818 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 9819 | &bw_data, NULL); |
| 9820 | if (ret) { |
| 9821 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9822 | "query veb bw config failed, err %s aq_err %s\n", |
| 9823 | i40e_stat_str(&pf->hw, ret), |
| 9824 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9825 | goto out; |
| 9826 | } |
| 9827 | |
| 9828 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 9829 | &ets_data, NULL); |
| 9830 | if (ret) { |
| 9831 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9832 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 9833 | i40e_stat_str(&pf->hw, ret), |
| 9834 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9835 | goto out; |
| 9836 | } |
| 9837 | |
| 9838 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 9839 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 9840 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 9841 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9842 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 9843 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 9844 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 9845 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 9846 | veb->bw_tc_limit_credits[i] = |
| 9847 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 9848 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 9849 | } |
| 9850 | |
| 9851 | out: |
| 9852 | return ret; |
| 9853 | } |
| 9854 | |
| 9855 | /** |
| 9856 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 9857 | * @pf: board private structure |
| 9858 | * |
| 9859 | * On error: returns error code (negative) |
| 9860 | * On success: returns vsi index in PF (positive) |
| 9861 | **/ |
| 9862 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 9863 | { |
| 9864 | int ret = -ENOENT; |
| 9865 | struct i40e_veb *veb; |
| 9866 | int i; |
| 9867 | |
| 9868 | /* Need to protect the allocation of switch elements at the PF level */ |
| 9869 | mutex_lock(&pf->switch_mutex); |
| 9870 | |
| 9871 | /* VEB list may be fragmented if VEB creation/destruction has |
| 9872 | * been happening. We can afford to do a quick scan to look |
| 9873 | * for any free slots in the list. |
| 9874 | * |
| 9875 | * find next empty veb slot, looping back around if necessary |
| 9876 | */ |
| 9877 | i = 0; |
| 9878 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 9879 | i++; |
| 9880 | if (i >= I40E_MAX_VEB) { |
| 9881 | ret = -ENOMEM; |
| 9882 | goto err_alloc_veb; /* out of VEB slots! */ |
| 9883 | } |
| 9884 | |
| 9885 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 9886 | if (!veb) { |
| 9887 | ret = -ENOMEM; |
| 9888 | goto err_alloc_veb; |
| 9889 | } |
| 9890 | veb->pf = pf; |
| 9891 | veb->idx = i; |
| 9892 | veb->enabled_tc = 1; |
| 9893 | |
| 9894 | pf->veb[i] = veb; |
| 9895 | ret = i; |
| 9896 | err_alloc_veb: |
| 9897 | mutex_unlock(&pf->switch_mutex); |
| 9898 | return ret; |
| 9899 | } |
| 9900 | |
| 9901 | /** |
| 9902 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 9903 | * @branch: where to start deleting |
| 9904 | * |
| 9905 | * This uses recursion to find the tips of the branch to be |
| 9906 | * removed, deleting until we get back to and can delete this VEB. |
| 9907 | **/ |
| 9908 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 9909 | { |
| 9910 | struct i40e_pf *pf = branch->pf; |
| 9911 | u16 branch_seid = branch->seid; |
| 9912 | u16 veb_idx = branch->idx; |
| 9913 | int i; |
| 9914 | |
| 9915 | /* release any VEBs on this VEB - RECURSION */ |
| 9916 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9917 | if (!pf->veb[i]) |
| 9918 | continue; |
| 9919 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 9920 | i40e_switch_branch_release(pf->veb[i]); |
| 9921 | } |
| 9922 | |
| 9923 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 9924 | * |
| 9925 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 9926 | * the VEB itself, so don't use (*branch) after this loop. |
| 9927 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9928 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9929 | if (!pf->vsi[i]) |
| 9930 | continue; |
| 9931 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 9932 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9933 | i40e_vsi_release(pf->vsi[i]); |
| 9934 | } |
| 9935 | } |
| 9936 | |
| 9937 | /* There's one corner case where the VEB might not have been |
| 9938 | * removed, so double check it here and remove it if needed. |
| 9939 | * This case happens if the veb was created from the debugfs |
| 9940 | * commands and no VSIs were added to it. |
| 9941 | */ |
| 9942 | if (pf->veb[veb_idx]) |
| 9943 | i40e_veb_release(pf->veb[veb_idx]); |
| 9944 | } |
| 9945 | |
| 9946 | /** |
| 9947 | * i40e_veb_clear - remove veb struct |
| 9948 | * @veb: the veb to remove |
| 9949 | **/ |
| 9950 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 9951 | { |
| 9952 | if (!veb) |
| 9953 | return; |
| 9954 | |
| 9955 | if (veb->pf) { |
| 9956 | struct i40e_pf *pf = veb->pf; |
| 9957 | |
| 9958 | mutex_lock(&pf->switch_mutex); |
| 9959 | if (pf->veb[veb->idx] == veb) |
| 9960 | pf->veb[veb->idx] = NULL; |
| 9961 | mutex_unlock(&pf->switch_mutex); |
| 9962 | } |
| 9963 | |
| 9964 | kfree(veb); |
| 9965 | } |
| 9966 | |
| 9967 | /** |
| 9968 | * i40e_veb_release - Delete a VEB and free its resources |
| 9969 | * @veb: the VEB being removed |
| 9970 | **/ |
| 9971 | void i40e_veb_release(struct i40e_veb *veb) |
| 9972 | { |
| 9973 | struct i40e_vsi *vsi = NULL; |
| 9974 | struct i40e_pf *pf; |
| 9975 | int i, n = 0; |
| 9976 | |
| 9977 | pf = veb->pf; |
| 9978 | |
| 9979 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9980 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9981 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 9982 | n++; |
| 9983 | vsi = pf->vsi[i]; |
| 9984 | } |
| 9985 | } |
| 9986 | if (n != 1) { |
| 9987 | dev_info(&pf->pdev->dev, |
| 9988 | "can't remove VEB %d with %d VSIs left\n", |
| 9989 | veb->seid, n); |
| 9990 | return; |
| 9991 | } |
| 9992 | |
| 9993 | /* move the remaining VSI to uplink veb */ |
| 9994 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 9995 | if (veb->uplink_seid) { |
| 9996 | vsi->uplink_seid = veb->uplink_seid; |
| 9997 | if (veb->uplink_seid == pf->mac_seid) |
| 9998 | vsi->veb_idx = I40E_NO_VEB; |
| 9999 | else |
| 10000 | vsi->veb_idx = veb->veb_idx; |
| 10001 | } else { |
| 10002 | /* floating VEB */ |
| 10003 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10004 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10005 | } |
| 10006 | |
| 10007 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10008 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10009 | } |
| 10010 | |
| 10011 | /** |
| 10012 | * i40e_add_veb - create the VEB in the switch |
| 10013 | * @veb: the VEB to be instantiated |
| 10014 | * @vsi: the controlling VSI |
| 10015 | **/ |
| 10016 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10017 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10018 | struct i40e_pf *pf = veb->pf; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10019 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10020 | int ret; |
| 10021 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10022 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10023 | veb->enabled_tc, false, |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 10024 | &veb->seid, enable_stats, NULL); |
Mitch Williams | 5bc1603 | 2016-05-16 10:26:43 -0700 | [diff] [blame] | 10025 | |
| 10026 | /* get a VEB from the hardware */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10027 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10028 | dev_info(&pf->pdev->dev, |
| 10029 | "couldn't add VEB, err %s aq_err %s\n", |
| 10030 | i40e_stat_str(&pf->hw, ret), |
| 10031 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10032 | return -EPERM; |
| 10033 | } |
| 10034 | |
| 10035 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10036 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10037 | &veb->stats_idx, NULL, NULL, NULL); |
| 10038 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10039 | dev_info(&pf->pdev->dev, |
| 10040 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10041 | i40e_stat_str(&pf->hw, ret), |
| 10042 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10043 | return -EPERM; |
| 10044 | } |
| 10045 | ret = i40e_veb_get_bw_info(veb); |
| 10046 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10047 | dev_info(&pf->pdev->dev, |
| 10048 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10049 | i40e_stat_str(&pf->hw, ret), |
| 10050 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10051 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10052 | return -ENOENT; |
| 10053 | } |
| 10054 | |
| 10055 | vsi->uplink_seid = veb->seid; |
| 10056 | vsi->veb_idx = veb->idx; |
| 10057 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10058 | |
| 10059 | return 0; |
| 10060 | } |
| 10061 | |
| 10062 | /** |
| 10063 | * i40e_veb_setup - Set up a VEB |
| 10064 | * @pf: board private structure |
| 10065 | * @flags: VEB setup flags |
| 10066 | * @uplink_seid: the switch element to link to |
| 10067 | * @vsi_seid: the initial VSI seid |
| 10068 | * @enabled_tc: Enabled TC bit-map |
| 10069 | * |
| 10070 | * This allocates the sw VEB structure and links it into the switch |
| 10071 | * It is possible and legal for this to be a duplicate of an already |
| 10072 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10073 | * to be zero, in order to create a floating VEB. |
| 10074 | * |
| 10075 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10076 | * success, otherwise returns NULL on failure. |
| 10077 | **/ |
| 10078 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10079 | u16 uplink_seid, u16 vsi_seid, |
| 10080 | u8 enabled_tc) |
| 10081 | { |
| 10082 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10083 | int vsi_idx, veb_idx; |
| 10084 | int ret; |
| 10085 | |
| 10086 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10087 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10088 | (uplink_seid + vsi_seid != 0)) { |
| 10089 | dev_info(&pf->pdev->dev, |
| 10090 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10091 | uplink_seid, vsi_seid); |
| 10092 | return NULL; |
| 10093 | } |
| 10094 | |
| 10095 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10096 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10097 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10098 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10099 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10100 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10101 | vsi_seid); |
| 10102 | return NULL; |
| 10103 | } |
| 10104 | |
| 10105 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10106 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10107 | if (pf->veb[veb_idx] && |
| 10108 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10109 | uplink_veb = pf->veb[veb_idx]; |
| 10110 | break; |
| 10111 | } |
| 10112 | } |
| 10113 | if (!uplink_veb) { |
| 10114 | dev_info(&pf->pdev->dev, |
| 10115 | "uplink seid %d not found\n", uplink_seid); |
| 10116 | return NULL; |
| 10117 | } |
| 10118 | } |
| 10119 | |
| 10120 | /* get veb sw struct */ |
| 10121 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10122 | if (veb_idx < 0) |
| 10123 | goto err_alloc; |
| 10124 | veb = pf->veb[veb_idx]; |
| 10125 | veb->flags = flags; |
| 10126 | veb->uplink_seid = uplink_seid; |
| 10127 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10128 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10129 | |
| 10130 | /* create the VEB in the switch */ |
| 10131 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10132 | if (ret) |
| 10133 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10134 | if (vsi_idx == pf->lan_vsi) |
| 10135 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10136 | |
| 10137 | return veb; |
| 10138 | |
| 10139 | err_veb: |
| 10140 | i40e_veb_clear(veb); |
| 10141 | err_alloc: |
| 10142 | return NULL; |
| 10143 | } |
| 10144 | |
| 10145 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10146 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10147 | * @pf: board private structure |
| 10148 | * @ele: element we are building info from |
| 10149 | * @num_reported: total number of elements |
| 10150 | * @printconfig: should we print the contents |
| 10151 | * |
| 10152 | * helper function to assist in extracting a few useful SEID values. |
| 10153 | **/ |
| 10154 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10155 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10156 | u16 num_reported, bool printconfig) |
| 10157 | { |
| 10158 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10159 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10160 | u8 element_type = ele->element_type; |
| 10161 | u16 seid = le16_to_cpu(ele->seid); |
| 10162 | |
| 10163 | if (printconfig) |
| 10164 | dev_info(&pf->pdev->dev, |
| 10165 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10166 | element_type, seid, uplink_seid, downlink_seid); |
| 10167 | |
| 10168 | switch (element_type) { |
| 10169 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10170 | pf->mac_seid = seid; |
| 10171 | break; |
| 10172 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10173 | /* Main VEB? */ |
| 10174 | if (uplink_seid != pf->mac_seid) |
| 10175 | break; |
| 10176 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10177 | int v; |
| 10178 | |
| 10179 | /* find existing or else empty VEB */ |
| 10180 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10181 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10182 | pf->lan_veb = v; |
| 10183 | break; |
| 10184 | } |
| 10185 | } |
| 10186 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10187 | v = i40e_veb_mem_alloc(pf); |
| 10188 | if (v < 0) |
| 10189 | break; |
| 10190 | pf->lan_veb = v; |
| 10191 | } |
| 10192 | } |
| 10193 | |
| 10194 | pf->veb[pf->lan_veb]->seid = seid; |
| 10195 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10196 | pf->veb[pf->lan_veb]->pf = pf; |
| 10197 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10198 | break; |
| 10199 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10200 | if (num_reported != 1) |
| 10201 | break; |
| 10202 | /* This is immediately after a reset so we can assume this is |
| 10203 | * the PF's VSI |
| 10204 | */ |
| 10205 | pf->mac_seid = uplink_seid; |
| 10206 | pf->pf_seid = downlink_seid; |
| 10207 | pf->main_vsi_seid = seid; |
| 10208 | if (printconfig) |
| 10209 | dev_info(&pf->pdev->dev, |
| 10210 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10211 | pf->pf_seid, pf->main_vsi_seid); |
| 10212 | break; |
| 10213 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10214 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10215 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10216 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10217 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10218 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10219 | /* ignore these for now */ |
| 10220 | break; |
| 10221 | default: |
| 10222 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10223 | element_type, seid); |
| 10224 | break; |
| 10225 | } |
| 10226 | } |
| 10227 | |
| 10228 | /** |
| 10229 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10230 | * @pf: board private structure |
| 10231 | * @printconfig: should we print the contents |
| 10232 | * |
| 10233 | * Get the current switch configuration from the device and |
| 10234 | * extract a few useful SEID values. |
| 10235 | **/ |
| 10236 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10237 | { |
| 10238 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10239 | u16 next_seid = 0; |
| 10240 | int ret = 0; |
| 10241 | u8 *aq_buf; |
| 10242 | int i; |
| 10243 | |
| 10244 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10245 | if (!aq_buf) |
| 10246 | return -ENOMEM; |
| 10247 | |
| 10248 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10249 | do { |
| 10250 | u16 num_reported, num_total; |
| 10251 | |
| 10252 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10253 | I40E_AQ_LARGE_BUF, |
| 10254 | &next_seid, NULL); |
| 10255 | if (ret) { |
| 10256 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10257 | "get switch config failed err %s aq_err %s\n", |
| 10258 | i40e_stat_str(&pf->hw, ret), |
| 10259 | i40e_aq_str(&pf->hw, |
| 10260 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10261 | kfree(aq_buf); |
| 10262 | return -ENOENT; |
| 10263 | } |
| 10264 | |
| 10265 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10266 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10267 | |
| 10268 | if (printconfig) |
| 10269 | dev_info(&pf->pdev->dev, |
| 10270 | "header: %d reported %d total\n", |
| 10271 | num_reported, num_total); |
| 10272 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10273 | for (i = 0; i < num_reported; i++) { |
| 10274 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10275 | &sw_config->element[i]; |
| 10276 | |
| 10277 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10278 | printconfig); |
| 10279 | } |
| 10280 | } while (next_seid != 0); |
| 10281 | |
| 10282 | kfree(aq_buf); |
| 10283 | return ret; |
| 10284 | } |
| 10285 | |
| 10286 | /** |
| 10287 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10288 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10289 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10290 | * |
| 10291 | * Returns 0 on success, negative value on failure |
| 10292 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10293 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10294 | { |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10295 | u16 flags = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10296 | int ret; |
| 10297 | |
| 10298 | /* find out what's out there already */ |
| 10299 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10300 | if (ret) { |
| 10301 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10302 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10303 | i40e_stat_str(&pf->hw, ret), |
| 10304 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10305 | return ret; |
| 10306 | } |
| 10307 | i40e_pf_reset_stats(pf); |
| 10308 | |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 10309 | /* set the switch config bit for the whole device to |
| 10310 | * support limited promisc or true promisc |
| 10311 | * when user requests promisc. The default is limited |
| 10312 | * promisc. |
| 10313 | */ |
| 10314 | |
| 10315 | if ((pf->hw.pf_id == 0) && |
| 10316 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) |
| 10317 | flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10318 | |
| 10319 | if (pf->hw.pf_id == 0) { |
| 10320 | u16 valid_flags; |
| 10321 | |
| 10322 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 10323 | ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, |
| 10324 | NULL); |
| 10325 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { |
| 10326 | dev_info(&pf->pdev->dev, |
| 10327 | "couldn't set switch config bits, err %s aq_err %s\n", |
| 10328 | i40e_stat_str(&pf->hw, ret), |
| 10329 | i40e_aq_str(&pf->hw, |
| 10330 | pf->hw.aq.asq_last_status)); |
| 10331 | /* not a fatal problem, just keep going */ |
| 10332 | } |
| 10333 | } |
| 10334 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10335 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10336 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10337 | struct i40e_vsi *vsi = NULL; |
| 10338 | u16 uplink_seid; |
| 10339 | |
| 10340 | /* Set up the PF VSI associated with the PF's main VSI |
| 10341 | * that is already in the HW switch |
| 10342 | */ |
| 10343 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10344 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10345 | else |
| 10346 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10347 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10348 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10349 | else if (reinit) |
| 10350 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10351 | if (!vsi) { |
| 10352 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10353 | i40e_fdir_teardown(pf); |
| 10354 | return -EAGAIN; |
| 10355 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10356 | } else { |
| 10357 | /* force a reset of TC and queue layout configurations */ |
| 10358 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10359 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10360 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10361 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10362 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10363 | } |
| 10364 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 10365 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10366 | i40e_fdir_sb_setup(pf); |
| 10367 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10368 | /* Setup static PF queue filter control settings */ |
| 10369 | ret = i40e_setup_pf_filter_control(pf); |
| 10370 | if (ret) { |
| 10371 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 10372 | ret); |
| 10373 | /* Failure here should not stop continuing other steps */ |
| 10374 | } |
| 10375 | |
| 10376 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 10377 | * the hash |
| 10378 | */ |
| 10379 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 10380 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10381 | |
| 10382 | /* fill in link information and enable LSE reporting */ |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 10383 | i40e_update_link_info(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10384 | i40e_link_event(pf); |
| 10385 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10386 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10387 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 10388 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10389 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10390 | i40e_ptp_init(pf); |
| 10391 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10392 | return ret; |
| 10393 | } |
| 10394 | |
| 10395 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10396 | * i40e_determine_queue_usage - Work out queue distribution |
| 10397 | * @pf: board private structure |
| 10398 | **/ |
| 10399 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 10400 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10401 | int queues_left; |
| 10402 | |
| 10403 | pf->num_lan_qps = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10404 | #ifdef I40E_FCOE |
| 10405 | pf->num_fcoe_qps = 0; |
| 10406 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10407 | |
| 10408 | /* Find the max queues to be put into basic use. We'll always be |
| 10409 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 10410 | * big RSS set. |
| 10411 | */ |
| 10412 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 10413 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10414 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10415 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10416 | /* one qp for PF, no queues for anything else */ |
| 10417 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10418 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10419 | |
| 10420 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10421 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10422 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10423 | #ifdef I40E_FCOE |
| 10424 | I40E_FLAG_FCOE_ENABLED | |
| 10425 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10426 | I40E_FLAG_FD_SB_ENABLED | |
| 10427 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10428 | I40E_FLAG_DCB_CAPABLE | |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 10429 | I40E_FLAG_DCB_ENABLED | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10430 | I40E_FLAG_SRIOV_ENABLED | |
| 10431 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10432 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 10433 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 10434 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10435 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10436 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10437 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10438 | queues_left -= pf->num_lan_qps; |
| 10439 | |
| 10440 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 10441 | I40E_FLAG_IWARP_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10442 | #ifdef I40E_FCOE |
| 10443 | I40E_FLAG_FCOE_ENABLED | |
| 10444 | #endif |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10445 | I40E_FLAG_FD_SB_ENABLED | |
| 10446 | I40E_FLAG_FD_ATR_ENABLED | |
| 10447 | I40E_FLAG_DCB_ENABLED | |
| 10448 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10449 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10450 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10451 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10452 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Dave Ertman | a036244 | 2016-08-29 17:38:26 -0700 | [diff] [blame] | 10453 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | |
| 10454 | I40E_FLAG_DCB_ENABLED); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10455 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 10456 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 10457 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 10458 | num_online_cpus()); |
| 10459 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 10460 | pf->hw.func_caps.num_tx_qp); |
| 10461 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10462 | queues_left -= pf->num_lan_qps; |
| 10463 | } |
| 10464 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10465 | #ifdef I40E_FCOE |
| 10466 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 10467 | if (I40E_DEFAULT_FCOE <= queues_left) { |
| 10468 | pf->num_fcoe_qps = I40E_DEFAULT_FCOE; |
| 10469 | } else if (I40E_MINIMUM_FCOE <= queues_left) { |
| 10470 | pf->num_fcoe_qps = I40E_MINIMUM_FCOE; |
| 10471 | } else { |
| 10472 | pf->num_fcoe_qps = 0; |
| 10473 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 10474 | dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n"); |
| 10475 | } |
| 10476 | |
| 10477 | queues_left -= pf->num_fcoe_qps; |
| 10478 | } |
| 10479 | |
| 10480 | #endif |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10481 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10482 | if (queues_left > 1) { |
| 10483 | queues_left -= 1; /* save 1 queue for FD */ |
| 10484 | } else { |
| 10485 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 10486 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 10487 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10488 | } |
| 10489 | |
| 10490 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10491 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10492 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 10493 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10494 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 10495 | } |
| 10496 | |
| 10497 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 10498 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 10499 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 10500 | (queues_left / pf->num_vmdq_qps)); |
| 10501 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 10502 | } |
| 10503 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10504 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10505 | dev_dbg(&pf->pdev->dev, |
| 10506 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 10507 | pf->hw.func_caps.num_tx_qp, |
| 10508 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10509 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 10510 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 10511 | queues_left); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10512 | #ifdef I40E_FCOE |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10513 | 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] | 10514 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10515 | } |
| 10516 | |
| 10517 | /** |
| 10518 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 10519 | * @pf: PF to be setup |
| 10520 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10521 | * 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] | 10522 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 10523 | * based filter sizes required for them. It also enables Flow director, |
| 10524 | * ethertype and macvlan type filter settings for the pf. |
| 10525 | * |
| 10526 | * Returns 0 on success, negative on failure |
| 10527 | **/ |
| 10528 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 10529 | { |
| 10530 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 10531 | |
| 10532 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 10533 | |
| 10534 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10535 | 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] | 10536 | settings->enable_fdir = true; |
| 10537 | |
| 10538 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 10539 | settings->enable_ethtype = true; |
| 10540 | settings->enable_macvlan = true; |
| 10541 | |
| 10542 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 10543 | return -ENOENT; |
| 10544 | |
| 10545 | return 0; |
| 10546 | } |
| 10547 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10548 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10549 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10550 | static void i40e_print_features(struct i40e_pf *pf) |
| 10551 | { |
| 10552 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10553 | char *buf; |
| 10554 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10555 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10556 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 10557 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10558 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10559 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10560 | 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] | 10561 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10562 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10563 | #endif |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10564 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10565 | pf->hw.func_caps.num_vsis, |
Jesse Brandeburg | 1a557afc | 2016-04-20 19:43:37 -0700 | [diff] [blame] | 10566 | pf->vsi[pf->lan_vsi]->num_queue_pairs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10567 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10568 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10569 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10570 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10571 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10572 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 10573 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10574 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10575 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10576 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10577 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10578 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10579 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10580 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10581 | #ifdef I40E_FCOE |
| 10582 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10583 | i += snprintf(&buf[i], REMAIN(i), " FCOE"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10584 | #endif |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10585 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10586 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10587 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10588 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10589 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10590 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 10591 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10592 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10593 | } |
| 10594 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10595 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10596 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
| 10597 | * |
| 10598 | * @pdev: PCI device information struct |
| 10599 | * @pf: board private structure |
| 10600 | * |
| 10601 | * Look up the MAC address in Open Firmware on systems that support it, |
| 10602 | * and use IDPROM on SPARC if no OF address is found. On return, the |
| 10603 | * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value |
| 10604 | * has been selected. |
| 10605 | **/ |
| 10606 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 10607 | { |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10608 | pf->flags &= ~I40E_FLAG_PF_MAC; |
Sowmini Varadhan | ba94272 | 2016-01-12 19:32:31 -0800 | [diff] [blame] | 10609 | if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10610 | pf->flags |= I40E_FLAG_PF_MAC; |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10611 | } |
| 10612 | |
| 10613 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10614 | * i40e_probe - Device initialization routine |
| 10615 | * @pdev: PCI device information struct |
| 10616 | * @ent: entry in i40e_pci_tbl |
| 10617 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10618 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 10619 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10620 | * and a hardware reset occur. |
| 10621 | * |
| 10622 | * Returns 0 on success, negative on failure |
| 10623 | **/ |
| 10624 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 10625 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 10626 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10627 | struct i40e_pf *pf; |
| 10628 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10629 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10630 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10631 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 10632 | int err; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10633 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10634 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10635 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10636 | |
| 10637 | err = pci_enable_device_mem(pdev); |
| 10638 | if (err) |
| 10639 | return err; |
| 10640 | |
| 10641 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10642 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10643 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 10644 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10645 | if (err) { |
| 10646 | dev_err(&pdev->dev, |
| 10647 | "DMA configuration failed: 0x%x\n", err); |
| 10648 | goto err_dma; |
| 10649 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10650 | } |
| 10651 | |
| 10652 | /* set up pci connections */ |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10653 | err = pci_request_mem_regions(pdev, i40e_driver_name); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10654 | if (err) { |
| 10655 | dev_info(&pdev->dev, |
| 10656 | "pci_request_selected_regions failed %d\n", err); |
| 10657 | goto err_pci_reg; |
| 10658 | } |
| 10659 | |
| 10660 | pci_enable_pcie_error_reporting(pdev); |
| 10661 | pci_set_master(pdev); |
| 10662 | |
| 10663 | /* Now that we have a PCI connection, we need to do the |
| 10664 | * low level device setup. This is primarily setting up |
| 10665 | * the Admin Queue structures and then querying for the |
| 10666 | * device's current profile information. |
| 10667 | */ |
| 10668 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 10669 | if (!pf) { |
| 10670 | err = -ENOMEM; |
| 10671 | goto err_pf_alloc; |
| 10672 | } |
| 10673 | pf->next_vsi = 0; |
| 10674 | pf->pdev = pdev; |
| 10675 | set_bit(__I40E_DOWN, &pf->state); |
| 10676 | |
| 10677 | hw = &pf->hw; |
| 10678 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10679 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10680 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 10681 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10682 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10683 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10684 | if (!hw->hw_addr) { |
| 10685 | err = -EIO; |
| 10686 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 10687 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10688 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10689 | goto err_ioremap; |
| 10690 | } |
| 10691 | hw->vendor_id = pdev->vendor; |
| 10692 | hw->device_id = pdev->device; |
| 10693 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 10694 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 10695 | hw->subsystem_device_id = pdev->subsystem_device; |
| 10696 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 10697 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10698 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10699 | |
Shannon Nelson | de03d2b | 2016-03-10 14:59:44 -0800 | [diff] [blame] | 10700 | /* set up the locks for the AQ, do this only once in probe |
| 10701 | * and destroy them only once in remove |
| 10702 | */ |
| 10703 | mutex_init(&hw->aq.asq_mutex); |
| 10704 | mutex_init(&hw->aq.arq_mutex); |
| 10705 | |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 10706 | pf->msg_enable = netif_msg_init(debug, |
| 10707 | NETIF_MSG_DRV | |
| 10708 | NETIF_MSG_PROBE | |
| 10709 | NETIF_MSG_LINK); |
| 10710 | if (debug < -1) |
| 10711 | pf->hw.debug_mask = debug; |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 10712 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10713 | /* do a special CORER for clearing PXE mode once at init */ |
| 10714 | if (hw->revision_id == 0 && |
| 10715 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 10716 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 10717 | i40e_flush(hw); |
| 10718 | msleep(200); |
| 10719 | pf->corer_count++; |
| 10720 | |
| 10721 | i40e_clear_pxe_mode(hw); |
| 10722 | } |
| 10723 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10724 | /* 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] | 10725 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10726 | err = i40e_pf_reset(hw); |
| 10727 | if (err) { |
| 10728 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 10729 | goto err_pf_reset; |
| 10730 | } |
| 10731 | pf->pfr_count++; |
| 10732 | |
| 10733 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 10734 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 10735 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10736 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10737 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10738 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 10739 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10740 | "%s-%s:misc", |
| 10741 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10742 | |
| 10743 | err = i40e_init_shared_code(hw); |
| 10744 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 10745 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 10746 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10747 | goto err_pf_reset; |
| 10748 | } |
| 10749 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10750 | /* set up a default setting for link flow control */ |
| 10751 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 10752 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10753 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 10754 | if (err) { |
| 10755 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 10756 | dev_info(&pdev->dev, |
| 10757 | "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"); |
| 10758 | else |
| 10759 | dev_info(&pdev->dev, |
| 10760 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 10761 | |
| 10762 | goto err_pf_reset; |
| 10763 | } |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10764 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10765 | /* provide nvm, fw, api versions */ |
| 10766 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 10767 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 10768 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 10769 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10770 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10771 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 10772 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10773 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10774 | "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"); |
| 10775 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 10776 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10777 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10778 | "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] | 10779 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 10780 | i40e_verify_eeprom(pf); |
| 10781 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 10782 | /* Rev 0 hardware was never productized */ |
| 10783 | if (hw->revision_id < 1) |
| 10784 | 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"); |
| 10785 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 10786 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10787 | err = i40e_get_capabilities(pf); |
| 10788 | if (err) |
| 10789 | goto err_adminq_setup; |
| 10790 | |
| 10791 | err = i40e_sw_init(pf); |
| 10792 | if (err) { |
| 10793 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 10794 | goto err_sw_init; |
| 10795 | } |
| 10796 | |
| 10797 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 10798 | hw->func_caps.num_rx_qp, |
| 10799 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 10800 | if (err) { |
| 10801 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 10802 | goto err_init_lan_hmc; |
| 10803 | } |
| 10804 | |
| 10805 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 10806 | if (err) { |
| 10807 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 10808 | err = -ENOENT; |
| 10809 | goto err_configure_lan_hmc; |
| 10810 | } |
| 10811 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10812 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 10813 | * Ignore error return codes because if it was already disabled via |
| 10814 | * hardware settings this will fail |
| 10815 | */ |
Neerav Parikh | f1bbad3 | 2016-01-13 16:51:39 -0800 | [diff] [blame] | 10816 | if (pf->flags & I40E_FLAG_STOP_FW_LLDP) { |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10817 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 10818 | i40e_aq_stop_lldp(hw, true, NULL); |
| 10819 | } |
| 10820 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10821 | i40e_get_mac_addr(hw, hw->mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10822 | /* allow a platform config to override the HW addr */ |
| 10823 | i40e_get_platform_mac_addr(pdev, pf); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 10824 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10825 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 10826 | err = -EIO; |
| 10827 | goto err_mac_addr; |
| 10828 | } |
| 10829 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 10830 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10831 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 10832 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 10833 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10834 | #ifdef I40E_FCOE |
| 10835 | err = i40e_get_san_mac_addr(hw, hw->mac.san_addr); |
| 10836 | if (err) |
| 10837 | dev_info(&pdev->dev, |
| 10838 | "(non-fatal) SAN MAC retrieval failed: %d\n", err); |
| 10839 | if (!is_valid_ether_addr(hw->mac.san_addr)) { |
| 10840 | dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n", |
| 10841 | hw->mac.san_addr); |
| 10842 | ether_addr_copy(hw->mac.san_addr, hw->mac.addr); |
| 10843 | } |
| 10844 | dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr); |
| 10845 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10846 | |
| 10847 | pci_set_drvdata(pdev, pf); |
| 10848 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10849 | #ifdef CONFIG_I40E_DCB |
| 10850 | err = i40e_init_pf_dcb(pf); |
| 10851 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 10852 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
David Ertman | c17ef43 | 2016-09-30 01:36:21 -0700 | [diff] [blame] | 10853 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED); |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 10854 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10855 | } |
| 10856 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10857 | |
| 10858 | /* set up periodic task facility */ |
| 10859 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 10860 | pf->service_timer_period = HZ; |
| 10861 | |
| 10862 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 10863 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 10864 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10865 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10866 | /* NVM bit on means WoL disabled for the port */ |
| 10867 | 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] | 10868 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10869 | pf->wol_en = false; |
| 10870 | else |
| 10871 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 10872 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 10873 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10874 | /* set up the main switch operations */ |
| 10875 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 10876 | err = i40e_init_interrupt_scheme(pf); |
| 10877 | if (err) |
| 10878 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10879 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10880 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 10881 | * to us; HW supports far more and we share the remaining pool with |
| 10882 | * the other PFs. We allocate space for more than the guarantee with |
| 10883 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10884 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10885 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 10886 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 10887 | else |
| 10888 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 10889 | |
| 10890 | /* 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] | 10891 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
| 10892 | GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 10893 | if (!pf->vsi) { |
| 10894 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10895 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 10896 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10897 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 10898 | #ifdef CONFIG_PCI_IOV |
| 10899 | /* prep for VF support */ |
| 10900 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10901 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 10902 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 10903 | if (pci_num_vf(pdev)) |
| 10904 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 10905 | } |
| 10906 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10907 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10908 | if (err) { |
| 10909 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 10910 | goto err_vsis; |
| 10911 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10912 | |
| 10913 | /* Make sure flow control is set according to current settings */ |
| 10914 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 10915 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 10916 | dev_dbg(&pf->pdev->dev, |
| 10917 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 10918 | i40e_stat_str(hw, err), |
| 10919 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 10920 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 10921 | dev_dbg(&pf->pdev->dev, |
| 10922 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 10923 | i40e_stat_str(hw, err), |
| 10924 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 10925 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 10926 | dev_dbg(&pf->pdev->dev, |
| 10927 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 10928 | i40e_stat_str(hw, err), |
| 10929 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 10930 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10931 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10932 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10933 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 10934 | i40e_vsi_open(pf->vsi[i]); |
| 10935 | break; |
| 10936 | } |
| 10937 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10938 | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 10939 | /* The driver only wants link up/down and module qualification |
| 10940 | * reports from firmware. Note the negative logic. |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 10941 | */ |
| 10942 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 10943 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
Shannon Nelson | 867a79e | 2016-03-18 12:18:15 -0700 | [diff] [blame] | 10944 | I40E_AQ_EVENT_MEDIA_NA | |
Shannon Nelson | 2f0aff4 | 2016-01-04 10:33:08 -0800 | [diff] [blame] | 10945 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 10946 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10947 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 10948 | i40e_stat_str(&pf->hw, err), |
| 10949 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 10950 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10951 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 10952 | * of TSO, so that we avoid the MDD being fired and causing |
| 10953 | * a reset in the case of small MSS+TSO. |
| 10954 | */ |
| 10955 | val = rd32(hw, I40E_REG_MSS); |
| 10956 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 10957 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 10958 | val |= I40E_64BYTE_MSS; |
| 10959 | wr32(hw, I40E_REG_MSS, val); |
| 10960 | } |
| 10961 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 10962 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 10963 | msleep(75); |
| 10964 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 10965 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10966 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 10967 | i40e_stat_str(&pf->hw, err), |
| 10968 | i40e_aq_str(&pf->hw, |
| 10969 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 10970 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10971 | /* The main driver is (mostly) up and happy. We need to set this state |
| 10972 | * before setting up the misc vector or we get a race and the vector |
| 10973 | * ends up disabled forever. |
| 10974 | */ |
| 10975 | clear_bit(__I40E_DOWN, &pf->state); |
| 10976 | |
| 10977 | /* In case of MSIX we are going to setup the misc vector right here |
| 10978 | * to handle admin queue events etc. In case of legacy and MSI |
| 10979 | * the misc functionality and queue processing is combined in |
| 10980 | * the same vector and that gets setup at open. |
| 10981 | */ |
| 10982 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 10983 | err = i40e_setup_misc_vector(pf); |
| 10984 | if (err) { |
| 10985 | dev_info(&pdev->dev, |
| 10986 | "setup of misc vector failed: %d\n", err); |
| 10987 | goto err_vsis; |
| 10988 | } |
| 10989 | } |
| 10990 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 10991 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10992 | /* prep for VF support */ |
| 10993 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 10994 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 10995 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10996 | /* disable link interrupts for VFs */ |
| 10997 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 10998 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 10999 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11000 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11001 | |
| 11002 | if (pci_num_vf(pdev)) { |
| 11003 | dev_info(&pdev->dev, |
| 11004 | "Active VFs found, allocating resources.\n"); |
| 11005 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11006 | if (err) |
| 11007 | dev_info(&pdev->dev, |
| 11008 | "Error %d allocating resources for existing VFs\n", |
| 11009 | err); |
| 11010 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11011 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11012 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11013 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11014 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
| 11015 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 11016 | pf->num_iwarp_msix, |
| 11017 | I40E_IWARP_IRQ_PILE_ID); |
| 11018 | if (pf->iwarp_base_vector < 0) { |
| 11019 | dev_info(&pdev->dev, |
| 11020 | "failed to get tracking for %d vectors for IWARP err=%d\n", |
| 11021 | pf->num_iwarp_msix, pf->iwarp_base_vector); |
| 11022 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; |
| 11023 | } |
| 11024 | } |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11025 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11026 | i40e_dbg_pf_init(pf); |
| 11027 | |
| 11028 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11029 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11030 | |
| 11031 | /* since everything's happy, start the service_task timer */ |
| 11032 | mod_timer(&pf->service_timer, |
| 11033 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11034 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11035 | /* add this PF to client device list and launch a client service task */ |
| 11036 | err = i40e_lan_add_device(pf); |
| 11037 | if (err) |
| 11038 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", |
| 11039 | err); |
| 11040 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11041 | #ifdef I40E_FCOE |
| 11042 | /* create FCoE interface */ |
| 11043 | i40e_fcoe_vsi_setup(pf); |
| 11044 | |
| 11045 | #endif |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11046 | #define PCI_SPEED_SIZE 8 |
| 11047 | #define PCI_WIDTH_SIZE 8 |
| 11048 | /* Devices on the IOSF bus do not have this information |
| 11049 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11050 | * checking them. |
| 11051 | */ |
| 11052 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { |
| 11053 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11054 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11055 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11056 | /* Get the negotiated link width and speed from PCI config |
| 11057 | * space |
| 11058 | */ |
| 11059 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11060 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11061 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11062 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11063 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11064 | switch (hw->bus.speed) { |
| 11065 | case i40e_bus_speed_8000: |
| 11066 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11067 | case i40e_bus_speed_5000: |
| 11068 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11069 | case i40e_bus_speed_2500: |
| 11070 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11071 | default: |
| 11072 | break; |
| 11073 | } |
| 11074 | switch (hw->bus.width) { |
| 11075 | case i40e_bus_width_pcie_x8: |
| 11076 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11077 | case i40e_bus_width_pcie_x4: |
| 11078 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11079 | case i40e_bus_width_pcie_x2: |
| 11080 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11081 | case i40e_bus_width_pcie_x1: |
| 11082 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11083 | default: |
| 11084 | break; |
| 11085 | } |
| 11086 | |
| 11087 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11088 | speed, width); |
| 11089 | |
| 11090 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11091 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11092 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11093 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11094 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11095 | } |
| 11096 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11097 | /* get the requested speeds from the fw */ |
| 11098 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11099 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11100 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11101 | i40e_stat_str(&pf->hw, err), |
| 11102 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11103 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11104 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11105 | /* get the supported phy types from the fw */ |
| 11106 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11107 | if (err) |
| 11108 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11109 | i40e_stat_str(&pf->hw, err), |
| 11110 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 11111 | pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type); |
| 11112 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11113 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11114 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11115 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11116 | * PF/VF VSIs. |
| 11117 | * The FW can still send Flow control frames if enabled. |
| 11118 | */ |
| 11119 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11120 | pf->main_vsi_seid); |
| 11121 | |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 11122 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
| 11123 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
| 11124 | pf->flags |= I40E_FLAG_HAVE_10GBASET_PHY; |
| 11125 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11126 | /* print a string summarizing features */ |
| 11127 | i40e_print_features(pf); |
| 11128 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11129 | return 0; |
| 11130 | |
| 11131 | /* Unwind what we've done if something failed in the setup */ |
| 11132 | err_vsis: |
| 11133 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11134 | i40e_clear_interrupt_scheme(pf); |
| 11135 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11136 | err_switch_setup: |
| 11137 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11138 | del_timer_sync(&pf->service_timer); |
| 11139 | err_mac_addr: |
| 11140 | err_configure_lan_hmc: |
| 11141 | (void)i40e_shutdown_lan_hmc(hw); |
| 11142 | err_init_lan_hmc: |
| 11143 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11144 | err_sw_init: |
| 11145 | err_adminq_setup: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11146 | err_pf_reset: |
| 11147 | iounmap(hw->hw_addr); |
| 11148 | err_ioremap: |
| 11149 | kfree(pf); |
| 11150 | err_pf_alloc: |
| 11151 | pci_disable_pcie_error_reporting(pdev); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11152 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11153 | err_pci_reg: |
| 11154 | err_dma: |
| 11155 | pci_disable_device(pdev); |
| 11156 | return err; |
| 11157 | } |
| 11158 | |
| 11159 | /** |
| 11160 | * i40e_remove - Device removal routine |
| 11161 | * @pdev: PCI device information struct |
| 11162 | * |
| 11163 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11164 | * that is should release a PCI device. This could be caused by a |
| 11165 | * Hot-Plug event, or because the driver is going to be removed from |
| 11166 | * memory. |
| 11167 | **/ |
| 11168 | static void i40e_remove(struct pci_dev *pdev) |
| 11169 | { |
| 11170 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11171 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11172 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11173 | int i; |
| 11174 | |
| 11175 | i40e_dbg_pf_exit(pf); |
| 11176 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11177 | i40e_ptp_stop(pf); |
| 11178 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11179 | /* Disable RSS in hw */ |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 11180 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
| 11181 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11182 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11183 | /* no more scheduling of any task */ |
Pandi Kumar Maharajan | a4618ec | 2016-02-18 09:19:25 -0800 | [diff] [blame] | 11184 | set_bit(__I40E_SUSPENDED, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11185 | set_bit(__I40E_DOWN, &pf->state); |
Shannon Nelson | c99abb4 | 2016-03-10 14:59:45 -0800 | [diff] [blame] | 11186 | if (pf->service_timer.data) |
| 11187 | del_timer_sync(&pf->service_timer); |
| 11188 | if (pf->service_task.func) |
| 11189 | cancel_work_sync(&pf->service_task); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11190 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11191 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11192 | i40e_free_vfs(pf); |
| 11193 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11194 | } |
| 11195 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11196 | i40e_fdir_teardown(pf); |
| 11197 | |
| 11198 | /* If there is a switch structure or any orphans, remove them. |
| 11199 | * This will leave only the PF's VSI remaining. |
| 11200 | */ |
| 11201 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11202 | if (!pf->veb[i]) |
| 11203 | continue; |
| 11204 | |
| 11205 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11206 | pf->veb[i]->uplink_seid == 0) |
| 11207 | i40e_switch_branch_release(pf->veb[i]); |
| 11208 | } |
| 11209 | |
| 11210 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11211 | * adminq and hmc. |
| 11212 | */ |
| 11213 | if (pf->vsi[pf->lan_vsi]) |
| 11214 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11215 | |
Anjali Singhai Jain | e3219ce | 2016-01-20 13:40:01 -0600 | [diff] [blame] | 11216 | /* remove attached clients */ |
| 11217 | ret_code = i40e_lan_del_device(pf); |
| 11218 | if (ret_code) { |
| 11219 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", |
| 11220 | ret_code); |
| 11221 | } |
| 11222 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11223 | /* shutdown and destroy the HMC */ |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11224 | if (hw->hmc.hmc_obj) { |
| 11225 | ret_code = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11226 | if (ret_code) |
| 11227 | dev_warn(&pdev->dev, |
| 11228 | "Failed to destroy the HMC resources: %d\n", |
| 11229 | ret_code); |
| 11230 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11231 | |
| 11232 | /* shutdown the adminq */ |
Henry Tieman | ac9c5c6 | 2016-09-06 18:05:11 -0700 | [diff] [blame] | 11233 | i40e_shutdown_adminq(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11234 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11235 | /* destroy the locks only once, here */ |
| 11236 | mutex_destroy(&hw->aq.arq_mutex); |
| 11237 | mutex_destroy(&hw->aq.asq_mutex); |
| 11238 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11239 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11240 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11241 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11242 | if (pf->vsi[i]) { |
| 11243 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11244 | i40e_vsi_clear(pf->vsi[i]); |
| 11245 | pf->vsi[i] = NULL; |
| 11246 | } |
| 11247 | } |
| 11248 | |
| 11249 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11250 | kfree(pf->veb[i]); |
| 11251 | pf->veb[i] = NULL; |
| 11252 | } |
| 11253 | |
| 11254 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11255 | kfree(pf->vsi); |
| 11256 | |
Jesse Brandeburg | f734dff | 2016-01-15 14:33:11 -0800 | [diff] [blame] | 11257 | iounmap(hw->hw_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11258 | kfree(pf); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 11259 | pci_release_mem_regions(pdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11260 | |
| 11261 | pci_disable_pcie_error_reporting(pdev); |
| 11262 | pci_disable_device(pdev); |
| 11263 | } |
| 11264 | |
| 11265 | /** |
| 11266 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11267 | * @pdev: PCI device information struct |
| 11268 | * |
| 11269 | * Called to warn that something happened and the error handling steps |
| 11270 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11271 | * remediation. |
| 11272 | **/ |
| 11273 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11274 | enum pci_channel_state error) |
| 11275 | { |
| 11276 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11277 | |
| 11278 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11279 | |
Guilherme G Piccoli | edfc23ee | 2016-10-03 00:31:12 -0700 | [diff] [blame] | 11280 | if (!pf) { |
| 11281 | dev_info(&pdev->dev, |
| 11282 | "Cannot recover - error happened during device probe\n"); |
| 11283 | return PCI_ERS_RESULT_DISCONNECT; |
| 11284 | } |
| 11285 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11286 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11287 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11288 | rtnl_lock(); |
| 11289 | i40e_prep_for_reset(pf); |
| 11290 | rtnl_unlock(); |
| 11291 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11292 | |
| 11293 | /* Request a slot reset */ |
| 11294 | return PCI_ERS_RESULT_NEED_RESET; |
| 11295 | } |
| 11296 | |
| 11297 | /** |
| 11298 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11299 | * @pdev: PCI device information struct |
| 11300 | * |
| 11301 | * Called to find if the driver can work with the device now that |
| 11302 | * the pci slot has been reset. If a basic connection seems good |
| 11303 | * (registers are readable and have sane content) then return a |
| 11304 | * happy little PCI_ERS_RESULT_xxx. |
| 11305 | **/ |
| 11306 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11307 | { |
| 11308 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11309 | pci_ers_result_t result; |
| 11310 | int err; |
| 11311 | u32 reg; |
| 11312 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11313 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11314 | if (pci_enable_device_mem(pdev)) { |
| 11315 | dev_info(&pdev->dev, |
| 11316 | "Cannot re-enable PCI device after reset.\n"); |
| 11317 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11318 | } else { |
| 11319 | pci_set_master(pdev); |
| 11320 | pci_restore_state(pdev); |
| 11321 | pci_save_state(pdev); |
| 11322 | pci_wake_from_d3(pdev, false); |
| 11323 | |
| 11324 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11325 | if (reg == 0) |
| 11326 | result = PCI_ERS_RESULT_RECOVERED; |
| 11327 | else |
| 11328 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11329 | } |
| 11330 | |
| 11331 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11332 | if (err) { |
| 11333 | dev_info(&pdev->dev, |
| 11334 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11335 | err); |
| 11336 | /* non-fatal, continue */ |
| 11337 | } |
| 11338 | |
| 11339 | return result; |
| 11340 | } |
| 11341 | |
| 11342 | /** |
| 11343 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11344 | * @pdev: PCI device information struct |
| 11345 | * |
| 11346 | * Called to allow the driver to bring things back up after PCI error |
| 11347 | * and/or reset recovery has finished. |
| 11348 | **/ |
| 11349 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11350 | { |
| 11351 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11352 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11353 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11354 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 11355 | return; |
| 11356 | |
| 11357 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11358 | i40e_handle_reset_warning(pf); |
Vasily Averin | 4c4935a | 2015-07-08 15:04:26 +0300 | [diff] [blame] | 11359 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11360 | } |
| 11361 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11362 | /** |
| 11363 | * i40e_shutdown - PCI callback for shutting down |
| 11364 | * @pdev: PCI device information struct |
| 11365 | **/ |
| 11366 | static void i40e_shutdown(struct pci_dev *pdev) |
| 11367 | { |
| 11368 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11369 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11370 | |
| 11371 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11372 | set_bit(__I40E_DOWN, &pf->state); |
| 11373 | rtnl_lock(); |
| 11374 | i40e_prep_for_reset(pf); |
| 11375 | rtnl_unlock(); |
| 11376 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11377 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11378 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11379 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11380 | del_timer_sync(&pf->service_timer); |
| 11381 | cancel_work_sync(&pf->service_task); |
| 11382 | i40e_fdir_teardown(pf); |
| 11383 | |
| 11384 | rtnl_lock(); |
| 11385 | i40e_prep_for_reset(pf); |
| 11386 | rtnl_unlock(); |
| 11387 | |
| 11388 | wr32(hw, I40E_PFPM_APM, |
| 11389 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11390 | wr32(hw, I40E_PFPM_WUFC, |
| 11391 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11392 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 11393 | i40e_clear_interrupt_scheme(pf); |
| 11394 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11395 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11396 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11397 | pci_set_power_state(pdev, PCI_D3hot); |
| 11398 | } |
| 11399 | } |
| 11400 | |
| 11401 | #ifdef CONFIG_PM |
| 11402 | /** |
| 11403 | * i40e_suspend - PCI callback for moving to D3 |
| 11404 | * @pdev: PCI device information struct |
| 11405 | **/ |
| 11406 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11407 | { |
| 11408 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11409 | struct i40e_hw *hw = &pf->hw; |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11410 | int retval = 0; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11411 | |
| 11412 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11413 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 11414 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11415 | rtnl_lock(); |
| 11416 | i40e_prep_for_reset(pf); |
| 11417 | rtnl_unlock(); |
| 11418 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11419 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11420 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11421 | |
Greg Rose | b33d3b7 | 2016-05-16 10:26:37 -0700 | [diff] [blame] | 11422 | i40e_stop_misc_vector(pf); |
| 11423 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11424 | retval = pci_save_state(pdev); |
| 11425 | if (retval) |
| 11426 | return retval; |
| 11427 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11428 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11429 | pci_set_power_state(pdev, PCI_D3hot); |
| 11430 | |
Greg Rose | 059ff69 | 2016-05-16 10:26:38 -0700 | [diff] [blame] | 11431 | return retval; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11432 | } |
| 11433 | |
| 11434 | /** |
| 11435 | * i40e_resume - PCI callback for waking up from D3 |
| 11436 | * @pdev: PCI device information struct |
| 11437 | **/ |
| 11438 | static int i40e_resume(struct pci_dev *pdev) |
| 11439 | { |
| 11440 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11441 | u32 err; |
| 11442 | |
| 11443 | pci_set_power_state(pdev, PCI_D0); |
| 11444 | pci_restore_state(pdev); |
| 11445 | /* pci_restore_state() clears dev->state_saves, so |
| 11446 | * call pci_save_state() again to restore it. |
| 11447 | */ |
| 11448 | pci_save_state(pdev); |
| 11449 | |
| 11450 | err = pci_enable_device_mem(pdev); |
| 11451 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11452 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11453 | return err; |
| 11454 | } |
| 11455 | pci_set_master(pdev); |
| 11456 | |
| 11457 | /* no wakeup events while running */ |
| 11458 | pci_wake_from_d3(pdev, false); |
| 11459 | |
| 11460 | /* handling the reset will rebuild the device state */ |
| 11461 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11462 | clear_bit(__I40E_DOWN, &pf->state); |
| 11463 | rtnl_lock(); |
| 11464 | i40e_reset_and_rebuild(pf, false); |
| 11465 | rtnl_unlock(); |
| 11466 | } |
| 11467 | |
| 11468 | return 0; |
| 11469 | } |
| 11470 | |
| 11471 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11472 | static const struct pci_error_handlers i40e_err_handler = { |
| 11473 | .error_detected = i40e_pci_error_detected, |
| 11474 | .slot_reset = i40e_pci_error_slot_reset, |
| 11475 | .resume = i40e_pci_error_resume, |
| 11476 | }; |
| 11477 | |
| 11478 | static struct pci_driver i40e_driver = { |
| 11479 | .name = i40e_driver_name, |
| 11480 | .id_table = i40e_pci_tbl, |
| 11481 | .probe = i40e_probe, |
| 11482 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11483 | #ifdef CONFIG_PM |
| 11484 | .suspend = i40e_suspend, |
| 11485 | .resume = i40e_resume, |
| 11486 | #endif |
| 11487 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11488 | .err_handler = &i40e_err_handler, |
| 11489 | .sriov_configure = i40e_pci_sriov_configure, |
| 11490 | }; |
| 11491 | |
| 11492 | /** |
| 11493 | * i40e_init_module - Driver registration routine |
| 11494 | * |
| 11495 | * i40e_init_module is the first routine called when the driver is |
| 11496 | * loaded. All it does is register with the PCI subsystem. |
| 11497 | **/ |
| 11498 | static int __init i40e_init_module(void) |
| 11499 | { |
| 11500 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 11501 | i40e_driver_string, i40e_driver_version_str); |
| 11502 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 11503 | |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11504 | /* we will see if single thread per module is enough for now, |
| 11505 | * it can't be any worse than using the system workqueue which |
| 11506 | * was already single threaded |
| 11507 | */ |
Jacob Keller | 6992a6c | 2016-08-04 11:37:01 -0700 | [diff] [blame] | 11508 | i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1, |
| 11509 | i40e_driver_name); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11510 | if (!i40e_wq) { |
| 11511 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); |
| 11512 | return -ENOMEM; |
| 11513 | } |
| 11514 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11515 | i40e_dbg_init(); |
| 11516 | return pci_register_driver(&i40e_driver); |
| 11517 | } |
| 11518 | module_init(i40e_init_module); |
| 11519 | |
| 11520 | /** |
| 11521 | * i40e_exit_module - Driver exit cleanup routine |
| 11522 | * |
| 11523 | * i40e_exit_module is called just before the driver is removed |
| 11524 | * from memory. |
| 11525 | **/ |
| 11526 | static void __exit i40e_exit_module(void) |
| 11527 | { |
| 11528 | pci_unregister_driver(&i40e_driver); |
Jesse Brandeburg | 2803b16 | 2015-12-22 14:25:08 -0800 | [diff] [blame] | 11529 | destroy_workqueue(i40e_wq); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11530 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11531 | } |
| 11532 | module_exit(i40e_exit_module); |